Overview
Integration details
Class | Package | Local | Serializable | JS support | Downloads | Version |
---|---|---|---|---|---|---|
ChatWriter | langchain-writer | ❌ | ❌ | ❌ |
Model features
Tool calling | Structured output | JSON mode | Image input | Audio input | Video input | Token-level streaming | Native async | Token usage | Logprobs |
---|---|---|---|---|---|---|---|---|---|
✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ |
Credentials
Sign up for WRITER AI Studio and follow this Quickstart to obtain an API key. Then, set the WRITER_API_KEY environment variable:Installation
ChatWriter
is available from the langchain-writer
package. Install it with:
Instantiation
Now we can instantiate our model object in order to generate chat completions:Usage
To use the model, you pass in a list of messages and call theinvoke
method:
Streaming
You can also stream the response. First, create a stream:Tool calling
WRITER models like Palmyra X5 support tool calling, which lets you describe tools and their arguments. The model will return a JSON object with a tool to invoke and the inputs to that tool.Binding tools
WithChatWriter.bind_tools
, you can easily pass in Pydantic classes, dictionary schemas, LangChain tools, or even functions as tools to the model. Under the hood, these are converted to tool schemas, which look like this:
ChatWriter.bind_tools
:
A note on tool binding
TheChatWriter.bind_tools()
method does not create a new instance with bound tools, but stores the received tools
and tool_choice
in the initial class instance attributes to pass them as parameters during the Palmyra LLM call while using ChatWriter
invocation. This approach allows the support of different tool types, e.g. function
and graph
. Graph
is one of the remotely called WRITER Palmyra tools. For further information, visit our docs.
For more information about tool usage in LangChain, visit the LangChain tool calling documentation.
Batching
You can also batch requests and set themax_concurrency
:
Asynchronous usage
All features above (invocation, streaming, batching, tools calling) also support asynchronous usage.Prompt templates
Prompt templates help to translate user input and parameters into instructions for a language model. You can useChatWriter
with a prompt template like so: