get_model

Function get_model 

Source
pub fn get_model(fallback: Option<&str>, prefer_env: bool) -> Option<String>
Expand description

Get the model name with optional environment variable override.

This function provides flexible model name resolution with opt-in environment variable support. Unlike get_base_url, environment variable checking is controlled by the prefer_env parameter.

§Resolution Priority

If prefer_env is true:

  1. Environment Variable: OPEN_AGENT_MODEL (if set)
  2. Fallback Parameter: Explicit fallback value

If prefer_env is false:

  1. Fallback Parameter: Explicit fallback value only

§Why Optional Environment Override?

Model names are often specified explicitly in code for consistency across environments. The prefer_env flag gives you control over whether to allow environment overrides.

§Arguments

  • fallback - Optional explicit model name
  • prefer_env - Whether to check environment variable first

§Returns

Some(String) if a model name was found, None if no model specified

§Examples

use open_agent::get_model;

// Use explicit model name, allow environment override
let model = get_model(Some("llama3:8b"), true);

// Force specific model (ignore environment)
let model = get_model(Some("qwen2.5-32b"), false);

// Try environment only
let model = get_model(None, true);
// Returns Some(model) if OPEN_AGENT_MODEL is set, None otherwise