-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
simple apis now cited/context doc indices #2419
Merged
+134
−36
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,7 @@ | |
from danswer.tools.internet_search.internet_search_tool import InternetSearchTool | ||
from danswer.tools.message import build_tool_message | ||
from danswer.tools.message import ToolCallSummary | ||
from danswer.tools.search.search_tool import FINAL_CONTEXT_DOCUMENTS | ||
from danswer.tools.search.search_tool import FINAL_CONTEXT_DOCUMENTS_ID | ||
from danswer.tools.search.search_tool import SEARCH_DOC_CONTENT_ID | ||
from danswer.tools.search.search_tool import SEARCH_RESPONSE_SUMMARY_ID | ||
from danswer.tools.search.search_tool import SearchResponseSummary | ||
|
@@ -433,7 +433,7 @@ def _raw_output_for_non_explicit_tool_calling_llms( | |
if tool.name in {SearchTool._NAME, InternetSearchTool._NAME}: | ||
final_context_documents = None | ||
for response in tool_runner.tool_responses(): | ||
if response.id == FINAL_CONTEXT_DOCUMENTS: | ||
if response.id == FINAL_CONTEXT_DOCUMENTS_ID: | ||
final_context_documents = cast(list[LlmDoc], response.response) | ||
yield response | ||
|
||
|
@@ -501,12 +501,10 @@ def _process_stream( | |
message = None | ||
|
||
# special things we need to keep track of for the SearchTool | ||
search_results: list[ | ||
LlmDoc | ||
] | None = None # raw results that will be displayed to the user | ||
final_context_docs: list[ | ||
LlmDoc | ||
] | None = None # processed docs to feed into the LLM | ||
# raw results that will be displayed to the user | ||
search_results: list[LlmDoc] | None = None | ||
# processed docs to feed into the LLM | ||
final_context_docs: list[LlmDoc] | None = None | ||
|
||
for message in stream: | ||
if isinstance(message, ToolCallKickoff) or isinstance( | ||
|
@@ -525,8 +523,9 @@ def _process_stream( | |
SearchResponseSummary, message.response | ||
).top_sections | ||
] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here we yield the final context docs |
||
elif message.id == FINAL_CONTEXT_DOCUMENTS: | ||
elif message.id == FINAL_CONTEXT_DOCUMENTS_ID: | ||
final_context_docs = cast(list[LlmDoc], message.response) | ||
yield message | ||
|
||
elif ( | ||
message.id == SEARCH_DOC_CONTENT_ID | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,31 @@ | ||
import json | ||
from datetime import datetime | ||
from typing import Any | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. made this function able to encode datetime objects |
||
def get_json_line(json_dict: dict) -> str: | ||
return json.dumps(json_dict) + "\n" | ||
class DateTimeEncoder(json.JSONEncoder): | ||
"""Custom JSON encoder that converts datetime objects to ISO format strings.""" | ||
|
||
def default(self, obj: Any) -> Any: | ||
if isinstance(obj, datetime): | ||
return obj.isoformat() | ||
return super().default(obj) | ||
|
||
|
||
def get_json_line( | ||
json_dict: dict[str, Any], encoder: type[json.JSONEncoder] = DateTimeEncoder | ||
) -> str: | ||
""" | ||
Convert a dictionary to a JSON string with datetime handling, and add a newline. | ||
|
||
Args: | ||
json_dict: The dictionary to be converted to JSON. | ||
encoder: JSON encoder class to use, defaults to DateTimeEncoder. | ||
|
||
Returns: | ||
A JSON string representation of the input dictionary with a newline character. | ||
""" | ||
return json.dumps(json_dict, cls=encoder) + "\n" | ||
|
||
|
||
def mask_string(sensitive_str: str) -> str: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed this everywhere