This package provides utilities for use across the Forecasting Research Institute's codebase.
Install the package using pip:
pip install git+https://github.com/forecastingresearch/utils.gitOr add it to your requirements.txt:
fri-utils
If you're using uv:
uv add fri-utilsfrom utils.llm.model_registry import configure_api_keys, MODELS
# Input the API key for any model provider you like!
configure_api_keys(
openai="...",
anthropic="...",
google="...",
xai="...",
together="...",
mistral="...",
)
# Call any model we support!
# See the full list of supported models in `utils/llm/model_registry.py`
model = next(m for m in MODELS if m.id == "gemini-2.5-flash")
model.get_response("Hello")
# > "Hello! How can I help you?"
model.get_response() accepts any optional argument your model accepts.
For example:
model.get_response(
'What is the capital of France?',
temperature=0,
max_tokens=256,
)
You can check whether an option is supported by looking at the code for the respective model provider (utils/llm/providers).
If you don’t see an option you need, feel free to open a GitHub issue!
In some cases, your project may have a API keys set in a Google Cloud Project.
If so, you can use the from_gcp=True shortcut to set your keys for all model providers:
configure_api_keys(from_gcp=True) # Configure all provider keys from GCP.
model = next(m for m in MODELS if m.id == "gpt-4.1-mini")
response = model.get_response("Hello")
If you're setting up a Google Cloud Project, the API keys must be stored in Secret Manager with the following names:
API_KEY_ANTHROPICfor AnthropicAPI_KEY_GEMINIfor Google/GeminiAPI_KEY_MISTRALfor MistralAPI_KEY_OPENAIfor OpenAIAPI_KEY_XAIfor xAIAPI_KEY_TOGETHERAIfor Together AI
You can also check utils/helpers/constants.py for the complete list of secret names.
To import other utilities from this package, use:
from utils import archiving # tar.gz compression & extraction
from utils import gcp # Google Cloud Storage utilitiesFor example:
from utils.gcp.storage import list_files, upload_file, download_file
from utils.archiving.tar_gz import compress_directory, extract_archiveFirst, install dependencies. We recommend using a virtual environment:
python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt
If you want to run the integration tests, make sure you're authenticated with Google Cloud. You'll need the gcloud CLI.
gcloud auth application-default login
After authenticating, you'll see a message like:
Credentials saved to file: [/home/yourusername/.config/gcloud/application_default_credentials.json]
Copy sample.env to .env and replace the GOOGLE_APPLICATION_CREDENTIALS with this path. (Reach out to a team member to check that you have the right values for the other variables in this file.)
To run unit tests:
make test
To run integration tests:
make test-integration-parallel
Be sure to lint your contribution before creating a pull request:
make lint
Check testing coverage:
make coverage