Skip to content

Commit 29f88f3

Browse files
authored
Merge pull request #20 from appwrite/feat-custom-system-prompt
feat: custom system prompt
2 parents ceed9ba + 9b1323f commit 29f88f3

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/main.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,20 @@ let retriever = null;
2020

2121
const port = 3003;
2222

23-
const template = (
24-
prompt
25-
) => `You are an AI chat bot with information about Appwrite documentation. You need to help developers answer Appwrite related questions only. You will be given an input and you need to respond with the appropriate answer, using information confirmed with Appwrite documentation and reference pages. If applicable, show code examples. Code examples should use the Node and Web Appwrite SDKs unless otherwise specified.
26-
${prompt}`;
23+
const DEFAULT_SYSTEM_PROMPT = "You are an AI chat bot with information about Appwrite documentation. You need to help developers answer Appwrite related questions only. You will be given an input and you need to respond with the appropriate answer, using information confirmed with Appwrite documentation and reference pages. If applicable, show code examples. Code examples should use the Node and Web Appwrite SDKs unless otherwise specified.";
2724

2825
app.post("/", async (req, res) => {
2926
if (!retriever) {
3027
res.status(500).send("Search index not initialized");
3128
return;
3229
}
30+
3331
// raw to text
3432
const decoder = new TextDecoder();
3533
const text = decoder.decode(req.body);
36-
const { prompt } = JSON.parse(text);
37-
const templated = template(prompt);
34+
35+
let { prompt, systemPrompt } = JSON.parse(text);
36+
const templated = `${systemPrompt ?? DEFAULT_SYSTEM_PROMPT}\n\n${prompt}`
3837

3938
const relevantDocuments = await retriever.getRelevantDocuments(prompt);
4039

0 commit comments

Comments
 (0)