Skip to content

Commit

Permalink
fix: prompt enhancer [object] issue
Browse files Browse the repository at this point in the history
  • Loading branch information
xKevIsDev committed Oct 31, 2024
1 parent 808d751 commit d05fd7a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 7 additions & 2 deletions app/lib/hooks/usePromptEnhancer.ts
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -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,
}),
});

Expand Down
11 changes: 9 additions & 2 deletions app/routes/api.enhancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
},
});
Expand All @@ -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,
Expand Down

0 comments on commit d05fd7a

Please sign in to comment.