使用 OpenLLMetry 实现可观测性
OpenLLMetry 是一个基于 OpenTelemetry 的开源项目,用于追踪和监控 LLM 应用程序。它能连接所有主流可观测性平台(如 Datadog、Dynatrace、Honeycomb、New Relic 等),并在几分钟内完成安装。
如果你在 Colab 上打开这个笔记本,你可能需要安装 LlamaIndex 🦙 和 OpenLLMetry。
!pip install llama-index!pip install traceloop-sdk在 app.traceloop.com 注册 Traceloop。然后,前往 API 密钥页面 并创建一个新的 API 密钥。复制该密钥并粘贴到下方的单元格中。
如果您倾向于使用其他可观测性平台,如Datadog、Dynatrace、Honeycomb或其他平台,您可以在此处找到如何配置它的说明。
import os
os.environ["OPENAI_API_KEY"] = "sk-..."os.environ["TRACELOOP_API_KEY"] = "..."初始化 OpenLLMetry
Section titled “Initialize OpenLLMetry”from traceloop.sdk import Traceloop
Traceloop.init()[32mTraceloop syncing configuration and prompts[39m[32mTraceloop exporting traces to https://api.traceloop.com authenticating with bearer token[39m!mkdir -p 'data/paul_graham/'!wget 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/examples/data/paul_graham/paul_graham_essay.txt' -O 'data/paul_graham/paul_graham_essay.txt'--2024-01-12 12:43:16-- https://raw.githubusercontent.com/run-llama/llama_index/main/docs/examples/data/paul_graham/paul_graham_essay.txtResolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.109.133, 185.199.108.133, 185.199.111.133, ...Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.109.133|:443... connected.HTTP request sent, awaiting response... 200 OKLength: 75042 (73K) [text/plain]Saving to: ‘data/paul_graham/paul_graham_essay.txt’
data/paul_graham/pa 100%[===================>] 73.28K --.-KB/s in 0.02s
2024-01-12 12:43:17 (3.68 MB/s) - ‘data/paul_graham/paul_graham_essay.txt’ saved [75042/75042]from llama_index.core import SimpleDirectoryReader
docs = SimpleDirectoryReader("./data/paul_graham/").load_data()from llama_index.core import VectorStoreIndex
index = VectorStoreIndex.from_documents(docs)query_engine = index.as_query_engine()response = query_engine.query("What did the author do growing up?")print(response)The author wrote short stories and also worked on programming, specifically on an IBM 1401 computer in 9th grade. They used an early version of Fortran and typed programs on punch cards. They also mentioned getting a microcomputer, a TRS-80, in about 1980 and started programming on it.前往 Traceloop 或您喜欢的平台查看结果
Section titled “Go to Traceloop or your favorite platform to view the results”