解析 response 中的 token 文本列表
(response)
| 120 | |
| 121 | |
| 122 | def get_probs_list(response): |
| 123 | """解析 response 中的 token 文本列表""" |
| 124 | probs_list = [] |
| 125 | |
| 126 | try: |
| 127 | content_logprobs = response["choices"][0]["logprobs"]["content"] |
| 128 | except (KeyError, IndexError, TypeError) as e: |
| 129 | base_logger.error(f"解析失败:{e}") |
| 130 | return [] |
| 131 | |
| 132 | for token_info in content_logprobs: |
| 133 | token = token_info.get("logprob") |
| 134 | if token is not None: |
| 135 | probs_list.append(math.exp(token)) |
| 136 | |
| 137 | base_logger.info(f"probs List:{probs_list}") |
| 138 | return probs_list |