-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: use json schema from openapi doc and recover in case of assistant protocol error #64
base: development
Are you sure you want to change the base?
Conversation
/deploy-review
|
/deploy-review
|
1 similar comment
/deploy-review
|
|
||
from langchain_community.utilities.openapi import OpenAPISpec | ||
from openai.types.chat import ChatCompletionToolParam | ||
from openapi_pydantic import DataType, Reference, Schema |
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.
Add openapi-pydantic
and langchain-community
to pyproject.
|
||
request_body = spec.get_request_body_for_operation(operation) | ||
if request_body is not None: | ||
for key, media_type in request_body.content.items(): |
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.
You could lookup the dictionary media_type = request_body.content.get("application/json")
instead of looping through all items.
from aidial_assistant.open_api.requester import ( | ||
OpenAPIEndpointRequester, | ||
ParamMapping, | ||
) | ||
|
||
|
||
class OpenAPIChatCommand(Command): |
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.
It has nothing to do with Chat strictly speaking. Maybe simply OpenAPICommand
?
# The function is necessary to capture the current value of op. | ||
# Otherwise, only first op will be used for all commands | ||
command_dict[name] = create_command(op) | ||
return lambda: OpenAPIChatCommand.create( |
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.
There is a way to get rid of this function:
command_dict: CommandDict = {
op.operation_id: lambda op=op: OpenAPIChatCommand.create(
spec_url, op, self.plugin.auth
)
for op in operations
}
|
||
commands: CommandToolDict = { | ||
name: create_command_tool(op) for name, op in ops.items() | ||
operation.operation_id: (create_command(operation), tool) |
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.
Hard to read: three for's where only two are required.
Maybe rewrite it as two explicit for-loops.
And you can remove the create_command
method as I suggested in another comment.
No description provided.