diff --git a/src/api/api.ts b/src/api/api.ts index 68c308ffe..0fe9a6ccf 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -18,9 +18,18 @@ export const getChatCompletion = async ( if (isAzureEndpoint(endpoint) && apiKey) { headers['api-key'] = apiKey; - const model = config.model === 'gpt-3.5-turbo' ? 'gpt-35-turbo' : config.model === 'gpt-3.5-turbo-16k' ? 'gpt-35-turbo-16k' : config.model; + const modelmapping = { + 'gpt-3': 'gpt3', + 'gpt-3.5-turbo': 'gpt-35-turbo', + 'gpt-3.5-turbo-16k': 'gpt35-turbo-16k', + 'gpt-4': 'gpt4-4', + 'gpt-4-32k': 'gpt4-4-32k', + } + + const model = modelmapping[config.model] || config.model - const apiVersion = '2023-03-15-preview'; + // set api version to 2023-07-01-preview for gpt-4 and gpt-4-32k, otherwise use 2023-03-15-preview + const apiVersion = model === 'gpt4-4' || model === 'gpt4-4-32k' ? '2023-07-01-preview' : '2023-03-15-preview' const path = `openai/deployments/${model}/chat/completions?api-version=${apiVersion}`; @@ -63,10 +72,18 @@ export const getChatCompletionStream = async ( if (isAzureEndpoint(endpoint) && apiKey) { headers['api-key'] = apiKey; - const model = config.model === 'gpt-3.5-turbo' ? 'gpt-35-turbo' : config.model === 'gpt-3.5-turbo-16k' ? 'gpt-35-turbo-16k' : config.model; + const modelmapping = { + 'gpt-3': 'gpt3', + 'gpt-3.5-turbo': 'gpt-35-turbo', + 'gpt-3.5-turbo-16k': 'gpt35-turbo-16k', + 'gpt-4': 'gpt4-4', + 'gpt-4-32k': 'gpt4-4-32k', + } - const apiVersion = '2023-03-15-preview'; + const model = modelmapping[config.model] || config.model + // set api version to 2023-07-01-preview for gpt-4 and gpt-4-32k, otherwise use 2023-03-15-preview + const apiVersion = model === 'gpt4-4' || model === 'gpt4-4-32k' ? '2023-07-01-preview' : '2023-03-15-preview' const path = `openai/deployments/${model}/chat/completions?api-version=${apiVersion}`; if (!endpoint.endsWith(path)) { @@ -89,6 +106,7 @@ export const getChatCompletionStream = async ( }); if (response.status === 404 || response.status === 405) { const text = await response.text(); + if (text.includes('model_not_found')) { throw new Error( text + diff --git a/src/hooks/useSubmit.ts b/src/hooks/useSubmit.ts index 3240f4143..cd6efc5aa 100644 --- a/src/hooks/useSubmit.ts +++ b/src/hooks/useSubmit.ts @@ -122,7 +122,7 @@ const useSubmit = () => { if (typeof curr === 'string') { partial += curr; } else { - const content = curr.choices[0].delta.content; + const content = curr.choices[0]?.delta?.content ?? null; if (content) output += content; } return output;