openinference-instrumentation-langchain 0.1.37
pip install openinference-instrumentation-langchain
Released:
OpenInference LangChain Instrumentation
Navigation
Unverified details
These details have not been verified by PyPIProject links
Meta
-
License Expression: Apache-2.0
SPDX License Expression - Author: OpenInference Authors
- Requires: Python <3.14, >=3.9
-
Provides-Extra:
instruments
,test
,type-check
Classifiers
- Development Status
- Intended Audience
- License
- Programming Language
Project description
OpenInference LangChain Instrumentation
Python auto-instrumentation library for LangChain.
These traces are fully OpenTelemetry compatible and can be sent to an OpenTelemetry collector for viewing, such as arize-phoenix
.
Installation
pip install openinference-instrumentation-langchain
Quickstart
Install packages needed for this demonstration.
pip install openinference-instrumentation-langchain langchain arize-phoenix opentelemetry-sdk opentelemetry-exporter-otlp
Start the Phoenix app in the background as a collector. By default, it listens on http://localhost:6006
. You can visit the app via a browser at the same address.
The Phoenix app does not send data over the internet. It only operates locally on your machine.
python -m phoenix.server.main serve
The following Python code sets up the LangChainInstrumentor
to trace langchain
and send the traces to Phoenix at the endpoint shown below.
from langchain.chains import LLMChain
from langchain_core.prompts import PromptTemplate
from langchain_openai import OpenAI
from openinference.instrumentation.langchain import LangChainInstrumentor
from opentelemetry import trace as trace_api
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk import trace as trace_sdk
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor
endpoint = "http://127.0.0.1:6006/v1/traces"
tracer_provider = trace_sdk.TracerProvider()
trace_api.set_tracer_provider(tracer_provider)
tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))
tracer_provider.add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter()))
LangChainInstrumentor().instrument()
To demonstrate langchain
tracing, we'll make a simple chain to tell a joke. First, configure your OpenAI credentials.
import os
os.environ["OPENAI_API_KEY"] = "<your openai key>"
Now we can create a chain and run it.
prompt_template = "Tell me a {adjective} joke"
prompt = PromptTemplate(input_variables=["adjective"], template=prompt_template)
llm = LLMChain(llm=OpenAI(), prompt=prompt, metadata={"category": "jokes"})
completion = llm.predict(adjective="funny", metadata={"variant": "funny"})
print(completion)
Visit the Phoenix app at http://localhost:6006
to see the traces.
More Info
Project details
Unverified details
These details have not been verified by PyPIProject links
Meta
-
License Expression: Apache-2.0
SPDX License Expression - Author: OpenInference Authors
- Requires: Python <3.14, >=3.9
-
Provides-Extra:
instruments
,test
,type-check
Classifiers
- Development Status
- Intended Audience
- License
- Programming Language
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Uploaded
Python 3
File details
Details for the file openinference_instrumentation_langchain-0.1.37.tar.gz
.
File metadata
- Download URL: openinference_instrumentation_langchain-0.1.37.tar.gz
- Upload date:
- Size: 49.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcd40a534777c89078dba7c77ed3b6c991cfab1761e7b516c7536a4a0cc30aef |
|
MD5 | 6f6c9af2bc3c5fc5c5f1d7c8cc5535fc |
|
BLAKE2b-256 | a27a56e9a4ff81c67c9a84af5ed69e5a6eab0196ab8a1a3f131f9217716f79db |
File details
Details for the file openinference_instrumentation_langchain-0.1.37-py3-none-any.whl
.
File metadata
- Download URL: openinference_instrumentation_langchain-0.1.37-py3-none-any.whl
- Upload date:
- Size: 18.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 335c4fc3a17f5645b5269b73147efc2c2d82ad8ac400a610c7d0a6e840b728ff |
|
MD5 | fde2722068f3f4516de76335781128f9 |
|
BLAKE2b-256 | 17451b8001b149665c5c39e0dfaf2ff93a0474f5717af5bc43a72d76f37ee54a |