Log10(日志10)
本页面介绍如何在LangChain中使用Log10。
什么是Log10?
Log10是一个无代理的LLM数据管理和应用开发平台,是一个开源项目(GitHub链接),它可以让您记录、调试和标记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.chat_models import ChatOpenAI
from langchain.schema 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_name="gpt-3.5-turbo", callbacks=[log10_callback])
更多详细信息 + 截图,包括自托管日志的说明。
如何在Log10中使用标签
from langchain import OpenAI
from langchain.chat_models import ChatAnthropic
from langchain.chat_models import ChatOpenAI
from langchain.schema 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_name="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="text-davinci-003", 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 import OpenAI
log10(openai)
with log10_session(tags=["foo", "bar"]):
# 记录直接的OpenAI调用
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)
# 通过Langchain记录调用
llm = OpenAI(model_name="text-ada-001", temperature=0.5)
response = llm.predict("You are a ping pong machine.\nPing?\n")
print(response)