Skip to main content
This guide provides a quick overview for getting started with WRITER chat. WRITER has several chat models. You can find information about their latest models and their costs, context windows, and supported input types in the WRITER docs.

Overview

Integration details

Model features

Credentials

Sign up for WRITER AI Studio and follow this Quickstart to obtain an API key. Then, set the WRITER_API_KEY environment variable:
If you want to get automated tracing of your model calls, you can also set your LangSmith API key by uncommenting below:

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 the invoke method:
Then, you can access the content of the message:

Streaming

You can also stream the response. First, create a stream:
Then, iterate over the stream to get the chunks:

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

With ChatWriter.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:
These are passed in every model invocation. For example, to use a tool that gets the weather in a given location, you can define a Pydantic class and pass it to ChatWriter.bind_tools:
Then, you can invoke the model with the tool:
Finally, you can access the tool calls and proceed to execute your functions:

A note on tool binding

The ChatWriter.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 the max_concurrency:
Then, iterate over the batch to get the results:

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 use ChatWriter with a prompt template like so:

API reference

For detailed documentation of all ChatWriter features and configurations, head to the API reference.

Additional resources

You can find information about WRITER’s models (including costs, context windows, and supported input types) and tools in the WRITER docs.