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(py): Python GoogleAi plugin #2173

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kamilkorski
Copy link

Created google ai plugin

  • plugin code
  • plugin models
  • plugin sample

Checklist (if applicable):

@kamilkorski kamilkorski requested a review from Irillit February 26, 2025 14:58
@github-actions github-actions bot added docs Improvements or additions to documentation python Python config labels Feb 26, 2025
Copy link
Contributor

@kirgrim kirgrim left a comment

Choose a reason for hiding this comment

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

Please also introduce some tests verifying it works structure-wise, you can copy and adapt tests from https://github.com/firebase/genkit/pull/1828/files#diff-285168c0aaeff7b2a46f86c5cfd05113fdd9f050e75d40d9c4c9c2b9a085561eR12

return f'googleai/{name}'


class GoogleAiPluginOptions(pydantic.BaseModel):
Copy link
Contributor

Choose a reason for hiding this comment

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

please move schemas to the separate file, e.g. models.py



class GoogleAi(plugin_abc.Plugin):
def __init__(self, plugin_params=GoogleAiPluginOptions):
Copy link
Contributor

Choose a reason for hiding this comment

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

annotate it as GoogleAiPluginOptions | None and assign to None by default -> if its None set it to GoogleAiPluginOptions. This will be the safest option to handle the default behaviour:

def __init__(self, plugin_params: GoogleAiPluginOptions | None = None): self.plugin_params = plugin_params or GoogleAiPluginOptions

def _create_callback(
self, model: str
) -> Callable[[GenerateRequest], GenerateResponse]:
def model_callback(request: GenerateRequest) -> GenerateResponse:
Copy link
Contributor

Choose a reason for hiding this comment

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

we are currently approaching defining callbacks via dedicated Model handler that create in initialise, I believe that will make code more readable and easier to maintain, example: https://github.com/firebase/genkit/pull/1828/files#diff-e147b482a7fce3760b369ebb507f3d27e8b6f5d44629772c295fcf016eb218f6R114

Copy link
Contributor

Choose a reason for hiding this comment

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

also consider handling streaming API by passing ctx: ActionRunContext | None = None parameter and calling send_chunk explicitly

reqest_msgs.append(
genai.types.Content(parts=message_parts, role=msg.role)
)
response = self._client.models.generate_content(
Copy link
Contributor

Choose a reason for hiding this comment

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

as we are aiming at async-first solution, is it possible to use this client SDK in an async version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
config docs Improvements or additions to documentation python Python
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants