Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

claude + gpt4turbo #90

Merged
merged 5 commits into from Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { modelMaxToken } from '@constants/chat';
import countTokens from '@utils/messageUtils';
import { ShareGPTSubmitBodyInterface } from '@type/api';
import { ConfigInterface, MessageInterface } from '@type/chat';
import { isAzureEndpoint } from '@utils/api';
import { isAzureEndpoint, uuidv4 } from '@utils/api';

export const getChatCompletion = async (
endpoint: string,
Expand Down Expand Up @@ -47,6 +47,9 @@ export const getChatCompletion = async (
restConfig.model = 'gpt-3.5-turbo';
}

// todo: option in config
restConfig.user = uuidv4();

const response = await fetch(endpoint, {
method: 'POST',
headers,
Expand Down Expand Up @@ -98,6 +101,9 @@ export const getChatCompletionStream = async (

const { max_context, ...restConfig } = config;

// todo: option in config
restConfig.user = uuidv4();

const response = await fetch(endpoint, {
method: 'POST',
headers,
Expand Down
11 changes: 4 additions & 7 deletions src/api/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ export const parseEventSource = (
data: string
): '[DONE]' | EventSourceData[] => {
const result = data
.split('\n\n')
.filter(Boolean)
.map((chunk) => {
const jsonString = chunk
.split('\n')
.map((line) => line.replace(/^data: /, ''))
.join('');
if (jsonString === '[DONE]') return jsonString;
.filter(line => line.startsWith('data: ') || line === '[DONE]')
.map((line) => {
if (line === '[DONE]') return line;
const jsonString = line.replace(/^data: /, '');
try {
const json = JSON.parse(jsonString);
return json;
Expand Down
3 changes: 3 additions & 0 deletions src/components/ConfigMenu/ModelSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ export const ModelSelect = ({
switch (m) {
case 'gpt-4':
case 'gpt-4-32k':
case 'gpt-4-1106-preview':
case 'gpt-3.5-turbo':
case 'gpt-3.5-turbo-16k':
case 'claude-2':
case 'claude-instant-1':
break;
}
_setModel(m);
Expand Down
18 changes: 18 additions & 0 deletions src/constants/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ Respond using Markdown.`;
export const modelOptions: ModelChoice[] = [
'gpt-3.5-turbo',
'gpt-3.5-turbo-16k',
'gpt-4-1106-preview',
'gpt-4',
'gpt-4-32k',
'claude-2',
'claude-instant-1',
// 'gpt-3.5-turbo-0301',
// 'gpt-4-0314',
// 'gpt-4-32k-0314',
Expand All @@ -38,9 +41,12 @@ export const modelMaxToken = {
'gpt-4': 8192,
'gpt-4-0314': 8192,
'gpt-4-0613': 8192,
'gpt-4-1106-preview': 128000,
'gpt-4-32k': 32768,
'gpt-4-32k-0314': 32768,
'gpt-4-32k-0613': 32768,
'claude-2': 100000,
'claude-instant-1': 100000,
};

export const modelCost = {
Expand Down Expand Up @@ -76,6 +82,10 @@ export const modelCost = {
prompt: { price: 0.03, unit: 1000 },
completion: { price: 0.06, unit: 1000 },
},
'gpt-4-1106-preview': {
prompt: { price: 0.01, unit: 1000 },
completion: { price: 0.03, unit: 1000 }
},
'gpt-4-32k': {
prompt: { price: 0.06, unit: 1000 },
completion: { price: 0.12, unit: 1000 },
Expand All @@ -88,6 +98,14 @@ export const modelCost = {
prompt: { price: 0.06, unit: 1000 },
completion: { price: 0.12, unit: 1000 },
},
'claude-2': {
prompt: { price: 0.01102, unit: 1000 },
completion: { price: 0.03268, unit: 1000 },
},
'claude-instant-1': {
prompt: { price: 0.00163, unit: 1000 },
completion: { price: 0.00551, unit: 1000},
}
};

export const defaultUserMaxToken = 4000;
Expand Down
6 changes: 5 additions & 1 deletion src/types/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface ConfigInterface {
presence_penalty: number;
top_p: number;
frequency_penalty: number;
user?: string;
}

export interface ChatHistoryInterface {
Expand Down Expand Up @@ -53,8 +54,11 @@ export interface Folder {
export type ModelChoice =
| 'gpt-4'
| 'gpt-4-32k'
| 'gpt-4-1106-preview'
| 'gpt-3.5-turbo'
| 'gpt-3.5-turbo-16k';
| 'gpt-3.5-turbo-16k'
| 'claude-2'
| 'claude-instant-1';
// | 'gpt-3.5-turbo-0301';
// | 'gpt-4-0314'
// | 'gpt-4-32k-0314'
Expand Down
5 changes: 5 additions & 0 deletions src/utils/api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export const isAzureEndpoint = (endpoint: string) => {
return endpoint.includes('openai.azure.com');
};

export const uuidv4 = (): string =>
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c =>
((c === 'x' ? Math.random() * 16 : (Math.random() * 16 & 0x3 | 0x8)) | 0).toString(16)
);
Loading