AI.ProviderRegistry (AI SDK v0.0.1-rc.0)

View Source

A registry for AI providers and their language models.

This module provides a central registry for managing different AI providers and their associated language models, enabling dynamic registration and lookup.

Summary

Functions

Returns a specification to start this module under a supervisor.

Gets a language model by its model ID string.

Retrieves a provider by its ID.

Registers a provider module with the given ID.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_language_model(model_id, opts \\ [])

Gets a language model by its model ID string.

Model IDs can be in the format "provider:model" to specify which provider should handle the model, e.g., "openai:gpt-4" or "anthropic:claude-3-sonnet".

Parameters

  • model_id - A string identifying the model, in format "provider:model_name"
  • opts - Optional configuration for the model

Returns

  • {:ok, language_model} - The initialized language model
  • {:error, reason} - If the model or provider could not be found

get_provider(provider_id)

Retrieves a provider by its ID.

Parameters

  • provider_id - The string ID of the provider to get

Returns

  • {:ok, provider} - The provider with its module and options
  • {:error, :not_found} - If no provider with that ID is registered

register(provider_id, provider_module, opts \\ [])

Registers a provider module with the given ID.

Parameters

  • provider_id - A string ID for the provider
  • provider_module - The module that implements the provider
  • opts - Optional configuration for the provider

Returns

  • :ok - If registration was successful
  • {:error, reason} - If registration failed

start_link(opts \\ [])