(&self, request: ChatRequest)
| 364 | } |
| 365 | |
| 366 | async fn chat_legacy(&self, request: ChatRequest) -> Result<ChatResponse, ProviderError> { |
| 367 | let url = self.config.base_url.as_deref().unwrap_or(COPILOT_API_URL); |
| 368 | let copilot_request = self.convert_request(request); |
| 369 | |
| 370 | let response = self |
| 371 | .client |
| 372 | .post(url) |
| 373 | .header("Content-Type", "application/json") |
| 374 | .header( |
| 375 | "Authorization", |
| 376 | format!("Bearer {}", self.config.oauth_token), |
| 377 | ) |
| 378 | .header("Copilot-Integration-Id", "vscode-chat") |
| 379 | .json(&copilot_request) |
| 380 | .send() |
| 381 | .await |
| 382 | .map_err(|e| ProviderError::NetworkError(e.to_string()))?; |
| 383 | |
| 384 | if !response.status().is_success() { |
| 385 | let status = response.status(); |
| 386 | let body = response.text().await.unwrap_or_default(); |
| 387 | return Err(ProviderError::api_error_with_status( |
| 388 | format!("{}: {}", status, body), |
| 389 | status.as_u16(), |
| 390 | )); |
| 391 | } |
| 392 | |
| 393 | let copilot_response: CopilotResponse = response |
| 394 | .json() |
| 395 | .await |
| 396 | .map_err(|e| ProviderError::ApiError(e.to_string()))?; |
| 397 | |
| 398 | Ok(convert_copilot_response(copilot_response)) |
| 399 | } |
| 400 | |
| 401 | async fn chat_stream_legacy( |
| 402 | &self, |
no test coverage detected