mirror of
https://github.com/RightNow-AI/openfang.git
synced 2026-07-30 06:32:17 +00:00
fix(claude-code): pass system prompt via --system-prompt flag instead of inlining in -p
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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",
|
||||
@@ -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");
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user