Introduction to LangSmith Client SDKs
LangSmith Client SDKs are powerful tools designed to facilitate seamless interaction with the LangSmith platform. These software development kits (SDKs) are available in both Python and JavaScript, enabling developers to integrate, debug, evaluate, and monitor language models and intelligent agents with ease.
Overview
Developed by LangChain, the same team behind the LangChain framework, LangSmith serves as a versatile companion for any Language Model (LLM) application. It provides robust support, including native integrations with open-source libraries like LangChain Python and LangChain JS. This integration helps users effectively manage and optimize their language models.
Getting Started with LangSmith SDKs
Python SDK
To begin using the LangSmith SDK for Python, you need to install the package from the Python Package Index (PyPI). Installation can be completed with the following commands:
pip install -U langsmith
export LANGCHAIN_TRACING_V2=true
export LANGCHAIN_API_KEY=ls_...
Following installation, you can start tracing your language model applications. Integrating LangSmith involves wrapping your existing OpenAI client to track interactions:
import openai
from langsmith import traceable
from langsmith.wrappers import wrap_openai
client = wrap_openai(openai.Client())
client.chat.completions.create(
messages=[{"role": "user", "content": "Hello, world"}],
model="gpt-3.5-turbo"
)
JavaScript/TypeScript SDK
For JavaScript and TypeScript users, the LangSmith SDK can be added via npm:
yarn add langsmith
export LANGCHAIN_TRACING_V2=true
export LANGCHAIN_API_KEY=ls_...
Once the package is installed, you can begin tracing your language models similar to the Python SDK. Here's how to do it with an OpenAI client:
import { OpenAI } from "openai";
import { traceable } from "langsmith/traceable";
import { wrapOpenAI } from "langsmith/wrappers";
const client = wrapOpenAI(new OpenAI());
await client.chat.completions.create({
model: "gpt-3.5-turbo",
messages: [{ content: "Hi there!", role: "user" }],
});
The above implementation logs the response and interaction details, aiding in comprehensive model monitoring and debugging.
Additional Resources
-
Cookbook: For more advanced tutorials and guides, the LangSmith Cookbook provides a treasure trove of examples and best practices to help you maximize the potential of LangSmith SDKs. You can explore these resources on GitHub.
-
Documentation: For a deeper understanding of the features and capabilities of the LangSmith platform, refer to the comprehensive LangSmith Documentation.
LangSmith SDKs offer a robust and user-friendly platform for developers seeking to enhance their application’s interaction with language models. Whether you're working with Python or JavaScript, these SDKs provide the tools necessary to ensure your language model applications run smoothly and efficiently.