-
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 branch 'main' into package-zip
- Loading branch information
Showing
7 changed files
with
206 additions
and
3 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 |
---|---|---|
@@ -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
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,42 @@ | ||
import requests | ||
from rich.console import Console | ||
from rich.table import Table | ||
from rich.text import Text | ||
import time | ||
import click | ||
from yaspin import yaspin | ||
|
||
def fetch_and_display_logs(cloud_url, headers, params): | ||
console = Console() | ||
table = Table(show_header=True, header_style="bold magenta") | ||
table.add_column("Timestamp") | ||
table.add_column("Severity") | ||
table.add_column("Summary") | ||
|
||
while True: | ||
with yaspin(text="Logs...", color="yellow") as spinner: | ||
response = requests.get(cloud_url, headers=headers, params=params) | ||
|
||
if response.ok: | ||
response_data = response.json() | ||
data = response_data.get('data') | ||
if data is not None: | ||
logs = data.get('logs') | ||
if logs: | ||
for log in logs: | ||
severity_color = 'blue' if log['severity'].lower() in ['notice', 'info', 'debug'] else 'red' if log['severity'].lower() in ['alert', 'critical', 'error'] else 'yellow' | ||
|
||
table.add_row(log['timestamp'], Text(log['severity'], style=severity_color), Text(log.get('text', ''), style=severity_color)) | ||
|
||
console.clear() | ||
console.print(table) | ||
# Update the params for the next request | ||
params['pageToken'] = data.get('nextPageToken') | ||
params['startTime'] = data.get('startTime') | ||
else: | ||
click.echo(click.style("No logs found in the response.", fg='yellow')) | ||
else: | ||
click.echo(click.style("Failed to retrieve logs.", fg='red')) | ||
|
||
# Poll the endpoint every 3 seconds | ||
time.sleep(3) |