Unverified 提交 3a69bf4b authored 作者: Will Chen's avatar Will Chen 提交者: GitHub

Make messages clearer with codebase context (#8)

上级 b616598b
...@@ -148,24 +148,11 @@ export function registerChatStreamHandlers() { ...@@ -148,24 +148,11 @@ export function registerChatStreamHandlers() {
codebaseInfo.length / 4 codebaseInfo.length / 4
); );
// Append codebase information to the user's prompt if available
const userPrompt = codebaseInfo
? `${req.prompt}\n\nHere's the codebase:\n${codebaseInfo}`
: req.prompt;
// Prepare message history for the AI // Prepare message history for the AI
const messageHistory = updatedChat.messages.map((message) => ({ const messageHistory = updatedChat.messages.map((message) => ({
role: message.role as "user" | "assistant" | "system", role: message.role as "user" | "assistant" | "system",
content: message.content, content: message.content,
})); }));
// Remove the last user message (we'll replace it with our enhanced version)
if (
messageHistory.length > 0 &&
messageHistory[messageHistory.length - 1].role === "user"
) {
messageHistory.pop();
}
let systemPrompt = SYSTEM_PROMPT; let systemPrompt = SYSTEM_PROMPT;
if (readSettings().experiments?.enableSupabaseIntegration) { if (readSettings().experiments?.enableSupabaseIntegration) {
if (updatedChat.app?.supabaseProjectId) { if (updatedChat.app?.supabaseProjectId) {
...@@ -186,12 +173,15 @@ export function registerChatStreamHandlers() { ...@@ -186,12 +173,15 @@ export function registerChatStreamHandlers() {
model: modelClient, model: modelClient,
system: systemPrompt, system: systemPrompt,
messages: [ messages: [
...messageHistory,
// Add the enhanced user prompt
{ {
role: "user", role: "user",
content: userPrompt, content: "This is my codebase. " + codebaseInfo,
}, },
{
role: "assistant",
content: "OK, got it. I'm ready to help",
},
...messageHistory,
], ],
onError: (error) => { onError: (error) => {
logger.error("Error streaming text:", error); logger.error("Error streaming text:", error);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论