Packages
llm_composer
0.17.0
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_response/parser/ollama.ex
defmodule LlmComposer.ProviderResponse.Parser.Ollama do
@moduledoc false
alias LlmComposer.LlmResponse
alias LlmComposer.Message
@spec parse({:ok | :error, any()}, atom(), keyword()) ::
{:ok, LlmResponse.t()} | {:error, term()}
def parse({:error, resp}, _provider, _opts), do: {:error, resp}
def parse({:ok, %{response: stream}} = raw_result, :ollama, _opts) when is_function(stream) do
{:ok,
LlmResponse.new(%{
provider: :ollama,
status: :ok,
stream: stream,
raw: raw_result
})}
end
def parse({:ok, %{response: response}} = raw_result, :ollama, _opts) when is_list(response) do
if Enum.all?(response, &is_binary/1) do
{:ok,
LlmResponse.new(%{
provider: :ollama,
status: :ok,
stream: response,
raw: raw_result
})}
else
{:error,
%{
reason: :unhandled_response_format,
provider: :ollama,
response: raw_result
}}
end
end
def parse({:ok, %{response: response} = provider_response}, :ollama, _opts) do
message_data = response["message"]
base_message =
message_data["role"]
|> String.to_existing_atom()
|> Message.new(message_data["content"], %{original: message_data})
message = %{base_message | reasoning: message_data["thinking"]}
{:ok,
LlmResponse.new(%{
provider: :ollama,
status: :ok,
main_response: message,
cost_info: Map.get(provider_response, :cost_info),
raw: response
})}
end
def parse(result, provider, _opts) do
{:error,
%{
reason: :unhandled_response_format,
provider: provider,
response: result
}}
end
end