-
Notifications
You must be signed in to change notification settings - Fork 195
/
echobot.py
37 lines (25 loc) · 958 Bytes
/
echobot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
Sample bot that echoes back messages.
This is the simplest possible bot and a great place to start if you want to build your own bot.
"""
from __future__ import annotations
from typing import AsyncIterable
import fastapi_poe as fp
from modal import App, Image, asgi_app
class EchoBot(fp.PoeBot):
async def get_response(
self, request: fp.QueryRequest
) -> AsyncIterable[fp.PartialResponse]:
last_message = request.query[-1].content
yield fp.PartialResponse(text=last_message)
REQUIREMENTS = ["fastapi-poe==0.0.48"]
image = Image.debian_slim().pip_install(*REQUIREMENTS)
app = App("echobot-poe")
@app.function(image=image)
@asgi_app()
def fastapi_app():
bot = EchoBot()
# see https://creator.poe.com/docs/quick-start#configuring-the-access-credentials
# app = fp.make_app(bot, access_key=<YOUR_ACCESS_KEY>, bot_name=<YOUR_BOT_NAME>)
app = fp.make_app(bot, allow_without_key=True)
return app