11import { ShareGPTSubmitBodyInterface } from '@type/api' ;
2- import { ConfigInterface , MessageInterface , ModelOptions } from '@type/chat' ;
2+ import {
3+ ConfigInterface ,
4+ ImageContentInterface ,
5+ MessageInterface ,
6+ ModelOptions ,
7+ } from '@type/chat' ;
38import { isAzureEndpoint } from '@utils/api' ;
49
510export const getChatCompletion = async (
611 endpoint : string ,
712 messages : MessageInterface [ ] ,
813 config : ConfigInterface ,
914 apiKey ?: string ,
10- customHeaders ?: Record < string , string >
15+ customHeaders ?: Record < string , string > ,
16+ apiVersionToUse ?: string
1117) => {
1218 const headers : HeadersInit = {
1319 'Content-Type' : 'application/json' ,
@@ -29,9 +35,10 @@ export const getChatCompletion = async (
2935
3036 // set api version to 2023-07-01-preview for gpt-4 and gpt-4-32k, otherwise use 2023-03-15-preview
3137 const apiVersion =
32- model === 'gpt-4' || model === 'gpt-4-32k'
38+ apiVersionToUse ??
39+ ( model === 'gpt-4' || model === 'gpt-4-32k'
3340 ? '2023-07-01-preview'
34- : '2023-03-15-preview' ;
41+ : '2023-03-15-preview' ) ;
3542
3643 const path = `openai/deployments/${ model } /chat/completions?api-version=${ apiVersion } ` ;
3744
@@ -42,6 +49,7 @@ export const getChatCompletion = async (
4249 endpoint += path ;
4350 }
4451 }
52+ endpoint = endpoint . trim ( ) ;
4553
4654 const response = await fetch ( endpoint , {
4755 method : 'POST' ,
@@ -63,7 +71,8 @@ export const getChatCompletionStream = async (
6371 messages : MessageInterface [ ] ,
6472 config : ConfigInterface ,
6573 apiKey ?: string ,
66- customHeaders ?: Record < string , string >
74+ customHeaders ?: Record < string , string > ,
75+ apiVersionToUse ?: string
6776) => {
6877 const headers : HeadersInit = {
6978 'Content-Type' : 'application/json' ,
@@ -83,9 +92,10 @@ export const getChatCompletionStream = async (
8392
8493 // set api version to 2023-07-01-preview for gpt-4 and gpt-4-32k, otherwise use 2023-03-15-preview
8594 const apiVersion =
86- model === 'gpt-4' || model === 'gpt-4-32k'
95+ apiVersionToUse ??
96+ ( model === 'gpt-4' || model === 'gpt-4-32k'
8797 ? '2023-07-01-preview'
88- : '2023-03-15-preview' ;
98+ : '2023-03-15-preview' ) ;
8999 const path = `openai/deployments/${ model } /chat/completions?api-version=${ apiVersion } ` ;
90100
91101 if ( ! endpoint . endsWith ( path ) ) {
@@ -95,7 +105,7 @@ export const getChatCompletionStream = async (
95105 endpoint += path ;
96106 }
97107 }
98-
108+ endpoint = endpoint . trim ( ) ;
99109 const response = await fetch ( endpoint , {
100110 method : 'POST' ,
101111 headers,
0 commit comments