Packages
llm_composer
0.18.2
0.20.2
0.20.1
0.20.0
0.19.6
0.19.5
0.19.4
0.19.3
0.19.2
0.19.1
0.19.0
0.18.2
0.18.1
0.18.0
0.17.1
0.17.0
0.16.2
0.16.1
0.16.0
0.15.0
0.14.2
0.14.1
0.14.0
0.13.1
0.13.0
0.12.3
0.12.2
0.12.0
0.11.2
0.11.1
0.11.0
0.10.0
0.8.0
0.7.0
0.6.0
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.0
0.3.6
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.3.0
0.2.0
0.1.0
LlmComposer is an Elixir library that facilitates chat interactions with language models, providing tools to handle user messages, generate responses, and execute functions automatically based on model outputs.
Current section
Files
Jump to
Current section
Files
lib/llm_composer/provider.ex
defmodule LlmComposer.Provider do
@moduledoc """
Behaviour for provider modules used by `LlmComposer`.
A provider is responsible for:
- receiving normalized `LlmComposer.Message` inputs,
- calling an upstream API,
- returning a normalized `LlmComposer.LlmResponse`.
## Required callbacks
- `name/0`: returns the provider atom (for example, `:open_ai`, `:google`).
- `run/3`: executes one completion request.
`run/3` receives:
- `messages`: user/assistant/tool messages,
- `system_message`: system prompt message (or `nil`),
- `opts`: provider options (model, credentials, request params, stream flag, etc.).
It must return:
- `{:ok, %LlmComposer.LlmResponse{}}` on success,
- `{:error, reason}` on failure.
## Minimal implementation shape
```elixir
defmodule LlmComposer.Providers.MyProvider do
@behaviour LlmComposer.Provider
@impl LlmComposer.Provider
def name, do: :my_provider
@impl LlmComposer.Provider
def run(messages, system_message, opts) do
# 1) validate required opts (for example, :model / auth)
# 2) build provider request from messages + system_message
# 3) call API and map result into {:ok, %{response: body}} | {:error, reason}
# 4) normalize through your ProviderResponse adapter
end
end
```
For consistency with built-in providers, implement a `LlmComposer.ProviderResponse.*`
adapter so provider-specific payloads are parsed into `LlmComposer.LlmResponse`.
If streaming is supported, also add a `LlmComposer.ProviderStreamChunk.*` adapter.
"""
alias LlmComposer.LlmResponse
alias LlmComposer.Message
@callback run([Message.t()], Message.t() | nil, keyword()) ::
{:ok, LlmResponse.t()} | {:error, term()}
@callback name() :: atom
end