Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions crates/openfang-kernel/src/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1996,19 +1996,24 @@ impl OpenFangKernel {
// Persist usage to database (same as non-streaming path)
let model = &manifest.model.model;
let cost = MeteringEngine::estimate_cost_with_catalog(
&kernel_clone.model_catalog.read().unwrap_or_else(|e| e.into_inner()),
&kernel_clone
.model_catalog
.read()
.unwrap_or_else(|e| e.into_inner()),
model,
result.total_usage.input_tokens,
result.total_usage.output_tokens,
);
let _ = kernel_clone.metering.record(&openfang_memory::usage::UsageRecord {
agent_id,
model: model.clone(),
input_tokens: result.total_usage.input_tokens,
output_tokens: result.total_usage.output_tokens,
cost_usd: cost,
tool_calls: result.iterations.saturating_sub(1),
});
let _ = kernel_clone
.metering
.record(&openfang_memory::usage::UsageRecord {
agent_id,
model: model.clone(),
input_tokens: result.total_usage.input_tokens,
output_tokens: result.total_usage.output_tokens,
cost_usd: cost,
tool_calls: result.iterations.saturating_sub(1),
});

let _ = kernel_clone
.registry
Expand Down
16 changes: 10 additions & 6 deletions crates/openfang-runtime/src/drivers/claude_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,6 @@ impl ClaudeCodeDriver {
fn build_prompt(request: &CompletionRequest) -> String {
let mut parts = Vec::new();

if let Some(ref sys) = request.system {
parts.push(format!("[System]\n{sys}"));
}

for msg in &request.messages {
let role_label = match msg.role {
Role::User => "User",
Expand Down Expand Up @@ -240,6 +236,10 @@ impl LlmDriver for ClaudeCodeDriver {
.arg("--output-format")
.arg("json");

if let Some(ref sys) = request.system {
cmd.arg("--system-prompt").arg(sys);
}

if self.skip_permissions {
cmd.arg("--dangerously-skip-permissions");
}
Expand Down Expand Up @@ -413,6 +413,10 @@ impl LlmDriver for ClaudeCodeDriver {
.arg("stream-json")
.arg("--verbose");

if let Some(ref sys) = request.system {
cmd.arg("--system-prompt").arg(sys);
}

if self.skip_permissions {
cmd.arg("--dangerously-skip-permissions");
}
Expand Down Expand Up @@ -645,8 +649,8 @@ mod tests {
};

let prompt = ClaudeCodeDriver::build_prompt(&request);
assert!(prompt.contains("[System]"));
assert!(prompt.contains("You are helpful."));
assert!(!prompt.contains("[System]"));
assert!(!prompt.contains("You are helpful."));
assert!(prompt.contains("[User]"));
assert!(prompt.contains("Hello"));
}
Expand Down
12 changes: 3 additions & 9 deletions crates/openfang-runtime/src/drivers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,9 +791,7 @@ mod tests {
let config = DriverConfig {
provider: "azure".to_string(),
api_key: Some("test-azure-key".to_string()),
base_url: Some(
"https://myresource.openai.azure.com/openai/deployments".to_string(),
),
base_url: Some("https://myresource.openai.azure.com/openai/deployments".to_string()),
skip_permissions: true,
};
let driver = create_driver(&config);
Expand All @@ -805,9 +803,7 @@ mod tests {
let config = DriverConfig {
provider: "azure".to_string(),
api_key: None,
base_url: Some(
"https://myresource.openai.azure.com/openai/deployments".to_string(),
),
base_url: Some("https://myresource.openai.azure.com/openai/deployments".to_string()),
skip_permissions: true,
};
let result = create_driver(&config);
Expand Down Expand Up @@ -843,9 +839,7 @@ mod tests {
let config = DriverConfig {
provider: "azure-openai".to_string(),
api_key: Some("test-azure-key".to_string()),
base_url: Some(
"https://myresource.openai.azure.com/openai/deployments".to_string(),
),
base_url: Some("https://myresource.openai.azure.com/openai/deployments".to_string()),
skip_permissions: true,
};
let driver = create_driver(&config);
Expand Down
3 changes: 1 addition & 2 deletions crates/openfang-runtime/src/drivers/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ impl OpenAIDriver {
if self.azure_mode {
builder = builder.header("api-key", self.api_key.as_str());
} else {
builder =
builder.header("authorization", format!("Bearer {}", self.api_key.as_str()));
builder = builder.header("authorization", format!("Bearer {}", self.api_key.as_str()));
}
builder
}
Expand Down
11 changes: 5 additions & 6 deletions crates/openfang-runtime/src/model_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@

use openfang_types::model_catalog::{
AuthStatus, ModelCatalogEntry, ModelTier, ProviderInfo, AI21_BASE_URL, ANTHROPIC_BASE_URL,
AZURE_OPENAI_BASE_URL, BEDROCK_BASE_URL, CEREBRAS_BASE_URL, CHUTES_BASE_URL,
COHERE_BASE_URL, DEEPSEEK_BASE_URL, FIREWORKS_BASE_URL, GEMINI_BASE_URL,
GITHUB_COPILOT_BASE_URL, GROQ_BASE_URL, HUGGINGFACE_BASE_URL, KIMI_CODING_BASE_URL,
LEMONADE_BASE_URL, LMSTUDIO_BASE_URL, MINIMAX_BASE_URL, MISTRAL_BASE_URL,
MOONSHOT_BASE_URL, NVIDIA_NIM_BASE_URL, OLLAMA_BASE_URL, OPENAI_BASE_URL,
OPENROUTER_BASE_URL, PERPLEXITY_BASE_URL, QIANFAN_BASE_URL, QWEN_BASE_URL,
AZURE_OPENAI_BASE_URL, BEDROCK_BASE_URL, CEREBRAS_BASE_URL, CHUTES_BASE_URL, COHERE_BASE_URL,
DEEPSEEK_BASE_URL, FIREWORKS_BASE_URL, GEMINI_BASE_URL, GITHUB_COPILOT_BASE_URL, GROQ_BASE_URL,
HUGGINGFACE_BASE_URL, KIMI_CODING_BASE_URL, LEMONADE_BASE_URL, LMSTUDIO_BASE_URL,
MINIMAX_BASE_URL, MISTRAL_BASE_URL, MOONSHOT_BASE_URL, NVIDIA_NIM_BASE_URL, OLLAMA_BASE_URL,
OPENAI_BASE_URL, OPENROUTER_BASE_URL, PERPLEXITY_BASE_URL, QIANFAN_BASE_URL, QWEN_BASE_URL,
REPLICATE_BASE_URL, SAMBANOVA_BASE_URL, TOGETHER_BASE_URL, VENICE_BASE_URL, VLLM_BASE_URL,
VOLCENGINE_BASE_URL, VOLCENGINE_CODING_BASE_URL, XAI_BASE_URL, ZAI_BASE_URL,
ZAI_CODING_BASE_URL, ZHIPU_BASE_URL, ZHIPU_CODING_BASE_URL,
Expand Down