Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Context Template from settings for QueryDocs Allowing the text … #1398

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions private_gpt/server/chat/chat_service.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were is set (at usage) this new context_template?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if I understand.

If "query docs" is being used, it creates a ContextChatEngine (from llama_index) that accepts this parameter. Currently it's never passed, so it defaults to a hardcoded value. With this change, if there is a value defined in the settings file, the value in settings will be used instead. This should work both from the Gradio UI or from the API.

As per the Discord discussion, I didn't expose this configuration to the API

Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def __init__(
embed_model=embedding_component.embedding_model,
show_progress=True,
)
self.default_context_template = settings.rag.default_context_template

def _chat_engine(
self,
Expand All @@ -109,6 +110,10 @@ def _chat_engine(
) -> BaseChatEngine:
settings = self.settings
if use_context:
if self.default_context_template is not None:
context_template = self.default_context_template
else:
context_template = None
vector_index_retriever = self.vector_store_component.get_retriever(
index=self.index,
context_filter=context_filter,
Expand All @@ -132,6 +137,7 @@ def _chat_engine(
retriever=vector_index_retriever,
llm=self.llm_component.llm, # Takes no effect at the moment
node_postprocessors=node_postprocessors,
context_template=context_template,
)
else:
return SimpleChatEngine.from_defaults(
Expand Down
7 changes: 7 additions & 0 deletions private_gpt/settings/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,13 @@ class RerankSettings(BaseModel):


class RagSettings(BaseModel):
default_context_template: str | None = Field(
None,
description=(
"The default context template to use for the chat engine when using RAG. "
"If none is given - use the default system prompt (from the llama_index). "
),
)
similarity_top_k: int = Field(
2,
description="This value controls the number of documents returned by the RAG pipeline or considered for reranking if enabled.",
Expand Down
16 changes: 11 additions & 5 deletions settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ llm:
temperature: 0.1 # The temperature of the model. Increasing the temperature will make the model answer more creatively. A value of 0.1 would be more factual. (Default: 0.1)

rag:
default_context_template: |
Context information is below.
--------------------
{context_str}
--------------------
similarity_top_k: 2
#This value controls how many "top" documents the RAG returns to use in the context.
#similarity_value: 0.45
Expand All @@ -54,11 +59,11 @@ rag:
top_n: 1

clickhouse:
host: localhost
port: 8443
username: admin
password: clickhouse
database: embeddings
host: localhost
port: 8443
username: admin
password: clickhouse
database: embeddings

llamacpp:
llm_hf_repo_id: TheBloke/Mistral-7B-Instruct-v0.2-GGUF
Expand Down Expand Up @@ -125,3 +130,4 @@ gemini:
api_key: ${GOOGLE_API_KEY:}
model: models/gemini-pro
embedding_model: models/embedding-001

Loading