-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Tool Call Accuracy OpenAPI Tools #42494
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
singankit
wants to merge
5
commits into
main
Choose a base branch
from
users/singankit/openapi_tools
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
Changes from all commits
Commits
Show all changes
5 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 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 | ||||
---|---|---|---|---|---|---|
|
@@ -52,7 +52,6 @@ | |||||
_AZURE_AI_SEARCH: "Search an Azure AI Search index for relevant data.", | ||||||
_SHAREPOINT_GROUNDING: "Allows agents to access and retrieve relevant content from Microsoft SharePoint document libraries, grounding responses in organizational knowledge.", | ||||||
_FABRIC_DATAAGENT: "Connect to Microsoft Fabric data agents to retrieve data across different data sources.", | ||||||
_OPENAPI: "Connects agents to external RESTful APIs using OpenAPI 3.0 specifications, enabling seamless access to third-party services.", | ||||||
} | ||||||
|
||||||
# Built-in tool parameters are hidden, but we include basic parameters for evaluation purposes. | ||||||
|
@@ -101,13 +100,6 @@ | |||||
"type": "object", | ||||||
"properties": {"input": {"type": "string", "description": "Search terms to use."}}, | ||||||
}, | ||||||
_OPENAPI: { | ||||||
"type": "object", | ||||||
"properties": { | ||||||
"name": {"type": "string", "description": "The name of the function to call."}, | ||||||
"arguments": {"type": "string", "description": "JSON string of the arguments to pass to the function."}, | ||||||
}, | ||||||
}, | ||||||
} | ||||||
|
||||||
|
||||||
|
@@ -245,6 +237,27 @@ class ToolDefinition(BaseModel): | |||||
parameters: dict | ||||||
|
||||||
|
||||||
class OpenAPIToolDefinition(BaseModel): | ||||||
"""Represents OpenAPI tool definition that will be used in the agent. | ||||||
:param name: The name of the tool. | ||||||
:type name: str | ||||||
:param type: The type of the tool. | ||||||
:type type: str | ||||||
:param description: A description of the tool. | ||||||
:type description: str | ||||||
:param parameters: The parameters required by the tool. | ||||||
:type parameters: dict | ||||||
""" | ||||||
|
||||||
name: str | ||||||
type: str | ||||||
description: Optional[str] = None | ||||||
spec: object | ||||||
auth: object | ||||||
default_params: Optional[list[str]] = None | ||||||
functions: list[ToolDefinition] | ||||||
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. Use
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
|
||||||
|
||||||
class ToolCall: | ||||||
"""Represents a tool call, used as an intermediate step in the conversion process. | ||||||
|
@@ -275,7 +288,7 @@ class EvaluatorData(BaseModel): | |||||
|
||||||
query: List[Message] | ||||||
response: List[Message] | ||||||
tool_definitions: List[ToolDefinition] | ||||||
tool_definitions: List[Union[ToolDefinition, OpenAPIToolDefinition]] | ||||||
|
||||||
def to_json(self): | ||||||
"""Converts the result to a JSON string. | ||||||
|
@@ -305,14 +318,16 @@ def break_tool_call_into_messages(tool_call: ToolCall, run_id: str) -> List[Mess | |||||
# all in most of the cases, and bing would only show the API URL, without arguments or results. | ||||||
# Bing grounding would have "bing_grounding" in details with "requesturl" that will just be the API path with query. | ||||||
# TODO: Work with AI Services to add converter support for BingGrounding and CodeInterpreter. | ||||||
if hasattr(tool_call.details, _FUNCTION): | ||||||
if hasattr(tool_call.details, _FUNCTION) or tool_call.details.get("function"): | ||||||
# This is the internals of the content object that will be included with the tool call. | ||||||
tool_call_id = tool_call.details.id | ||||||
content_tool_call = { | ||||||
"type": _TOOL_CALL, | ||||||
"tool_call_id": tool_call_id, | ||||||
"name": tool_call.details.function.name, | ||||||
"arguments": safe_loads(tool_call.details.function.arguments), | ||||||
"name": tool_call.details.get(_FUNCTION).get("name") if tool_call.details.get(_FUNCTION) else None, | ||||||
"arguments": safe_loads( | ||||||
tool_call.details.get(_FUNCTION).get("arguments") if tool_call.details.get(_FUNCTION) else None | ||||||
), | ||||||
} | ||||||
else: | ||||||
# Treat built-in tools separately. Object models may be unique so handle each case separately | ||||||
|
@@ -350,8 +365,8 @@ 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)) | ||||||
|
||||||
if hasattr(tool_call.details, _FUNCTION): | ||||||
output = safe_loads(tool_call.details.function["output"]) | ||||||
if hasattr(tool_call.details, _FUNCTION) or tool_call.details.get("function"): | ||||||
output = safe_loads(tool_call.details.get("function")["output"]) | ||||||
else: | ||||||
try: | ||||||
# Some built-ins may have output, others may not | ||||||
|
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
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.
Use
Optional[List[str]]
instead ofOptional[list[str]]
for consistency with other type annotations in the codebase.Copilot uses AI. Check for mistakes.