LLM的Comet日志记录器
项目描述
CometLLM 已被 opik 替换 - 请参阅 https://github.com/comet-ml/opik
CometLLM 是一个用于记录和可视化您的LLM提示和链的工具。使用CometLLM来识别有效的提示策略,简化您的故障排除,并确保可重复的工作流程!
⚡️ 快速开始
使用pip安装 comet_llm
Python库
pip install comet_llm
如果您还没有,请创建您的免费Comet账户 并从账户设置页面获取您的API密钥。
现在您可以开始记录您的第一个提示和响应
import comet_llm
comet_llm.log_prompt(
prompt="What is your name?",
output=" My name is Alex.",
api_key="<YOUR_COMET_API_KEY>",
)
🎯 功能
- 记录您的提示和响应,包括提示模板、变量、时间戳、持续时间以及您需要的任何元数据。
- 在UI中可视化您的提示和响应。
- 记录您所需的粒度的链执行。
- 在UI中可视化您的链执行。
- 自动跟踪使用OpenAI聊天模型时的提示。
- 跟踪和分析用户反馈。
- 在UI中比较提示并链式执行。
👀 示例
要将单个LLM调用作为单个提示记录,请使用comet_llm.log_prompt
。如果您需要更精细的记录,可以使用comet_llm.start_chain
记录一个可能包括多个LLM调用、上下文检索或数据预处理和后处理的执行链。
记录完整提示和响应
import comet_llm
comet_llm.log_prompt(
prompt="Answer the question and if the question can't be answered, say \"I don't know\"\n\n---\n\nQuestion: What is your name?\nAnswer:",
prompt_template="Answer the question and if the question can't be answered, say \"I don't know\"\n\n---\n\nQuestion: {{question}}?\nAnswer:",
prompt_template_variables={"question": "What is your name?"},
metadata= {
"usage.prompt_tokens": 7,
"usage.completion_tokens": 5,
"usage.total_tokens": 12,
},
output=" My name is Alex.",
duration=16.598,
)
记录LLM链
from comet_llm import Span, end_chain, start_chain
import datetime
from time import sleep
def retrieve_context(user_question):
if "open" in user_question:
return "Opening hours: 08:00 to 17:00 all days"
def llm_answering(user_question, current_time, context):
prompt_template = """You are a helpful chatbot. You have access to the following context:
{context}
The current time is: {current_time}
Analyze the following user question and decide if you can answer it, if the question can't be answered, say \"I don't know\":
{user_question}
"""
prompt = prompt_template.format(
user_question=user_question, current_time=current_time, context=context
)
with Span(
category="llm-call",
inputs={"prompt_template": prompt_template, "prompt": prompt},
) as span:
# Call your LLM model here
sleep(0.1)
result = "Yes we are currently open"
usage = {"prompt_tokens": 52, "completion_tokens": 12, "total_tokens": 64}
span.set_outputs(outputs={"result": result}, metadata={"usage": usage})
return result
def main(user_question, current_time):
start_chain(inputs={"user_question": user_question, "current_time": current_time})
with Span(
category="context-retrieval",
name="Retrieve Context",
inputs={"user_question": user_question},
) as span:
context = retrieve_context(user_question)
span.set_outputs(outputs={"context": context})
with Span(
category="llm-reasoning",
inputs={
"user_question": user_question,
"current_time": current_time,
"context": context,
},
) as span:
result = llm_answering(user_question, current_time, context)
span.set_outputs(outputs={"result": result})
end_chain(outputs={"result": result})
main("Are you open?", str(datetime.datetime.now().time()))
⚙️ 配置
您可以配置您的Comet凭据以及您要记录数据的位置
名称 | Python参数名称 | 环境变量名称 |
---|---|---|
Comet API密钥 | api_key | COMET_API_KEY |
Comet工作区名称 | workspace | COMET_WORKSPACE |
Comet项目名称 | project | COMET_PROJECT_NAME |
📝 许可证
版权所有(c)Comet 2023年至今。cometLLM
是免费且开源的软件,许可协议为MIT许可证。
CometLLM 已被 opik 替换 - 请参阅 https://github.com/comet-ml/opik
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源分发
comet_llm-2.2.7.tar.gz (37.0 kB 查看哈希值)
构建分发
comet_llm-2.2.7-py3-none-any.whl (73.2 kB 查看哈希值)
关闭
comet_llm-2.2.7.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 3fc5a394055e7042c0e35121df911647fca942a95097beca9cd57c5f50a795cb |
|
MD5 | b2719c1adba1cc432d51290e71c5d89c |
|
BLAKE2b-256 | b69abe0acd99cd78193882e6cd82113582921a4c00ae5dcd334c8232bdb49295 |
关闭
comet_llm-2.2.7-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | e70f8fca067b8fc576d473f920dac28be97b3222e86e8ae013eca9c0215ad5ef |
|
MD5 | b3e84b32fbc40d6ba24737a276ea2fdb |
|
BLAKE2b-256 | 1dc7a6a12810ae27883d0e3ff23a0c4c3dd0eb01c18624b5f56cd9082754a5c5 |