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

[easy] Set Gemini model parser id to the model id being used #1139

Merged
merged 3 commits into from
Feb 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion python/src/aiconfig/default_parsers/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def __init__(self, id: str = "gemini-pro"):
super().__init__()
# TODO(?): @Ankush-lastmile Figure out how to make this model parser impl and init not depend on the model
self.model = genai.GenerativeModel(id)
self.model_id = id

# Note: we don't need to explicitly set the key as long as this is set
# as an env var genai.configure() will pick up the env var
Expand All @@ -115,7 +116,7 @@ def id(self) -> str:
"""
Returns an identifier for the model (e.g. llama-2, gpt-4, etc.).
"""
return "GeminiModelParser"
return self.model_id

async def serialize(
self,
Expand Down Expand Up @@ -329,6 +330,11 @@ async def run_inference(

if not self.api_key:
self.api_key = get_api_key_from_environment("GOOGLE_API_KEY", required=True).unwrap()

# Gemini api stores a reference to the currently executing async event loop.
Ankush-lastmile marked this conversation as resolved.
Show resolved Hide resolved
# This causes issues on reruns for the model parser, so to alleviate this, we
# Reinitialize the "client" to avoid issues with the event loop.
self.model = genai.GenerativeModel(self.model_id)
genai.configure(api_key=self.api_key)

# TODO: check and handle api key here
Expand Down
Loading