View Source LangChain.Utils.ChainResult (LangChain v0.2.0)

Module to help when working with the results of a chain.

Summary

Functions

Write the result to the given map as the value of the given key.

Write the result to the given map as the value of the given key. If invalid, an exception is raised.

Return the result of the chain as a string. Returned in an :ok tuple format. An {:error, reason} is returned for various reasons. These include

Return the last message's content when it is valid to use it. Otherwise it raises and exception with the reason why it cannot be used. See the docs for to_string/2 for details.

Functions

@spec to_map(LangChain.Chains.LLMChain.t(), map(), any()) ::
  {:ok, map()} | {:error, String.t()}

Write the result to the given map as the value of the given key.

Link to this function

to_map!(chain, map, key)

View Source
@spec to_map!(LangChain.Chains.LLMChain.t(), map(), any()) :: map() | no_return()

Write the result to the given map as the value of the given key. If invalid, an exception is raised.

@spec to_string(
  LangChain.Chains.LLMChain.t()
  | {:ok, LangChain.Chains.LLMChain.t(), LangChain.Message.t()}
  | {:error, String.t()}
) :: {:ok, String.t()} | {:error, String.t()}

Return the result of the chain as a string. Returned in an :ok tuple format. An {:error, reason} is returned for various reasons. These include:

  • The last message of the chain is not an :assistant message.
  • The last message of the chain is incomplete.
  • There is no last message.

This supports passing in the final, updated LLMChain, or the result of the LLMChain.run/2 function.

@spec to_string!(
  LangChain.Chains.LLMChain.t()
  | {:ok, LangChain.Chains.LLMChain.t(), LangChain.Message.t()}
  | {:error, String.t()}
) :: String.t() | no_return()

Return the last message's content when it is valid to use it. Otherwise it raises and exception with the reason why it cannot be used. See the docs for to_string/2 for details.