mirror of
https://github.com/aljazceru/goose.git
synced 2026-02-14 02:54:30 +01:00
Merge pull request #16 from aljazceru/codex/analyze-goose-api-config-initialization
Improve goose-api configuration
This commit is contained in:
@@ -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):
|
||||
|
||||
|
||||
8
crates/goose-api/config
Normal file
8
crates/goose-api/config
Normal file
@@ -0,0 +1,8 @@
|
||||
# API server configuration
|
||||
host: 0.0.0.0
|
||||
port: 8080
|
||||
api_key: kurac
|
||||
|
||||
# Provider configuration
|
||||
provider: ollama
|
||||
model: qwen3:8b
|
||||
@@ -8,7 +8,23 @@ use config::{builder::DefaultState, ConfigBuilder, Environment, File};
|
||||
use serde_json::Value;
|
||||
|
||||
pub fn load_configuration() -> std::result::Result<config::Config, config::ConfigError> {
|
||||
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::<DefaultState>::default()
|
||||
.add_source(File::with_name(&config_path).required(false))
|
||||
.add_source(Environment::with_prefix("GOOSE_API"));
|
||||
|
||||
Reference in New Issue
Block a user