MCPcopy
hub / github.com/Tele-AI/Telechat / doc_gptDialog_v2

Function doc_gptDialog_v2

service/telechat_service.py:108–146  ·  view source on GitHub ↗
(item: dict)

Source from the content-addressed store, hash-verified

106
107@app.post('/telechat/gptDialog/v2')
108async def doc_gptDialog_v2(item: dict):
109 session_res = []
110 # 参数校验
111 try:
112 dialog = item["dialog"]
113 except:
114 result_info = response_data("", "10301", "服务必填参数缺失", "0", "执行失败")
115 return result_info
116 # 暴露参数读取
117 do_sample = item.get("do_sample", True)
118 max_length = item.get("max_length", 4096)
119 top_k = item.get("top_k", 20)
120 top_p = item.get("top_p", 0.2)
121 temperature = item.get("temperature", 0.1)
122 repetition_penalty = item.get("repetition_penalty", 1.03)
123 odd = [i for i in range(len(dialog)) if i % 2 == 0]
124 even = [x for x in range(len(dialog)) if x % 2 == 1]
125 for index in odd:
126 if dialog[index].get("role", "") != "user":
127 result_info = response_data("", "10904", "服务请求参数dialog错误", "0", "执行失败")
128 return result_info
129 for index in even:
130 if dialog[index].get("role", "") != "bot":
131 result_info = response_data("", "10904", "服务请求参数dialog错误", "0", "执行失败")
132 return result_info
133 if not check_ex(do_sample, max_length, top_k, top_p, temperature, repetition_penalty):
134 result_info = response_data("", "10305", "请求参数范围错误", "0", "执行失败")
135 return result_info
136 try:
137 history, query = parse_data(dialog)
138 return StreamingResponse(
139 streamresponse_v2(tokenizer, query, history, do_sample, max_length, top_k, top_p, temperature,
140 repetition_penalty),
141 media_type="text/html")
142 except Exception:
143 import traceback
144 traceback.print_exc()
145 result_info = response_data('', "10903", "服务执行失败", "0", "执行失败")
146 return result_info
147
148
149@app.post('/telechat/gptDialog/v4')

Callers

nothing calls this directly

Calls 4

response_dataFunction · 0.85
check_exFunction · 0.85
parse_dataFunction · 0.85
streamresponse_v2Function · 0.85

Tested by

no test coverage detected