MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / chat

Method chat

crates/opencode-provider/src/google.rs:175–205  ·  view source on GitHub ↗
(&self, request: ChatRequest)

Source from the content-addressed store, hash-verified

173 }
174
175 async fn chat(&self, request: ChatRequest) -> Result<ChatResponse, ProviderError> {
176 let base_url = self.config.base_url.as_deref().unwrap_or(GOOGLE_API_URL);
177 let url = format!(
178 "{}/{}:generateContent?key={}",
179 base_url, request.model, self.config.api_key
180 );
181
182 let google_request = self.convert_request(request);
183
184 let response = self
185 .client
186 .post(&url)
187 .header("Content-Type", "application/json")
188 .json(&google_request)
189 .send()
190 .await
191 .map_err(|e| ProviderError::NetworkError(e.to_string()))?;
192
193 if !response.status().is_success() {
194 let status = response.status();
195 let body = response.text().await.unwrap_or_default();
196 return Err(ProviderError::ApiError(format!("{}: {}", status, body)));
197 }
198
199 let google_response: GoogleResponse = response
200 .json()
201 .await
202 .map_err(|e| ProviderError::ApiError(e.to_string()))?;
203
204 Ok(convert_google_response(google_response))
205 }
206
207 async fn chat_stream(&self, request: ChatRequest) -> Result<StreamResult, ProviderError> {
208 let base_url = self.config.base_url.as_deref().unwrap_or(GOOGLE_API_URL);

Callers

nothing calls this directly

Calls 6

convert_google_responseFunction · 0.85
ApiErrorEnum · 0.50
convert_requestMethod · 0.45
sendMethod · 0.45
statusMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected