Skip to main content

An integration package connecting Writer and LangChain

Project description

langchain-writer

This package contains the official LangChain integrations for Writer through their writer-sdk.

Installation and Setup

  • Install the LangChain partner package:
pip install -U langchain-writer
  • Sign up for Writer AI Studio and follow this Quickstart to obtain an API key.
  • Set your Writer API key as an environment variable (WRITER_API_KEY).

Chat capabilities

The ChatWriter class provides support of streaming and non-streaming chat completions, tool calls, batching, and asynchronous usage.

Streaming (sync/async):

from langchain_writer import ChatWriter

llm = ChatWriter()

# Sync chat call
generator = llm.stream("Sing a ballad of LangChain.")

for chunk in generator:
    print(chunk)

# Async chat call
generator = await llm.astream("Sing a ballad of LangChain.")

async for chunk in generator:
    print(chunk)

Non-streaming (sync/async):

from langchain_writer import ChatWriter

llm = ChatWriter()

# Sync chat call
llm.invoke("Sing a ballad of LangChain.")

# Async chat call
await llm.ainvoke("Sing a ballad of LangChain.")

Batching (sync/async)

from langchain_writer import ChatWriter

llm = ChatWriter()

llm.batch(
        [
            "How to cook pancakes?",
            "How to compose poem?",
            "How to run faster?",
        ],
        config={"max_concurrency": 2},
    )

Tool binding

from langchain_writer import ChatWriter
from langchain_core.tools import tool
from typing import Optional
from pydantic import BaseModel, Field


@tool
def get_supercopa_trophies_count(club_name: str) -> Optional[int]:
    """Returns information about supercopa trophies count.

    Args:
        club_name: Club you want to investigate info of supercopa trophies about

    Returns:
        Number of supercopa trophies or None if there is no info about requested club
    """
    # Tool implementation


class GetWeather(BaseModel):
    '''Get the current weather in a given location'''

    location: str = Field(..., description="The city and state, e.g. San Francisco, CA")


llm = ChatWriter()

llm.bind_tools([get_supercopa_trophies_count, GetWeather])

Additional resources

To learn more about LangChain, see the official LangChain documentation. To learn more about Writer, see the Writer developer documentation.

About Writer

Writer is the full-stack generative AI platform for enterprises. Quickly and easily build and deploy generative AI apps with a suite of developer tools fully integrated with our platform of LLMs, graph-based RAG tools, AI guardrails, and more. Learn more at writer.com.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_writer-0.3.2.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

langchain_writer-0.3.2-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file langchain_writer-0.3.2.tar.gz.

File metadata

  • Download URL: langchain_writer-0.3.2.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.7 Linux/6.8.0-59-generic

File hashes

Hashes for langchain_writer-0.3.2.tar.gz
Algorithm Hash digest
SHA256 242a69c700cd8c5c4438da2147f2ff8bb25309f08972391d5c87ff82c811d9f3
MD5 40debdbd67ed5ddbdd8288c44b408b62
BLAKE2b-256 be39455d0cff9877fc40fb20c19b8aa37452725fa859734529e9a4800a93092f

See more details on using hashes here.

File details

Details for the file langchain_writer-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: langchain_writer-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.7 Linux/6.8.0-59-generic

File hashes

Hashes for langchain_writer-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 10fbfecd48a22f4dd1ae63ea102b0ee86eb81d0fb14bdeb6820f65d9e7d66670
MD5 3c0305e1e266a86d9b7663e27347162f
BLAKE2b-256 d9835f12f5e937eff6906cc7dc5b8cbd476dc8bf87a02ab84828a6a2cc42401d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page