Jacek Zadrożny commited on
Commit
f21ff52
·
1 Parent(s): ed9cfa3

Fix: Make LLM base_url optional to prevent startup hang

Browse files

- Changed llm_base_url in config.py to be optional (defaulting to None).
- Updated 11y_agent.py to only pass ase_url to the OpenAI client if it is explicitly provided.

This prevents potential network hangs during OpenAI client initialization on platforms like Hugging Face Spaces, making the default setup more robust.

Files changed (2) hide show
  1. agent/a11y_agent.py +6 -2
  2. config.py +3 -3
agent/a11y_agent.py CHANGED
@@ -182,8 +182,12 @@ def create_agent(language: Optional[str] = None) -> A11yExpertAgent:
182
  vector_store.connect()
183
 
184
  api_key = settings.openai_api_key
185
- base_url = settings.llm_base_url
186
- llm_client = OpenAI(api_key=api_key, base_url=base_url)
 
 
 
 
187
 
188
  agent = A11yExpertAgent(
189
  vector_store=vector_store,
 
182
  vector_store.connect()
183
 
184
  api_key = settings.openai_api_key
185
+
186
+ client_args = {"api_key": api_key}
187
+ if settings.llm_base_url:
188
+ client_args["base_url"] = settings.llm_base_url
189
+
190
+ llm_client = OpenAI(**client_args)
191
 
192
  agent = A11yExpertAgent(
193
  vector_store=vector_store,
config.py CHANGED
@@ -48,9 +48,9 @@ class Settings(BaseSettings):
48
  default="gpt-4o",
49
  description="Language model for chat completions"
50
  )
51
- llm_base_url: str = Field(
52
- default="https://api.openai.com/v1",
53
- description="Base URL for OpenAI-compatible API"
54
  )
55
 
56
  # Embeddings Configuration
 
48
  default="gpt-4o",
49
  description="Language model for chat completions"
50
  )
51
+ llm_base_url: Optional[str] = Field(
52
+ default=None,
53
+ description="Base URL for OpenAI-compatible API (optional)"
54
  )
55
 
56
  # Embeddings Configuration