View Source LangChain.Chains.TextToTitleChain (LangChain v0.2.0)

A convenience chain for turning a user's prompt text into a summarized title for the anticipated conversation.

Summary

Functions

Runs the TextToTitleChain and evaluates the result to return the final answer. If it was unable to generate a title, the fallback_title is returned.

Start a new LLMChain configuration.

Start a new TextToTitleChain and return it or raise an error if invalid.

Run a simple LLMChain to summarize the user's prompt into a title for the conversation. Uses the provided model. Recommend faster, simpler LLMs without streaming.

Types

@type t() :: %LangChain.Chains.TextToTitleChain{
  fallback_title: term(),
  input_text: term(),
  llm: term(),
  verbose: term()
}

Functions

Link to this function

evaluate(chain, opts \\ [])

View Source
@spec evaluate(t(), Keyword.t()) :: String.t()

Runs the TextToTitleChain and evaluates the result to return the final answer. If it was unable to generate a title, the fallback_title is returned.

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

Start a new LLMChain configuration.

{:ok, chain} = LLMChain.new(%{
  llm: %ChatOpenAI{model: "gpt-3.5-turbo", stream: false},
  input_text: "Let's create a marketing blog post about our new product 'Fuzzy Furries'"
})
@spec new!(attrs :: map()) :: t() | no_return()

Start a new TextToTitleChain and return it or raise an error if invalid.

chain = TextToTitleChain.new!(%{
  llm: %ChatOpenAI{model: "gpt-3.5-turbo", stream: false},
  input_text: "Let's create a marketing blog post about our new product 'Fuzzy Furries'"
})
@spec run(t(), Keyword.t()) :: String.t() | no_return()

Run a simple LLMChain to summarize the user's prompt into a title for the conversation. Uses the provided model. Recommend faster, simpler LLMs without streaming.

If it fails to summarize to a title, it returns the default text.

new_title = TextToTitleChain.new!(%{
  llm: %ChatOpenAI{model: "gpt-3.5-turbo", stream: false},
  input_text: "Let's create a marketing blog post about our new product 'Fuzzy Furries'"
})
|> TextToTitleChain.run()