-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathechobot.py
50 lines (37 loc) · 1.14 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
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
import os
from typing import AsyncIterable
import fastapi_poe as fp
from modal import App, Image, asgi_app
# TODO: set your bot access key and bot name for full functionality
# see https://creator.poe.com/docs/quick-start#configuring-the-access-credentials
bot_access_key = os.getenv("POE_ACCESS_KEY")
bot_name = ""
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"]
image = (
Image.debian_slim()
.pip_install(*REQUIREMENTS)
.env({"POE_ACCESS_KEY": bot_access_key})
)
app = App("echobot-poe")
@app.function(image=image)
@asgi_app()
def fastapi_app():
bot = EchoBot()
app = fp.make_app(
bot,
access_key=bot_access_key,
bot_name=bot_name,
allow_without_key=not (bot_access_key and bot_name),
)
return app