43
43
from onyx .chat .prompt_builder .answer_prompt_builder import AnswerPromptBuilder
44
44
from onyx .chat .prompt_builder .answer_prompt_builder import default_build_system_message
45
45
from onyx .chat .prompt_builder .answer_prompt_builder import default_build_user_message
46
+ from onyx .chat .prompt_builder .citations_prompt import (
47
+ compute_max_document_tokens_for_persona ,
48
+ )
46
49
from onyx .configs .chat_configs import CHAT_TARGET_CHUNK_PERCENTAGE
47
50
from onyx .configs .chat_configs import DISABLE_LLM_CHOOSE_SEARCH
48
51
from onyx .configs .chat_configs import MAX_CHUNKS_FED_TO_CHAT
92
95
from onyx .db .models import UserFile
93
96
from onyx .db .persona import get_persona_by_id
94
97
from onyx .db .search_settings import get_current_search_settings
98
+ from onyx .db .user_documents import calculate_user_files_token_count
95
99
from onyx .document_index .factory import get_default_document_index
96
100
from onyx .file_store .models import ChatFileType
97
101
from onyx .file_store .models import FileDescriptor
133
137
INTERNET_SEARCH_RESPONSE_ID ,
134
138
)
135
139
from onyx .tools .tool_implementations .internet_search .internet_search_tool import (
136
- internet_search_response_to_search_docs ,
140
+ InternetSearchTool ,
137
141
)
138
- from onyx .tools .tool_implementations .internet_search .internet_search_tool import (
142
+ from onyx .tools .tool_implementations .internet_search .models import (
139
143
InternetSearchResponse ,
140
144
)
141
- from onyx .tools .tool_implementations .internet_search .internet_search_tool import (
142
- InternetSearchTool ,
145
+ from onyx .tools .tool_implementations .internet_search .utils import (
146
+ internet_search_response_to_search_docs ,
143
147
)
144
148
from onyx .tools .tool_implementations .search .search_tool import (
145
149
FINAL_CONTEXT_DOCUMENTS_ID ,
@@ -279,6 +283,9 @@ def _handle_search_tool_response_summary(
279
283
)
280
284
281
285
286
+ # TODO: this takes the entire internet search response and sends it to LLM --> not correct
287
+ # TODO: Internet search yields first an InternetSearchResponse to populate search results
288
+ # and then yields a list of LlmDocs that should be added to context
282
289
def _handle_internet_search_tool_response_summary (
283
290
packet : ToolResponse ,
284
291
db_session : Session ,
@@ -864,10 +871,6 @@ def stream_chat_message_objects(
864
871
file_id_to_user_file = {file .file_id : file for file in user_files }
865
872
866
873
# Calculate token count for the files
867
- from onyx .db .user_documents import calculate_user_files_token_count
868
- from onyx .chat .prompt_builder .citations_prompt import (
869
- compute_max_document_tokens_for_persona ,
870
- )
871
874
872
875
total_tokens = calculate_user_files_token_count (
873
876
user_file_ids or [],
@@ -1048,6 +1051,16 @@ def create_response(
1048
1051
structured_response_format = new_msg_req .structured_response_format ,
1049
1052
)
1050
1053
1054
+ # Temp to get a pruning config for internet search
1055
+ available_tokens = compute_max_document_tokens_for_persona (
1056
+ db_session = db_session ,
1057
+ persona = persona ,
1058
+ actual_user_input = message_text ,
1059
+ )
1060
+
1061
+ internet_pruning_config = document_pruning_config .copy ()
1062
+ internet_pruning_config .max_tokens = available_tokens
1063
+
1051
1064
tool_dict = construct_tools (
1052
1065
persona = persona ,
1053
1066
prompt_config = prompt_config ,
@@ -1071,6 +1084,7 @@ def create_response(
1071
1084
),
1072
1085
internet_search_tool_config = InternetSearchToolConfig (
1073
1086
answer_style_config = answer_style_config ,
1087
+ document_pruning_config = internet_pruning_config ,
1074
1088
),
1075
1089
image_generation_tool_config = ImageGenerationToolConfig (
1076
1090
additional_headers = litellm_additional_headers ,
0 commit comments