opik-langchain 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +113 -0
- package/package.json +11 -15
package/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Opik LangChain Integration
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/opik-langchain)
|
|
4
|
+
[](https://github.com/comet-ml/opik/blob/main/LICENSE)
|
|
5
|
+
|
|
6
|
+
Seamlessly integrate [Opik](https://www.comet.com/docs/opik/) observability with your [LangChain](https://js.langchain.com/) applications to trace, monitor, and debug your LLM chains, agents, and tools.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- 🔍 **Comprehensive Tracing**: Automatically trace LLM calls, chains, tools, retrievers, and agents
|
|
11
|
+
- 📊 **Hierarchical Visualization**: View your LangChain execution as a structured trace with parent-child relationships
|
|
12
|
+
- 📝 **Detailed Metadata Capture**: Record model names, prompts, completions, usage statistics, and custom metadata
|
|
13
|
+
- 🚨 **Error Handling**: Capture and visualize errors at every step of your LangChain execution
|
|
14
|
+
- 🏷️ **Custom Tagging**: Add custom tags to organize and filter your traces
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
# npm
|
|
20
|
+
npm install opik-langchain
|
|
21
|
+
|
|
22
|
+
# yarn
|
|
23
|
+
yarn add opik-langchain
|
|
24
|
+
|
|
25
|
+
# pnpm
|
|
26
|
+
pnpm add opik-langchain
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Requirements
|
|
30
|
+
|
|
31
|
+
- Node.js ≥ 18
|
|
32
|
+
- LangChain (`@langchain/core` ≥ 0.3.42)
|
|
33
|
+
- Opik SDK (automatically installed as a dependency)
|
|
34
|
+
|
|
35
|
+
## Quick Start
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { OpikCallbackHandler } from "opik-langchain";
|
|
39
|
+
import { ChatOpenAI } from "@langchain/openai";
|
|
40
|
+
|
|
41
|
+
// Create the Opik callback handler
|
|
42
|
+
const opikHandler = new OpikCallbackHandler();
|
|
43
|
+
|
|
44
|
+
// Create your LangChain components with the handler
|
|
45
|
+
const llm = new ChatOpenAI({
|
|
46
|
+
callbacks: [opikHandler],
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Run LLM
|
|
50
|
+
const response = await llm.invoke("Hello, how can you help me today?", {
|
|
51
|
+
callbacks: [opikHandler],
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Optionally, ensure all traces are sent before your app terminates
|
|
55
|
+
await opikHandler.flushAsync();
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Advanced Configuration
|
|
59
|
+
|
|
60
|
+
The `OpikCallbackHandler` constructor accepts the following options:
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
interface OpikCallbackHandlerOptions {
|
|
64
|
+
// Optional array of tags to apply to all traces
|
|
65
|
+
tags?: string[];
|
|
66
|
+
|
|
67
|
+
// Optional metadata to include with all traces
|
|
68
|
+
metadata?: Record<string, unknown>;
|
|
69
|
+
|
|
70
|
+
// Optional project name for Opik
|
|
71
|
+
projectName?: string;
|
|
72
|
+
|
|
73
|
+
// Optional pre-configured Opik client
|
|
74
|
+
client?: Opik;
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Capturing Custom Metadata
|
|
79
|
+
|
|
80
|
+
You can pass custom metadata when invoking your chains:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
const response = await chain.invoke(
|
|
84
|
+
{ input: "Tell me about AI" },
|
|
85
|
+
{
|
|
86
|
+
callbacks: [opikHandler],
|
|
87
|
+
metadata: {
|
|
88
|
+
userId: "user-123",
|
|
89
|
+
sessionId: "session-456",
|
|
90
|
+
requestId: "req-789",
|
|
91
|
+
},
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Viewing Traces
|
|
97
|
+
|
|
98
|
+
To view your traces:
|
|
99
|
+
|
|
100
|
+
1. Sign in to your [Comet account](https://www.comet.com/signin)
|
|
101
|
+
2. Navigate to the Opik section
|
|
102
|
+
3. Select your project to view all traces
|
|
103
|
+
4. Click on a specific trace to see the detailed execution flow
|
|
104
|
+
|
|
105
|
+
## Learn More
|
|
106
|
+
|
|
107
|
+
- [Opik Documentation](https://www.comet.com/docs/opik/)
|
|
108
|
+
- [LangChain Documentation](https://js.langchain.com/)
|
|
109
|
+
- [Opik TypeScript SDK](https://github.com/comet-ml/opik/tree/main/sdks/typescript)
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
Apache 2.0
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opik-langchain",
|
|
3
3
|
"description": "Opik TypeScript and JavaScript SDK integration with LangChain",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.1",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18"
|
|
7
7
|
},
|
|
@@ -32,20 +32,18 @@
|
|
|
32
32
|
"typescript-sdk",
|
|
33
33
|
"comet"
|
|
34
34
|
],
|
|
35
|
-
"main": "./dist/index.cjs",
|
|
36
|
-
"module": "./dist/index.js",
|
|
37
|
-
"types": "./dist/index.d.ts",
|
|
38
|
-
"type": "module",
|
|
39
35
|
"exports": {
|
|
40
|
-
"
|
|
36
|
+
"./package.json": "./package.json",
|
|
37
|
+
".": {
|
|
41
38
|
"types": "./dist/index.d.ts",
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
"import": {
|
|
45
|
-
"types": "./dist/index.d.mts",
|
|
46
|
-
"default": "./dist/index.mjs"
|
|
39
|
+
"import": "./dist/index.js",
|
|
40
|
+
"require": "./dist/index.cjs"
|
|
47
41
|
}
|
|
48
42
|
},
|
|
43
|
+
"main": "dist/index.cjs",
|
|
44
|
+
"module": "dist/index.js",
|
|
45
|
+
"types": "dist/index.d.ts",
|
|
46
|
+
"type": "module",
|
|
49
47
|
"scripts": {
|
|
50
48
|
"build": "tsup",
|
|
51
49
|
"watch": "tsup --watch",
|
|
@@ -58,11 +56,9 @@
|
|
|
58
56
|
"dist/**/*",
|
|
59
57
|
"README.md"
|
|
60
58
|
],
|
|
61
|
-
"dependencies": {
|
|
62
|
-
"opik": "^1.6.12"
|
|
63
|
-
},
|
|
64
59
|
"peerDependencies": {
|
|
65
|
-
"@langchain/core": "^0.3.42"
|
|
60
|
+
"@langchain/core": "^0.3.42",
|
|
61
|
+
"opik": "^1.6.12"
|
|
66
62
|
},
|
|
67
63
|
"devDependencies": {
|
|
68
64
|
"typescript": "^5.7.2",
|