Writer is a platform to generate different language content.
This example goes over how to use LangChain to interact with Writer
models.
To access Writer models you'll need to create a Writer account, get an API key, and install the writer-sdk
and langchain-community
packages.
Head to Writer AI Studio to sign up to OpenAI and generate an API key. Once you've done this set the WRITER_API_KEY environment variable:
import getpass
import os
if not os.environ.get("WRITER_API_KEY"):
os.environ["WRITER_API_KEY"] = getpass.getpass("Enter your Writer API key:")
Installation
The LangChain Writer integration lives in the langchain-community
package:
%pip install -qU langchain-community writer-sdk
[1m[[0m[34;49mnotice[0m[1;39;49m][0m[39;49m A new release of pip is available: [0m[31;49m24.2[0m[39;49m -> [0m[32;49m24.3.1[0m
[1m[[0m[34;49mnotice[0m[1;39;49m][0m[39;49m To update, run: [0m[32;49mpip install --upgrade pip[0m
Note: you may need to restart the kernel to use updated packages.
Now we can initialize our model object to interact with writer LLMs
from langchain_community.llms import Writer as WriterLLM
llm = WriterLLM(
temperature=0.7,
max_tokens=1000,
)
Invocation
response_text = llm.invoke(input="Write a poem")
Streaming
stream_response = llm.stream(input="Tell me a fairytale")
for chunk in stream_response:
print(chunk, end="")
Async
Writer support asynchronous calls via ainvoke() and astream() methods
API referenceFor detailed documentation of all Writer features, head to our API reference.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4