18
18
from danswer .chat .models import MessageSpecificCitations
19
19
from danswer .chat .models import QADocsResponse
20
20
from danswer .chat .models import StreamingError
21
+ from danswer .chat .models import StreamStopInfo
21
22
from danswer .configs .app_configs import AZURE_DALLE_API_BASE
22
23
from danswer .configs .app_configs import AZURE_DALLE_API_KEY
23
24
from danswer .configs .app_configs import AZURE_DALLE_API_VERSION
77
78
from danswer .server .query_and_chat .models import CreateChatMessageRequest
78
79
from danswer .server .utils import get_json_line
79
80
from danswer .tools .built_in_tools import get_built_in_tool_by_id
80
- from danswer .tools .custom .custom_tool import (
81
+ from danswer .tools .force import ForceUseTool
82
+ from danswer .tools .models import DynamicSchemaInfo
83
+ from danswer .tools .models import ToolResponse
84
+ from danswer .tools .tool import Tool
85
+ from danswer .tools .tool_implementations .custom .custom_tool import (
81
86
build_custom_tools_from_openapi_schema_and_headers ,
82
87
)
83
- from danswer .tools .custom .custom_tool import CUSTOM_TOOL_RESPONSE_ID
84
- from danswer .tools .custom .custom_tool import CustomToolCallSummary
85
- from danswer .tools .force import ForceUseTool
86
- from danswer .tools .images .image_generation_tool import IMAGE_GENERATION_RESPONSE_ID
87
- from danswer .tools .images .image_generation_tool import ImageGenerationResponse
88
- from danswer .tools .images .image_generation_tool import ImageGenerationTool
89
- from danswer .tools .internet_search .internet_search_tool import (
88
+ from danswer .tools .tool_implementations .custom .custom_tool import (
89
+ CUSTOM_TOOL_RESPONSE_ID ,
90
+ )
91
+ from danswer .tools .tool_implementations .custom .custom_tool import CustomToolCallSummary
92
+ from danswer .tools .tool_implementations .images .image_generation_tool import (
93
+ IMAGE_GENERATION_RESPONSE_ID ,
94
+ )
95
+ from danswer .tools .tool_implementations .images .image_generation_tool import (
96
+ ImageGenerationResponse ,
97
+ )
98
+ from danswer .tools .tool_implementations .images .image_generation_tool import (
99
+ ImageGenerationTool ,
100
+ )
101
+ from danswer .tools .tool_implementations .internet_search .internet_search_tool import (
90
102
INTERNET_SEARCH_RESPONSE_ID ,
91
103
)
92
- from danswer .tools .internet_search .internet_search_tool import (
104
+ from danswer .tools .tool_implementations . internet_search .internet_search_tool import (
93
105
internet_search_response_to_search_docs ,
94
106
)
95
- from danswer .tools .internet_search .internet_search_tool import InternetSearchResponse
96
- from danswer .tools .internet_search .internet_search_tool import InternetSearchTool
97
- from danswer .tools .models import DynamicSchemaInfo
98
- from danswer .tools .search .search_tool import FINAL_CONTEXT_DOCUMENTS_ID
99
- from danswer .tools .search .search_tool import SEARCH_RESPONSE_SUMMARY_ID
100
- from danswer .tools .search .search_tool import SearchResponseSummary
101
- from danswer .tools .search .search_tool import SearchTool
102
- from danswer .tools .search .search_tool import SECTION_RELEVANCE_LIST_ID
103
- from danswer .tools .tool import Tool
104
- from danswer .tools .tool import ToolResponse
107
+ from danswer .tools .tool_implementations .internet_search .internet_search_tool import (
108
+ InternetSearchResponse ,
109
+ )
110
+ from danswer .tools .tool_implementations .internet_search .internet_search_tool import (
111
+ InternetSearchTool ,
112
+ )
113
+ from danswer .tools .tool_implementations .search .search_tool import (
114
+ FINAL_CONTEXT_DOCUMENTS_ID ,
115
+ )
116
+ from danswer .tools .tool_implementations .search .search_tool import (
117
+ SEARCH_RESPONSE_SUMMARY_ID ,
118
+ )
119
+ from danswer .tools .tool_implementations .search .search_tool import SearchResponseSummary
120
+ from danswer .tools .tool_implementations .search .search_tool import SearchTool
121
+ from danswer .tools .tool_implementations .search .search_tool import (
122
+ SECTION_RELEVANCE_LIST_ID ,
123
+ )
105
124
from danswer .tools .tool_runner import ToolCallFinalResult
106
125
from danswer .tools .utils import compute_all_tool_tokens
107
126
from danswer .tools .utils import explicit_tool_calling_supported
@@ -260,6 +279,7 @@ def _get_force_search_settings(
260
279
| CustomToolResponse
261
280
| MessageSpecificCitations
262
281
| MessageResponseIDInfo
282
+ | StreamStopInfo
263
283
)
264
284
ChatPacketStream = Iterator [ChatPacket ]
265
285
@@ -532,6 +552,13 @@ def stream_chat_message_objects(
532
552
if not persona
533
553
else PromptConfig .from_model (persona .prompts [0 ])
534
554
)
555
+ answer_style_config = AnswerStyleConfig (
556
+ citation_config = CitationConfig (
557
+ all_docs_useful = selected_db_search_docs is not None
558
+ ),
559
+ document_pruning_config = document_pruning_config ,
560
+ structured_response_format = new_msg_req .structured_response_format ,
561
+ )
535
562
536
563
# find out what tools to use
537
564
search_tool : SearchTool | None = None
@@ -550,13 +577,16 @@ def stream_chat_message_objects(
550
577
llm = llm ,
551
578
fast_llm = fast_llm ,
552
579
pruning_config = document_pruning_config ,
580
+ answer_style_config = answer_style_config ,
553
581
selected_sections = selected_sections ,
554
582
chunks_above = new_msg_req .chunks_above ,
555
583
chunks_below = new_msg_req .chunks_below ,
556
584
full_doc = new_msg_req .full_doc ,
557
- evaluation_type = LLMEvaluationType .BASIC
558
- if persona .llm_relevance_filter
559
- else LLMEvaluationType .SKIP ,
585
+ evaluation_type = (
586
+ LLMEvaluationType .BASIC
587
+ if persona .llm_relevance_filter
588
+ else LLMEvaluationType .SKIP
589
+ ),
560
590
)
561
591
tool_dict [db_tool_model .id ] = [search_tool ]
562
592
elif tool_cls .__name__ == ImageGenerationTool .__name__ :
@@ -626,7 +656,11 @@ def stream_chat_message_objects(
626
656
"Internet search tool requires a Bing API key, please contact your Danswer admin to get it added!"
627
657
)
628
658
tool_dict [db_tool_model .id ] = [
629
- InternetSearchTool (api_key = bing_api_key )
659
+ InternetSearchTool (
660
+ api_key = bing_api_key ,
661
+ answer_style_config = answer_style_config ,
662
+ prompt_config = prompt_config ,
663
+ )
630
664
]
631
665
632
666
continue
@@ -667,13 +701,7 @@ def stream_chat_message_objects(
667
701
is_connected = is_connected ,
668
702
question = final_msg .message ,
669
703
latest_query_files = latest_query_files ,
670
- answer_style_config = AnswerStyleConfig (
671
- citation_config = CitationConfig (
672
- all_docs_useful = selected_db_search_docs is not None
673
- ),
674
- document_pruning_config = document_pruning_config ,
675
- structured_response_format = new_msg_req .structured_response_format ,
676
- ),
704
+ answer_style_config = answer_style_config ,
677
705
prompt_config = prompt_config ,
678
706
llm = (
679
707
llm
@@ -777,7 +805,8 @@ def stream_chat_message_objects(
777
805
response = custom_tool_response .tool_result ,
778
806
tool_name = custom_tool_response .tool_name ,
779
807
)
780
-
808
+ elif isinstance (packet , StreamStopInfo ):
809
+ pass
781
810
else :
782
811
if isinstance (packet , ToolCallFinalResult ):
783
812
tool_result = packet
@@ -807,6 +836,7 @@ def stream_chat_message_objects(
807
836
808
837
# Post-LLM answer processing
809
838
try :
839
+ logger .debug ("Post-LLM answer processing" )
810
840
message_specific_citations : MessageSpecificCitations | None = None
811
841
if reference_db_search_docs :
812
842
message_specific_citations = _translate_citations (
0 commit comments