Don't try to resolve unknown tiktoken models

This commit is contained in:
Cohee 2023-09-15 19:31:17 +03:00
parent aa89a74901
commit eaca6ddaf0
2 changed files with 59 additions and 4 deletions

View File

@ -123,6 +123,32 @@ const j2_max_pres = 5.0;
const openrouter_website_model = 'OR_Website'; const openrouter_website_model = 'OR_Website';
const openai_max_stop_strings = 4; const openai_max_stop_strings = 4;
const textCompletionModels = [
"text-davinci-003",
"text-davinci-002",
"text-davinci-001",
"text-curie-001",
"text-babbage-001",
"text-ada-001",
"code-davinci-002",
"code-davinci-001",
"code-cushman-002",
"code-cushman-001",
"text-davinci-edit-001",
"code-davinci-edit-001",
"text-embedding-ada-002",
"text-similarity-davinci-001",
"text-similarity-curie-001",
"text-similarity-babbage-001",
"text-similarity-ada-001",
"text-search-davinci-doc-001",
"text-search-curie-doc-001",
"text-search-babbage-doc-001",
"text-search-ada-doc-001",
"code-search-babbage-code-001",
"code-search-ada-code-001",
];
let biasCache = undefined; let biasCache = undefined;
let model_list = []; let model_list = [];
@ -1123,7 +1149,7 @@ async function sendOpenAIRequest(type, openai_msgs_tosend, signal) {
const isOpenRouter = oai_settings.chat_completion_source == chat_completion_sources.OPENROUTER; const isOpenRouter = oai_settings.chat_completion_source == chat_completion_sources.OPENROUTER;
const isScale = oai_settings.chat_completion_source == chat_completion_sources.SCALE; const isScale = oai_settings.chat_completion_source == chat_completion_sources.SCALE;
const isAI21 = oai_settings.chat_completion_source == chat_completion_sources.AI21; const isAI21 = oai_settings.chat_completion_source == chat_completion_sources.AI21;
const isTextCompletion = oai_settings.chat_completion_source == chat_completion_sources.OPENAI && (oai_settings.openai_model.startsWith('text-') || oai_settings.openai_model.startsWith('code-')); const isTextCompletion = oai_settings.chat_completion_source == chat_completion_sources.OPENAI && textCompletionModels.includes(oai_settings.openai_model);
const isQuiet = type === 'quiet'; const isQuiet = type === 'quiet';
const stream = oai_settings.stream_openai && !isQuiet && !isScale && !isAI21; const stream = oai_settings.stream_openai && !isQuiet && !isScale && !isAI21;

View File

@ -235,6 +235,35 @@ function countClaudeTokens(tokenizer, messages) {
const tokenizersCache = {}; const tokenizersCache = {};
/**
* @type {import('@dqbd/tiktoken').TiktokenModel[]}
*/
const textCompletionModels = [
"text-davinci-003",
"text-davinci-002",
"text-davinci-001",
"text-curie-001",
"text-babbage-001",
"text-ada-001",
"code-davinci-002",
"code-davinci-001",
"code-cushman-002",
"code-cushman-001",
"text-davinci-edit-001",
"code-davinci-edit-001",
"text-embedding-ada-002",
"text-similarity-davinci-001",
"text-similarity-curie-001",
"text-similarity-babbage-001",
"text-similarity-ada-001",
"text-search-davinci-doc-001",
"text-search-curie-doc-001",
"text-search-babbage-doc-001",
"text-search-ada-doc-001",
"code-search-babbage-code-001",
"code-search-ada-code-001",
];
function getTokenizerModel(requestModel) { function getTokenizerModel(requestModel) {
if (requestModel.includes('claude')) { if (requestModel.includes('claude')) {
return 'claude'; return 'claude';
@ -252,7 +281,7 @@ function getTokenizerModel(requestModel) {
return 'gpt-3.5-turbo'; return 'gpt-3.5-turbo';
} }
if (requestModel.startsWith('text-') || requestModel.startsWith('code-')) { if (textCompletionModels.includes(requestModel)) {
return requestModel; return requestModel;
} }
@ -3389,7 +3418,7 @@ app.post("/generate_openai", jsonParser, function (request, response_generate_op
bodyParams['stop'] = request.body.stop; bodyParams['stop'] = request.body.stop;
} }
const isTextCompletion = Boolean(request.body.model && (request.body.model.startsWith('text-') || request.body.model.startsWith('code-'))); const isTextCompletion = Boolean(request.body.model && textCompletionModels.includes(request.body.model));
const textPrompt = isTextCompletion ? convertChatMLPrompt(request.body.messages) : ''; const textPrompt = isTextCompletion ? convertChatMLPrompt(request.body.messages) : '';
const endpointUrl = isTextCompletion ? `${api_url}/completions` : `${api_url}/chat/completions`; const endpointUrl = isTextCompletion ? `${api_url}/completions` : `${api_url}/chat/completions`;
@ -3418,7 +3447,7 @@ app.post("/generate_openai", jsonParser, function (request, response_generate_op
"frequency_penalty": request.body.frequency_penalty, "frequency_penalty": request.body.frequency_penalty,
"top_p": request.body.top_p, "top_p": request.body.top_p,
"top_k": request.body.top_k, "top_k": request.body.top_k,
"stop": request.body.stop, "stop": isTextCompletion === false ? request.body.stop : undefined,
"logit_bias": request.body.logit_bias, "logit_bias": request.body.logit_bias,
...bodyParams, ...bodyParams,
}), }),