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: Add Support for Google Palm AI API #123

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
Feat: Add Support for Google Palm AI API
  • Loading branch information
GeekGawd committed Sep 3, 2023
commit f4093f0fc12d61ad486fd9fe951ea6a37c7edf4c
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ tabulate = "^0.9.0"
functions-framework = "^3.4.0"
yaspin = "^3.0.0"
pydantic = "^2.3.0"
google-generativeai = "^0.1.0"

[build-system]
requires = ["poetry-core"]
39 changes: 38 additions & 1 deletion textbase/models.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import traceback

from textbase import Message
import google.generativeai as palm

# Return list of values of content.
def get_contents(message: Message, data_type: str):
@@ -143,4 +144,40 @@ def generate(
data = json.loads(response.text) # parse the JSON data into a dictionary
message = data['message']

return message
return message

class PalmAI:
api_key = None
response = None
client = None

@classmethod
def generate(
cls,
system_prompt: str,
message_history: list[Message],
model="models/chat-bison-001",
examples: typing.List[typing.Tuple] = None,
temperature = 0.7,
):
assert cls.api_key is not None, "PalmAI API key is not set."
if cls.client == None:
palm.configure(api_key=cls.api_key)
cls.client = palm

most_recent_message = get_contents(message_history[-1], "STRING")[0]["content"]

if cls.response == None:
cls.response = cls.client.chat(
context = system_prompt,
model = model,
temperature=temperature,
messages=most_recent_message
)

else:
cls.response = cls.response.reply(
message=most_recent_message
)

return cls.response.last