MCPcopy Index your code
hub / github.com/nashsu/FreeAskInternet / predict

Function predict

server.py:141–178  ·  view source on GitHub ↗
(query: str, history: None, model_id: str)

Source from the content-addressed store, hash-verified

139
140
141def predict(query: str, history: None, model_id: str):
142 choice_data = ChatCompletionResponseStreamChoice(
143 index=0,
144 delta=DeltaMessage(role="assistant"),
145 finish_reason=None
146 )
147 chunk = ChatCompletionResponse(model=model_id, choices=[
148 choice_data], object="chat.completion.chunk")
149 yield "{}".format(chunk.json(exclude_unset=True))
150 new_response = ""
151 current_length = 0
152 for token in free_ask_internet.ask_internet(query=query):
153
154 new_response += token
155 if len(new_response) == current_length:
156 continue
157
158 new_text = new_response[current_length:]
159 current_length = len(new_response)
160
161 choice_data = ChatCompletionResponseStreamChoice(
162 index=0,
163 delta=DeltaMessage(content=new_text,role="assistant"),
164 finish_reason=None
165 )
166 chunk = ChatCompletionResponse(model=model_id, choices=[
167 choice_data], object="chat.completion.chunk")
168 yield "{}".format(chunk.json(exclude_unset=True))
169
170 choice_data = ChatCompletionResponseStreamChoice(
171 index=0,
172 delta=DeltaMessage(),
173 finish_reason="stop"
174 )
175 chunk = ChatCompletionResponse(model=model_id, choices=[
176 choice_data], object="chat.completion.chunk")
177 yield "{}".format(chunk.json(exclude_unset=True))
178 yield '[DONE]'
179
180
181

Callers 1

create_chat_completionFunction · 0.85

Calls 3

DeltaMessageClass · 0.85

Tested by

no test coverage detected