From 2ae8ec1739bbfcafb5746cdb8b32147ab015da95 Mon Sep 17 00:00:00 2001 From: Stan Girard Date: Sun, 18 Feb 2024 16:22:21 -0800 Subject: [PATCH] feat: Update system templates with custom personality support (#2209) This pull request updates the system templates to include support for custom personality. It adds a new parameter called "custom_personality" to the generate_stream function, which allows users to provide a custom personality for the AI assistant. This feature enhances the user experience by allowing them to personalize the assistant's responses. --- backend/modules/brain/integrations/Big/Brain.py | 6 +++++- backend/modules/brain/integrations/GPT4/Brain.py | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/backend/modules/brain/integrations/Big/Brain.py b/backend/modules/brain/integrations/Big/Brain.py index ab7cd9858..bf210a45c 100644 --- a/backend/modules/brain/integrations/Big/Brain.py +++ b/backend/modules/brain/integrations/Big/Brain.py @@ -36,7 +36,8 @@ class BigBrain(KnowledgeBrainQA): def get_chain(self): system_template = """Combine these summaries in a way that makes sense and answer the user's question. - Use markdown or any other techniques to display the content in a nice and aerated way. + Use markdown or any other techniques to display the content in a nice and aerated way. + Here are user instructions on how to respond: {custom_personality} ______________________ {summaries}""" messages = [ @@ -88,6 +89,9 @@ class BigBrain(KnowledgeBrainQA): { "question": question.question, "chat_history": transformed_history, + "custom_personality": ( + self.prompt_to_use.content if self.prompt_to_use else None + ), } ): if "answer" in chunk: diff --git a/backend/modules/brain/integrations/GPT4/Brain.py b/backend/modules/brain/integrations/GPT4/Brain.py index 03db2cd1d..505b4d4f9 100644 --- a/backend/modules/brain/integrations/GPT4/Brain.py +++ b/backend/modules/brain/integrations/GPT4/Brain.py @@ -28,7 +28,10 @@ class GPT4Brain(KnowledgeBrainQA): prompt = ChatPromptTemplate.from_messages( [ - ("system", "You are GPT-4 powered by Quivr. You are an assistant."), + ( + "system", + "You are GPT-4 powered by Quivr. You are an assistant. {custom_personality}", + ), MessagesPlaceholder(variable_name="chat_history"), ("human", "{question}"), ] @@ -53,6 +56,9 @@ class GPT4Brain(KnowledgeBrainQA): { "question": question.question, "chat_history": transformed_history, + "custom_personality": ( + self.prompt_to_use.content if self.prompt_to_use else None + ), } ): response_tokens.append(chunk.content)