Spaces:
Configuration error
Configuration error
Download get_model.py from manaankit/hf-final-assignment-agents-course: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/spaces/manaankit/hf-final-assignment-agents-course/resolve/main/get_model.py
- Command line
-
hf download hf://spaces/manaankit/hf-final-assignment-agents-course/get_model.py
-
curl -L -o get_model.py https://huggingface.co/spaces/manaankit/hf-final-assignment-agents-course/resolve/main/get_model.py
1.1 kB
| # get_model.py | |
| from loguru import logger | |
| from smolagents import InferenceClientModel as HfApiModel | |
| import os | |
| try: | |
| from smolagents import GeminiModel | |
| except ImportError: | |
| GeminiModel = None | |
| DEFAULT_MODEL_ID = "HuggingFaceH4/zephyr-7b-beta" | |
| def get_model(cat: str = "hf", provider=None, model_id=None): | |
| """ | |
| Create and return a conversational model for the agent. | |
| Args: | |
| cat: category, hf, gemini, llama (default: hf) | |
| provider: for HfApiModel (cat='hf') | |
| model_id: model name (default: HuggingFaceH4/zephyr-7b-beta or $HF_MODEL_ID) | |
| Returns: | |
| Model instance | |
| """ | |
| if cat == "gemini": | |
| if GeminiModel is None: | |
| raise ImportError("GeminiModel is not available. Please install the required package.") | |
| logger.info("Using GeminiModel.") | |
| return GeminiModel() | |
| else: | |
| model_id = model_id or os.getenv("HF_MODEL_ID", DEFAULT_MODEL_ID) | |
| logger.info(f"Using HfApiModel with model_id={model_id!r}. Make sure you set HF_TOKEN if required.") | |
| return HfApiModel(provider=provider, model_id=model_id) |