forked from poe-platform/server-bot-quick-start
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatgpt_allcapsbot.py
31 lines (25 loc) · 1.05 KB
/
chatgpt_allcapsbot.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
"""
Sample bot that wraps chatGPT but makes responses use all-caps.
"""
from __future__ import annotations
from typing import AsyncIterable
from fastapi_poe import PoeBot
from fastapi_poe.client import MetaMessage, stream_request
from fastapi_poe.types import QueryRequest
from sse_starlette.sse import ServerSentEvent
class ChatGPTAllCapsBot(PoeBot):
async def get_response(self, query: QueryRequest) -> AsyncIterable[ServerSentEvent]:
async for msg in stream_request(query, "chatGPT", query.access_key):
if isinstance(msg, MetaMessage):
yield self.meta_event(
content_type=msg.content_type,
linkify=msg.linkify,
suggested_replies=True,
)
continue
elif msg.is_suggested_reply:
yield self.suggested_reply_event(msg.text.upper())
elif msg.is_replace_response:
yield self.replace_response_event(msg.text.upper())
else:
yield self.text_event(msg.text.upper())