From 66466335ccefb7ae6275662daef8bdae1eb54c56 Mon Sep 17 00:00:00 2001 From: Igor Ilic Date: Tue, 9 Sep 2025 13:57:07 +0200 Subject: [PATCH] refactor: dont forward empty or None values to baml llm config --- cognee/infrastructure/llm/config.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/cognee/infrastructure/llm/config.py b/cognee/infrastructure/llm/config.py index 51ba0f210..fc9b0eee5 100644 --- a/cognee/infrastructure/llm/config.py +++ b/cognee/infrastructure/llm/config.py @@ -71,16 +71,18 @@ class LLMConfig(BaseSettings): def model_post_init(self, __context) -> None: """Initialize the BAML registry after the model is created.""" + raw_options = { + "model": self.baml_llm_model, + "temperature": self.baml_llm_temperature, + "api_key": self.baml_llm_api_key, + "base_url": self.baml_llm_endpoint, + "api_version": self.baml_llm_api_version, + } + + # Note: keep the item only when the value is not None or an empty string (they would override baml default values) + options = {k: v for k, v in raw_options.items() if v not in (None, "")} self.baml_registry.add_llm_client( - name=self.baml_llm_provider, - provider=self.baml_llm_provider, - options={ - "model": self.baml_llm_model, - # "temperature": self.baml_llm_temperature, - "api_key": self.baml_llm_api_key, - # "base_url": self.baml_llm_endpoint, - # "api_version": self.baml_llm_api_version, - }, + name=self.baml_llm_provider, provider=self.baml_llm_provider, options=options ) # Sets the primary client self.baml_registry.set_primary(self.baml_llm_provider)