@@ -3077,9 +3077,19 @@ async def handle_sse_stream(self, genparams, api_format):
30773077 await self .send_kai_sse_event (event_str )
30783078 tokenStr = "" # now the final finish reason can be sent alone
30793079 if api_format == 4 : # if oai chat, set format to expected openai streaming response
3080+ if streamDone and ("logprobs" in genparams and genparams ["logprobs" ]): # this is a hack that sends an extra message containing ALL the logprobs
3081+ lastlogprobs = handle .last_logprobs ()
3082+ logprobsdict = parse_last_logprobs (lastlogprobs )
3083+ addonstr = json .dumps ({"id" :"koboldcpp" ,"object" :"chat.completion.chunk" ,"created" :int (time .time ()),"model" :friendlymodelname ,"choices" :[{"index" :0 ,"finish_reason" :None ,"delta" :{'role' :'assistant' ,'content' :'' },"logprobs" :logprobsdict }]})
3084+ await self .send_oai_sse_event (addonstr )
30803085 event_str = json .dumps ({"id" :"koboldcpp" ,"object" :"chat.completion.chunk" ,"created" :int (time .time ()),"model" :friendlymodelname ,"choices" :[{"index" :0 ,"finish_reason" :currfinishreason ,"delta" :{'role' :'assistant' ,'content' :tokenStr }}]})
30813086 await self .send_oai_sse_event (event_str )
30823087 elif api_format == 3 : # non chat completions
3088+ if streamDone and ("logprobs" in genparams and genparams ["logprobs" ]): # this is a hack that sends an extra message containing ALL the logprobs
3089+ lastlogprobs = handle .last_logprobs ()
3090+ logprobsdict = parse_last_logprobs (lastlogprobs )
3091+ addonstr = json .dumps ({"id" :"koboldcpp" ,"object" :"text_completion" ,"created" :int (time .time ()),"model" :friendlymodelname ,"choices" :[{"index" :0 ,"finish_reason" :None ,"text" :"" ,"logprobs" :logprobsdict }]})
3092+ await self .send_oai_sse_event (addonstr )
30833093 event_str = json .dumps ({"id" :"koboldcpp" ,"object" :"text_completion" ,"created" :int (time .time ()),"model" :friendlymodelname ,"choices" :[{"index" :0 ,"finish_reason" :currfinishreason ,"text" :tokenStr }]})
30843094 await self .send_oai_sse_event (event_str )
30853095 else :
0 commit comments