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

Method complete

core/src/llm/replicate.rs:240–324  ·  view source on GitHub ↗
(&self, request: LlmRequest)

Source from the content-addressed store, hash-verified

238 }
239
240 async fn complete(&self, request: LlmRequest) -> GraphBitResult<LlmResponse> {
241 let model_identifier = self.get_model_identifier();
242
243 // Convert messages to prompt format
244 let mut prompt = String::new();
245
246 // Add tools information if available and model supports it
247 if !request.tools.is_empty() && self.model_supports_function_calling() {
248 prompt.push_str(&Self::format_tools_for_prompt(&request.tools));
249 }
250
251 prompt.push_str(&Self::convert_messages_to_prompt(&request.messages));
252
253 // Prepare input based on model type
254 let mut input = serde_json::json!({
255 "prompt": prompt
256 });
257
258 // Add common parameters
259 if let Some(max_tokens) = request.max_tokens {
260 input["max_new_tokens"] = serde_json::Value::Number(max_tokens.into());
261 }
262 if let Some(temperature) = request.temperature {
263 input["temperature"] = serde_json::json!(temperature);
264 }
265 if let Some(top_p) = request.top_p {
266 input["top_p"] = serde_json::json!(top_p);
267 }
268
269 // Add extra parameters
270 for (key, value) in request.extra_params {
271 input[key] = value;
272 }
273
274 let prediction_request = if self.version.is_some() {
275 ReplicatePredictionRequest {
276 version: self.version.clone(),
277 input,
278 webhook: None,
279 }
280 } else {
281 // For models without explicit version, we need to use the model endpoint
282 ReplicatePredictionRequest {
283 version: Some(model_identifier),
284 input,
285 webhook: None,
286 }
287 };
288
289 // Create prediction
290 let url = format!("{}/predictions", self.base_url);
291 let response = self
292 .client
293 .post(&url)
294 .header("Authorization", format!("Token {}", self.api_key))
295 .header("Content-Type", "application/json")
296 .json(&prediction_request)
297 .send()

Callers

nothing calls this directly

Calls 8

get_model_identifierMethod · 0.80
cloneMethod · 0.80
to_stringMethod · 0.80
poll_predictionMethod · 0.80
is_emptyMethod · 0.45
is_successMethod · 0.45

Tested by

no test coverage detected