In the LangCainJS documentation it is stated
Content blocks were introduced as a new property on messages in LangChain v1 to standardize content formats across providers while maintaining backward compatibility with existing code.
Content blocks are not a replacement for the content property, but rather a new property that can be used to access the content of a message in a standardized format.
I’m a bit confused by the phrasing here.
- Content blocks are not a replacement for the
contentproperty
When invoking a model with a HumanMessage, we can construct a HumanMessage with these contentBlocks.
Should we continue using the content property, or switch to the new contentBlocks property to define what we want to send ?
I believe all messages below are equivalent but content blocks offer a more standardized and type safe way of defining the input.
Or is the first option (using the standard langchain content format) sufficiently “standardized” to work across all providers already ?
// 1. Standard lanchain content format ?
new HumanMessage({
content: [
{ type: "text", text: "Describe the content of this document." },
{ type: "image", source_type: "url", url: publicImageUrl, },
],
});
// 2. openai native content format ?
new HumanMessage({
content: [
{ type: "text", text: "Describe this image." },
{
type: "image_url",
image_url: { url: publicImageUrl },
},
],
});
// 3. new contentBlock typed api
new HumanMessage({
contentBlocks: [
{type: "text", text: "Describe this image."},
{type: "image", url: publicImageUrl},
],
});
Is using the new contentBlock types the way to go also when constructing messages (and if so would they not act as a replacement for the content property ?
- lazily parse the
contentattribute into a standard, type-safe representation.
Another use-case as shown in the docs seems to be to “lazy-load” the existing content property into the new contentBlocks typing.
Use-case here is having a type safe and unified way to parse model results (regardless of providers I assume ?) (at the time of writing not all providers have support for these contentBlocks so not all of them can be lazy loaded into the new typing.
Is my understanding correct here ?