From 074161024d1bbea51a2bcb1e1b2654ca74597aac Mon Sep 17 00:00:00 2001 From: Andrew Trokhymenko Date: Thu, 21 Nov 2024 23:31:41 -0500 Subject: [PATCH] merge with upstream --- app/lib/.server/llm/model.ts | 3 --- app/lib/.server/llm/stream-text.ts | 34 ++++++++++++++---------------- app/routes/api.chat.ts | 2 -- app/utils/constants.ts | 2 +- 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/app/lib/.server/llm/model.ts b/app/lib/.server/llm/model.ts index a6a560e..307c817 100644 --- a/app/lib/.server/llm/model.ts +++ b/app/lib/.server/llm/model.ts @@ -22,7 +22,6 @@ export function getAnthropicModel(apiKey: string, model: string) { } export function getOpenAILikeModel(baseURL: string, apiKey: string, model: string) { - // console.log('OpenAILike config:', { baseURL, hasApiKey: !!apiKey, model }); const openai = createOpenAI({ baseURL, apiKey, @@ -132,8 +131,6 @@ export function getModel(provider: string, model: string, env: Env, apiKeys?: Re apiKey = getAPIKey(env, provider, apiKeys); // Then assign baseURL = getBaseURL(env, provider); - // console.log('getModel inputs:', { provider, model, baseURL, hasApiKey: !!apiKey }); - switch (provider) { case 'Anthropic': return getAnthropicModel(apiKey, model); diff --git a/app/lib/.server/llm/stream-text.ts b/app/lib/.server/llm/stream-text.ts index c2e161d..965ec95 100644 --- a/app/lib/.server/llm/stream-text.ts +++ b/app/lib/.server/llm/stream-text.ts @@ -52,12 +52,9 @@ function extractPropertiesFromMessage(message: Message): { model: string; provid }) : textContent.replace(MODEL_REGEX, '').replace(PROVIDER_REGEX, ''); - // console.log('Model from message:', model); - // console.log('Found in MODEL_LIST:', MODEL_LIST.find((m) => m.name === model)); - // console.log('Current MODEL_LIST:', MODEL_LIST); - return { model, provider, content: cleanedContent }; } + export function streamText( messages: Messages, env: Env, @@ -79,20 +76,21 @@ export function streamText( return { ...message, content }; } + return message; + }); - const modelDetails = MODEL_LIST.find((m) => m.name === currentModel); + const modelDetails = MODEL_LIST.find((m) => m.name === currentModel); - const dynamicMaxTokens = - modelDetails && modelDetails.maxTokenAllowed - ? modelDetails.maxTokenAllowed - : MAX_TOKENS; + const dynamicMaxTokens = + modelDetails && modelDetails.maxTokenAllowed + ? modelDetails.maxTokenAllowed + : MAX_TOKENS; - return _streamText({ - model: getModel(currentProvider, currentModel, env, apiKeys), - system: getSystemPrompt(), - maxTokens: dynamicMaxTokens, - messages: convertToCoreMessages(processedMessages), - ...options, - }); - } -)} + return _streamText({ + ...options, + model: getModel(currentProvider, currentModel, env, apiKeys), + system: getSystemPrompt(), + maxTokens: dynamicMaxTokens, + messages: convertToCoreMessages(processedMessages), + }); +} diff --git a/app/routes/api.chat.ts b/app/routes/api.chat.ts index bc42fb2..789beb0 100644 --- a/app/routes/api.chat.ts +++ b/app/routes/api.chat.ts @@ -37,8 +37,6 @@ async function chatAction({ context, request }: ActionFunctionArgs) { model: string }>(); - // console.log('ChatAction:', JSON.stringify(messages)); - const cookieHeader = request.headers.get("Cookie"); // Parse the cookie's value (returns an object or null if no cookie exists) diff --git a/app/utils/constants.ts b/app/utils/constants.ts index f96dceb..d781353 100644 --- a/app/utils/constants.ts +++ b/app/utils/constants.ts @@ -32,7 +32,7 @@ const PROVIDER_LIST: ProviderInfo[] = [ name: 'OpenAILike', staticModels: [ { name: 'o1-mini', label: 'o1-mini', provider: 'OpenAILike' }, - { name: 'gpt-4o-mini', label: 'GPT-4o Mini', provider: 'OpenAI' }, + { name: 'gpt-4o-mini', label: 'GPT-4o Mini', provider: 'OpenAILike' }, ], getDynamicModels: getOpenAILikeModels },