diff --git a/crates/goose-api/README.md b/crates/goose-api/README.md index 3b5469a4..b7fb63a5 100644 --- a/crates/goose-api/README.md +++ b/crates/goose-api/README.md @@ -28,15 +28,19 @@ cargo build --release ## Configuration -Goose API supports configuration through both environment variables and a configuration file. The precedence order is: +Goose API supports configuration via environment variables and configuration files. +The precedence order is: 1. Environment variables (highest priority) -2. Configuration file (lower priority) -3. Default values (lowest priority) +2. Goose CLI configuration file (usually `~/.config/goose/config.yaml`) if it exists +3. `config` file shipped with the crate +4. Default values (lowest priority) ### Configuration File -Create a file named `config` (with no extension) in the directory where you run the goose-api. The format can be JSON, YAML, TOML, etc. (the `config` crate will detect the format automatically). +If no CLI configuration file is found, goose-api looks for a `config` file in its +crate directory. This file has no extension and can be JSON, YAML, TOML, etc. +The `config` crate will detect the format automatically. Example `config` file (YAML format): diff --git a/crates/goose-api/config b/crates/goose-api/config new file mode 100644 index 00000000..6c721877 --- /dev/null +++ b/crates/goose-api/config @@ -0,0 +1,8 @@ +# API server configuration +host: 0.0.0.0 +port: 8080 +api_key: kurac + +# Provider configuration +provider: ollama +model: qwen3:8b diff --git a/crates/goose-api/src/config.rs b/crates/goose-api/src/config.rs index 11911206..cc6057b9 100644 --- a/crates/goose-api/src/config.rs +++ b/crates/goose-api/src/config.rs @@ -8,7 +8,23 @@ use config::{builder::DefaultState, ConfigBuilder, Environment, File}; use serde_json::Value; pub fn load_configuration() -> std::result::Result { - let config_path = std::env::var("GOOSE_CONFIG").unwrap_or_else(|_| "config".to_string()); + // Determine the configuration file based on priority: + // 1. Explicit GOOSE_CONFIG env var + // 2. Goose CLI config if it exists + // 3. Fallback to config file packaged with goose-api + + let config_path = if let Ok(path) = std::env::var("GOOSE_CONFIG") { + path + } else { + let global = Config::global(); + if global.exists() { + global.path() + } else { + // Use the config file that ships with goose-api + format!("{}/config", env!("CARGO_MANIFEST_DIR")) + } + }; + let builder = ConfigBuilder::::default() .add_source(File::with_name(&config_path).required(false)) .add_source(Environment::with_prefix("GOOSE_API"));