In our application, we want to use ollama and that infrastructure in dev_resources.py
. I created a little hack in settings.py
in the workspace:
runtime_env = getenv("RUNTIME_ENV", "dev")
are_we_in_dev = runtime_env is not None and runtime_env == "dev"
But this seems redundant and error prone when calling a function like this:
def get_dev_model_and_embedder(model_id: str = "llama3.1:8b"):
from agno.embedder.ollama import OllamaEmbedder
from ollama import AsyncClient as AsyncOllamaClient
print("IN DEV")
ollama_host = getenv("OLLAMA_HOST", "http://ollama:11434")
embedder = OllamaEmbedder(host=ollama_host)
async_client = AsyncOllamaClient(host=ollama_host)
model = Ollama(id=model_id, host=ollama_host, async_client=async_client)
return model, embedder
def get_prd_model_and_embedder(model_id: str = "gpt-4o-mini"):
from agno.models.openai import OpenAIChat
from agno.embedder.openai import OpenAIEmbedder
from workspace.prd_resources import prd_secret
print("IN PROD", prd_secret.get_secret_value("OPENAI_API_KEY"))
openai_api_key = prd_secret.get_secret_value("OPENAI_API_KEY")
embedder = OpenAIEmbedder(api_key=openai_api_key)
model = OpenAIChat(id=model_id, api_key=openai_api_key)
return model, embedder
model, embedder = get_dev_model_and_embedder() if are_we_in_dev else get_prd_model_and_embedder()
In order to get this to work, we have to call our ag ws
commands with an environment variable:
AGNO_ENV=prd ag ws up --env prd --infra docker --type image
Isn’t it redundant to have to have both AGNO_ENV=prd
and the --env prd
flag? How can we just use the env
that is passed into the ag ws
command?