diff --git a/src/api/api.ts b/src/api/api.ts index 0989207..20073cf 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -14,7 +14,24 @@ export const getChatCompletion = async ( ...customHeaders, }; if (apiKey) headers.Authorization = `Bearer ${apiKey}`; - if (isAzureEndpoint(endpoint) && apiKey) headers['api-key'] = apiKey; + + if (isAzureEndpoint(endpoint) && apiKey) { + headers['api-key'] = apiKey; + + const gpt3forAzure = 'gpt-35-turbo'; + const model = + config.model === 'gpt-3.5-turbo' ? gpt3forAzure : config.model; + const apiVersion = '2023-03-15-preview'; + + const path = `openai/deployments/${model}/chat/completions?api-version=${apiVersion}`; + + if (!endpoint.endsWith(path)) { + if (!endpoint.endsWith('/')) { + endpoint += '/'; + } + endpoint += path; + } + } const response = await fetch(endpoint, { method: 'POST', @@ -43,7 +60,24 @@ export const getChatCompletionStream = async ( ...customHeaders, }; if (apiKey) headers.Authorization = `Bearer ${apiKey}`; - if (isAzureEndpoint(endpoint) && apiKey) headers['api-key'] = apiKey; + + if (isAzureEndpoint(endpoint) && apiKey) { + headers['api-key'] = apiKey; + + const gpt3forAzure = 'gpt-35-turbo'; + const model = + config.model === 'gpt-3.5-turbo' ? gpt3forAzure : config.model; + const apiVersion = '2023-03-15-preview'; + + const path = `openai/deployments/${model}/chat/completions?api-version=${apiVersion}`; + + if (!endpoint.endsWith(path)) { + if (!endpoint.endsWith('/')) { + endpoint += '/'; + } + endpoint += path; + } + } const response = await fetch(endpoint, { method: 'POST',