| 317 | } |
| 318 | |
| 319 | fn convert_response(response: AnthropicResponse) -> ChatResponse { |
| 320 | let content = response |
| 321 | .content |
| 322 | .iter() |
| 323 | .filter_map(|c| c.text.clone()) |
| 324 | .collect::<Vec<_>>() |
| 325 | .join(""); |
| 326 | |
| 327 | ChatResponse { |
| 328 | id: response.id, |
| 329 | model: response.model, |
| 330 | choices: vec![Choice { |
| 331 | index: 0, |
| 332 | message: Message::assistant(&content), |
| 333 | finish_reason: Some("stop".to_string()), |
| 334 | }], |
| 335 | usage: Some(Usage { |
| 336 | prompt_tokens: response.usage.input_tokens, |
| 337 | completion_tokens: response.usage.output_tokens, |
| 338 | total_tokens: response.usage.input_tokens + response.usage.output_tokens, |
| 339 | cache_read_input_tokens: None, |
| 340 | cache_creation_input_tokens: None, |
| 341 | }), |
| 342 | } |
| 343 | } |