解析 response 中的 token 文本列表
(response)
| 101 | |
| 102 | |
| 103 | def get_logprobs_list(response): |
| 104 | """解析 response 中的 token 文本列表""" |
| 105 | logprobs_list = [] |
| 106 | |
| 107 | try: |
| 108 | content_logprobs = response["choices"][0]["logprobs"]["content"] |
| 109 | except (KeyError, IndexError, TypeError) as e: |
| 110 | base_logger.error(f"解析失败:{e}") |
| 111 | return [] |
| 112 | |
| 113 | for token_info in content_logprobs: |
| 114 | token = token_info.get("logprob") |
| 115 | if token is not None: |
| 116 | logprobs_list.append(token) |
| 117 | |
| 118 | base_logger.info(f"Logprobs List:{logprobs_list}") |
| 119 | return logprobs_list |
| 120 | |
| 121 | |
| 122 | def get_probs_list(response): |