Spaces:
Configuration error
Configuration error
Download openhands/server/routes/public.py from flyingdarkdev/README: direct link, hf CLI and curl.
- Browser
- Download file 3.36 kB
-
https://huggingface.co/spaces/flyingdarkdev/README/resolve/main/openhands/server/routes/public.py
- Command line
-
hf download hf://spaces/flyingdarkdev/README/openhands/server/routes/public.py
-
curl -L -o public.py https://huggingface.co/spaces/flyingdarkdev/README/resolve/main/openhands/server/routes/public.py
3.36 kB
| import warnings | |
| from typing import Any | |
| import httpx | |
| from fastapi import APIRouter | |
| from openhands.security.options import SecurityAnalyzers | |
| with warnings.catch_warnings(): | |
| warnings.simplefilter('ignore') | |
| import litellm | |
| from openhands.controller.agent import Agent | |
| from openhands.core.config import LLMConfig | |
| from openhands.core.logger import openhands_logger as logger | |
| from openhands.llm import bedrock | |
| from openhands.server.shared import config, server_config | |
| app = APIRouter(prefix='/api/options') | |
| async def get_litellm_models() -> list[str]: | |
| """Get all models supported by LiteLLM. | |
| This function combines models from litellm and Bedrock, removing any | |
| error-prone Bedrock models. | |
| To get the models: | |
| ```sh | |
| curl http://localhost:3000/api/litellm-models | |
| ``` | |
| Returns: | |
| list[str]: A sorted list of unique model names. | |
| """ | |
| litellm_model_list = litellm.model_list + list(litellm.model_cost.keys()) | |
| litellm_model_list_without_bedrock = bedrock.remove_error_modelId( | |
| litellm_model_list | |
| ) | |
| # TODO: for bedrock, this is using the default config | |
| llm_config: LLMConfig = config.get_llm_config() | |
| bedrock_model_list = [] | |
| if ( | |
| llm_config.aws_region_name | |
| and llm_config.aws_access_key_id | |
| and llm_config.aws_secret_access_key | |
| ): | |
| bedrock_model_list = bedrock.list_foundation_models( | |
| llm_config.aws_region_name, | |
| llm_config.aws_access_key_id.get_secret_value(), | |
| llm_config.aws_secret_access_key.get_secret_value(), | |
| ) | |
| model_list = litellm_model_list_without_bedrock + bedrock_model_list | |
| for llm_config in config.llms.values(): | |
| ollama_base_url = llm_config.ollama_base_url | |
| if llm_config.model.startswith('ollama'): | |
| if not ollama_base_url: | |
| ollama_base_url = llm_config.base_url | |
| if ollama_base_url: | |
| ollama_url = ollama_base_url.strip('/') + '/api/tags' | |
| try: | |
| ollama_models_list = httpx.get(ollama_url, timeout=3).json()['models'] | |
| for model in ollama_models_list: | |
| model_list.append('ollama/' + model['name']) | |
| break | |
| except httpx.HTTPError as e: | |
| logger.error(f'Error getting OLLAMA models: {e}') | |
| return list(sorted(set(model_list))) | |
| async def get_agents() -> list[str]: | |
| """Get all agents supported by LiteLLM. | |
| To get the agents: | |
| ```sh | |
| curl http://localhost:3000/api/agents | |
| ``` | |
| Returns: | |
| list[str]: A sorted list of agent names. | |
| """ | |
| return sorted(Agent.list_agents()) | |
| async def get_security_analyzers() -> list[str]: | |
| """Get all supported security analyzers. | |
| To get the security analyzers: | |
| ```sh | |
| curl http://localhost:3000/api/security-analyzers | |
| ``` | |
| Returns: | |
| list[str]: A sorted list of security analyzer names. | |
| """ | |
| return sorted(SecurityAnalyzers.keys()) | |
| async def get_config() -> dict[str, Any]: | |
| """Get current config. | |
| Returns: | |
| dict[str, Any]: The current server configuration. | |
| """ | |
| return server_config.get_config() | |