MCPcopy Create free account
hub / github.com/CL-lau/SQL-GPT / processResponse

Method processResponse

gpt/chat.py:209–236  ·  view source on GitHub ↗

:param response: :return: result id: 请求的ID object:返回的对象类型(例如,chat.completion) created: 请求的时间戳 model:用于生成 response 的模型的全名 usage:用于生成回复、对prompt计数、完成completion 的 总计使用的 token 数 choices:completion 的列表(只有一个,除非将 n 设置为大

(self, response)

Source from the content-addressed store, hash-verified

207 return ""
208
209 def processResponse(self, response):
210 """
211 :param response:
212 :return: result
213 id: 请求的ID
214 object:返回的对象类型(例如,chat.completion)
215 created: 请求的时间戳
216 model:用于生成 response 的模型的全名
217 usage:用于生成回复、对prompt计数、完成completion 的 总计使用的 token 数
218 choices:completion 的列表(只有一个,除非将 n 设置为大于 1)
219 message:模型生成的消息对象,有role和content
220 finish_reason:模型停止生成文本的原因(如果达到 max_tokens 限制,则为 stop 或 length)
221 index: completion在 choices 列表中的索引
222 """
223 result = response['choices'][0]['message']['content']
224 completion_tokens = response['usage']['completion_tokens']
225 prompt_tokens = response['usage']['prompt_tokens']
226 total_tokens = response['usage']['total_tokens']
227 finish_reason = response['choices'][0]['finish_reason']
228 index = response['choices'][0]['finish_reason']
229 if total_tokens > self.MAX_TOKEN:
230 logging.error("the input token exceed the max token.")
231 logging.info("the token cost" + str(
232 {"completion_tokens": completion_tokens,
233 "prompt_tokens": prompt_tokens,
234 "total_tokens": total_tokens,
235 "finish_reason": finish_reason}))
236 return result
237
238 def num_tokens_from_messages(self, messages):
239 """Returns the number of tokens used by a list of messages."""

Callers 2

chatMethod · 0.95
contextual_chatMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected