(item: dict, )
| 148 | |
| 149 | @app.post('/telechat/gptDialog/v4') |
| 150 | async def doc_gptDialog_v3(item: dict, ): |
| 151 | session_res = [] |
| 152 | try: |
| 153 | dialog = item["dialog"] |
| 154 | except: |
| 155 | result_info = response_data("", "10301", "服务必填参数缺失", "0", "执行失败") |
| 156 | return result_info |
| 157 | odd = [i for i in range(len(dialog)) if i % 2 == 0] |
| 158 | even = [x for x in range(len(dialog)) if x % 2 == 1] |
| 159 | for index in odd: |
| 160 | if dialog[index].get("role", "") != "user": |
| 161 | result_info = response_data("", "10904", "服务请求参数dialog错误", "0", "执行失败") |
| 162 | return result_info |
| 163 | for index in even: |
| 164 | if dialog[index].get("role", "") != "bot": |
| 165 | result_info = response_data("", "10904", "服务请求参数dialog错误", "0", "执行失败") |
| 166 | return result_info |
| 167 | do_sample = item.get("do_sample", True) |
| 168 | max_length = item.get("max_length", 4096) |
| 169 | top_k = item.get("top_k", 20) |
| 170 | top_p = item.get("top_p", 0.2) |
| 171 | temperature = item.get("temperature", 0.1) |
| 172 | repetition_penalty = item.get("repetition_penalty", 1.03) |
| 173 | if not check_ex(do_sample, max_length, top_k, top_p, temperature, repetition_penalty): |
| 174 | result_info = response_data("", "10305", "请求参数范围错误", "0", "执行失败") |
| 175 | return result_info |
| 176 | try: |
| 177 | history, query = parse_data(dialog) |
| 178 | t_resp = model.chat(tokenizer, query, history=history, generation_config=generate_config, stream=False, |
| 179 | do_sample=do_sample, max_length=max_length, top_k=top_k, temperature=temperature, |
| 180 | repetition_penalty=repetition_penalty, top_p=top_p) |
| 181 | |
| 182 | res_data = { |
| 183 | 'role': "bot", |
| 184 | 'content': t_resp |
| 185 | } |
| 186 | result_info = res_data |
| 187 | except Exception: |
| 188 | import traceback |
| 189 | traceback.print_exc() |
| 190 | result_info = response_data('', "10903", "服务执行失败", "0", "执行失败") |
| 191 | return result_info |
| 192 | |
| 193 | |
| 194 | if __name__ == "__main__": |
nothing calls this directly
no test coverage detected