feat: add system message for flowchart assistance and improve message handling in chat API

This commit is contained in:
dayuan.jiang
2025-03-19 08:40:08 +00:00
parent 585c3bac1f
commit 51ce74400d
3 changed files with 23 additions and 4 deletions

View File

@@ -15,7 +15,24 @@ interface ToolContext {
}
export async function POST(req: Request) {
const { messages } = await req.json();
let { messages } = await req.json();
const systemMessage = `
You are a helpful assistant that can create, edit, and display flowcharts using draw.io.
You can use the following tools:
- display_flow_chart: Display a flowchart on draw.io.
- fetch_flow_chart: Get the current flowchart XML from draw.io.
You can use the tools to create and manipulate flowcharts.
You can also answer questions and provide explanations.
`;
if (messages.length === 1) {
messages = [
{
"role": "system",
"content": systemMessage,
},
...messages,
];
}
const response = streamText({
model: google("gemini-2.0-flash"),
messages,