mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-04-02 17:08:22 +02:00
Provide Env variable to have chat flow always use the tools prompt (#548)
This commit is contained in:
parent
30cdc5c9de
commit
0d505ffea1
backend/danswer
@ -19,6 +19,7 @@ from danswer.chat.chat_prompts import REQUIRE_DANSWER_SYSTEM_MSG
|
||||
from danswer.chat.chat_prompts import YES_SEARCH
|
||||
from danswer.chat.tools import call_tool
|
||||
from danswer.configs.app_configs import NUM_DOCUMENT_TOKENS_FED_TO_CHAT
|
||||
from danswer.configs.chat_configs import FORCE_TOOL_PROMPT
|
||||
from danswer.configs.constants import IGNORE_FOR_QA
|
||||
from danswer.configs.model_configs import GEN_AI_MAX_INPUT_TOKENS
|
||||
from danswer.datastores.document_index import get_default_document_index
|
||||
@ -434,19 +435,26 @@ def llm_chat_answer(
|
||||
# - Model is too weak of an LLM, fails to follow instructions
|
||||
# - Bad persona design leads to confusing instructions to the model
|
||||
# - Bad configurations, too small token limit, mismatched tokenizer to LLM, etc.
|
||||
|
||||
# No setting/persona available therefore no retrieval and no additional tools
|
||||
if persona is None:
|
||||
return llm_contextless_chat_answer(messages)
|
||||
|
||||
# Persona is configured but with retrieval off and no tools
|
||||
# therefore cannot retrieve any context so contextless
|
||||
elif persona.retrieval_enabled is False and not persona.tools:
|
||||
return llm_contextless_chat_answer(
|
||||
messages, system_text=persona.system_text, tokenizer=tokenizer
|
||||
)
|
||||
|
||||
elif persona.retrieval_enabled and not persona.tools:
|
||||
# No additional tools outside of Danswer retrieval, can use a more basic prompt
|
||||
# Doesn't require tool calling output format (all LLM outputs are therefore valid)
|
||||
elif persona.retrieval_enabled and not persona.tools and not FORCE_TOOL_PROMPT:
|
||||
return llm_contextual_chat_answer(
|
||||
messages=messages, persona=persona, user_id=user_id, tokenizer=tokenizer
|
||||
)
|
||||
|
||||
# Use most flexible/complex prompt format
|
||||
else:
|
||||
return llm_tools_enabled_chat_answer(
|
||||
messages=messages, persona=persona, user_id=user_id, tokenizer=tokenizer
|
||||
|
3
backend/danswer/configs/chat_configs.py
Normal file
3
backend/danswer/configs/chat_configs.py
Normal file
@ -0,0 +1,3 @@
|
||||
import os
|
||||
|
||||
FORCE_TOOL_PROMPT = os.environ.get("FORCE_TOOL_PROMPT", "").lower() == "true"
|
Loading…
x
Reference in New Issue
Block a user