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: add provider agnostic call decorator #740

Draft
wants to merge 41 commits into
base: main
Choose a base branch
from

Conversation

koxudaxi
Copy link
Collaborator

No description provided.

@koxudaxi koxudaxi requested a review from willbakst as a code owner December 11, 2024 17:13
@koxudaxi koxudaxi marked this pull request as draft December 11, 2024 17:13
mirascope/core/base/_call_factory.py Outdated Show resolved Hide resolved
mirascope/llm/_base_provider_converter.py Outdated Show resolved Hide resolved
mirascope/llm/call_response.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Dec 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (23c3614) to head (c58f206).

Additional details and impacted files
@@                Coverage Diff                @@
##           release/v1.14      #740     +/-   ##
=================================================
  Coverage         100.00%   100.00%             
=================================================
  Files                407       457     +50     
  Lines              14669     16733   +2064     
=================================================
+ Hits               14669     16733   +2064     
Flag Coverage Δ
tests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.



FinishReason: TypeAlias = Literal[
"stop", "length", "tool_calls", "content_filter", "function_call"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: i think we can drop "function_call" since that is deprecated?


@property
def common_usage(self) -> Usage | None:
if self.input_tokens is None and self.output_tokens is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why have a shared utility for the finish reason conversion but not he usage creation?

is there any reason not to just have shared utilities for all of these? Even if it's just a simple cast line so that any changes in the future happen only in one place?


@property
def common_message_param(self) -> BaseMessageParam:
return _convert_parts_to_base_message_param(self.response.parts)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why have a utility here for gemini and not the other providers?


@property
def common_message_param(self) -> BaseMessageParam:
raise NotImplementedError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we planning on implementing this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, my mistake

return cast(list[FinishReason], self.finish_reasons)

@property
def common_message_param(self) -> BaseMessageParam:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

realizing that we need to update BaseMessageParam to account for tool calls. This means we'll need to add support for role="tool" (including whatever other metadata tool messages might have and converting these into provider-specific tool messages, which we currently don't do because we assume the user is using provider-specific tool messages right now).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should try our best to match the utilities across all providers so that the structure of the codebase remains consistent.

For example, if we're going to have a utility for one provider, that means we should have the same utility for all providers. This will also help to ensure that we maintain consistent interfaces both externally and internally.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have created ToolCallPart and ToolResultPart and added processing for them.
However, currently there are no use cases for ToolCallPart.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized that while we plan to convert ToolResultPart to provider-specific Messages, there's a constraint that tool_results can only be sent to the provider that requested the tool because a tool_call_id is required.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in line with my previous comment, this is missing a provider-agnostic version of tool_message_params


return inner

def _wrap_result(result: BaseCallResponse | Stream) -> CallResponse | Stream:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: define this above wrapper since inner uses this method (or pull it out into a private utility so we don't define it every time?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also missing the provider-agnostic tool_message_params method.

@willbakst willbakst changed the base branch from main to release/v1.14 December 19, 2024 18:19
@koxudaxi koxudaxi requested a review from willbakst December 20, 2024 20:54
@willbakst willbakst changed the base branch from release/v1.14 to main December 21, 2024 07:13
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.

2 participants