Skip to content

Commit 7e9a7f9

Browse files
committed
chore: checkpoint ai/mcp changes
1 parent 583fe8b commit 7e9a7f9

File tree

9 files changed

+86
-446
lines changed

9 files changed

+86
-446
lines changed

crates/codegraph-ai/src/agentic_schemas.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ impl AgenticOutput {
236236
// layers and coupling_metrics are now flexible Value types
237237
o.hub_nodes.iter().collect()
238238
}
239-
Self::APISurface(o) => {
239+
Self::APISurface(_) => {
240240
// integration_points are now flexible Value types, can't extract directly
241241
vec![]
242242
}

crates/codegraph-ai/src/llm_factory.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ impl LLMProviderFactory {
2626
let provider_name = config.provider.to_lowercase();
2727

2828
match provider_name.as_str() {
29-
"ollama" | "qwen" => Self::create_qwen_provider(config),
29+
"ollama" => Self::create_ollama_openai_provider(config),
30+
"qwen" => Self::create_qwen_provider(config),
3031
"lmstudio" => Self::create_lmstudio_provider(config),
3132
#[cfg(feature = "anthropic")]
3233
"anthropic" => Self::create_anthropic_provider(config),
@@ -58,6 +59,38 @@ impl LLMProviderFactory {
5859
}
5960
}
6061

62+
/// Create an Ollama provider using the OpenAI-compatible endpoint
63+
fn create_ollama_openai_provider(config: &LLMConfig) -> Result<Arc<dyn LLMProvider>> {
64+
#[cfg(feature = "openai-compatible")]
65+
{
66+
let base_url = format!("{}/v1", config.ollama_url.trim_end_matches('/'));
67+
let compat_config = OpenAICompatibleConfig {
68+
base_url,
69+
model: config
70+
.model
71+
.clone()
72+
.unwrap_or_else(|| "qwen2.5-coder:14b".to_string()),
73+
context_window: config.context_window,
74+
timeout_secs: config.timeout_secs,
75+
max_retries: 3,
76+
api_key: None,
77+
provider_name: "ollama".to_string(),
78+
use_responses_api: false,
79+
};
80+
81+
Ok(Arc::new(OpenAICompatibleProvider::new(compat_config)?))
82+
}
83+
84+
#[cfg(not(feature = "openai-compatible"))]
85+
{
86+
let _ = config;
87+
Err(anyhow!(
88+
"Ollama provider now relies on the 'openai-compatible' feature. \
89+
Rebuild with --features codegraph-ai/openai-compatible or use 'qwen' provider instead."
90+
))
91+
}
92+
}
93+
6194
/// Create a Qwen provider (Ollama-based)
6295
fn create_qwen_provider(config: &LLMConfig) -> Result<Arc<dyn LLMProvider>> {
6396
let qwen_config = QwenConfig {
@@ -99,6 +132,7 @@ impl LLMProviderFactory {
99132

100133
#[cfg(not(feature = "openai-compatible"))]
101134
{
135+
let _ = config;
102136
Err(anyhow!(
103137
"LM Studio provider requires 'openai-compatible' feature to be enabled. \
104138
Please rebuild with --features openai-compatible or use 'ollama' provider instead."
@@ -222,6 +256,7 @@ impl LLMProviderFactory {
222256

223257
/// Get a list of supported providers (based on enabled features)
224258
pub fn supported_providers() -> Vec<&'static str> {
259+
#[allow(unused_mut)]
225260
let mut providers = vec!["ollama", "qwen"];
226261

227262
#[cfg(feature = "openai-compatible")]

crates/codegraph-ai/src/openai_compatible_provider.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl Default for OpenAICompatibleConfig {
3131
Self {
3232
base_url: "http://localhost:1234/v1".to_string(),
3333
model: "local-model".to_string(),
34-
context_window: config.context_window,
34+
context_window: 128_000,
3535
timeout_secs: 120,
3636
max_retries: 3,
3737
api_key: None,
@@ -47,7 +47,7 @@ impl OpenAICompatibleConfig {
4747
Self {
4848
base_url: "http://localhost:1234/v1".to_string(),
4949
model,
50-
context_window: config.context_window,
50+
context_window: 128_000,
5151
provider_name: "lmstudio".to_string(),
5252
use_responses_api: false, // LM Studio doesn't support Responses API
5353
..Default::default()
@@ -59,7 +59,7 @@ impl OpenAICompatibleConfig {
5959
Self {
6060
base_url: "http://localhost:11434/v1".to_string(),
6161
model,
62-
context_window: config.context_window,
62+
context_window: 128_000,
6363
provider_name: "ollama".to_string(),
6464
use_responses_api: false, // Ollama doesn't support Responses API
6565
..Default::default()

crates/codegraph-ai/src/openai_llm_provider.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl Default for OpenAIConfig {
3333
api_key: std::env::var("OPENAI_API_KEY").unwrap_or_default(),
3434
base_url: OPENAI_API_BASE.to_string(),
3535
model: DEFAULT_MODEL.to_string(),
36-
context_window: config.context_window,
36+
context_window: 128_000,
3737
timeout_secs: 120,
3838
max_retries: 3,
3939
organization: std::env::var("OPENAI_ORG_ID").ok(),

crates/codegraph-ai/src/optimization/models.rs

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::sync::Arc;
22
use std::time::{Duration, Instant};
33

44
use anyhow::Result;
5-
use futures::FutureExt;
5+
66
use parking_lot::RwLock;
77
use prometheus::{
88
register_gauge, register_histogram, register_int_counter, Gauge, Histogram, IntCounter,
@@ -351,21 +351,7 @@ impl ModelOptimizer {
351351

352352
// Quantization APIs – backend-specific implementations behind feature flags.
353353
pub fn quantize_fp16(&self) -> Result<()> {
354-
#[cfg(feature = "tch")]
355-
{
356-
// With tch, a full-graph conversion requires model-specific access.
357-
// For now, expose as not implemented until integrated with a model holder.
358-
return Err(AiOptimizeError::NotImplemented("tch fp16 quantization").into());
359-
}
360-
#[cfg(feature = "onnx")]
361-
{
362-
// ONNX Runtime quantization should be handled offline or through tooling.
363-
return Err(AiOptimizeError::NotImplemented("onnx fp16 quantization").into());
364-
}
365-
#[cfg(feature = "candle")]
366-
{
367-
return Err(AiOptimizeError::NotImplemented("candle fp16 quantization").into());
368-
}
354+
369355
#[allow(unreachable_code)]
370356
{
371357
warn!("fp16 quantization requested but no backend enabled");
@@ -374,18 +360,7 @@ impl ModelOptimizer {
374360
}
375361

376362
pub fn quantize_int8(&self) -> Result<()> {
377-
#[cfg(feature = "onnx")]
378-
{
379-
return Err(AiOptimizeError::NotImplemented("onnx int8 quantization").into());
380-
}
381-
#[cfg(feature = "tch")]
382-
{
383-
return Err(AiOptimizeError::NotImplemented("tch int8 quantization").into());
384-
}
385-
#[cfg(feature = "candle")]
386-
{
387-
return Err(AiOptimizeError::NotImplemented("candle int8 quantization").into());
388-
}
363+
389364
#[allow(unreachable_code)]
390365
{
391366
warn!("int8 quantization requested but no backend enabled");
@@ -434,26 +409,7 @@ impl ModelOptimizer {
434409

435410
pub fn start_monitoring(&self) {
436411
// GPU utilization polling via NVML if available
437-
#[cfg(feature = "nvml")]
438-
{
439-
use nvml_wrapper::Nvml;
440-
let nvml = Nvml::init().ok();
441-
let metrics = self.metrics.clone();
442-
tokio::spawn(async move {
443-
if let Some(nvml) = nvml {
444-
loop {
445-
if let Ok(device) = nvml.device_by_index(0) {
446-
if let Ok(util) = device.utilization_rates() {
447-
metrics.gpu_utilization.set(util.gpu as f64);
448-
}
449-
}
450-
sleep(Duration::from_millis(1000)).await;
451-
}
452-
} else {
453-
warn!("NVML init failed; GPU utilization metrics disabled");
454-
}
455-
});
456-
}
412+
457413

458414
// Alerting loop to check thresholds; emits logs (integrate with Alertmanager externally)
459415
let thresholds = self.thresholds.clone();

0 commit comments

Comments
 (0)