Mbonea commited on
Commit
3164c55
1 Parent(s): 963ef2b

web access gpt

Browse files
App/Chat/PoeChatrouter.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import APIRouter
2
+ from .utils.PoeBot import SendMessage
3
+ from .Schemas import BotRequest
4
+
5
+
6
+ chat_router = APIRouter(tags=["Chat"])
7
+
8
+
9
+ @chat_router.post("/chat")
10
+ async def chat(req: BotRequest):
11
+ return await SendMessage(req)
App/Chat/Schemas.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from pydantic import BaseModel
2
+
3
+
4
+ class BotRequest(BaseModel):
5
+ message: str
6
+ bot: str
App/Chat/utils/PoeBot.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
10
+
11
+ async def SendMessage(req: BotRequest):
12
+ global CHAT_CODE
13
+ if CHAT_CODE == "":
14
+ for chunk in client.send_message(
15
+ req.bot, req.message, chatCode="2rx4w5jt6zf96tn7dr1"
16
+ ):
17
+ pass
18
+ CHAT_CODE = chunk["chatCode"]
19
+ else:
20
+ for chunk in client.send_message(req.bot, req.message, chatCode=CHAT_CODE):
21
+ pass
22
+
23
+ return chunk["text"]
App/app.py CHANGED
@@ -1,10 +1,11 @@
1
  from fastapi import FastAPI
2
 
3
  from fastapi.middleware.gzip import GZipMiddleware
 
4
  from .TTS.TTSRoutes import tts_router
5
 
6
  from .Embedding.EmbeddingRoutes import embeddigs_router
7
-
8
 
9
  from fastapi.middleware.cors import CORSMiddleware
10
 
@@ -47,3 +48,4 @@ async def landing_page():
47
 
48
  app.include_router(embeddigs_router)
49
  app.include_router(tts_router)
 
 
1
  from fastapi import FastAPI
2
 
3
  from fastapi.middleware.gzip import GZipMiddleware
4
+
5
  from .TTS.TTSRoutes import tts_router
6
 
7
  from .Embedding.EmbeddingRoutes import embeddigs_router
8
+ from .Chat.PoeChatrouter import chat_router
9
 
10
  from fastapi.middleware.cors import CORSMiddleware
11
 
 
48
 
49
  app.include_router(embeddigs_router)
50
  app.include_router(tts_router)
51
+ app.include_router(chat_router)