-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix for mypy 1.14.1 #41674
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
Open
luigiw
wants to merge
1
commit into
Azure:main
Choose a base branch
from
luigiw:hancwang/mypy1141
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fix for mypy 1.14.1 #41674
Changes from all commits
Commits
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 hidden or 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 hidden or 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 hidden or 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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,17 +3,17 @@ | |||||||||
|
||||||||||
from pydantic import BaseModel | ||||||||||
|
||||||||||
from typing import List, Optional, Union | ||||||||||
from typing import List, Optional, Union, TYPE_CHECKING, Any | ||||||||||
|
||||||||||
# Models moved in a later version of agents SDK, so try a few different locations | ||||||||||
try: | ||||||||||
from azure.ai.projects.models import RunStepFunctionToolCall | ||||||||||
except ImportError: | ||||||||||
pass | ||||||||||
try: | ||||||||||
from azure.ai.agents.models import RunStepFunctionToolCall | ||||||||||
except ImportError: | ||||||||||
pass | ||||||||||
if TYPE_CHECKING: | ||||||||||
try: | ||||||||||
from azure.ai.projects.models import RunStepFunctionToolCall | ||||||||||
except ImportError: | ||||||||||
try: | ||||||||||
from azure.ai.agents.models import RunStepFunctionToolCall | ||||||||||
except ImportError: | ||||||||||
RunStepFunctionToolCall = Any | ||||||||||
|
||||||||||
# Message roles constants. | ||||||||||
_SYSTEM = "system" | ||||||||||
|
@@ -244,14 +244,16 @@ def break_tool_call_into_messages(tool_call: ToolCall, run_id: str) -> List[Mess | |||||||||
# Treat built-in tools separately. Object models may be unique so handle each case separately | ||||||||||
# Just converting to dicts here rather than custom serializers for simplicity for now. | ||||||||||
# Don't fail if we run into a newly seen tool, just skip | ||||||||||
if tool_call.details["type"] == "code_interpreter": | ||||||||||
arguments = {"input": tool_call.details.code_interpreter.input} | ||||||||||
elif tool_call.details["type"] == "bing_grounding": | ||||||||||
arguments = {"requesturl": tool_call.details["bing_grounding"]["requesturl"]} | ||||||||||
elif tool_call.details["type"] == "file_search": | ||||||||||
options = tool_call.details["file_search"]["ranking_options"] | ||||||||||
if hasattr(tool_call.details, "type") and tool_call.details.type == "code_interpreter": # type: ignore | ||||||||||
arguments = {"input": getattr(tool_call.details, "code_interpreter", {}).get("input", "")} # type: ignore | ||||||||||
elif hasattr(tool_call.details, "type") and tool_call.details.type == "bing_grounding": # type: ignore | ||||||||||
bing_grounding = getattr(tool_call.details, "bing_grounding", {}) # type: ignore | ||||||||||
arguments = {"requesturl": bing_grounding.get("requesturl", "")} | ||||||||||
elif hasattr(tool_call.details, "type") and tool_call.details.type == "file_search": # type: ignore | ||||||||||
file_search = getattr(tool_call.details, "file_search", {}) # type: ignore | ||||||||||
options = file_search.get("ranking_options", {}) | ||||||||||
arguments = { | ||||||||||
"ranking_options": {"ranker": options["ranker"], "score_threshold": options["score_threshold"]} | ||||||||||
"ranking_options": {"ranker": options.get("ranker", ""), "score_threshold": options.get("score_threshold", 0)} | ||||||||||
} | ||||||||||
elif tool_call.details["type"] == "azure_ai_search": | ||||||||||
arguments = {"input": tool_call.details["azure_ai_search"]["input"]} | ||||||||||
|
@@ -276,46 +278,52 @@ def break_tool_call_into_messages(tool_call: ToolCall, run_id: str) -> List[Mess | |||||||||
# assistant's action of calling the tool. | ||||||||||
messages.append(AssistantMessage(run_id=run_id, content=[to_dict(content_tool_call)], createdAt=tool_call.created)) | ||||||||||
|
||||||||||
output = None | ||||||||||
if hasattr(tool_call.details, _FUNCTION): | ||||||||||
output = safe_loads(tool_call.details.function["output"]) | ||||||||||
output = safe_loads(getattr(tool_call.details, "function", {}).get("output", "")) # type: ignore | ||||||||||
else: | ||||||||||
try: | ||||||||||
# Some built-ins may have output, others may not | ||||||||||
# Try to retrieve it, but if we don't find anything, skip adding the message | ||||||||||
# Just manually converting to dicts for easy serialization for now rather than custom serializers | ||||||||||
if tool_call.details.type == _CODE_INTERPRETER: | ||||||||||
output = tool_call.details.code_interpreter.outputs | ||||||||||
elif tool_call.details.type == _BING_GROUNDING: | ||||||||||
if hasattr(tool_call.details, "type") and tool_call.details.type == _CODE_INTERPRETER: # type: ignore | ||||||||||
output = getattr(tool_call.details, "code_interpreter", {}).get("outputs", []) # type: ignore | ||||||||||
elif hasattr(tool_call.details, "type") and tool_call.details.type == _BING_GROUNDING: # type: ignore | ||||||||||
return messages # not supported yet from bing grounding tool | ||||||||||
elif tool_call.details.type == _FILE_SEARCH: | ||||||||||
elif hasattr(tool_call.details, "type") and tool_call.details.type == _FILE_SEARCH: # type: ignore | ||||||||||
file_search_results = getattr(tool_call.details, "file_search", {}).get("results", []) # type: ignore | ||||||||||
output = [ | ||||||||||
{ | ||||||||||
"file_id": result.file_id, | ||||||||||
"file_name": result.file_name, | ||||||||||
"score": result.score, | ||||||||||
"content": result.content, | ||||||||||
"file_id": getattr(result, "file_id", ""), | ||||||||||
"file_name": getattr(result, "file_name", ""), | ||||||||||
"score": getattr(result, "score", 0), | ||||||||||
"content": getattr(result, "content", ""), | ||||||||||
} | ||||||||||
for result in tool_call.details.file_search.results | ||||||||||
for result in file_search_results | ||||||||||
] | ||||||||||
elif tool_call.details.type == _AZURE_AI_SEARCH: | ||||||||||
output = tool_call.details.azure_ai_search["output"] | ||||||||||
elif tool_call.details.type == _FABRIC_DATAAGENT: | ||||||||||
output = tool_call.details.fabric_dataagent["output"] | ||||||||||
elif hasattr(tool_call.details, "type") and tool_call.details.type == _AZURE_AI_SEARCH: # type: ignore | ||||||||||
azure_ai_search = getattr(tool_call.details, "azure_ai_search", {}) # type: ignore | ||||||||||
output = azure_ai_search.get("output", "") | ||||||||||
elif hasattr(tool_call.details, "type") and tool_call.details.type == _FABRIC_DATAAGENT: # type: ignore | ||||||||||
fabric_dataagent = getattr(tool_call.details, "fabric_dataagent", {}) # type: ignore | ||||||||||
output = fabric_dataagent.get("output", "") | ||||||||||
except: | ||||||||||
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. [nitpick] Catching a bare
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||
return messages | ||||||||||
|
||||||||||
# Now, onto the tool result, which only includes the result of the function call. | ||||||||||
content_tool_call_result = {"type": _TOOL_RESULT, _TOOL_RESULT: output} | ||||||||||
|
||||||||||
# Since this is a tool's action of returning, we put it as a tool message. | ||||||||||
messages.append( | ||||||||||
ToolMessage( | ||||||||||
run_id=run_id, | ||||||||||
tool_call_id=tool_call_id, | ||||||||||
content=[to_dict(content_tool_call_result)], | ||||||||||
createdAt=tool_call.completed, | ||||||||||
# Only add tool result if we have output | ||||||||||
if output is not None: | ||||||||||
# Now, onto the tool result, which only includes the result of the function call. | ||||||||||
content_tool_call_result = {"type": _TOOL_RESULT, _TOOL_RESULT: output} | ||||||||||
|
||||||||||
# Since this is a tool's action of returning, we put it as a tool message. | ||||||||||
messages.append( | ||||||||||
ToolMessage( | ||||||||||
run_id=run_id, | ||||||||||
tool_call_id=tool_call_id, | ||||||||||
content=[to_dict(content_tool_call_result)], | ||||||||||
createdAt=tool_call.completed, | ||||||||||
) | ||||||||||
) | ||||||||||
) | ||||||||||
return messages | ||||||||||
|
||||||||||
|
||||||||||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
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.
[nitpick] The
Union[str, str, ...]
includesstr
twice, which is redundant. Removing the duplicate entry will simplify the type definition.Copilot uses AI. Check for mistakes.