Skip to content

Commit

Permalink
feat: Add Dialectic Response to Thought Panel
Browse files Browse the repository at this point in the history
  • Loading branch information
VVoruganti committed Dec 5, 2024
1 parent 78dae52 commit 0b31308
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
28 changes: 20 additions & 8 deletions www/app/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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`, {
Expand All @@ -47,7 +47,7 @@ async function fetchStream(
message,
conversationId,
thought,
honchoContent,
honchoThought,
}),
});

Expand All @@ -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) {
Expand All @@ -87,6 +89,10 @@ interface ChatProps {
initialConversationId: string | null | undefined
}

interface HonchoResponse {
content: string;
}

export default function Chat({
initialUserId,
initialEmail,
Expand Down Expand Up @@ -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');

Expand Down
13 changes: 8 additions & 5 deletions www/app/api/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
});
}

Expand Down

0 comments on commit 0b31308

Please sign in to comment.