From 0244f05c72dd374c5bf4d0dbd32a6e9e05bb01bd Mon Sep 17 00:00:00 2001 From: J Chris Anderson Date: Tue, 25 Mar 2025 11:59:33 -0700 Subject: [PATCH] refactor(api.chat): remove debug logs and unused MAX_TOKENS constant for cleaner code --- app/routes/api.chat.ts | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/app/routes/api.chat.ts b/app/routes/api.chat.ts index e61e338..b17f632 100644 --- a/app/routes/api.chat.ts +++ b/app/routes/api.chat.ts @@ -1,5 +1,5 @@ import { type ActionFunctionArgs } from '@remix-run/cloudflare'; -import { MAX_RESPONSE_SEGMENTS, MAX_TOKENS } from '~/lib/.server/llm/constants'; +import { MAX_RESPONSE_SEGMENTS } from '~/lib/.server/llm/constants'; import { CONTINUE_PROMPT } from '~/lib/.server/llm/prompts'; import { streamText, type Messages, type StreamingOptions } from '~/lib/.server/llm/stream-text'; import SwitchableStream from '~/lib/.server/llm/switchable-stream'; @@ -12,36 +12,23 @@ export async function action(args: ActionFunctionArgs) { async function chatAction({ context, request }: ActionFunctionArgs) { const { messages } = await request.json<{ messages: Messages }>(); - console.log('[DEBUG] api.chat - Original messages:', JSON.stringify(messages)); - // detect libraries mentioned in the chat history const detectedLibraries = detectLibrariesFromChatHistory(messages); - console.log('[DEBUG] api.chat - Detected libraries from history:', detectedLibraries); // if libraries are detected, enhance the latest user message with library documentation if (detectedLibraries.length > 0 && messages.length > 0) { const lastUserMessageIndex = messages.findIndex((msg, idx) => msg.role === 'user' && idx === messages.length - 1); - console.log('[DEBUG] api.chat - Last user message index:', lastUserMessageIndex); if (lastUserMessageIndex !== -1) { // enhance the user's last message with library documentation const lastUserMessage = messages[lastUserMessageIndex]; - console.log('[DEBUG] api.chat - Last user message before enhancement:', lastUserMessage.content); - const enhancedContent = enhancePromptWithLibraryDocumentation(lastUserMessage.content, detectedLibraries); - console.log( - '[DEBUG] api.chat - Enhanced content includes Fireproof?', - enhancedContent.includes('Fireproof'), - enhancedContent.includes(''), - ); // replace the content with enhanced content messages[lastUserMessageIndex] = { ...lastUserMessage, content: enhancedContent, }; - - console.log('[DEBUG] api.chat - Message after enhancement:', JSON.stringify(messages[lastUserMessageIndex])); } } @@ -59,10 +46,6 @@ async function chatAction({ context, request }: ActionFunctionArgs) { throw Error('Cannot continue message: Maximum segments reached'); } - const switchesLeft = MAX_RESPONSE_SEGMENTS - stream.switches; - - console.log(`Reached max token limit (${MAX_TOKENS}): Continuing message (${switchesLeft} switches left)`); - messages.push({ role: 'assistant', content }); messages.push({ role: 'user', content: CONTINUE_PROMPT }); @@ -83,8 +66,7 @@ async function chatAction({ context, request }: ActionFunctionArgs) { }, }); } catch (error) { - console.log(error); - + console.error('Chat API error:', error); throw new Response(null, { status: 500, statusText: 'Internal Server Error',