MCPcopy Create free account
hub / github.com/InfinitiBit/graphbit / complete

Method complete

core/src/llm/mistralai.rs:199–261  ·  view source on GitHub ↗
(&self, request: LlmRequest)

Source from the content-addressed store, hash-verified

197 }
198
199 async fn complete(&self, request: LlmRequest) -> GraphBitResult<LlmResponse> {
200 let url = format!("{}/chat/completions", self.base_url);
201
202 let messages: Vec<MistralAiMessage> =
203 request.messages.iter().map(Self::convert_message).collect();
204
205 let tools: Option<Vec<MistralAiTool>> = if request.tools.is_empty() {
206 None
207 } else {
208 Some(request.tools.iter().map(Self::convert_tool).collect())
209 };
210
211 let body = MistralAiRequest {
212 model: self.model.clone(),
213 messages,
214 max_tokens: request.max_tokens,
215 temperature: request.temperature,
216 top_p: request.top_p,
217 tools: tools.clone(),
218 tool_choice: if tools.is_some() {
219 Some("auto".to_string())
220 } else {
221 None
222 },
223 };
224
225 // Add extra parameters
226 let mut request_json = serde_json::to_value(&body)?;
227 if let serde_json::Value::Object(ref mut map) = request_json {
228 for (key, value) in request.extra_params {
229 map.insert(key, value);
230 }
231 }
232
233 let response = self
234 .client
235 .post(&url)
236 .header("Authorization", format!("Bearer {}", self.api_key))
237 .header("Content-Type", "application/json")
238 .json(&request_json)
239 .send()
240 .await
241 .map_err(|e| {
242 GraphBitError::llm_provider("mistralai", format!("Request failed: {e}"))
243 })?;
244
245 if !response.status().is_success() {
246 let error_text = response
247 .text()
248 .await
249 .unwrap_or_else(|_| "Unknown error".to_string());
250 return Err(GraphBitError::llm_provider(
251 "mistralai",
252 format!("API error: {error_text}"),
253 ));
254 }
255
256 let mistralai_response: MistralAiResponse = response.json().await.map_err(|e| {

Callers

nothing calls this directly

Calls 6

cloneMethod · 0.80
to_stringMethod · 0.80
insertMethod · 0.80
is_emptyMethod · 0.45
is_successMethod · 0.45
parse_responseMethod · 0.45

Tested by

no test coverage detected