View Source Ollamex.Helpers (Ollamex v0.2.0)
Module containing helper functions used by the other modules of Ollamex.
Summary
Functions
Consolidates a list of %Ollamex.LLMResponse{}
structs into a single response, dealing with stream: false
and stream: true
, regardless of the origin of the responses (/chat
or /generate
).
Creates an async task from the provided function fun
with arguments args
.
Because the body of the responses of the /generate
, /chat
and /embeddings
endpoints of the Ollama REST API return different data structures, this helper function detects the endpoint from which a list of responses originated.
Extracts the chat message fragments from a list of %Ollamex.LLMResponse{}
from the /chat
endpoint and concatenates them into a string.
Extracts the response fragments from a list of %Ollamex.LLMResponse{}
from the /generate
endpoint and concatenates them into a string.
Converts a map to a target struct, so that API responses can be converted to Ollamex structs.
Yields the result of a task if within the provided timeout
(in milliseconds, default value 120_000
), or shuts the task down.
Functions
Consolidates a list of %Ollamex.LLMResponse{}
structs into a single response, dealing with stream: false
and stream: true
, regardless of the origin of the responses (/chat
or /generate
).
Creates an async task from the provided function fun
with arguments args
.
Because the body of the responses of the /generate
, /chat
and /embeddings
endpoints of the Ollama REST API return different data structures, this helper function detects the endpoint from which a list of responses originated.
Extracts the chat message fragments from a list of %Ollamex.LLMResponse{}
from the /chat
endpoint and concatenates them into a string.
Extracts the response fragments from a list of %Ollamex.LLMResponse{}
from the /generate
endpoint and concatenates them into a string.
Converts a map to a target struct, so that API responses can be converted to Ollamex structs.
yield_or_timeout_and_shutdown(task, timeout \\ 120_000)
View Source (since 0.1.0)Yields the result of a task if within the provided timeout
(in milliseconds, default value 120_000
), or shuts the task down.
Utilized by the Ollamex.generate_with_timeout/2
, Ollamex.generate_with_timeout/3
, Ollamex.chat_with_timeout/2
and Ollamex.chat_with_timeout/3
functions to deal with cases where the LLM keeps going on and on with repetition.