目录
创建API key
进入Getting started with LangSmith 点击
在新的页面需要登录,然后点击头像,然后是Settings
第一行API keys,然后Create Api Key
输入描述
得到key
设置环境变量(windows10)
or
os.environ['LANGCHAIN_API_KEY'] = LANGCHAIN_KEY
验证环境变量
api_key = os.getenv('LANGCHAIN_API_KEY')
print(api_key)
安装LangSmith库
命令
pip install -U langsmith
检查
pip show langsmith
结果
Name: langsmith
Version: 0.1.40
Summary: Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.
Home-page: https://smith.langchain.com/
Author: LangChain
Author-email: support@langchain.dev
License: MIT
Location: c:\users\grit\.conda\envs\sophia39\lib\site-packages
Requires: orjson, pydantic, requests
Required-by: langchain, langchain-community, langchain-core
Log your first trace
import sys
import os
current_dir = os.path.dirname(__file__)
parent_dir = os.path.dirname(current_dir)
sys.path.append(parent_dir)
from constants import LANGCHAIN_KEY,OEPNAI_KEY,PROXY_URL
os.environ['LANGCHAIN_API_KEY'] = LANGCHAIN_KEY
os.environ['OPENAI_API_KEY'] = OEPNAI_KEY
os.environ['OPENAI_API_BASE'] = PROXY_URL
import openai
from langsmith.wrappers import wrap_openai
from langsmith import traceable
# Auto-trace LLM calls in-context
client = wrap_openai(openai.Client())
@traceable # Auto-trace this function
def pipeline(user_input: str):
result = client.chat.completions.create(
messages=[{"role": "user", "content": user_input}],
model="gpt-3.5-turbo"
)
return result.choices[0].message.content
print(pipeline("Hello, world!"))
输出
Hello! How can I assist you today?
查看LangSmith输出轨迹
参考文献