fix(llm): nightly uses the gateway's models; no OpenAI defaults #575

Merged
sharang merged 1 commits from fix/nightly-llm-models into main 2026-10-29 07:43:22 +00:00
8 changed files with 53 additions and 7 deletions

No files matched your search

+2 -1
View File
@@ -5,7 +5,8 @@ MONGODB_DATABASE=compliance_scanner
# LiteLLM
LITELLM_URL=http://localhost:4000
LITELLM_API_KEY=
LITELLM_MODEL=gpt-4o
LITELLM_MODEL=Qwen3.8-27B
LITELLM_EMBED_MODEL=bge-multilingual-gemma2
# GitHub
GITHUB_TOKEN=
+5
View File
@@ -67,6 +67,11 @@ jobs:
# which the report lists as advisory; it never fails the run.
LITELLM_URL: ${{ secrets.NIGHTLY_LITELLM_URL }}
LITELLM_API_KEY: ${{ secrets.NIGHTLY_LITELLM_API_KEY }}
# The models stage and prod run. Without them the agent asked for
# gpt-4o / text-embedding-3-small, which the gateway refuses (425
# failed requests a night until 2026-10-28).
LITELLM_MODEL: Qwen3.8-27B
LITELLM_EMBED_MODEL: bge-multilingual-gemma2
# Optional. The CODESYS CVE match queries NVD, which rate-limits
# unauthenticated clients; a key keeps those CVEs from going missing.
NVD_API_KEY: ${{ secrets.NIGHTLY_NVD_API_KEY }}
+7
View File
@@ -56,6 +56,13 @@ pub struct ComplianceAgent {
impl ComplianceAgent {
pub fn new(config: AgentConfig, db_pool: DatabasePool) -> Self {
if config.litellm_model.is_empty() || config.litellm_embed_model.is_empty() {
tracing::warn!(
chat = !config.litellm_model.is_empty(),
embeddings = !config.litellm_embed_model.is_empty(),
"LITELLM_MODEL / LITELLM_EMBED_MODEL not set: those LLM parts are off"
);
}
let llm = Arc::new(LlmClient::new(
config.litellm_url.clone(),
config.litellm_api_key.clone(),
+4 -3
View File
@@ -49,9 +49,10 @@ fn build_config(app_env: AppEnv) -> Result<AgentConfig, AgentError> {
litellm_url: env_var_opt("LITELLM_URL")
.unwrap_or_else(|| "http://localhost:4000".to_string()),
litellm_api_key: SecretString::from(env_var_opt("LITELLM_API_KEY").unwrap_or_default()),
litellm_model: env_var_opt("LITELLM_MODEL").unwrap_or_else(|| "gpt-4o".to_string()),
litellm_embed_model: env_var_opt("LITELLM_EMBED_MODEL")
.unwrap_or_else(|| "text-embedding-3-small".to_string()),
// No default model: our gateway serves none of the OpenAI names, so an
// unset model means the LLM parts are off (LlmClient refuses to call).
litellm_model: env_var_opt("LITELLM_MODEL").unwrap_or_default(),
litellm_embed_model: env_var_opt("LITELLM_EMBED_MODEL").unwrap_or_default(),
github_token: env_secret_opt("GITHUB_TOKEN"),
github_webhook_secret: env_secret_opt("GITHUB_WEBHOOK_SECRET"),
gitlab_url: env_var_opt("GITLAB_URL"),
+19
View File
@@ -255,6 +255,9 @@ impl LlmClient {
&self,
request_body: &B,
) -> Result<(LlmResponse, Option<String>), AgentError> {
if self.model.is_empty() {
return Err(AgentError::Other(NO_CHAT_MODEL.to_string()));
}
let mut req = self
.http
.post(self.chat_url())
@@ -319,6 +322,9 @@ impl LlmClient {
}
}
/// The error when no chat model is configured: the request is not sent.
pub(crate) const NO_CHAT_MODEL: &str = "LLM off: LITELLM_MODEL is not set";
/// A text answer, and whether the model stopped at its token budget.
#[derive(Debug, Clone, PartialEq)]
pub struct ChatAnswer {
@@ -448,6 +454,19 @@ mod budget_tests {
assert_eq!(seen.lock().unwrap().len(), 2);
}
#[tokio::test]
async fn no_chat_model_makes_no_request() {
let seen: Seen = Arc::default();
let mut llm = client(fake_gateway(seen.clone(), 0).await);
llm.model = String::new();
let err = llm.chat("s", "u", None).await.unwrap_err();
assert_eq!(err.to_string(), NO_CHAT_MODEL);
assert!(
seen.lock().unwrap().is_empty(),
"no request may reach the gateway"
);
}
#[tokio::test]
async fn an_answer_in_budget_is_one_request() {
let seen: Seen = Arc::default();
+13
View File
@@ -51,6 +51,11 @@ impl LlmClient {
/// Embed one backend-sized batch (≤ [`EMBED_BATCH_SIZE`]) in a single request.
async fn embed_batch(&self, texts: Vec<String>) -> Result<Vec<Vec<f64>>, AgentError> {
if self.embed_model.is_empty() {
return Err(AgentError::Other(
"embeddings off: LITELLM_EMBED_MODEL is not set".to_string(),
));
}
let url = format!("{}/v1/embeddings", self.base_url.trim_end_matches('/'));
let request_body = EmbeddingRequest {
@@ -113,4 +118,12 @@ mod tests {
let out = client().embed(Vec::new()).await.unwrap();
assert!(out.is_empty());
}
#[tokio::test]
async fn no_embed_model_makes_no_request() {
let mut llm = client();
llm.embed_model = String::new();
let err = llm.embed(vec!["x".into()]).await.unwrap_err();
assert!(err.to_string().contains("LITELLM_EMBED_MODEL"), "{err}");
}
}
+2 -2
View File
@@ -322,8 +322,8 @@ impl Default for AgentConfig {
mongodb_database: "compliance_scanner".to_string(),
litellm_url: "http://localhost:4000".to_string(),
litellm_api_key: SecretString::from(String::new()),
litellm_model: "gpt-4o".to_string(),
litellm_embed_model: "text-embedding-3-small".to_string(),
litellm_model: String::new(),
litellm_embed_model: String::new(),
github_token: None,
github_webhook_secret: None,
gitlab_url: None,
+1 -1
View File
@@ -51,6 +51,6 @@ The help chat uses the same LiteLLM configuration as other LLM features:
| Environment Variable | Description | Default |
|---------------------|-------------|---------|
| `LITELLM_URL` | LiteLLM API base URL | `http://localhost:4000` |
| `LITELLM_MODEL` | Model for chat responses | `gpt-4o` |
| `LITELLM_MODEL` | Model for chat responses (stage/prod: `Qwen3.8-27B`) | -- (unset: the LLM parts are off) |
| `LITELLM_API_KEY` | API key (optional) | -- |
| `HELP_DOCS_PATH` | Directory containing `README.md` and `docs/`, if it is not found next to the agent | -- |