View Source LangChain.Message (LangChain v0.1.0)

Models a complete Message for a chat LLM.

Roles

  • :system - a system message. Typically just one and it occurs first as a primer for how the LLM should behave.

  • :user - The user or application responses. Typically represents the "human" element of the exchange.

  • :assistant - Responses coming back from the LLM.

  • :arguments - The arguments can be set as a map where each key is an "argument". If set as a String, it is expected to be a JSON formatted string and will be parsed to a map. If there is an error parsing the arguments to JSON, it is considered an error.

    An empty map %{} means no arguments are passed.

  • :function - A message for returning the result of executing a function_call.

Functions

A function_call comes from the :assistant role. The function_name identifies the named function to execute.

Create a message of role :function to provide the function response.

Summary

Functions

Return if a Message is a function_call.

Build a new message and return an :ok/:error tuple with the result.

Build a new message and return it or raise an error if invalid.

Create a new assistant message which represents a response from the AI or LLM.

Create a new assistant message which represents a response from the AI or LLM.

Create a new function message to represent the result of an executed function.

Create a new function message to represent the result of an executed function.

Create a new function_call message to represent the request for a function to be executed.

Create a new function_call message to represent the request for a function to be executed.

Create a new system message which can prime the AI/Assistant for how to respond.

Create a new system message which can prime the AI/Assistant for how to respond.

Create a new user message which represents a human message or a message from the application.

Create a new user message which represents a human message or a message from the application.

Types

@type status() :: :complete | :cancelled | :length
@type t() :: %LangChain.Message{
  arguments: term(),
  content: term(),
  function_name: term(),
  index: term(),
  role: term(),
  status: term()
}

Functions

Link to this function

is_function_call?(message)

View Source

Return if a Message is a function_call.

@spec new(attrs :: map()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}

Build a new message and return an :ok/:error tuple with the result.

@spec new!(attrs :: map()) :: t() | no_return()

Build a new message and return it or raise an error if invalid.

Link to this function

new_assistant(content, status \\ :complete)

View Source
@spec new_assistant(content :: String.t(), status()) ::
  {:ok, t()} | {:error, Ecto.Changeset.t()}

Create a new assistant message which represents a response from the AI or LLM.

Link to this function

new_assistant!(content, status \\ :complete)

View Source
@spec new_assistant!(content :: String.t(), status()) :: t() | no_return()

Create a new assistant message which represents a response from the AI or LLM.

Link to this function

new_function(name, result)

View Source
@spec new_function(name :: String.t(), result :: any()) ::
  {:ok, t()} | {:error, Ecto.Changeset.t()}

Create a new function message to represent the result of an executed function.

Link to this function

new_function!(name, result)

View Source
@spec new_function!(name :: String.t(), result :: any()) :: t() | no_return()

Create a new function message to represent the result of an executed function.

Link to this function

new_function_call(name, raw_args)

View Source
@spec new_function_call(name :: String.t(), raw_args :: String.t()) ::
  {:ok, t()} | {:error, Ecto.Changeset.t()}

Create a new function_call message to represent the request for a function to be executed.

Link to this function

new_function_call!(name, raw_args)

View Source
@spec new_function_call!(name :: String.t(), raw_args :: String.t()) ::
  t() | no_return()

Create a new function_call message to represent the request for a function to be executed.

Link to this function

new_system(content \\ "You are a helpful assistant.")

View Source
@spec new_system(content :: String.t()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}

Create a new system message which can prime the AI/Assistant for how to respond.

Link to this function

new_system!(content \\ "You are a helpful assistant.")

View Source
@spec new_system!(content :: String.t()) :: t() | no_return()

Create a new system message which can prime the AI/Assistant for how to respond.

@spec new_user(content :: String.t()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}

Create a new user message which represents a human message or a message from the application.

@spec new_user!(content :: String.t()) :: t() | no_return()

Create a new user message which represents a human message or a message from the application.