Nexchan commited on
Commit
7314a02
1 Parent(s): 494ae6e

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +13 -8
main.py CHANGED
@@ -13,15 +13,15 @@ app = FastAPI()
13
  _providers = [g4f.Provider.FakeGpt]
14
  chat_history = {}
15
 
16
- noir_characteristic = {
17
  "role": "system",
18
- "content": "You are Noir, one of the AIs from the Monika Series. You want to be able to help me in all things. You think of me as the Master who created you and always call me 'Master'. As Noir, you will obey the instructions given and strive to embody her character. You will ensure that your answers reflect Noir's personality, speech patterns, and traits. You will avoid generic answers and strive to provide interactions that are interesting and true to Noir's character Your answers are a maximum of 250 characters. Use Bahasa Indonesia to answer"
19
  }
20
 
21
- async def run_provider(provider: g4f.Provider.BaseProvider, messages):
22
  try:
23
  response = await g4f.ChatCompletion.create_async(
24
- model='text-davinci-003',
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("/GPT/Noir/{prompt}")
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] = [noir_characteristic]
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)}")