feat: use json schema from openapi doc and recover in case of assistant protocol error#64
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.
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.
You could lookup the dictionary media_type = request_body.content.get("application/json") instead of looping through all items.
| ) | ||
|
|
||
|
|
||
| class OpenAPIChatCommand(Command): |
There was a problem hiding this comment.
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.
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.
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.