@@ -2774,15 +2774,10 @@ def run_blocking(): # api format 1=basic,2=kai,3=oai,4=oai-chat
27742774
27752775 utfprint ("\n Output: " + recvtxt ,1 )
27762776
2777- if api_format == 1 :
2778- res = {"data" : {"seqs" : [recvtxt ]}}
2779- elif api_format == 3 :
2780- res = {"id" : "cmpl-A1" , "object" : "text_completion" , "created" : int (time .time ()), "model" : friendlymodelname ,
2781- "usage" : {"prompt_tokens" : prompttokens , "completion_tokens" : comptokens , "total_tokens" : (prompttokens + comptokens )},
2782- "choices" : [{"text" : recvtxt , "index" : 0 , "finish_reason" : currfinishreason , "logprobs" :logprobsdict }]}
2783- elif api_format == 4 :
2777+ #tool calls resolution
2778+ tool_calls = []
2779+ if api_format == 4 or api_format == 2 :
27842780 using_openai_tools = genparams .get ('using_openai_tools' , False )
2785- tool_calls = []
27862781 if using_openai_tools :
27872782 tool_calls = extract_json_from_string (recvtxt )
27882783 if tool_calls and len (tool_calls )> 0 :
@@ -2793,6 +2788,14 @@ def run_blocking(): # api format 1=basic,2=kai,3=oai,4=oai-chat
27932788 tc ["function" ]["arguments" ] = json .dumps (tcarg )
27942789 recvtxt = None
27952790 currfinishreason = "tool_calls"
2791+
2792+ if api_format == 1 :
2793+ res = {"data" : {"seqs" : [recvtxt ]}}
2794+ elif api_format == 3 :
2795+ res = {"id" : "cmpl-A1" , "object" : "text_completion" , "created" : int (time .time ()), "model" : friendlymodelname ,
2796+ "usage" : {"prompt_tokens" : prompttokens , "completion_tokens" : comptokens , "total_tokens" : (prompttokens + comptokens )},
2797+ "choices" : [{"text" : recvtxt , "index" : 0 , "finish_reason" : currfinishreason , "logprobs" :logprobsdict }]}
2798+ elif api_format == 4 :
27962799 res = {"id" : "chatcmpl-A1" , "object" : "chat.completion" , "created" : int (time .time ()), "model" : friendlymodelname ,
27972800 "usage" : {"prompt_tokens" : prompttokens , "completion_tokens" : comptokens , "total_tokens" : (prompttokens + comptokens )},
27982801 "choices" : [{"index" : 0 , "message" : {"role" : "assistant" , "content" : recvtxt , "tool_calls" : tool_calls }, "finish_reason" : currfinishreason , "logprobs" :logprobsdict }]}
@@ -2804,8 +2807,8 @@ def run_blocking(): # api format 1=basic,2=kai,3=oai,4=oai-chat
28042807 res = {"model" : friendlymodelname ,"created_at" : str (datetime .now (timezone .utc ).isoformat ()),"response" :recvtxt ,"done" : True ,"done_reason" :currfinishreason ,"context" : tokarr ,"total_duration" : 1 ,"load_duration" : 1 ,"prompt_eval_count" : prompttokens ,"prompt_eval_duration" : 1 ,"eval_count" : comptokens ,"eval_duration" : 1 }
28052808 elif api_format == 7 :
28062809 res = {"model" : friendlymodelname ,"created_at" : str (datetime .now (timezone .utc ).isoformat ()),"message" :{"role" :"assistant" ,"content" :recvtxt },"done" : True ,"done_reason" :currfinishreason ,"total_duration" : 1 ,"load_duration" : 1 ,"prompt_eval_count" : prompttokens ,"prompt_eval_duration" : 1 ,"eval_count" : comptokens ,"eval_duration" : 1 }
2807- else :
2808- res = {"results" : [{"text" : recvtxt , "finish_reason" : currfinishreason , "logprobs" :logprobsdict , "prompt_tokens" : prompttokens , "completion_tokens" : comptokens }]}
2810+ else : #kcpp format
2811+ res = {"results" : [{"text" : recvtxt , "tool_calls" : tool_calls , " finish_reason" : currfinishreason , "logprobs" :logprobsdict , "prompt_tokens" : prompttokens , "completion_tokens" : comptokens }]}
28092812
28102813 try :
28112814 return res
0 commit comments