forked from poe-platform/server-bot-quick-start
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'poe-platform:main' into master
- Loading branch information
Showing
10 changed files
with
268 additions
and
181 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
File renamed without changes.
File renamed without changes.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,48 @@ | ||
""" | ||
Sample bot that shows the query sent to the bot. | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
from typing import AsyncIterable | ||
|
||
import fastapi_poe as fp | ||
from devtools import PrettyFormat | ||
from modal import App, Image, asgi_app | ||
|
||
pformat = PrettyFormat(width=85) | ||
|
||
|
||
class LogBot(fp.PoeBot): | ||
async def get_response( | ||
self, request: fp.QueryRequest | ||
) -> AsyncIterable[fp.PartialResponse]: | ||
yield fp.PartialResponse(text="```python\n" + pformat(request) + "\n```") | ||
|
||
async def get_settings(self, setting: fp.SettingsRequest) -> fp.SettingsResponse: | ||
return fp.SettingsResponse( | ||
allow_attachments=True, enable_image_comprehension=True | ||
) | ||
|
||
|
||
REQUIREMENTS = ["fastapi-poe==0.0.47", "devtools==0.12.2"] | ||
image = Image.debian_slim().pip_install(*REQUIREMENTS) | ||
app = App("log-bot-poe") | ||
|
||
|
||
@app.function(image=image) | ||
@asgi_app() | ||
def fastapi_app(): | ||
bot = LogBot() | ||
# Optionally, provide your Poe access key here: | ||
# 1. You can go to https://poe.com/create_bot?server=1 to generate an access key. | ||
# 2. We strongly recommend using a key for a production bot to prevent abuse, | ||
# but the starter examples disable the key check for convenience. | ||
# 3. You can also store your access key on modal.com and retrieve it in this function | ||
# by following the instructions at: https://modal.com/docs/guide/secrets | ||
# POE_ACCESS_KEY = "" | ||
# app = make_app(bot, access_key=POE_ACCESS_KEY) | ||
app = fp.make_app(bot, allow_without_key=True) | ||
return app |
Oops, something went wrong.