From 3ef1df40ece1752669ba77a454c2da3532193378 Mon Sep 17 00:00:00 2001 From: none Date: Mon, 2 Oct 2023 23:40:17 +0300 Subject: [PATCH 1/5] Add claude and claude instant --- src/components/ConfigMenu/ModelSelect.tsx | 2 ++ src/constants/chat.ts | 12 ++++++++++++ src/types/chat.ts | 4 +++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/components/ConfigMenu/ModelSelect.tsx b/src/components/ConfigMenu/ModelSelect.tsx index c7caae7e..fa53a937 100644 --- a/src/components/ConfigMenu/ModelSelect.tsx +++ b/src/components/ConfigMenu/ModelSelect.tsx @@ -44,6 +44,8 @@ export const ModelSelect = ({ case 'gpt-4-32k': case 'gpt-3.5-turbo': case 'gpt-3.5-turbo-16k': + case 'claude-2': + case 'claude-instant-1': break; } _setModel(m); diff --git a/src/constants/chat.ts b/src/constants/chat.ts index 9b3a4a8c..6a5c6176 100644 --- a/src/constants/chat.ts +++ b/src/constants/chat.ts @@ -22,6 +22,8 @@ export const modelOptions: ModelChoice[] = [ 'gpt-3.5-turbo-16k', 'gpt-4', 'gpt-4-32k', + 'claude-2', + 'claude-instant-1', // 'gpt-3.5-turbo-0301', // 'gpt-4-0314', // 'gpt-4-32k-0314', @@ -41,6 +43,8 @@ export const modelMaxToken = { 'gpt-4-32k': 32768, 'gpt-4-32k-0314': 32768, 'gpt-4-32k-0613': 32768, + 'claude-2': 100000, + 'claude-instant-1': 100000, }; export const modelCost = { @@ -88,6 +92,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; diff --git a/src/types/chat.ts b/src/types/chat.ts index 59557669..79aac048 100644 --- a/src/types/chat.ts +++ b/src/types/chat.ts @@ -54,7 +54,9 @@ export type ModelChoice = | 'gpt-4' | 'gpt-4-32k' | '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' From 1e015b81e61224ef28f2a470980386545c667af0 Mon Sep 17 00:00:00 2001 From: "Danil Yarantsev (Yardanico)" Date: Mon, 2 Oct 2023 23:49:05 +0300 Subject: [PATCH 2/5] Fix SSE parsing --- src/api/helper.ts | 37 ++++++------------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/src/api/helper.ts b/src/api/helper.ts index 80782d07..a54e80fd 100644 --- a/src/api/helper.ts +++ b/src/api/helper.ts @@ -1,17 +1,14 @@ -import { EventSourceData } from '@type/api'; +import { EventSourceData } from "@type/api"; 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; @@ -20,26 +17,4 @@ export const parseEventSource = ( } }); return result; -}; - -export const createMultipartRelatedBody = ( - metadata: object, - file: File, - boundary: string -): Blob => { - const encoder = new TextEncoder(); - - const metadataPart = encoder.encode( - `--${boundary}\r\nContent-Type: application/json; charset=UTF-8\r\n\r\n${JSON.stringify( - metadata - )}\r\n` - ); - const filePart = encoder.encode( - `--${boundary}\r\nContent-Type: ${file.type}\r\n\r\n` - ); - const endBoundary = encoder.encode(`\r\n--${boundary}--`); - - return new Blob([metadataPart, filePart, file, endBoundary], { - type: 'multipart/related; boundary=' + boundary, - }); -}; +}; \ No newline at end of file From 8fd9b14955bca2b4676d4d94fa183e78c04b0044 Mon Sep 17 00:00:00 2001 From: "Danil Yarantsev (Yardanico)" Date: Mon, 2 Oct 2023 23:50:45 +0300 Subject: [PATCH 3/5] oopsie --- src/api/helper.ts | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/api/helper.ts b/src/api/helper.ts index a54e80fd..5ce879a2 100644 --- a/src/api/helper.ts +++ b/src/api/helper.ts @@ -1,4 +1,4 @@ -import { EventSourceData } from "@type/api"; +import { EventSourceData } from '@type/api'; export const parseEventSource = ( data: string @@ -17,4 +17,26 @@ export const parseEventSource = ( } }); return result; -}; \ No newline at end of file +}; + +export const createMultipartRelatedBody = ( + metadata: object, + file: File, + boundary: string +): Blob => { + const encoder = new TextEncoder(); + + const metadataPart = encoder.encode( + `--${boundary}\r\nContent-Type: application/json; charset=UTF-8\r\n\r\n${JSON.stringify( + metadata + )}\r\n` + ); + const filePart = encoder.encode( + `--${boundary}\r\nContent-Type: ${file.type}\r\n\r\n` + ); + const endBoundary = encoder.encode(`\r\n--${boundary}--`); + + return new Blob([metadataPart, filePart, file, endBoundary], { + type: 'multipart/related; boundary=' + boundary, + }); +}; From c780deab23592020255ed532c3803586d8168c34 Mon Sep 17 00:00:00 2001 From: "Danil Yarantsev (Yardanico)" Date: Tue, 7 Nov 2023 02:48:22 +0300 Subject: [PATCH 4/5] Add gpt-4 turbo preview --- src/components/ConfigMenu/ModelSelect.tsx | 1 + src/constants/chat.ts | 6 ++++++ src/types/chat.ts | 1 + 3 files changed, 8 insertions(+) diff --git a/src/components/ConfigMenu/ModelSelect.tsx b/src/components/ConfigMenu/ModelSelect.tsx index fa53a937..9298dd0b 100644 --- a/src/components/ConfigMenu/ModelSelect.tsx +++ b/src/components/ConfigMenu/ModelSelect.tsx @@ -42,6 +42,7 @@ 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': diff --git a/src/constants/chat.ts b/src/constants/chat.ts index 6a5c6176..c451b544 100644 --- a/src/constants/chat.ts +++ b/src/constants/chat.ts @@ -20,6 +20,7 @@ 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', @@ -40,6 +41,7 @@ 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, @@ -80,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 }, diff --git a/src/types/chat.ts b/src/types/chat.ts index 79aac048..99db46f2 100644 --- a/src/types/chat.ts +++ b/src/types/chat.ts @@ -53,6 +53,7 @@ export interface Folder { export type ModelChoice = | 'gpt-4' | 'gpt-4-32k' + | 'gpt-4-1106-preview' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-16k' | 'claude-2' From b58f96a9bfc9ace4d11b388526381fe33e1c7058 Mon Sep 17 00:00:00 2001 From: "Danil Yarantsev (Yardanico)" Date: Wed, 29 Nov 2023 15:32:22 +0300 Subject: [PATCH 5/5] Add randomized user IDs to requests --- src/api/api.ts | 8 +++++++- src/types/chat.ts | 1 + src/utils/api.ts | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/api/api.ts b/src/api/api.ts index a0ed63a9..60751522 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -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, @@ -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, @@ -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, diff --git a/src/types/chat.ts b/src/types/chat.ts index 99db46f2..67901dd8 100644 --- a/src/types/chat.ts +++ b/src/types/chat.ts @@ -26,6 +26,7 @@ export interface ConfigInterface { presence_penalty: number; top_p: number; frequency_penalty: number; + user?: string; } export interface ChatHistoryInterface { diff --git a/src/utils/api.ts b/src/utils/api.ts index d66c22a4..fed9c208 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -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) + ); \ No newline at end of file