View Source LangChain.Routing.PromptRoute (LangChain v0.3.0-rc.0)
Defines a route or direction a prompting interaction with an LLM can take.
This helps add complexity and specificity to an LLM's instructions without using many tokens and helps avoid combining many things into a single prompt setup. This works by letting the user's initial prompt define how the next prompt is setup. A first pass is run on the prompt to determine which of the provided PromptRoutes is the best match.
To better understand, let's see example of taking the user's input and classifying what supported activity or specialty it is best matched with.
User prompt:
Let's create a marketing focused blog post comparing three types of our trailer hitch products.
We want our assistant to use different prompts for the different types of activities it's capable of doing. Let's define the activities like this:
[
PromptRoute.new!(%{
name: "marketing_email",
description: "Create a marketing focused email",
chain: marketing_email_chain
}),
PromptRoute.new!(%{
name: "blog_post",
description: "Create a blog post that will be linked from the company's landing page",
chain: blog_post_chain
}),
PromptRoute.new!(%{
name: "support_triage",
description: "Triage a customer support request for severity and requested resolution",
chain: support_triage_chain
})
]
Given the user's prompt and the routes we provided, it will choose "blog_post". This leads to an LLMChain being setup for that purpose where the user's initial prompt can be re-run against the prompts we define for that route.
When a chain
is linked to each route, we can specify the model to use, the
prompt templates we want, and associate functions that can be used to
accomplish the task.
The selected LLMChain can then be run through a UI for chat interactions where the user and AI work together.
The name
will be returned by the LLM when a particular route is selected.
The description
is given to the LLM to help it determine if the route should
be selected based on the current input prompt.
Summary
Functions
Return the selected route based on the route name.
Build a new PromptRoute struct.
Build a new PromptRoute
struct and return it or raise an error if invalid.
Types
Functions
Return the selected route based on the route name.
@spec new(attrs :: map()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}
Build a new PromptRoute struct.
Build a new PromptRoute
struct and return it or raise an error if invalid.