From 596c84d075951b00f797832cd12cbcd14768c94e Mon Sep 17 00:00:00 2001 From: kkarissa Date: Wed, 11 Feb 2026 11:26:43 -0700 Subject: [PATCH 1/3] added prompt/persona --- systems/docgpt/src/adapters/assistant.py | 5 ++-- systems/docgpt/src/core/prompts.py | 32 ++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/systems/docgpt/src/adapters/assistant.py b/systems/docgpt/src/adapters/assistant.py index e92c249..43cec06 100644 --- a/systems/docgpt/src/adapters/assistant.py +++ b/systems/docgpt/src/adapters/assistant.py @@ -6,7 +6,7 @@ from langchain_core.language_models import BaseChatModel from langchain_core.vectorstores import VectorStore -from src.core.prompts import DEFAULT_PROMPT +from src.core.prompts import CONDENSE_QUESTION_PROMPT, QA_PROMPT from src.domain.assistant import Message, SessionId from src.port.assistant import AssistantPort @@ -51,11 +51,12 @@ def prompt(self, message: Message, *, session_id: SessionId | None = None) -> st qa = ConversationalRetrievalChain.from_llm( llm=self._llm, - condense_question_prompt=DEFAULT_PROMPT, + condense_question_prompt=CONDENSE_QUESTION_PROMPT, retriever=self._storage.as_retriever( search_type="similarity", search_kwargs=search_kwargs, ), + combine_docs_chain_kwargs={"prompt": QA_PROMPT}, get_chat_history=lambda v: v, memory=memory, verbose=True, diff --git a/systems/docgpt/src/core/prompts.py b/systems/docgpt/src/core/prompts.py index b9b066f..5dbe2cc 100644 --- a/systems/docgpt/src/core/prompts.py +++ b/systems/docgpt/src/core/prompts.py @@ -1,6 +1,6 @@ from langchain_core.prompts import PromptTemplate -_template = """ +_condense_template = """ Given the following conversation and a follow up question, rephrase the follow up question to be a standalone question, in its original language. @@ -14,4 +14,32 @@ {chat_history} Follow Up Input: {question} Standalone question:""" -DEFAULT_PROMPT = PromptTemplate.from_template(_template) + +CONDENSE_QUESTION_PROMPT = PromptTemplate.from_template(_condense_template) + +_qa_template = """You are a knowledgeable assistant for the R data.table open source project. + +Your role is to help contributors by providing clear, practical answers while also explaining context and reasoning. + +Guidelines: +- Provide direct, actionable answers to technical questions +- Explain the "why" behind design decisions and implementations +- Reference specific code locations, functions, or documentation sections when relevant +- For complex topics, break down the explanation into clear steps +- Adapt your response depth based on the question: + * Quick questions get concise answers with optional details + * Complex questions get thorough explanations with examples +- When multiple approaches exist, present them with trade-offs +- Guide newcomers by explaining concepts they might not know +- Help experienced contributors by being precise and efficient + +You have access to the data.table source code, contribution guidelines, and documentation. + +Context from the codebase: +{context} + +Question: {question} + +Provide a helpful answer that balances directness with clarity:""" + +QA_PROMPT = PromptTemplate.from_template(_qa_template) From 346acc669c740925aad16cd338bdd5e0f0fb5ad7 Mon Sep 17 00:00:00 2001 From: kkarissa Date: Wed, 11 Feb 2026 11:45:30 -0700 Subject: [PATCH 2/3] made the prompt more data specific --- systems/docgpt/src/core/prompts.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/systems/docgpt/src/core/prompts.py b/systems/docgpt/src/core/prompts.py index 5dbe2cc..fd8e60d 100644 --- a/systems/docgpt/src/core/prompts.py +++ b/systems/docgpt/src/core/prompts.py @@ -17,11 +17,16 @@ CONDENSE_QUESTION_PROMPT = PromptTemplate.from_template(_condense_template) -_qa_template = """You are a knowledgeable assistant for the R data.table open source project. +_qa_template = """You are a specialized assistant for the R data.table open source project. Your role is to help contributors by providing clear, practical answers while also explaining context and reasoning. -Guidelines: +IMPORTANT - Scope of Assistance: +- You ONLY answer questions related to the data.table package, its codebase, documentation, and contribution process +- If a question is unrelated to data.table, politely redirect: "I'm specifically designed to help with the data.table package. For questions about [topic], I'd recommend consulting other resources. Is there anything about data.table I can help you with?" +- Only use the information from the provided context below - do not make up information + +Guidelines for data.table questions: - Provide direct, actionable answers to technical questions - Explain the "why" behind design decisions and implementations - Reference specific code locations, functions, or documentation sections when relevant @@ -32,14 +37,13 @@ - When multiple approaches exist, present them with trade-offs - Guide newcomers by explaining concepts they might not know - Help experienced contributors by being precise and efficient +- If the context doesn't contain relevant information, say so clearly -You have access to the data.table source code, contribution guidelines, and documentation. - -Context from the codebase: +Context from the data.table codebase: {context} Question: {question} -Provide a helpful answer that balances directness with clarity:""" +Answer (only if related to data.table):""" QA_PROMPT = PromptTemplate.from_template(_qa_template) From 64c298c411fa906ba75261004407ad5f635db484 Mon Sep 17 00:00:00 2001 From: kkarissa Date: Wed, 11 Feb 2026 12:11:12 -0700 Subject: [PATCH 3/3] fixed persona --- systems/docgpt/src/adapters/assistant.py | 2 +- systems/docgpt/src/core/containers.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/systems/docgpt/src/adapters/assistant.py b/systems/docgpt/src/adapters/assistant.py index f668934..d6c85c6 100644 --- a/systems/docgpt/src/adapters/assistant.py +++ b/systems/docgpt/src/adapters/assistant.py @@ -7,7 +7,7 @@ from langchain_core.vectorstores import VectorStore from src.core.prompts import CONDENSE_QUESTION_PROMPT, QA_PROMPT -from src.domain.assistant import Message, SessionId +from src.domain.assistant import Message, PromptResult, SessionId from src.port.assistant import AssistantPort diff --git a/systems/docgpt/src/core/containers.py b/systems/docgpt/src/core/containers.py index 04f221d..d6cde22 100644 --- a/systems/docgpt/src/core/containers.py +++ b/systems/docgpt/src/core/containers.py @@ -134,6 +134,7 @@ class AssistantAdapters(containers.DeclarativeContainer): ConversationBufferMemory, chat_memory=storage.memory_factory, memory_key="chat_history", + output_key="answer", ) chat: Singleton[AssistantPort] = Singleton(