-
Notifications
You must be signed in to change notification settings - Fork 165
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
base: main
Are you sure you want to change the base?
Conversation
e9f4018
to
fbdee64
Compare
There was a problem hiding this 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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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?
Created google ai plugin
Checklist (if applicable):