Skip to content

Commit

Permalink
fix api_key error
Browse files Browse the repository at this point in the history
  • Loading branch information
KCaverly committed Feb 21, 2024
1 parent 22ea0da commit 96949a7
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions dsp/modules/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
google_api_error = Exception
# print("Not loading Google because it is not installed.")


def backoff_hdlr(details):
"""Handler from https://pypi.org/project/backoff/"""
print(
Expand All @@ -33,10 +34,7 @@ class Google(LM):
"""

def __init__(
self,
model: str = "gemini-pro-1.0",
api_key: Optional[str] = None,
**kwargs
self, model: str = "gemini-pro-1.0", api_key: Optional[str] = None, **kwargs
):
"""
Parameters
Expand All @@ -51,15 +49,17 @@ def __init__(
Additional arguments to pass to the API provider.
"""
super().__init__(model)
self.google = genai.configure(api_key=self.api_key)
self.google = genai.configure(api_key=api_key)
self.provider = "google"
self.kwargs = {
"model_name": model,
"temperature": 0.0 if "temperature" not in kwargs else kwargs["temperature"],
"temperature": 0.0
if "temperature" not in kwargs
else kwargs["temperature"],
"max_output_tokens": 2048,
"top_p": 1,
"top_k": 1,
**kwargs
**kwargs,
}

self.history: list[dict[str, Any]] = []
Expand All @@ -85,7 +85,7 @@ def basic_request(self, prompt: str, **kwargs):

@backoff.on_exception(
backoff.expo,
(google_api_error),
(Exception),
max_time=1000,
on_backoff=backoff_hdlr,
giveup=giveup_hdlr,
Expand All @@ -99,6 +99,6 @@ def __call__(
prompt: str,
only_completed: bool = True,
return_sorted: bool = False,
**kwargs
**kwargs,
):
return self.request(prompt, **kwargs)

0 comments on commit 96949a7

Please sign in to comment.