-
Notifications
You must be signed in to change notification settings - Fork 166
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
212514e
to
cd4ba35
Compare
4d90976
to
cb598d4
Compare
def _genkit_to_googleai_cfg( | ||
self, genkit_cfg: GenerationCommonConfig | ||
) -> genai.types.GenerateContentConfig: | ||
"""Translate genkit generation config to Google Ai geberate config |
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.
Is it generate config
? I think, you have a typo.
) | ||
|
||
if ctx.is_streaming: | ||
ctx.send_chunk(chunk=response.text) |
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.
chunks need to be wrapped in GenerateResponseChunk objects.
The model's response to the generation request. | ||
""" | ||
|
||
reqest_msgs: list[genai.types.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.
I would rename this list.
return GenerateResponse( | ||
message=Message( | ||
role=Role.MODEL, | ||
content=[TextPart(text=response.text)], |
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 want to preserve the multipart structure of the response, so each response part needs to be converted separately. Ex: Gemini can have code execution parts...
for p in msg.content: | ||
message_parts.append( | ||
genai.types.Part.from_text(text=p.root.text) | ||
) |
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.
Need to support multimodal parts as well. Need to test and convert all these part types:
TextPart | MediaPart | ToolRequestPart | ToolResponsePart | DataPart |
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.
perhaps call out to a helper converter function, and we can add support for each part type separately.
f14804b
to
34397e2
Compare
34397e2
to
70d65f9
Compare
Created google ai plugin
Checklist (if applicable):