Replies: 1 comment 1 reply
-
What LLM are you using? Most people either use a) a chat model (where the model provider decides what to do with the parameters) or b) their own formatting (since they want to control the strings) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi everyone,
I want to discuss how message trajectories are formatted in inputs to an LLM. The root of what I'll discuss doesn't originate from LangGraph itself, the code is in LangChain, but it becomes apparent when working with LangGraph.
When a list of messages is added in a graph and is formatted in the invocation to an LLM it's formatted with the
_convert_input
method of the model, there the list is formatted using theChatPromptValue
class.What happens is that a prefix of "System:/AI:"/"Human:" is added before each message based on the message type.
Example trajectory:
[SystemMessage(content="You are a helpful bot"), HumanMessage(content="Tell me a joke")]
would result in the following:
So far so good, but there are 2 problems:
So for a graph with multiple steps, e.g. when we add an offensive output filtering after the generation, the output of the LLM looks something like this for the following trajectory:
[SystemMessage(content="You are a helpful bot"), HumanMessage(content="Tell me a joke"), AIMessage(content="Why does 6 afraid of 7? because 7 8 9")]
Output would be:
AI: There is no offensive language in the text
This cause the next trajectory string to be:
Trajectory:
[SystemMessage(content="You are a helpful bot"), HumanMessage(content="Tell me a joke"), AIMessage(content="Why does 6 afraid of 7? because 7 8 9"), AIMessage(content="AI: There is no offensive language in the text")]
String output:
This causes a lot of problems with generation.
Instead, the role can be supplied in the invocation, which could in tern add it as a prefix upon invocation, i.e. for
[SystemMessage(content="You are a helpful bot"), HumanMessage(content="Tell me a joke"), AIMessage(content="Why does 6 afraid of 7? because 7 8 9")]
The invocation would receive this string as input:
Beta Was this translation helpful? Give feedback.
All reactions