View Source LlmComposer.Helpers (llm_composer v0.8.0)

Provides helper functions for the LlmComposer module, particularly for managing function calls and handling language model responses.

These helpers are designed to execute functions as part of the response processing pipeline, manage completions, and log relevant information for debugging.

Summary

Functions

Completes the chat flow by appending function results to the messages and re-running the completion process.

Executes the functions specified in the language model response, if any.

Types

@type action_result() ::
  {:ok, LlmComposer.LlmResponse.t()}
  | {:completion, LlmComposer.LlmResponse.t(), llmfunctions()}
  | {:error, term()}
@type llmfunctions() :: [LlmComposer.Function.t()]
@type messages() :: [term()]

Functions

Link to this function

maybe_complete_chat(res, messages, run_completion_fn)

View Source
@spec maybe_complete_chat(action_result(), messages(), function()) :: action_result()

Completes the chat flow by appending function results to the messages and re-running the completion process.

Parameters

  • action_result: The result of a previous action or completion.
  • messages: The list of messages exchanged so far.
  • run_completion_fn: A function to re-run the completion with updated messages.

Returns

  • The result of re-running the completion with the new set of messages and function results.
Link to this function

maybe_exec_functions(res, llm_functions)

View Source
@spec maybe_exec_functions(LlmComposer.LlmResponse.t(), llmfunctions()) ::
  action_result()

Executes the functions specified in the language model response, if any.

Parameters

  • res: The language model response containing actions to be executed.
  • llm_functions: A list of functions available for execution.

Returns

  • {:ok, res} if no actions are found in the response.
  • {:completion, res, results} if actions are executed, returning the completion status and results.