Skip to content

Commit e782fd8

Browse files
Merge pull request #59 from gitcoder89431/core-lmstudio
Enhance local model handling: add provider detection, fetch local mod…
2 parents 770e8cb + 1ed5655 commit e782fd8

File tree

5 files changed

+372
-30
lines changed

5 files changed

+372
-30
lines changed

crates/agentic-core/src/cloud.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,25 @@ pub async fn call_cloud_model(
125125
.map(|choice| &choice.message.content)
126126
.ok_or(CloudError::ParseError)?;
127127

128+
// Extract JSON from markdown code blocks if present
129+
let clean_content = if message_content.contains("```json") {
130+
// Extract content between ```json and ```
131+
if let Some(json_start) = message_content.find("```json") {
132+
let after_start = &message_content[json_start + 7..]; // Skip "```json"
133+
if let Some(json_end) = after_start.find("```") {
134+
after_start[..json_end].trim()
135+
} else {
136+
message_content
137+
}
138+
} else {
139+
message_content
140+
}
141+
} else {
142+
message_content
143+
};
144+
128145
let atomic_note: AtomicNote =
129-
serde_json::from_str(message_content).map_err(|_| CloudError::ParseError)?;
146+
serde_json::from_str(clean_content).map_err(|_| CloudError::ParseError)?;
130147

131148
Ok(atomic_note)
132149
}

crates/agentic-core/src/lib.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,48 @@ mod tests {
295295
}
296296
}
297297

298+
#[tokio::test]
299+
async fn test_provider_detection() {
300+
use crate::models::{LocalProvider, ModelValidator};
301+
302+
println!("🧪 Testing provider detection system...");
303+
304+
let validator = ModelValidator::new();
305+
306+
// Test provider detection for common endpoints
307+
let ollama_provider = validator.detect_provider_type("localhost:11434").await;
308+
let lmstudio_provider = validator.detect_provider_type("localhost:1234").await;
309+
let custom_provider = validator.detect_provider_type("localhost:8080").await;
310+
311+
println!("Provider detection results:");
312+
println!(" Ollama (11434): {:?}", ollama_provider);
313+
println!(" LM Studio (1234): {:?}", lmstudio_provider);
314+
println!(" Custom (8080): {:?}", custom_provider);
315+
316+
// Test fetching local models if Ollama is available
317+
if ollama_provider == LocalProvider::Ollama {
318+
println!("Testing local model fetching...");
319+
match validator.fetch_local_models("localhost:11434").await {
320+
Ok(models) => {
321+
println!("✅ Successfully fetched {} local models", models.len());
322+
for model in models.iter().take(3) {
323+
println!(" - {} ({:?}, {})", model.name, model.provider, model.size);
324+
}
325+
}
326+
Err(e) => {
327+
println!(
328+
"⚠️ Could not fetch local models (Ollama not running): {}",
329+
e
330+
);
331+
}
332+
}
333+
} else {
334+
println!("⚠️ Ollama not detected, skipping local model test");
335+
}
336+
337+
println!("✅ Provider detection test completed!");
338+
}
339+
298340
#[test]
299341
fn test_api_key_truncation() {
300342
// Test the API key display formatting (simulating the settings modal function)

0 commit comments

Comments
 (0)