MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / make_resData

Function make_resData

examples/server/api_like_OAI.py:85–118  ·  view source on GitHub ↗
(data, chat=False, promptToken=[])

Source from the content-addressed store, hash-verified

83 return postData
84
85def make_resData(data, chat=False, promptToken=[]):
86 resData = {
87 "id": "chatcmpl" if (chat) else "cmpl",
88 "object": "chat.completion" if (chat) else "text_completion",
89 "created": int(time.time()),
90 "truncated": data["truncated"],
91 "model": "LLaMA_CPP",
92 "usage": {
93 "prompt_tokens": data["tokens_evaluated"],
94 "completion_tokens": data["tokens_predicted"],
95 "total_tokens": data["tokens_evaluated"] + data["tokens_predicted"]
96 }
97 }
98 if (len(promptToken) != 0):
99 resData["promptToken"] = promptToken
100 if (chat):
101 #only one choice is supported
102 resData["choices"] = [{
103 "index": 0,
104 "message": {
105 "role": "assistant",
106 "content": data["content"],
107 },
108 "finish_reason": "stop" if (data["stopped_eos"] or data["stopped_word"]) else "length"
109 }]
110 else:
111 #only one choice is supported
112 resData["choices"] = [{
113 "text": data["content"],
114 "index": 0,
115 "logprobs": None,
116 "finish_reason": "stop" if (data["stopped_eos"] or data["stopped_word"]) else "length"
117 }]
118 return resData
119
120def make_resData_stream(data, chat=False, time_now = 0, start=False):
121 resData = {

Callers 2

chat_completionsFunction · 0.85
completionFunction · 0.85

Calls 1

timeMethod · 0.80

Tested by

no test coverage detected