Ragex.AI.Behaviour behaviour
(Ragex v0.3.1)
View Source
Defines the behaviour for AI provider implementations.
This abstraction allows Ragex to support multiple AI providers (DeepSeek, OpenAI, Anthropic, local LLMs) with a unified interface.
Summary
Callbacks
Generate a response from the AI provider.
Get provider information (name, models, capabilities).
Stream a response from the AI provider.
Validate provider configuration.
Types
Callbacks
@callback generate(prompt :: String.t(), context :: map() | nil, opts()) :: {:ok, response()} | {:error, term()}
Generate a response from the AI provider.
Parameters
prompt- User query or instructioncontext- Retrieved code context (optional)opts- Provider-specific options
Options
:temperature- Sampling temperature (0.0-2.0):max_tokens- Maximum response length:system_prompt- System instructions:model- Model override
Returns
{:ok, response}- Successful generation{:error, reason}- API error, rate limit, etc.
@callback info() :: map()
Get provider information (name, models, capabilities).
@callback stream_generate(prompt :: String.t(), context :: map() | nil, opts()) :: {:ok, Enumerable.t(chunk())} | {:error, term()}
Stream a response from the AI provider.
Returns a stream of chunks that can be consumed incrementally. Useful for real-time UI updates in MCP clients.
@callback validate_config() :: :ok | {:error, String.t()}
Validate provider configuration.
Called at application startup to ensure API keys, endpoints, etc. are valid.