Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions crates/goose/src/providers/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub struct OpenAiProvider {
project: Option<String>,
model: ModelConfig,
custom_headers: Option<HashMap<String, String>>,
enable_streaming: bool,
enable_embeddings: bool,
}

impl Default for OpenAiProvider {
Expand All @@ -74,6 +76,16 @@ impl OpenAiProvider {
.or_else(|_| config.get_param("OPENAI_CUSTOM_HEADERS"))
.ok()
.map(parse_custom_headers);
let enable_streaming: bool = config
.get_param("OPENAI_ENABLE_STREAMING")
.unwrap_or_else(|_| "true".to_string())
.parse()
.unwrap_or(true);
let enable_embeddings: bool = config
.get_param("OPENAI_ENABLE_EMBEDDINGS")
.unwrap_or_else(|_| "true".to_string())
.parse()
.unwrap_or(true);
let timeout_secs: u64 = config.get_param("OPENAI_TIMEOUT").unwrap_or(600);
let client = Client::builder()
.timeout(Duration::from_secs(timeout_secs))
Expand All @@ -88,6 +100,8 @@ impl OpenAiProvider {
project,
model,
custom_headers,
enable_streaming,
enable_embeddings,
})
}

Expand Down Expand Up @@ -156,6 +170,8 @@ impl Provider for OpenAiProvider {
ConfigKey::new("OPENAI_ORGANIZATION", false, false, None),
ConfigKey::new("OPENAI_PROJECT", false, false, None),
ConfigKey::new("OPENAI_CUSTOM_HEADERS", false, true, None),
ConfigKey::new("OPENAI_ENABLE_STREAMING", false, false, Some("true")),
ConfigKey::new("OPENAI_ENABLE_EMBEDDINGS", false, false, Some("true")),
ConfigKey::new("OPENAI_TIMEOUT", false, false, Some("600")),
],
)
Expand Down Expand Up @@ -232,7 +248,7 @@ impl Provider for OpenAiProvider {
}

fn supports_embeddings(&self) -> bool {
true
self.enable_embeddings
}

async fn create_embeddings(&self, texts: Vec<String>) -> Result<Vec<Vec<f32>>, ProviderError> {
Expand All @@ -242,7 +258,7 @@ impl Provider for OpenAiProvider {
}

fn supports_streaming(&self) -> bool {
true
self.enable_streaming
}

async fn stream(
Expand Down
4 changes: 3 additions & 1 deletion documentation/docs/getting-started/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Goose relies heavily on tool calling capabilities and currently works best with
| [Groq](https://groq.com/) | High-performance inference hardware and tools for LLMs. | `GROQ_API_KEY` |
| [Ollama](https://ollama.com/) | Local model runner supporting Qwen, Llama, DeepSeek, and other open-source models. **Because this provider runs locally, you must first [download and run a model](#local-llms).** | `OLLAMA_HOST` |
| [Ramalama](https://ramalama.ai/) | Local model using native [OCI](https://opencontainers.org/) container runtimes, [CNCF](https://www.cncf.io/) tools, and supporting models as OCI artifacts. Ramalama API an compatible alternative to Ollama and can be used with the Goose Ollama provider. Supports Qwen, Llama, DeepSeek, and other open-source models. **Because this provider runs locally, you must first [download and run a model](#local-llms).** | `OLLAMA_HOST` |
| [OpenAI](https://platform.openai.com/api-keys) | Provides gpt-4o, o1, and other advanced language models. Also supports OpenAI-compatible endpoints (e.g., self-hosted LLaMA, vLLM, KServe). **o1-mini and o1-preview are not supported because Goose uses tool calling.** | `OPENAI_API_KEY`, `OPENAI_HOST` (optional), `OPENAI_ORGANIZATION` (optional), `OPENAI_PROJECT` (optional), `OPENAI_CUSTOM_HEADERS` (optional) |
| [OpenAI](https://platform.openai.com/api-keys) | Provides gpt-4o, o1, and other advanced language models. Also supports OpenAI-compatible endpoints (e.g., self-hosted LLaMA, vLLM, KServe). **o1-mini and o1-preview are not supported because Goose uses tool calling.** | `OPENAI_API_KEY`, `OPENAI_HOST` (optional), `OPENAI_ORGANIZATION` (optional), `OPENAI_PROJECT` (optional), `OPENAI_CUSTOM_HEADERS` (optional), `OPENAI_ENABLE_STREAMING` (optional), `OPENAI_ENABLE_EMBEDDINGS` (optional) |
| [OpenRouter](https://openrouter.ai/) | API gateway for unified access to various models with features like rate-limiting management. | `OPENROUTER_API_KEY` |
| [Snowflake](https://docs.snowflake.com/user-guide/snowflake-cortex/aisql#choosing-a-model) | Access the latest models using Snowflake Cortex services, including Claude models. **Requires a Snowflake account and programmatic access token (PAT)**. | `SNOWFLAKE_HOST`, `SNOWFLAKE_TOKEN` |
| [Venice AI](https://venice.ai/home) | Provides access to open source models like Llama, Mistral, and Qwen while prioritizing user privacy. **Requires an account and an [API key](https://docs.venice.ai/overview/guides/generating-api-key)**. | `VENICE_API_KEY`, `VENICE_HOST` (optional), `VENICE_BASE_PATH` (optional), `VENICE_MODELS_PATH` (optional) |
Expand Down Expand Up @@ -165,6 +165,8 @@ Goose supports using custom OpenAI-compatible endpoints, which is particularly u
| `OPENAI_ORGANIZATION` | No | Organization ID for usage tracking and governance |
| `OPENAI_PROJECT` | No | Project identifier for resource management |
| `OPENAI_CUSTOM_HEADERS` | No | Additional headers to include in the request. Can be set via environment variable, configuration file, or CLI, in the format `HEADER_A=VALUE_A,HEADER_B=VALUE_B`. |
| `OPENAI_ENABLE_STREAMING` | No | Enable or disable streaming support (defaults to true) |
| `OPENAI_ENABLE_EMBEDDINGS` | No | Enable or disable embeddings support (defaults to true) |

### Example Configurations

Expand Down
Loading