@@ -25,42 +25,12 @@ def status():
2525 "models" : {s : persona .config .get (s , {}).get ("model" )
2626 for s in persona .solvers .loaded_modules .keys ()}}
2727
28- @app .route ("/completions" , methods = ["POST" ])
29- def completions ():
30- prompt = request .get_json ().get ("prompt" )
31-
32- completion_id = "" .join (random .choices (string .ascii_letters + string .digits , k = 28 ))
33- completion_timestamp = int (time .time ())
34-
35- response = persona .complete (prompt )
36-
37- return {"choices" : [
38- {
39- "finish_reason" : "length" ,
40- "index" : 0 ,
41- "text" : response
42- }
43- ],
44- "id" : f"chatcmpl-{ completion_id } " ,
45- "created" : completion_timestamp ,
46- "model" : persona .name ,
47- "object" : "text_completion" ,
48- "usage" : {
49- "prompt_tokens" : None ,
50- "completion_tokens" : None ,
51- "total_tokens" : None ,
52- },
53-
54- }
55-
5628 @app .route ("/chat/completions" , methods = ["POST" ])
5729 def chat_completions ():
5830 data = request .get_json ()
5931 stream = data .get ("stream" , False )
6032 messages = data .get ("messages" )
6133
62- response = persona .chat (messages )
63-
6434 completion_id = "" .join (random .choices (string .ascii_letters + string .digits , k = 28 ))
6535 completion_timestamp = int (time .time ())
6636
@@ -75,7 +45,7 @@ def chat_completions():
7545 "index" : 0 ,
7646 "message" : {
7747 "role" : "assistant" ,
78- "content" : response ,
48+ "content" : persona . chat ( messages ) ,
7949 },
8050 "finish_reason" : "stop" ,
8151 }
@@ -88,7 +58,7 @@ def chat_completions():
8858 }
8959
9060 def streaming ():
91- for chunk in response :
61+ for chunk in persona . stream ( messages ) :
9262 completion_data = {
9363 "id" : f"chatcmpl-{ completion_id } " ,
9464 "object" : "chat.completion.chunk" ,
0 commit comments