diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json index 657e8a5cb..e7f06810e 100644 --- a/app/appearance/langs/en_US.json +++ b/app/appearance/langs/en_US.json @@ -282,6 +282,8 @@ "apiBaseURL": "API Base URL", "apiBaseURLTip": "The base address of the request, such as https://api.openai.com/v1", "apiUserAgentTip": "The user agent that initiated the request, that is, the HTTP header User-Agent", + "apiVersion": "API version", + "apiVersionTip": "Only required when using the Azure OpenAI service", "apiProvider": "API Provider", "apiProviderTip": "Use the selected API provider to implement AI-related functions", "skip": "Skip", diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json index 953e7fcc2..53ad69ee2 100644 --- a/app/appearance/langs/es_ES.json +++ b/app/appearance/langs/es_ES.json @@ -282,6 +282,8 @@ "apiBaseURL": "URL base de la API", "apiBaseURLTip": "La dirección base de la solicitud, como https://api.openai.com/v1", "apiUserAgentTip": "El agente de usuario que inició la solicitud, es decir, el encabezado HTTP User-Agent", + "apiVersion": "Versión API", + "apiVersionTip": "Sólo es necesario cuando se utiliza el servicio Azure OpenAI", "apiProvider": "API proveedor", "apiProviderTip": "Utilice el proveedor de API seleccionado para implementar funciones relacionadas con la IA", "skip": "barco", diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json index 4a029ab2f..91f01c1b8 100644 --- a/app/appearance/langs/fr_FR.json +++ b/app/appearance/langs/fr_FR.json @@ -282,6 +282,8 @@ "apiBaseURL": "URL de base de l'API", "apiBaseURLTip": "L'adresse de base de la requête, telle que https://api.openai.com/v1", "apiUserAgentTip": "L'agent utilisateur qui a initié la requête, c'est-à-dire l'en-tête HTTP User-Agent", + "apiVersion": "Version API", + "apiVersionTip": "Requis uniquement lors de l'utilisation du service Azure OpenAI", "apiProvider": "API du fournisseur", "apiProviderTip": "Utiliser le fournisseur d'API sélectionné pour implémenter les fonctions liées à l'IA", "skip": "Navire", diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json index d7af78be9..fb55a49a5 100644 --- a/app/appearance/langs/zh_CHT.json +++ b/app/appearance/langs/zh_CHT.json @@ -282,6 +282,8 @@ "apiBaseURL": "API 基礎地址", "apiBaseURLTip": "發起請求的基礎地址,如 https://api.openai.com/v1", "apiUserAgentTip": "發起請求的使用者代理,即 HTTP 標頭 User-Agent", + "apiVersion": "API 版本", + "apiVersionTip": "僅在使用 Azure OpenAI 服務時需要設定", "apiProvider": "API 提供商", "apiProviderTip": "選擇後將使用該提供商的 API 服務實現 AI 相關功能", "skip": "跳過", diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json index 6ed3e852f..f13448b10 100644 --- a/app/appearance/langs/zh_CN.json +++ b/app/appearance/langs/zh_CN.json @@ -281,6 +281,8 @@ "apiMaxTokensTip": "请求 API 时传入的 max_tokens 参数,用于控制生成的文本长度", "apiBaseURL": "API 基础地址", "apiBaseURLTip": "发起请求的基础地址,如 https://api.openai.com/v1", + "apiVersion": "API 版本", + "apiVersionTip": "仅在使用 Azure OpenAI 服务时需要设置", "apiUserAgentTip": "发起请求的用户代理,即 HTTP 标头 User-Agent", "apiProvider": "API 提供商", "apiProviderTip": "选择后将使用该提供商的 API 服务实现 AI 相关功能", diff --git a/app/src/config/ai.ts b/app/src/config/ai.ts index 8285a6842..322716751 100644 --- a/app/src/config/ai.ts +++ b/app/src/config/ai.ts @@ -53,6 +53,12 @@ export const ai = {
${window.siyuan.languages.apiBaseURLTip}
+
+ ${window.siyuan.languages.apiVersion} +
+ +
${window.siyuan.languages.apiVersionTip}
+
User-Agent
@@ -119,6 +125,14 @@ export const ai = {
+
+
+ ${window.siyuan.languages.apiVersion} +
${window.siyuan.languages.apiVersionTip}
+ + +
+
User-Agent @@ -146,6 +160,7 @@ export const ai = { openAI: { apiUserAgent: (ai.element.querySelector("#apiUserAgent") as HTMLInputElement).value, apiBaseURL: (ai.element.querySelector("#apiBaseURL") as HTMLInputElement).value, + apiVersion: (ai.element.querySelector("#apiVersion") as HTMLInputElement).value, apiKey: (ai.element.querySelector("#apiKey") as HTMLInputElement).value, apiModel: (ai.element.querySelector("#apiModel") as HTMLSelectElement).value, apiMaxTokens: parseInt((ai.element.querySelector("#apiMaxTokens") as HTMLInputElement).value), diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts index 2c4cbb435..1b78eed88 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -147,7 +147,7 @@ interface Window { } mermaid: { initialize(options: any): void, - render(id: string, text: string): { svg:string } + render(id: string, text: string): { svg: string } }; plantumlEncoder: { encode(options: string): string, @@ -727,6 +727,7 @@ interface IConfig { apiProvider: string // OpenAI, Azure apiUserAgent: string apiBaseURL: string + apiVersion: string apiKey: string apiModel: string apiMaxTokens: number diff --git a/kernel/conf/ai.go b/kernel/conf/ai.go index 0d5f8759a..a21e2227a 100644 --- a/kernel/conf/ai.go +++ b/kernel/conf/ai.go @@ -37,6 +37,7 @@ type OpenAI struct { APIBaseURL string `json:"apiBaseURL"` APIUserAgent string `json:"apiUserAgent"` APIProvider string `json:"apiProvider"` // OpenAI, Azure + APIVersion string `json:"apiVersion"` // Azure API version } func NewAI() *AI { diff --git a/kernel/model/ai.go b/kernel/model/ai.go index 5c5035839..be147199e 100644 --- a/kernel/model/ai.go +++ b/kernel/model/ai.go @@ -92,7 +92,7 @@ func chatGPTContinueWrite(msg string, contextMsgs []string, cloud bool) (ret str if cloud { gpt = &CloudGPT{} } else { - gpt = &OpenAIGPT{c: util.NewOpenAIClient(Conf.AI.OpenAI.APIKey, Conf.AI.OpenAI.APIProxy, Conf.AI.OpenAI.APIBaseURL, Conf.AI.OpenAI.APIUserAgent)} + gpt = &OpenAIGPT{c: util.NewOpenAIClient(Conf.AI.OpenAI.APIKey, Conf.AI.OpenAI.APIProxy, Conf.AI.OpenAI.APIBaseURL, Conf.AI.OpenAI.APIUserAgent, Conf.AI.OpenAI.APIVersion, Conf.AI.OpenAI.APIProvider)} } buf := &bytes.Buffer{} diff --git a/kernel/util/openai.go b/kernel/util/openai.go index e7c90f629..50e1b6e2f 100644 --- a/kernel/util/openai.go +++ b/kernel/util/openai.go @@ -75,8 +75,13 @@ func ChatGPT(msg string, contextMsgs []string, c *openai.Client, model string, m return } -func NewOpenAIClient(apiKey, apiProxy, apiBaseURL, apiUserAgent string) *openai.Client { +func NewOpenAIClient(apiKey, apiProxy, apiBaseURL, apiUserAgent, apiVersion, apiProvider string) *openai.Client { config := openai.DefaultConfig(apiKey) + if "Azure" == apiProvider { + config = openai.DefaultAzureConfig(apiKey, apiBaseURL) + config.APIVersion = apiVersion + } + transport := &http.Transport{} if "" != apiProxy { proxyUrl, err := url.Parse(apiProxy)