/generate
Browse files- App/Chat/PoeChatrouter.py +6 -1
- App/Chat/utils/PoeBot.py +30 -0
App/Chat/PoeChatrouter.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
from fastapi import APIRouter
|
| 2 |
-
from .utils.PoeBot import SendMessage
|
| 3 |
from .Schemas import BotRequest
|
| 4 |
|
| 5 |
|
|
@@ -9,3 +9,8 @@ chat_router = APIRouter(tags=["Chat"])
|
|
| 9 |
@chat_router.post("/chat")
|
| 10 |
async def chat(req: BotRequest):
|
| 11 |
return await SendMessage(req)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import APIRouter
|
| 2 |
+
from .utils.PoeBot import SendMessage, GenerateImage
|
| 3 |
from .Schemas import BotRequest
|
| 4 |
|
| 5 |
|
|
|
|
| 9 |
@chat_router.post("/chat")
|
| 10 |
async def chat(req: BotRequest):
|
| 11 |
return await SendMessage(req)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@chat_router.post("/generate_image")
|
| 15 |
+
async def chat(req: BotRequest):
|
| 16 |
+
return await GenerateImage(req)
|
App/Chat/utils/PoeBot.py
CHANGED
|
@@ -1,12 +1,15 @@
|
|
| 1 |
from poe_api_wrapper import PoeApi
|
| 2 |
from App.Chat.Schemas import BotRequest
|
|
|
|
| 3 |
|
| 4 |
# import pprint
|
|
|
|
| 5 |
|
| 6 |
|
| 7 |
client = PoeApi("sXvCnfYy8CHnXNTRlxhmVg==")
|
| 8 |
CHAT_CODE = ""
|
| 9 |
print(client.get_chat_history()["data"])
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
async def SendMessage(req: BotRequest):
|
|
@@ -34,3 +37,30 @@ async def SendMessage(req: BotRequest):
|
|
| 34 |
CHAT_CODE = ""
|
| 35 |
counter += 1
|
| 36 |
print(client.get_chat_history()["data"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from poe_api_wrapper import PoeApi
|
| 2 |
from App.Chat.Schemas import BotRequest
|
| 3 |
+
import re
|
| 4 |
|
| 5 |
# import pprint
|
| 6 |
+
pattern = r"\!\[.*?\]\((.*?)\)"
|
| 7 |
|
| 8 |
|
| 9 |
client = PoeApi("sXvCnfYy8CHnXNTRlxhmVg==")
|
| 10 |
CHAT_CODE = ""
|
| 11 |
print(client.get_chat_history()["data"])
|
| 12 |
+
GEN_CODE = ""
|
| 13 |
|
| 14 |
|
| 15 |
async def SendMessage(req: BotRequest):
|
|
|
|
| 37 |
CHAT_CODE = ""
|
| 38 |
counter += 1
|
| 39 |
print(client.get_chat_history()["data"])
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
async def GenerateImage(req: BotRequest):
|
| 43 |
+
global GEN_CODE, client
|
| 44 |
+
counter = 0
|
| 45 |
+
while True:
|
| 46 |
+
try:
|
| 47 |
+
if GEN_CODE == "":
|
| 48 |
+
for chunk in client.send_message(
|
| 49 |
+
req.bot, req.message, chatCode="2rx4w5jt6zf96tn7dr1"
|
| 50 |
+
):
|
| 51 |
+
pass
|
| 52 |
+
GEN_CODE = chunk["chatCode"]
|
| 53 |
+
else:
|
| 54 |
+
for chunk in client.send_message(
|
| 55 |
+
req.bot, req.message, chatCode=GEN_CODE
|
| 56 |
+
):
|
| 57 |
+
pass
|
| 58 |
+
|
| 59 |
+
return {"response": re.findall(pattern, chunk["response"])[0], "code": 200}
|
| 60 |
+
except:
|
| 61 |
+
if counter > 4:
|
| 62 |
+
return {"response": "Try again later", "code": 500}
|
| 63 |
+
client = PoeApi("sXvCnfYy8CHnXNTRlxhmVg==")
|
| 64 |
+
GEN_CODE = ""
|
| 65 |
+
counter += 1
|
| 66 |
+
print(client.get_chat_history()["data"])
|