Yuuki0125 commited on
Commit
ba292df
·
1 Parent(s): 20454c3
Files changed (3) hide show
  1. Dockerfile +11 -0
  2. main.py +57 -0
  3. requirements.txt +4 -0
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10.9
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ COPY . .
10
+
11
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
main.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import List
2
+ from fastapi import FastAPI, HTTPException, Response, Query, Request
3
+ from typing import Optional
4
+ from pydantic import BaseModel
5
+ from characterai import PyCAI
6
+
7
+ app = FastAPI()
8
+
9
+ @app.get("/")
10
+ def Another():
11
+ return {"Another": "Apa Lu Liat-liat?"}
12
+
13
+
14
+ @app.get("/AnotherAPI/{character}/chat/{api_key}/{message}")
15
+ async def chat_endpoint(character: str, api_key: str, message: str):
16
+ try:
17
+ if character == '2B':
18
+ client = PyCAI(api_key)
19
+ chat = client.chat.get_chat('csTC3hw0Fnj1Whnl0uV1Nb3_oYIillMQtdBH5NEl0Gs')
20
+ elif character == 'Narator':
21
+ client = PyCAI(api_key)
22
+ chat = client.chat.get_chat('oRrOSTDibssHQwoKEfNtwBwgBEFDr1aKfVPXjY1d8nA')
23
+ else:
24
+ return {"Another": "API Lu Mana?."}
25
+
26
+ participants = chat.get('participants', [])
27
+ if not participants:
28
+ return {"error": "Error"}
29
+ tgt = participants[1]['user']['username']
30
+ data = client.chat.send_message(chat['external_id'], tgt, message)
31
+ text = data['replies'][0]['text']
32
+ return {character.capitalize(): f"{text}"}
33
+ except Exception as e:
34
+ return {"error": f"Error: {e}"}
35
+
36
+ @app.get("/AnotherAPI/{character}/new_chat/{api_key}/{prompt}")
37
+ async def new_chat_endpoint(character: str, api_key: str, prompt: str):
38
+ try:
39
+ if character == '2B':
40
+ client = PyCAI(api_key)
41
+ chat = client.chat.new_chat('csTC3hw0Fnj1Whnl0uV1Nb3_oYIillMQtdBH5NEl0Gs')
42
+ elif character == 'Narator':
43
+ client = PyCAI(api_key)
44
+ chat = client.chat.new_chat('oRrOSTDibssHQwoKEfNtwBwgBEFDr1aKfVPXjY1d8nA')
45
+ else:
46
+ return {"Another": "API Lu Mana?."}
47
+
48
+ participants = chat.get('participants', [])
49
+ if not participants:
50
+ return {"error": "Error"}
51
+ tgt = participants[1]['user']['username']
52
+ data = client.chat.send_message(chat['external_id'], tgt, prompt)
53
+ text = data['replies'][0]['text']
54
+ return {character.capitalize(): f"{text}"}
55
+ except Exception as e:
56
+ return {"error": f"Error: {e}"}
57
+
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ characterai
4
+ g4f