Skip to content

Commit

Permalink
Merge pull request #20 from appwrite/feat-custom-system-prompt
Browse files Browse the repository at this point in the history
feat: custom system prompt
  • Loading branch information
loks0n authored Dec 12, 2024
2 parents ceed9ba + 9b1323f commit 29f88f3
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,20 @@ let retriever = null;

const port = 3003;

const template = (
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.
${prompt}`;
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.";

app.post("/", async (req, res) => {
if (!retriever) {
res.status(500).send("Search index not initialized");
return;
}

// raw to text
const decoder = new TextDecoder();
const text = decoder.decode(req.body);
const { prompt } = JSON.parse(text);
const templated = template(prompt);

let { prompt, systemPrompt } = JSON.parse(text);
const templated = `${systemPrompt ?? DEFAULT_SYSTEM_PROMPT}\n\n${prompt}`

const relevantDocuments = await retriever.getRelevantDocuments(prompt);

Expand Down

0 comments on commit 29f88f3

Please sign in to comment.