Skip to content

Commit

Permalink
fix typing
Browse files Browse the repository at this point in the history
  • Loading branch information
ztjhz committed Nov 11, 2023
1 parent 914ab69 commit b25e5c1
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ShareGPTSubmitBodyInterface } from '@type/api';
import { ConfigInterface, MessageInterface } from '@type/chat';
import { ConfigInterface, MessageInterface, ModelOptions } from '@type/chat';
import { isAzureEndpoint } from '@utils/api';

export const getChatCompletion = async (
Expand All @@ -18,18 +18,20 @@ export const getChatCompletion = async (
if (isAzureEndpoint(endpoint) && apiKey) {
headers['api-key'] = apiKey;

const modelmapping = {
'gpt-3': 'gpt3',
const modelmapping: Partial<Record<ModelOptions, string>> = {
'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 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 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}`;

Expand Down Expand Up @@ -72,18 +74,20 @@ export const getChatCompletionStream = async (
if (isAzureEndpoint(endpoint) && apiKey) {
headers['api-key'] = apiKey;

const modelmapping = {
'gpt-3': 'gpt3',
const modelmapping: Partial<Record<ModelOptions, string>> = {
'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 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 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)) {
Expand All @@ -106,7 +110,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 +
Expand Down

0 comments on commit b25e5c1

Please sign in to comment.