diff --git a/.env.example b/.env.example index c3fef9b..50db198 100644 --- a/.env.example +++ b/.env.example @@ -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= diff --git a/.gitea/workflows/nightly.yml b/.gitea/workflows/nightly.yml index fd75f42..7310404 100644 --- a/.gitea/workflows/nightly.yml +++ b/.gitea/workflows/nightly.yml @@ -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 }} diff --git a/compliance-agent/src/agent.rs b/compliance-agent/src/agent.rs index 97eed9c..7210ac9 100644 --- a/compliance-agent/src/agent.rs +++ b/compliance-agent/src/agent.rs @@ -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(), diff --git a/compliance-agent/src/config.rs b/compliance-agent/src/config.rs index 0e31633..c221469 100644 --- a/compliance-agent/src/config.rs +++ b/compliance-agent/src/config.rs @@ -49,9 +49,10 @@ fn build_config(app_env: AppEnv) -> Result { 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"), diff --git a/compliance-agent/src/llm/client.rs b/compliance-agent/src/llm/client.rs index 31a262e..44fa12d 100644 --- a/compliance-agent/src/llm/client.rs +++ b/compliance-agent/src/llm/client.rs @@ -255,6 +255,9 @@ impl LlmClient { &self, request_body: &B, ) -> Result<(LlmResponse, Option), 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(); diff --git a/compliance-agent/src/llm/embedding.rs b/compliance-agent/src/llm/embedding.rs index 32d5a72..3ebe62d 100644 --- a/compliance-agent/src/llm/embedding.rs +++ b/compliance-agent/src/llm/embedding.rs @@ -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) -> Result>, 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}"); + } } diff --git a/compliance-core/src/config.rs b/compliance-core/src/config.rs index 811b08c..92a5ff4 100644 --- a/compliance-core/src/config.rs +++ b/compliance-core/src/config.rs @@ -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, diff --git a/docs/features/help-chat.md b/docs/features/help-chat.md index ea1c07d..9edd7fa 100644 --- a/docs/features/help-chat.md +++ b/docs/features/help-chat.md @@ -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 | -- |