Skip to content

Commit 563b63a

Browse files
committed
fix ai chat
1 parent 8d4af15 commit 563b63a

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

app/api/chat/route.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createOpenRouter } from '@openrouter/ai-sdk-provider';
2-
import { convertToModelMessages, streamText, tool, type UIMessage } from 'ai';
2+
import { streamText, tool, type UIMessage } from 'ai';
33
import { z } from 'zod';
44
import { liteClient } from 'algoliasearch/lite';
55

@@ -85,7 +85,16 @@ export async function POST(req: Request) {
8585
maxOutputTokens: 1024,
8686
messages: [
8787
{ role: 'system', content: `${systemPrompt}\n\n${contextBlock}` },
88-
...(await convertToModelMessages(messages)),
88+
...messages
89+
.filter((m) => m.role === 'user' || m.role === 'assistant')
90+
.map((m) => ({
91+
role: m.role as 'user' | 'assistant',
92+
content:
93+
m.parts
94+
?.filter((p: any) => p.type === 'text')
95+
.map((p: any) => p.text as string)
96+
.join('') ?? '',
97+
})),
8998
],
9099
});
91100

0 commit comments

Comments
 (0)