View Source LangChain.Utils (LangChain v0.1.10)

Collection of helpful utilities mostly for internal use.

Summary

Functions

Return changeset errors as text with comma separated description.

Only add the key to the map if the value is present. When the value is a list, the key will not be added when the list is empty. If the value is nil, it will not be added.

Fire a streaming callback if present.

Creates and returns an anonymous function to handle the streaming request.

Translates an error message using gettext.

Translates the errors for a field from a keyword list of errors.

Validation helper. Validates a struct changeset that the LLM is a struct.

Types

@type callback_data() ::
  {:ok, Message.t() | MessageDelta.t() | [Message.t() | MessageDelta.t()]}
  | {:error, String.t()}

Functions

Link to this function

changeset_error_to_string(changeset)

View Source

Return changeset errors as text with comma separated description.

Link to this function

conditionally_add_to_map(map, key, value)

View Source
@spec conditionally_add_to_map(
  %{required(any()) => any()},
  key :: any(),
  value :: nil | list()
) :: %{
  required(any()) => any()
}

Only add the key to the map if the value is present. When the value is a list, the key will not be added when the list is empty. If the value is nil, it will not be added.

Link to this function

fire_callback(arg1, data, callback_fn)

View Source
@spec fire_callback(
  %{optional(:stream) => boolean()},
  data :: callback_data() | [callback_data()],
  (callback_data() -> any())
) :: :ok

Fire a streaming callback if present.

Link to this function

handle_stream_fn(model, process_response_fn, callback_fn)

View Source
@spec handle_stream_fn(
  %{optional(:stream) => boolean()},
  process_response_fn :: function(),
  callback_fn :: function()
) :: function()

Creates and returns an anonymous function to handle the streaming request.

Translates an error message using gettext.

Link to this function

translate_errors(errors, field)

View Source

Translates the errors for a field from a keyword list of errors.

Link to this function

validate_llm_is_struct(changeset)

View Source
@spec validate_llm_is_struct(Ecto.Changeset.t()) :: Ecto.Changeset.t()

Validation helper. Validates a struct changeset that the LLM is a struct.