diff --git a/app/lib/hooks/usePromptEnhancer.ts b/app/lib/hooks/usePromptEnhancer.ts index 83a573d0..d0e2a707 100644 --- a/app/lib/hooks/usePromptEnhancer.ts +++ b/app/lib/hooks/usePromptEnhancer.ts @@ -1,6 +1,7 @@ import { useState } from 'react'; import { createScopedLogger } from '~/utils/logger'; -import { providerStore } from '~/lib/stores/provider'; +import { providerStore } from '../stores/provider'; +import { useStore } from '@nanostores/react'; const logger = createScopedLogger('usePromptEnhancement'); @@ -13,15 +14,19 @@ export function usePromptEnhancer() { setPromptEnhanced(false); }; + const provider = useStore(providerStore); + const enhancePrompt = async (input: string, setInput: (value: string) => void) => { setEnhancingPrompt(true); setPromptEnhanced(false); + const providerValue = provider === 'anthropic' ? 'anthropic' : { type: 'together', model: provider.model }; + const response = await fetch('/api/enhancer', { method: 'POST', body: JSON.stringify({ message: input, - provider: providerStore.get(), + provider: providerValue, }), }); diff --git a/app/routes/api.enhancer.ts b/app/routes/api.enhancer.ts index ff9a91bd..08fce1a3 100644 --- a/app/routes/api.enhancer.ts +++ b/app/routes/api.enhancer.ts @@ -41,8 +41,15 @@ async function enhancerAction({ context, request }: ActionFunctionArgs) { .split('\n') .filter((line) => line !== '') .map(parseStreamPart) - .map((part) => part.value) + .map((part) => { + if (typeof part.value === 'string') { + return part.value; + } + // If it's an object, it's likely metadata we don't want to send to the client + return ''; + }) .join(''); + controller.enqueue(encoder.encode(processedChunk)); }, }); @@ -51,7 +58,7 @@ async function enhancerAction({ context, request }: ActionFunctionArgs) { return new StreamingTextResponse(transformedStream); } catch (error) { - console.log(error); + console.error("Error in enhancerAction:", error); throw new Response(null, { status: 500,