Skip to main content

ProviderFactory

Struct ProviderFactory 

Source
pub struct ProviderFactory;
Expand description

Provider factory for creating LLM and embedding providers.

Provides environment-based auto-detection and explicit provider selection.

Implementations§

Source§

impl ProviderFactory

Source

pub fn from_env() -> Result<(Arc<dyn LLMProvider>, Arc<dyn EmbeddingProvider>)>

Auto-detect and create providers from environment.

§Priority
  1. EDGEQUAKE_LLM_PROVIDER environment variable (explicit selection)
  2. Auto-detect: OLLAMA_HOST → LMSTUDIO_HOST → OPENAI_API_KEY → Mock
§Returns

Returns a tuple of (LLMProvider, EmbeddingProvider). In most cases, the same provider implementation is used for both.

§Errors

Returns error if required configuration for selected provider is missing.

§Examples
std::env::set_var("OLLAMA_HOST", "http://localhost:11434");
let (llm, embedding) = ProviderFactory::from_env()?;
assert_eq!(llm.name(), "ollama");
Source

pub fn create( provider_type: ProviderType, ) -> Result<(Arc<dyn LLMProvider>, Arc<dyn EmbeddingProvider>)>

Create specific provider type.

§Arguments
  • provider_type - The type of provider to create
§Returns

Returns a tuple of (LLMProvider, EmbeddingProvider).

§Errors

Returns error if required configuration for the provider is missing.

Source

pub fn create_with_model( provider_type: ProviderType, model: Option<&str>, ) -> Result<(Arc<dyn LLMProvider>, Arc<dyn EmbeddingProvider>)>

OODA-04: Create specific provider type with a model override.

Like create() but allows specifying a model name instead of using defaults. Useful for CLI where user specifies --provider openrouter --model mistral/model.

§Arguments
  • provider_type - The type of provider to create
  • model - Optional model name to use instead of provider default
§Returns

Returns a tuple of (LLMProvider, EmbeddingProvider).

§Errors

Returns error if required configuration for the provider is missing.

Source

pub fn from_config( config: &ProviderConfig, ) -> Result<(Arc<dyn LLMProvider>, Arc<dyn EmbeddingProvider>)>

OODA-200: Create provider from TOML configuration.

This is the primary entry point for custom providers defined in models.toml. Supports both native providers (OpenAI, Ollama) and OpenAI-compatible APIs.

§Arguments
  • config - Provider configuration from models.toml
§Returns

Returns a tuple of (LLMProvider, EmbeddingProvider).

§Errors

Returns error if:

  • Required API key environment variable is not set
  • Base URL is not configured for OpenAI-compatible providers
§Examples
use edgequake_llm::{ModelsConfig, ProviderFactory};

let config = ModelsConfig::load()?;
let provider_config = config.get_provider("zai").unwrap();
let (llm, embedding) = ProviderFactory::from_config(provider_config)?;
Source

pub fn from_config_with_model( config: &ProviderConfig, model_name: Option<&str>, ) -> Result<(Arc<dyn LLMProvider>, Arc<dyn EmbeddingProvider>)>

Create provider from configuration with a specific model override.

This is used when the user selects a specific model via /model command that differs from the provider’s default model.

§Arguments
  • config - Provider configuration from models.toml
  • model_name - Optional model name to use instead of the default
§Returns

Tuple of (LLM provider, Embedding provider)

Source

pub fn create_azure_openai() -> Result<(Arc<dyn LLMProvider>, Arc<dyn EmbeddingProvider>)>

Create Azure OpenAI provider from environment variables.

Tries AZURE_OPENAI_CONTENTGEN_* first (common enterprise naming), then falls back to AZURE_OPENAI_* standard variables.

Environment variables (CONTENTGEN variant):

  • AZURE_OPENAI_CONTENTGEN_API_ENDPOINT → endpoint URL
  • AZURE_OPENAI_CONTENTGEN_API_KEY → API key
  • AZURE_OPENAI_CONTENTGEN_MODEL_DEPLOYMENT → deployment name
  • AZURE_OPENAI_CONTENTGEN_API_VERSION → (optional)

Environment variables (standard variant):

  • AZURE_OPENAI_ENDPOINT → endpoint URL
  • AZURE_OPENAI_API_KEY → API key
  • AZURE_OPENAI_DEPLOYMENT_NAME → deployment name
  • AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME → (optional)
  • AZURE_OPENAI_API_VERSION → (optional)
Source

pub fn embedding_dimension() -> Result<usize>

Get embedding dimension for current provider configuration.

Useful for configuring vector storage with the correct dimension.

§Examples
std::env::set_var("EDGEQUAKE_LLM_PROVIDER", "ollama");
let dim = ProviderFactory::embedding_dimension()?;
assert_eq!(dim, 768); // embeddinggemma dimension
Source

pub fn create_embedding_provider( provider_name: &str, model: &str, _dimension: usize, ) -> Result<Arc<dyn EmbeddingProvider>>

Create an embedding provider from workspace configuration.

This is used to create workspace-specific embedding providers for query execution. The provider is configured with the workspace’s embedding model and dimension.

@implements SPEC-032: Workspace-specific embedding in query process

§Arguments
  • provider_name - Provider type (e.g., “openai”, “ollama”, “lmstudio”, “vscode-copilot”, “mock”)
  • model - Embedding model name (e.g., “text-embedding-3-small”, “embeddinggemma:latest”)
  • dimension - Embedding dimension (e.g., 1536, 768)
§Returns

Returns an Arc<dyn EmbeddingProvider> configured for the workspace.

§Errors

Returns error if the provider type is unknown or required configuration is missing.

§Examples
let provider = ProviderFactory::create_embedding_provider(
    "ollama",
    "embeddinggemma:latest",
    768,
)?;
assert_eq!(provider.dimension(), 768);
Source

pub fn create_llm_provider( provider_name: &str, model: &str, ) -> Result<Arc<dyn LLMProvider>>

Create an LLM provider from workspace configuration.

This is used to create workspace-specific LLM providers for ingestion/extraction. The provider is configured with the workspace’s LLM model.

@implements SPEC-032: Workspace-specific LLM in ingestion process

§Arguments
  • provider_name - Provider type (e.g., “openai”, “ollama”, “lmstudio”, “mock”)
  • model - LLM model name (e.g., “gpt-4o-mini”, “gemma3:12b”)
§Returns

Returns an Arc<dyn LLMProvider> configured for the workspace.

§Errors

Returns error if the provider type is unknown or required configuration is missing.

§Examples
let provider = ProviderFactory::create_llm_provider(
    "ollama",
    "gemma3:12b",
)?;
assert_eq!(provider.model(), "gemma3:12b");

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more