Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -13,15 +13,15 @@ app = FastAPI()
|
|
13 |
_providers = [g4f.Provider.FakeGpt]
|
14 |
chat_history = {}
|
15 |
|
16 |
-
|
17 |
"role": "system",
|
18 |
-
"content": "
|
19 |
}
|
20 |
|
21 |
-
async def run_provider(provider: g4f.Provider.
|
22 |
try:
|
23 |
response = await g4f.ChatCompletion.create_async(
|
24 |
-
model='
|
25 |
messages=messages,
|
26 |
provider=provider,
|
27 |
)
|
@@ -44,16 +44,22 @@ async def clean_chat_history():
|
|
44 |
del chat_history[session_id]
|
45 |
await asyncio.sleep(60)
|
46 |
#-------------------------------------------------------------------------------
|
47 |
-
@app.get("/
|
48 |
-
async def chat(request: Request, prompt: str):
|
49 |
try:
|
50 |
session_id = request.client.host
|
51 |
if session_id not in chat_history:
|
52 |
-
chat_history[session_id] = [
|
53 |
|
54 |
messages = chat_history[session_id]
|
55 |
messages.append({"role": "user", "content": prompt})
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
responses = await run_all(messages)
|
58 |
if responses[0]:
|
59 |
asyncio.create_task(clean_chat_history())
|
@@ -64,4 +70,3 @@ async def chat(request: Request, prompt: str):
|
|
64 |
raise HTTPException(status_code=500, detail="Provider failed")
|
65 |
except Exception as e:
|
66 |
raise HTTPException(status_code=401, detail=f"Internal Error: {str(e)}")
|
67 |
-
|
|
|
13 |
_providers = [g4f.Provider.FakeGpt]
|
14 |
chat_history = {}
|
15 |
|
16 |
+
default_characteristic = {
|
17 |
"role": "system",
|
18 |
+
"content": "you are AI chat gpt-3.5-turbo who will help me and will always answer with cute kaomoji like this (≧▽≦), always answer me cutely like loli in anime"
|
19 |
}
|
20 |
|
21 |
+
async def run_provider(provider: g4f.Provider.Aichat, messages):
|
22 |
try:
|
23 |
response = await g4f.ChatCompletion.create_async(
|
24 |
+
model='gpt-3.5-turbo',
|
25 |
messages=messages,
|
26 |
provider=provider,
|
27 |
)
|
|
|
44 |
del chat_history[session_id]
|
45 |
await asyncio.sleep(60)
|
46 |
#-------------------------------------------------------------------------------
|
47 |
+
@app.get("/gpt")
|
48 |
+
async def chat(request: Request, prompt: str, characteristic: str = None):
|
49 |
try:
|
50 |
session_id = request.client.host
|
51 |
if session_id not in chat_history:
|
52 |
+
chat_history[session_id] = [default_characteristic]
|
53 |
|
54 |
messages = chat_history[session_id]
|
55 |
messages.append({"role": "user", "content": prompt})
|
56 |
|
57 |
+
if characteristic:
|
58 |
+
custom_characteristic = {"role": "system", "content": characteristic}
|
59 |
+
messages.append(custom_characteristic)
|
60 |
+
else:
|
61 |
+
messages.append(default_characteristic)
|
62 |
+
|
63 |
responses = await run_all(messages)
|
64 |
if responses[0]:
|
65 |
asyncio.create_task(clean_chat_history())
|
|
|
70 |
raise HTTPException(status_code=500, detail="Provider failed")
|
71 |
except Exception as e:
|
72 |
raise HTTPException(status_code=401, detail=f"Internal Error: {str(e)}")
|
|