(&self, request: ChatRequest)
| 138 | } |
| 139 | |
| 140 | async fn chat(&self, request: ChatRequest) -> Result<ChatResponse, ProviderError> { |
| 141 | let url = self.get_api_url(); |
| 142 | let gitlab_request = self.convert_request(request); |
| 143 | |
| 144 | let response = self |
| 145 | .client |
| 146 | .post(&url) |
| 147 | .header("Content-Type", "application/json") |
| 148 | .header("PRIVATE-TOKEN", &self.config.api_key) |
| 149 | .json(&gitlab_request) |
| 150 | .send() |
| 151 | .await |
| 152 | .map_err(|e| ProviderError::NetworkError(e.to_string()))?; |
| 153 | |
| 154 | if !response.status().is_success() { |
| 155 | let status = response.status(); |
| 156 | let body = response.text().await.unwrap_or_default(); |
| 157 | return Err(ProviderError::api_error_with_status( |
| 158 | format!("{}: {}", status, body), |
| 159 | status.as_u16(), |
| 160 | )); |
| 161 | } |
| 162 | |
| 163 | let gitlab_response: GitLabResponse = response |
| 164 | .json() |
| 165 | .await |
| 166 | .map_err(|e| ProviderError::ApiError(e.to_string()))?; |
| 167 | |
| 168 | Ok(convert_gitlab_response(gitlab_response)) |
| 169 | } |
| 170 | |
| 171 | async fn chat_stream(&self, request: ChatRequest) -> Result<StreamResult, ProviderError> { |
| 172 | let url = self.get_api_url(); |
nothing calls this directly
no test coverage detected