From 260d37a3f12781df2897d09806371f44cdd2bebe Mon Sep 17 00:00:00 2001 From: Thuc Pham <51660321+thucpn@users.noreply.github.com> Date: Mon, 20 May 2024 16:12:19 +0700 Subject: [PATCH] feat(ts): add system prompt for chat engine (#92) --- .changeset/silly-keys-wonder.md | 5 +++++ helpers/env-variables.ts | 13 ++++++------- .../components/engines/typescript/agent/chat.ts | 1 + .../components/engines/typescript/chat/chat.ts | 1 + 4 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 .changeset/silly-keys-wonder.md diff --git a/.changeset/silly-keys-wonder.md b/.changeset/silly-keys-wonder.md new file mode 100644 index 00000000..fb3056be --- /dev/null +++ b/.changeset/silly-keys-wonder.md @@ -0,0 +1,5 @@ +--- +"create-llama": patch +--- + +Add system prompt env variable for TS diff --git a/helpers/env-variables.ts b/helpers/env-variables.ts index 3ee3c55c..b5b36dd7 100644 --- a/helpers/env-variables.ts +++ b/helpers/env-variables.ts @@ -249,13 +249,6 @@ const getFrameworkEnvs = ( description: "The port to start the backend app.", value: port?.toString() || "8000", }, - // TODO: Once LlamaIndexTS supports string templates, move this to `getEngineEnvs` - { - name: "SYSTEM_PROMPT", - description: `Custom system prompt. -Example: -SYSTEM_PROMPT="You are a helpful assistant who helps users with their questions."`, - }, ]; }; @@ -267,6 +260,12 @@ const getEngineEnvs = (): EnvVar[] => { "The number of similar embeddings to return when retrieving documents.", value: "3", }, + { + name: "SYSTEM_PROMPT", + description: `Custom system prompt. +Example: +SYSTEM_PROMPT="You are a helpful assistant who helps users with their questions."`, + }, ]; }; diff --git a/templates/components/engines/typescript/agent/chat.ts b/templates/components/engines/typescript/agent/chat.ts index 9d16c8bd..856d36ee 100644 --- a/templates/components/engines/typescript/agent/chat.ts +++ b/templates/components/engines/typescript/agent/chat.ts @@ -41,5 +41,6 @@ export async function createChatEngine() { return new OpenAIAgent({ tools, + systemPrompt: process.env.SYSTEM_PROMPT, }); } diff --git a/templates/components/engines/typescript/chat/chat.ts b/templates/components/engines/typescript/chat/chat.ts index 5b47fe58..ef1dd5b6 100644 --- a/templates/components/engines/typescript/chat/chat.ts +++ b/templates/components/engines/typescript/chat/chat.ts @@ -16,5 +16,6 @@ export async function createChatEngine() { return new ContextChatEngine({ chatModel: Settings.llm, retriever, + systemPrompt: process.env.SYSTEM_PROMPT, }); } -- GitLab