Browse Source

safer model info access (#4619)

Robert Brennan 1 year ago
parent
commit
572b3ad682
1 changed files with 6 additions and 1 deletions
  1. 6 1
      openhands/llm/llm.py

+ 6 - 1
openhands/llm/llm.py

@@ -92,7 +92,12 @@ class LLM(RetryMixin, DebugMixin):
                 f'{self.config.base_url}/v1/model/info',
                 headers={'Authorization': f'Bearer {self.config.api_key}'},
             )
-            all_model_info = response.json()['data']
+            resp_json = response.json()
+            if 'data' not in resp_json:
+                logger.error(
+                    f'Error getting model info from LiteLLM proxy: {resp_json}'
+                )
+            all_model_info = resp_json.get('data', [])
             current_model_info = next(
                 (
                     info