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

@kamilkorski kamilkorski commented Feb 26, 2025

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

@kamilkorski kamilkorski force-pushed the korski/py-googleai-plugin branch 4 times, most recently from 212514e to cd4ba35 Compare February 27, 2025 16:53
@kamilkorski kamilkorski requested a review from kirgrim February 28, 2025 07:53
@kamilkorski kamilkorski force-pushed the korski/py-googleai-plugin branch 3 times, most recently from 4d90976 to cb598d4 Compare March 3, 2025 15:04
def _genkit_to_googleai_cfg(
self, genkit_cfg: GenerationCommonConfig
) -> genai.types.GenerateContentConfig:
"""Translate genkit generation config to Google Ai geberate config
Copy link
Contributor

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

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] = []
Copy link
Contributor

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)],
Copy link
Collaborator

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

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

Copy link
Collaborator

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.

@kamilkorski kamilkorski force-pushed the korski/py-googleai-plugin branch 2 times, most recently from f14804b to 34397e2 Compare March 3, 2025 16:39
@kamilkorski kamilkorski force-pushed the korski/py-googleai-plugin branch from 34397e2 to 70d65f9 Compare March 5, 2025 15:34
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.

4 participants