Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions systems/docgpt/src/adapters/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, PromptResult, SessionId
from src.port.assistant import AssistantPort

Expand Down Expand Up @@ -51,11 +51,12 @@ def prompt(self, message: Message, *, session_id: SessionId | None = None) -> Pr

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,
Expand Down
1 change: 1 addition & 0 deletions systems/docgpt/src/core/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
36 changes: 34 additions & 2 deletions systems/docgpt/src/core/prompts.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -14,4 +14,36 @@
{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 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.

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
- 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
- If the context doesn't contain relevant information, say so clearly

Context from the data.table codebase:
{context}

Question: {question}

Answer (only if related to data.table):"""

QA_PROMPT = PromptTemplate.from_template(_qa_template)
Loading