| 118 | return resData |
| 119 | |
| 120 | def make_resData_stream(data, chat=False, time_now = 0, start=False): |
| 121 | resData = { |
| 122 | "id": "chatcmpl" if (chat) else "cmpl", |
| 123 | "object": "chat.completion.chunk" if (chat) else "text_completion.chunk", |
| 124 | "created": time_now, |
| 125 | "model": "LLaMA_CPP", |
| 126 | "choices": [ |
| 127 | { |
| 128 | "finish_reason": None, |
| 129 | "index": 0 |
| 130 | } |
| 131 | ] |
| 132 | } |
| 133 | slot_id = data["slot_id"] |
| 134 | if (chat): |
| 135 | if (start): |
| 136 | resData["choices"][0]["delta"] = { |
| 137 | "role": "assistant" |
| 138 | } |
| 139 | else: |
| 140 | resData["choices"][0]["delta"] = { |
| 141 | "content": data["content"] |
| 142 | } |
| 143 | if (data["stop"]): |
| 144 | resData["choices"][0]["finish_reason"] = "stop" if (data["stopped_eos"] or data["stopped_word"]) else "length" |
| 145 | else: |
| 146 | resData["choices"][0]["text"] = data["content"] |
| 147 | if (data["stop"]): |
| 148 | resData["choices"][0]["finish_reason"] = "stop" if (data["stopped_eos"] or data["stopped_word"]) else "length" |
| 149 | |
| 150 | return resData |
| 151 | |
| 152 | |
| 153 | @app.route('/chat/completions', methods=['POST']) |