opik 0.0.7 → 0.1.0

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 CHANGED
@@ -19,23 +19,48 @@ You can install the `opik` package using your favorite package manager.
19
19
  npm install opik
20
20
  ```
21
21
 
22
- ## Usage
22
+ ## Opik Configuration
23
+
24
+ You can configure the Opik client using environment variables.
25
+
26
+ ```bash
27
+ export OPIK_API_KEY="your-api-key"
28
+ export OPIK_HOST="https://www.comet.com/opik/api"
29
+ export OPIK_PROJECT_NAME="your-project-name"
30
+ export OPIK_WORKSPACE_NAME="your-workspace-name"
31
+ ```
32
+
33
+ Or you can pass the configuration to the Opik client constructor.
23
34
 
24
35
  ```typescript
25
36
  import { Opik } from "opik";
26
37
 
27
- // Create a new Opik client with your configuration
28
38
  const client = new Opik({
29
39
  apiKey: "<your-api-key>",
30
40
  host: "https://www.comet.com/opik/api",
31
41
  projectName: "<your-project-name>",
32
42
  workspaceName: "<your-workspace-name>",
33
43
  });
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ ```typescript
49
+ import { Opik } from "opik";
50
+
51
+ // Create a new Opik client with your configuration
52
+ const client = new Opik();
34
53
 
35
54
  // Log 10 traces
36
55
  for (let i = 0; i < 10; i++) {
37
56
  const someTrace = client.trace({
38
57
  name: `Trace ${i}`,
58
+ input: {
59
+ prompt: `Hello, world! ${i}`,
60
+ },
61
+ output: {
62
+ response: `Hello, world! ${i}`,
63
+ },
39
64
  });
40
65
 
41
66
  // For each trace, log 10 spans
@@ -43,8 +68,17 @@ for (let i = 0; i < 10; i++) {
43
68
  const someSpan = someTrace.span({
44
69
  name: `Span ${i}-${j}`,
45
70
  type: "llm",
71
+ input: {
72
+ prompt: `Hello, world! ${i}:${j}`,
73
+ },
74
+ output: {
75
+ response: `Hello, world! ${i}:${j}`,
76
+ },
46
77
  });
47
78
 
79
+ // Some LLM work
80
+ await new Promise((resolve) => setTimeout(resolve, 100));
81
+
48
82
  // Mark the span as ended
49
83
  someSpan.end();
50
84
  }
@@ -57,6 +91,56 @@ for (let i = 0; i < 10; i++) {
57
91
  await client.flush();
58
92
  ```
59
93
 
94
+ ## Vercel AI SDK Integration
95
+
96
+ Opik provides seamless integration with the Vercel AI SDK through OpenTelemetry instrumentation.
97
+
98
+ ### Installation
99
+
100
+ Install the required dependencies:
101
+
102
+ ```bash
103
+ npm install opik ai @opentelemetry/sdk-node @opentelemetry/auto-instrumentations-node
104
+ ```
105
+
106
+ ### Usage
107
+
108
+ ```typescript
109
+ import { openai } from "@ai-sdk/openai";
110
+ import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
111
+ import { NodeSDK } from "@opentelemetry/sdk-node";
112
+ import { generateText } from "ai";
113
+ import { OpikExporter } from "opik/vercel";
114
+
115
+ const sdk = new NodeSDK({
116
+ traceExporter: new OpikExporter(),
117
+ instrumentations: [getNodeAutoInstrumentations()],
118
+ });
119
+
120
+ sdk.start();
121
+
122
+ const { text } = await generateText({
123
+ model: openai("gpt-4o-mini"),
124
+ prompt: "What is love? Describe it in 10 words or less.",
125
+ experimental_telemetry: OpikExporter.getSettings({
126
+ name: "ai-sdk-integration",
127
+ }),
128
+ });
129
+
130
+ await sdk.shutdown();
131
+ ```
132
+
133
+ This integration automatically captures:
134
+
135
+ - Input prompts and messages
136
+ - Model responses
137
+ - Token usage statistics
138
+ - Tool calls and their results
139
+ - Timing information
140
+ - Error states
141
+
142
+ All this telemetry data is automatically sent to your Opik project for analysis and monitoring.
143
+
60
144
  ## Contributing
61
145
 
62
146
  Contributions are welcome! If you have any suggestions or improvements, please feel free to open an [issue](https://github.com/comet-ml/opik/issues) or submit a [pull request](https://github.com/comet-ml/opik/pulls).