Log10
本页面介绍了如何在LangChain中使用Log10。
什么是Log10?
Log10 是一个 开源 的无代理 LLM 数据管理和应用开发平台,允许您记录、调试和标记您的 Langchain 调用。
快速开始
- 在log10.io创建您的免费账户
- 从设置和组织选项卡中分别添加您的
LOG10_TOKEN
和LOG10_ORG_ID
作为环境变量。 - 同时添加
LOG10_URL=https://log10.io
和你常用的 LLM API 密钥:例如OPENAI_API_KEY
或ANTHROPIC_API_KEY
到你的环境中
如何为Langchain启用Log10数据管理
与log10的集成是一个简单的单行log10_callback
集成,如下所示:
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage
from log10.langchain import Log10Callback
from log10.llm import Log10Config
log10_callback = Log10Callback(log10_config=Log10Config())
messages = [
HumanMessage(content="You are a ping pong machine"),
HumanMessage(content="Ping?"),
]
llm = ChatOpenAI(model="gpt-3.5-turbo", callbacks=[log10_callback])
API Reference:ChatOpenAI | HumanMessage
更多详情 + 截图 包括自托管日志的说明
如何使用标签与Log10
from langchain_openai import OpenAI
from langchain_community.chat_models import ChatAnthropic
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage
from log10.langchain import Log10Callback
from log10.llm import Log10Config
log10_callback = Log10Callback(log10_config=Log10Config())
messages = [
HumanMessage(content="You are a ping pong machine"),
HumanMessage(content="Ping?"),
]
llm = ChatOpenAI(model="gpt-3.5-turbo", callbacks=[log10_callback], temperature=0.5, tags=["test"])
completion = llm.predict_messages(messages, tags=["foobar"])
print(completion)
llm = ChatAnthropic(model="claude-2", callbacks=[log10_callback], temperature=0.7, tags=["baz"])
llm.predict_messages(messages)
print(completion)
llm = OpenAI(model_name="gpt-3.5-turbo-instruct", callbacks=[log10_callback], temperature=0.5)
completion = llm.predict("You are a ping pong machine.\nPing?\n")
print(completion)
你也可以混合使用直接的OpenAI调用和Langchain LLM调用:
import os
from log10.load import log10, log10_session
import openai
from langchain_openai import OpenAI
log10(openai)
with log10_session(tags=["foo", "bar"]):
# Log a direct OpenAI call
response = openai.Completion.create(
model="text-ada-001",
prompt="Where is the Eiffel Tower?",
temperature=0,
max_tokens=1024,
top_p=1,
frequency_penalty=0,
presence_penalty=0,
)
print(response)
# Log a call via Langchain
llm = OpenAI(model_name="text-ada-001", temperature=0.5)
response = llm.predict("You are a ping pong machine.\nPing?\n")
print(response)
API Reference:OpenAI