-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathprompt_bot.py
60 lines (46 loc) · 1.46 KB
/
prompt_bot.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
51
52
53
54
55
56
57
58
59
60
"""
Sample bot that wraps Claude-3-Haiku but makes responses Haikus
"""
from __future__ import annotations
import os
from typing import AsyncIterable
import fastapi_poe as fp
from modal import App, Image, asgi_app
SYSTEM_PROMPT = """
All your replies are Haikus.
""".strip()
# TODO: set your bot access key and bot name for this bot to work
# see https://creator.poe.com/docs/quick-start#configuring-the-access-credentials
bot_access_key = os.getenv("POE_ACCESS_KEY")
bot_name = ""
class PromptBot(fp.PoeBot):
async def get_response(
self, request: fp.QueryRequest
) -> AsyncIterable[fp.PartialResponse]:
request.query = [
fp.ProtocolMessage(role="system", content=SYSTEM_PROMPT)
] + request.query
async for msg in fp.stream_request(
request, "Claude-3-Haiku", request.access_key
):
yield msg
async def get_settings(self, setting: fp.SettingsRequest) -> fp.SettingsResponse:
return fp.SettingsResponse(server_bot_dependencies={"Claude-3-Haiku": 1})
REQUIREMENTS = ["fastapi-poe"]
image = (
Image.debian_slim()
.pip_install(*REQUIREMENTS)
.env({"POE_ACCESS_KEY": bot_access_key})
)
app = App("prompt-bot-poe")
@app.function(image=image)
@asgi_app()
def fastapi_app():
bot = PromptBot()
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