Support Openai structure output api (#feat 1214) (#1217)

Co-authored-by: Kent Dong <ch3cho@qq.com>
This commit is contained in:
Yang Beining
2024-08-22 12:33:35 +08:00
committed by GitHub
parent bdbfad8a8a
commit 0e58042fa6
4 changed files with 16 additions and 0 deletions

View File

@@ -181,6 +181,9 @@ type ProviderConfig struct {
// @Title zh-CN 翻译服务需指定的目标语种
// @Description zh-CN 翻译结果的语种目前仅适用于DeepL服务。
targetLang string `required:"false" yaml:"targetLang" json:"targetLang"`
// @Title zh-CN 指定服务返回的响应需满足的JSON Schema
// @Description zh-CN 目前仅适用于OpenAI部分模型服务。参考https://platform.openai.com/docs/guides/structured-outputs
responseJsonSchema map[string]interface{} `required:"false" yaml:"responseJsonSchema" json:"responseJsonSchema"`
}
func (c *ProviderConfig) FromJson(json gjson.Result) {
@@ -229,6 +232,13 @@ func (c *ProviderConfig) FromJson(json gjson.Result) {
}
}
c.targetLang = json.Get("targetLang").String()
if schemaValue, ok := json.Get("responseJsonSchema").Value().(map[string]interface{}); ok {
c.responseJsonSchema = schemaValue
} else {
c.responseJsonSchema = nil
}
}
func (c *ProviderConfig) Validate() error {