diff --git a/www/app/Chat.tsx b/www/app/Chat.tsx index 093917a..5654708 100644 --- a/www/app/Chat.tsx +++ b/www/app/Chat.tsx @@ -30,11 +30,11 @@ const Sidebar = dynamic(() => import('@/components/sidebar'), { }); async function fetchStream( - type: 'thought' | 'response', + type: 'thought' | 'response' | 'honcho', message: string, conversationId: string, thought = '', - honchoContent = '' + honchoThought = '' ) { try { const response = await fetch(`/api/chat`, { @@ -47,7 +47,7 @@ async function fetchStream( message, conversationId, thought, - honchoContent, + honchoThought, }), }); @@ -66,9 +66,11 @@ async function fetchStream( throw new Error(`No response body for ${type} stream`); } - if (!(response.body instanceof ReadableStream)) { - throw new Error(`Response body is not a ReadableStream for ${type} stream`); - } + console.log(response) + + // if (!(response.body instanceof ReadableStream)) { + // throw new Error(`Response body is not a ReadableStream for ${type} stream`); + // } return response.body; } catch (error) { @@ -87,6 +89,10 @@ interface ChatProps { initialConversationId: string | null | undefined } +interface HonchoResponse { + content: string; +} + export default function Chat({ initialUserId, initialEmail, @@ -301,15 +307,21 @@ export default function Chat({ thoughtReader.releaseLock(); thoughtReader = null; + const honchoResponse = await fetchStream('honcho', message, conversationId!, thoughtText); + const honchoContent = await new Response(honchoResponse).json() as HonchoResponse; + + thoughtText += "\n\nHoncho Dialectic Response:\n\n" + honchoContent.content; + setThought(thoughtText); + await new Promise((resolve) => setTimeout(resolve, 5000)); - // Get response stream using the thought + // Get response stream using the thought and dialectic response const responseStream = await fetchStream( 'response', message, conversationId!, thoughtText, - '' + honchoContent.content ); if (!responseStream) throw new Error('Failed to get response stream'); diff --git a/www/app/api/chat/route.ts b/www/app/api/chat/route.ts index edc01d9..76c7b55 100644 --- a/www/app/api/chat/route.ts +++ b/www/app/api/chat/route.ts @@ -144,7 +144,7 @@ export async function POST(req: NextRequest) { const data = await req.json(); - const { type, message, conversationId, thought } = data; + const { type, message, conversationId, thought, honchoThought } = data; const honchoApp = await getHonchoApp(); const honchoUser = await getHonchoUser(user.id); @@ -166,24 +166,27 @@ export async function POST(req: NextRequest) { userId: honchoUser.id, sessionId: conversationId, }); - } else { + } else if (type === 'honcho') { + console.log("Dialectic Query"); const dialecticQuery = await honcho.apps.users.sessions.chat( honchoApp.id, honchoUser.id, conversationId, { queries: thought } ); - const honchoResponse = dialecticQuery.content; + + return NextResponse.json({ content: dialecticQuery.content }) + } else { // @ts-ignore - honchoPayload['honchoContent'] = honchoResponse; + honchoPayload['honchoContent'] = honchoThought; messages = await respondCall({ userInput: message, appId: honchoApp.id, userId: honchoUser.id, sessionId: conversationId, - honchoContent: honchoResponse, + honchoContent: honchoThought, }); }