Skip to content
This repository was archived by the owner on Sep 26, 2025. It is now read-only.

feat: use json schema from openapi doc and recover in case of assistant protocol error#64

Open
Oleksii-Klimov wants to merge 4 commits into
developmentfrom
61-adjust-assistant-so-claude-21-could-reliably-run-addons-via-tools-api
Open

feat: use json schema from openapi doc and recover in case of assistant protocol error#64
Oleksii-Klimov wants to merge 4 commits into
developmentfrom
61-adjust-assistant-so-claude-21-could-reliably-run-addons-via-tools-api

Conversation

@Oleksii-Klimov

Copy link
Copy Markdown
Collaborator

No description provided.

@Oleksii-Klimov Oleksii-Klimov changed the title feat: use json schema from openapi doc feat: use json schema from openapi doc and recover in case of assistant protocol error Jan 25, 2024
@Oleksii-Klimov

Oleksii-Klimov commented Jan 25, 2024

Copy link
Copy Markdown
Collaborator Author

/deploy-review

Deployment status: success

@Oleksii-Klimov

Oleksii-Klimov commented Jan 25, 2024

Copy link
Copy Markdown
Collaborator Author

/deploy-review

Deployment status: success

1 similar comment
@Oleksii-Klimov

Oleksii-Klimov commented Jan 26, 2024

Copy link
Copy Markdown
Collaborator Author

/deploy-review

Deployment status: success


from langchain_community.utilities.openapi import OpenAPISpec
from openai.types.chat import ChatCompletionToolParam
from openapi_pydantic import DataType, Reference, Schema

@adubovik adubovik Jan 31, 2024

Copy link
Copy Markdown
Contributor

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():

Copy link
Copy Markdown
Contributor

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.

)


class OpenAPIChatCommand(Command):

Copy link
Copy Markdown
Contributor

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(

@adubovik adubovik Jan 31, 2024

Copy link
Copy Markdown
Contributor

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)

@adubovik adubovik Jan 31, 2024

Copy link
Copy Markdown
Contributor

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adjust assistant so Claude 2.1 could reliably run addons via tools API

2 participants