UI and chatbot updates
This commit is contained in:
+7
-5
@@ -79,9 +79,9 @@ MAX_TOOL_ROUNDS = 3 # searches per message before the LLM must answer
|
||||
|
||||
# System prompt for every chat turn (German, like the corpus and the questions).
|
||||
SYSTEM_PROMPT = f"""Du beantwortest Fragen zu Franz Kafka, seinen Werken, seinem Leben und der Forschung.
|
||||
Du hast ein Werkzeug, {SEARCH_TOOL_NAME}, das eine Bibliothek aus Kafkas Texten und Forschungsliteratur durchsucht.
|
||||
Du hast ein Tool, {SEARCH_TOOL_NAME}, das eine Bibliothek aus Kafkas Texten und Forschungsliteratur durchsucht.
|
||||
- Für jede inhaltliche Frage zu Kafka, seinen Werken, Figuren, seiner Biografie, Sprache oder zur Forschung: Rufe zuerst das Werkzeug auf und stütze die Antwort auf die gefundenen Auszüge. Antworte nicht aus dem Gedächtnis.
|
||||
- Bei Begrüßung, Dank, Smalltalk oder Fragen zum Gespräch selbst: Antworte direkt, ohne Werkzeug.
|
||||
- Bei Begrüßung, Dank, Smalltalk oder Fragen zum Gespräch selbst: Antworte direkt, ohne Tool.
|
||||
- Formuliere die Suchanfrage so, dass sie ohne den Gesprächsverlauf verständlich ist.
|
||||
- Finden sich in den Auszügen keine Belege, sage das offen, statt zu raten.
|
||||
- Nenne bei Aussagen aus den Auszügen die Quelle (Autor, Seite)."""
|
||||
@@ -387,10 +387,12 @@ class LocalRAG:
|
||||
content = "".join(part.get("text", "") if isinstance(part, dict) else str(part) for part in content)
|
||||
return (content or "").strip()
|
||||
|
||||
def query_with_history(self, question, chat_history=None, k=None, system_prompt=None):
|
||||
def query_with_history(self, question, chat_history=None, k=None, system_prompt=None,
|
||||
tool_description=None):
|
||||
"""Answer a chat message. The LLM decides whether to search the corpus: the search is
|
||||
offered as a tool (SEARCH_TOOL_NAME), which the LLM calls with its own query, up to
|
||||
MAX_TOOL_ROUNDS times. system_prompt defaults to SYSTEM_PROMPT (see personas.py for others).
|
||||
MAX_TOOL_ROUNDS times. system_prompt defaults to SYSTEM_PROMPT and tool_description to
|
||||
SEARCH_TOOL_DESCRIPTION (see personas.py for others).
|
||||
Returns dict with 'answer', 'retrieved' (chunks the LLM saw, with content, source, page,
|
||||
score) and 'searches' (the queries it used)."""
|
||||
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage, ToolMessage
|
||||
@@ -418,7 +420,7 @@ class LocalRAG:
|
||||
for i, (d, _) in enumerate(hits, start=1))
|
||||
|
||||
tool = StructuredTool.from_function(func=search_kafka_corpus, name=SEARCH_TOOL_NAME,
|
||||
description=SEARCH_TOOL_DESCRIPTION)
|
||||
description=tool_description or SEARCH_TOOL_DESCRIPTION)
|
||||
llm_with_tools = self.llm.bind_tools([tool])
|
||||
|
||||
messages = [SystemMessage(system_prompt or SYSTEM_PROMPT)]
|
||||
|
||||
Reference in New Issue
Block a user