-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from jahanvir/main
Added Support for Google PaLM API
- Loading branch information
Showing
5 changed files
with
120 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
OPENAI_API_KEY= | ||
HUGGINGFACEHUB_API_TOKEN= | ||
PALM_API_KEY= |
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,49 @@ | ||
--- | ||
sidebar_position: 2 | ||
--- | ||
|
||
# Google PaLM AI bot | ||
|
||
This bot makes an API call to PaLMAI and processes the user input. It uses PaLM Chat. | ||
|
||
```py | ||
import os | ||
from textbase import bot, Message | ||
from textbase.models import PalmAI | ||
from typing import List | ||
|
||
# Load your PALM API key | ||
# PALMAI.api_key = "" | ||
# or from environment variable: | ||
PalmAI.api_key = os.getenv("PALM_API_KEY") | ||
|
||
@bot() | ||
def on_message(message_history: List[Message], state: dict = None): | ||
|
||
bot_response = PalmAI.generate( | ||
message_history=message_history, # Assuming history is the list of user messages | ||
) | ||
|
||
response = { | ||
"data": { | ||
"messages": [ | ||
{ | ||
"data_type": "STRING", | ||
"value": bot_response | ||
} | ||
], | ||
"state": state | ||
}, | ||
"errors": [ | ||
{ | ||
"message": "" | ||
} | ||
] | ||
} | ||
|
||
return { | ||
"status_code": 200, | ||
"response": response | ||
} | ||
|
||
``` |
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,39 @@ | ||
import os | ||
from textbase import bot, Message | ||
from textbase.models import PalmAI | ||
from typing import List | ||
|
||
# Load your PALM API key | ||
# PALMAI.api_key = "" | ||
# or from environment variable: | ||
PalmAI.api_key = os.getenv("PALM_API_KEY") | ||
|
||
|
||
@bot() | ||
def on_message(message_history: List[Message], state: dict = None): | ||
|
||
bot_response = PalmAI.generate( | ||
message_history=message_history, # Assuming history is the list of user messages | ||
) | ||
|
||
response = { | ||
"data": { | ||
"messages": [ | ||
{ | ||
"data_type": "STRING", | ||
"value": bot_response | ||
} | ||
], | ||
"state": state | ||
}, | ||
"errors": [ | ||
{ | ||
"message": "" | ||
} | ||
] | ||
} | ||
|
||
return { | ||
"status_code": 200, | ||
"response": response | ||
} |
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