Download model.py from hibanail/First_agent_template: direct link, hf CLI and curl.
- Browser
- Download file 946 Bytes
-
https://huggingface.co/hibanail/First_agent_template/resolve/main/model.py
- Command line
-
hf download hf://hibanail/First_agent_template/model.py
-
curl -L -o model.py https://huggingface.co/hibanail/First_agent_template/resolve/main/model.py
946 Bytes
| import os | |
| from dotenv import load_dotenv | |
| from smolagents import OpenAIServerModel, LiteLLMModel | |
| load_dotenv() # reads MODEL_PROVIDER and OPENAI_API_KEY from .env | |
| # "openai" (cloud, needs OPENAI_API_KEY) or "ollama" (local, free) | |
| MODEL_PROVIDER = os.getenv("MODEL_PROVIDER", "openai") | |
| OPENAI_MODEL_ID = "gpt-4.1-mini" # any chat model your OpenAI account has access to | |
| OLLAMA_MODEL_ID = "qwen2:7b" # any model listed by `ollama list` | |
| def build_model(): | |
| if MODEL_PROVIDER == "openai": | |
| return OpenAIServerModel( | |
| model_id=OPENAI_MODEL_ID, | |
| api_key=os.environ["OPENAI_API_KEY"], | |
| ) | |
| if MODEL_PROVIDER == "ollama": | |
| return LiteLLMModel( | |
| model_id=f"ollama_chat/{OLLAMA_MODEL_ID}", | |
| api_base="http://127.0.0.1:11434", | |
| num_ctx=8192, | |
| ) | |
| raise ValueError(f"Unknown MODEL_PROVIDER {MODEL_PROVIDER!r}, use 'openai' or 'ollama'") | |
| model = build_model() | |