Skip to content
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

Open
wants to merge 4 commits into
base: development
Choose a base branch
from

Conversation

Oleksii-Klimov
Copy link
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
Copy link
Collaborator Author

Oleksii-Klimov commented Jan 25, 2024

/deploy-review

Deployment status: success

@Oleksii-Klimov
Copy link
Collaborator Author

Oleksii-Klimov commented Jan 25, 2024

/deploy-review

Deployment status: success

1 similar comment
@Oleksii-Klimov
Copy link
Collaborator Author

Oleksii-Klimov commented Jan 26, 2024

/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
Copy link
Contributor

@adubovik adubovik Jan 31, 2024

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
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.

from aidial_assistant.open_api.requester import (
OpenAPIEndpointRequester,
ParamMapping,
)


class OpenAPIChatCommand(Command):
Copy link
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(
Copy link
Contributor

@adubovik adubovik Jan 31, 2024

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)
Copy link
Contributor

@adubovik adubovik Jan 31, 2024

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 join this conversation on GitHub. Already have an account? Sign in to comment
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