-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for Google Palm (#126)
* feat: Add support for Google Palm * Fix linting * rename test * add generative-ai dependency * Refactor with Base class * fix linting issues
- Loading branch information
1 parent
a899d1a
commit baedcbc
Showing
6 changed files
with
506 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,7 @@ pandasai.egg-info | |
/venv | ||
|
||
# command line | ||
/pandasai_cli.egg-info | ||
/pandasai_cli.egg-info | ||
|
||
# pycharm | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""Google Palm LLM""" | ||
from .base import BaseGoogle | ||
|
||
|
||
class GooglePalm(BaseGoogle): | ||
"""Google Palm LLM""" | ||
|
||
model: str = "models/text-bison-001" | ||
|
||
def __init__(self, api_key: str, **kwargs): | ||
self._configure(api_key=api_key) | ||
self._set_params(**kwargs) | ||
|
||
def _valid_params(self): | ||
return super()._valid_params() + ["model"] | ||
|
||
def _validate(self): | ||
super()._validate() | ||
|
||
if not self.model: | ||
raise ValueError("model is required.") | ||
|
||
def _generate_text(self, prompt: str) -> str: | ||
""" | ||
Generates text for prompt | ||
Args: | ||
prompt (str): Prompt | ||
Returns: | ||
str: LLM response | ||
""" | ||
self._validate() | ||
completion = self.genai.generate_text( | ||
model=self.model, | ||
prompt=prompt, | ||
temperature=self.temperature, | ||
top_p=self.top_p, | ||
top_k=self.top_k, | ||
max_output_tokens=self.max_output_tokens, | ||
) | ||
return completion.result | ||
|
||
@property | ||
def type(self) -> str: | ||
return "google-palm" |
Oops, something went wrong.