(
self,
response_text: str,
*,
partial: bool,
)
| 7133 | return coerced |
| 7134 | |
| 7135 | def parse_chat_response( |
| 7136 | self, |
| 7137 | response_text: str, |
| 7138 | *, |
| 7139 | partial: bool, |
| 7140 | ) -> Dict[str, Any]: |
| 7141 | full_response_text = self._generation_prompt + response_text |
| 7142 | parsed = self._parse_response_value( |
| 7143 | full_response_text, |
| 7144 | self._schema, |
| 7145 | partial=partial, |
| 7146 | ) |
| 7147 | if not isinstance(parsed, dict): |
| 7148 | raise CompletionResponseParsingError("response_schema must produce an object") |
| 7149 | if partial: |
| 7150 | self._trim_partial_tool_call_prefix( |
| 7151 | response_text=full_response_text, |
| 7152 | parsed=parsed, |
| 7153 | ) |
| 7154 | tool_calls = parsed.get("tool_calls") |
| 7155 | if isinstance(tool_calls, list): |
| 7156 | normalized_tool_calls: List[Dict[str, Any]] = [] |
| 7157 | for tool_call in tool_calls: |
| 7158 | normalized = self._normalize_tool_call_item(tool_call, partial=partial) |
| 7159 | if normalized is None: |
| 7160 | continue |
| 7161 | normalized_tool_calls.append(normalized) |
| 7162 | if normalized_tool_calls: |
| 7163 | parsed["tool_calls"] = normalized_tool_calls |
| 7164 | else: |
| 7165 | parsed.pop("tool_calls", None) |
| 7166 | for field in ("reasoning_content", "thinking"): |
| 7167 | value = parsed.get(field) |
| 7168 | if isinstance(value, str) and not value.strip(): |
| 7169 | parsed.pop(field, None) |
| 7170 | return parsed |
| 7171 | |
| 7172 | def _normalize_tool_call_item( |
| 7173 | self, |
no test coverage detected