openlit 1.2.0 → 1.3.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 +57 -16
- package/package.json +1 -1
- package/src/features/base.ts +7 -0
- package/src/features/prompt-hub.ts +64 -0
- package/src/features/vault.ts +62 -0
- package/src/index.ts +2 -2
- package/src/types.ts +11 -2
package/README.md
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<img src="https://github.com/openlit/.github/blob/main/profile/assets/wide-logo-no-bg.png?raw=true" alt="OpenLIT Logo" width="30%"
|
|
3
|
-
OpenTelemetry
|
|
2
|
+
<img src="https://github.com/openlit/.github/blob/main/profile/assets/wide-logo-no-bg.png?raw=true" alt="OpenLIT Logo" width="30%">
|
|
3
|
+
<h3>OpenTelemetry-native</h3>
|
|
4
|
+
<h1>AI Observability, Monitoring and Evaluation Framework</h1>
|
|
4
5
|
|
|
5
|
-
**[Documentation](https://docs.openlit.io/) | [Quickstart](#-getting-started) | [
|
|
6
|
+
**[Documentation](https://docs.openlit.io/) | [Quickstart](#-getting-started-with-llm-observability) | [Roadmap](#️-roadmap) | [Feature Request](https://github.com/openlit/openlit/issues/new?assignees=&labels=%3Araised_hand%3A+Up+for+Grabs%2C+%3Arocket%3A+Feature&projects=&template=feature-request.md&title=%5BFeat%5D%3A) | [Report a Bug](https://github.com/openlit/openlit/issues/new?assignees=&labels=%3Abug%3A+Bug%2C+%3Araised_hand%3A+Up+for+Grabs&projects=&template=bug.md&title=%5BBug%5D%3A)**
|
|
6
7
|
|
|
7
8
|
[](https://github.com/openlit/openlit)
|
|
8
9
|
[](https://github.com/openlit/openlit/blob/main/LICENSE)
|
|
@@ -11,18 +12,23 @@ OpenTelemetry Auto-Instrumentation for GenAI & LLM Applications</h1>
|
|
|
11
12
|
[](https://github.com/openlit/openlit/graphs/contributors)
|
|
12
13
|
|
|
13
14
|
[](https://join.slack.com/t/openlit/shared_invite/zt-2etnfttwg-TjP_7BZXfYg84oAukY8QRQ)
|
|
14
|
-
[](https://discord.gg/CQnXwNT3)
|
|
15
15
|
[](https://twitter.com/openlit_io)
|
|
16
16
|
|
|
17
17
|

|
|
18
18
|
|
|
19
19
|
</div>
|
|
20
20
|
|
|
21
|
-
OpenLIT
|
|
21
|
+
OpenLIT SDK is a monitoring framework built on top of **OpenTelemetry** that gives your complete Observability for your AI stack, from LLMs to vector databases, with just one line of code with tracing and metrics. It also allows you to send the generated traces and metrics to your existing monitoring tools like Grafana, New Relic, and more.
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
This project proudly follows and maintains the [Semantic Conventions](https://github.com/open-telemetry/semantic-conventions/tree/main/docs/gen-ai) with the OpenTelemetry community, consistently updating to align with the latest standards in Observability.
|
|
24
|
+
|
|
25
|
+
## ⚡ Features
|
|
26
|
+
|
|
27
|
+
- 🔎 **Auto Instrumentation**: Works with 30+ LLM providers and vector databases with just one line of code.
|
|
28
|
+
- 🔭 **OpenTelemetry-Native Observability SDKs**: Vendor-neutral SDKs that can send traces and metrics to your existing observability tool like Prometheus and Jaeger.
|
|
29
|
+
- 💲 **Cost Tracking for Custom and Fine-Tuned Models**: Pass custom pricing files for accurate budgeting of custom and fine-tuned models.
|
|
30
|
+
- 🚀 **Suppport for OpenLIT Features**: Includes suppprt for prompt management and secrets management features available in OpenLIT.
|
|
24
31
|
|
|
25
|
-
This project adheres to the [Semantic Conventions](https://github.com/open-telemetry/semantic-conventions/tree/main/docs/gen-ai) proposed by the OpenTelemetry community. You can check out the current definitions [here](src/semantic-convention.ts).
|
|
26
32
|
|
|
27
33
|
## Auto Instrumentation Capabilities
|
|
28
34
|
|
|
@@ -30,6 +36,7 @@ This project adheres to the [Semantic Conventions](https://github.com/open-telem
|
|
|
30
36
|
| --------------------------------------------------------------------- |
|
|
31
37
|
| [✅ OpenAI](https://docs.openlit.io/latest/integrations/openai) | [✅ ChromaDB](https://docs.openlit.io/latest/integrations/chromadb) | [✅ LiteLLM](https://docs.openlit.io/latest/integrations/litellm) | |
|
|
32
38
|
| [✅ Anthropic](https://docs.openlit.io/latest/integrations/anthropic) |
|
|
39
|
+
| [✅ Cohere](https://docs.openlit.io/latest/integrations/cohere) |
|
|
33
40
|
|
|
34
41
|
## Supported Destinations
|
|
35
42
|
|
|
@@ -65,7 +72,7 @@ npm install openlit
|
|
|
65
72
|
|
|
66
73
|
### Step 2: Initialize OpenLIT in your Application
|
|
67
74
|
|
|
68
|
-
|
|
75
|
+
Integrate OpenLIT into your AI applications by adding the following lines to your code.
|
|
69
76
|
|
|
70
77
|
```typescript
|
|
71
78
|
import Openlit from 'openlit';
|
|
@@ -73,11 +80,14 @@ import Openlit from 'openlit';
|
|
|
73
80
|
Openlit.init();
|
|
74
81
|
```
|
|
75
82
|
|
|
76
|
-
|
|
83
|
+
Configure the telemetry data destination as follows:
|
|
77
84
|
|
|
78
|
-
|
|
85
|
+
| Purpose | Parameter/Environment Variable | For Sending to OpenLIT |
|
|
86
|
+
|-------------------------------------------|--------------------------------------------------|--------------------------------|
|
|
87
|
+
| Send data to an HTTP OTLP endpoint | `otlpEndpoint` or `OTEL_EXPORTER_OTLP_ENDPOINT` | `"http://127.0.0.1:4318"` |
|
|
88
|
+
| Authenticate telemetry backends | `otlpHeaders` or `OTEL_EXPORTER_OTLP_HEADERS` | Not required by default |
|
|
79
89
|
|
|
80
|
-
|
|
90
|
+
> 💡 Info: If the `otlp_endpoint` or `OTEL_EXPORTER_OTLP_ENDPOINT` is not provided, the OpenLIT SDK will output traces directly to your console, which is recommended during the development phase.
|
|
81
91
|
|
|
82
92
|
#### Example
|
|
83
93
|
|
|
@@ -129,16 +139,17 @@ export OTEL_EXPORTER_OTLP_HEADERS = "YOUR_OTEL_ENDPOINT_AUTH"
|
|
|
129
139
|
---
|
|
130
140
|
|
|
131
141
|
### Step 3: Visualize and Optimize!
|
|
142
|
+
Now that your LLM observability data is being collected and sent to configured OpenTelemetry destination, the next step is to visualize and analyze this data. This will help you understand your LLM application's performance and behavior and identify where it can be improved.
|
|
132
143
|
|
|
133
|
-
|
|
144
|
+
If you want to use OpenLIT's Observability Dashboard to monitor LLM usage—like cost, tokens, and user interactions—please check out our [Quickstart Guide](https://docs.openlit.io/latest/quickstart).
|
|
134
145
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
If you want to integrate and send metrics and traces to your existing observability tools, refer to our [Connections Guide](https://docs.openlit.io/latest/connections/intro) for detailed instructions.
|
|
146
|
+
If you're sending metrics and traces to other observability tools, take a look at our [Connections Guide](https://docs.openlit.io/latest/connections/intro) to start using a pre-built dashboard we have created for these tools.
|
|
138
147
|
|
|
139
148
|

|
|
140
149
|
|
|
141
|
-
|
|
150
|
+
## Configuration
|
|
151
|
+
|
|
152
|
+
### Observability - `Openlit.init()`
|
|
142
153
|
|
|
143
154
|
Below is a detailed overview of the configuration options available, allowing you to adjust OpenLIT's behavior and functionality to align with your specific observability needs:
|
|
144
155
|
|
|
@@ -155,6 +166,36 @@ Below is a detailed overview of the configuration options available, allowing yo
|
|
|
155
166
|
| `instrumentations` | Object of instrumentation modules for manual patching | `undefined` | No |
|
|
156
167
|
| `pricing_json` | URL or file path of the pricing JSON file. | `https://github.com/openlit/openlit/blob/main/assets/pricing.json` | No |
|
|
157
168
|
|
|
169
|
+
### OpenLIT Prompt Hub - `Openlit.getPrompt()`
|
|
170
|
+
|
|
171
|
+
Below are the parameters for use with the SDK for OpenLIT Prompt Hub for prompt management:
|
|
172
|
+
|
|
173
|
+
| Parameter | Description |
|
|
174
|
+
|------------------|------------------------------------------------------------------------------------------------------------------------------------|
|
|
175
|
+
| `url` | Sets the OpenLIT URL. Defaults to the `OPENLIT_URL` environment variable or `http://127.0.0.1:3000` if not set. |
|
|
176
|
+
| `apiKey` | Sets the OpenLIT API Key. Can also be provided via the `OPENLIT_API_KEY` environment variable. |
|
|
177
|
+
| `name` | Sets the name to fetch a unique prompt. Use this or `promptId`. |
|
|
178
|
+
| `promptId` | Sets the ID to fetch a unique prompt. Use this or `name`. Optional |
|
|
179
|
+
| `version` | Sets the version to retrieve a specific prompt. Optional |
|
|
180
|
+
| `shouldCompile` | Boolean value that compiles the prompt using the provided variables. Optional |
|
|
181
|
+
| `variables` | Sets the variables for prompt compilation. Optional |
|
|
182
|
+
| `metaProperties` | Sets the meta-properties for storing in the prompt's access history metadata. |
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
### OpenLIT Vault - `Openlit.getSecrets()`
|
|
186
|
+
|
|
187
|
+
Below are the parameters for use with the SDK for OpenLIT Vault for secret management:
|
|
188
|
+
|
|
189
|
+
| Parameter | Description |
|
|
190
|
+
|------------------|------------------------------------------------------------------------------------------------------------------------------------|
|
|
191
|
+
| `url` | Sets the Openlit URL. Defaults to the `OPENLIT_URL` environment variable or `http://127.0.0.1:3000` if not set. |
|
|
192
|
+
| `apiKey` | Sets the OpenLIT API Key. Can also be provided via the `OPENLIT_API_KEY` environment variable. |
|
|
193
|
+
| `key` | Sets the key to fetch a specific secret. Optional |
|
|
194
|
+
| `tags` | Sets the tags for fetching only the secrets that have the mentioned tags assigned. Optional |
|
|
195
|
+
| `shouldSetEnv` | Boolean value that sets all the secrets as environment variables for the application. Optional |
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
158
199
|
## 🌱 Contributing
|
|
159
200
|
|
|
160
201
|
Whether it's big or small, we love contributions 💚. Check out our [Contribution guide](../../CONTRIBUTING.md) to get started
|
package/package.json
CHANGED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import OpenlitConfig from '../config';
|
|
2
|
+
import { OPENLIT_URL } from '../constant';
|
|
3
|
+
import { PromptHubOptions } from '../types';
|
|
4
|
+
|
|
5
|
+
export default class PromptHub {
|
|
6
|
+
static async getPrompts(options: PromptHubOptions) {
|
|
7
|
+
const url = process.env.OPENLIT_URL || options.url || OPENLIT_URL;
|
|
8
|
+
const apiKey = process.env.OPENLIT_API_KEY || options.apiKey || '';
|
|
9
|
+
let metaProperties = {
|
|
10
|
+
applicationName: OpenlitConfig.applicationName,
|
|
11
|
+
environment: OpenlitConfig.environment,
|
|
12
|
+
};
|
|
13
|
+
if (
|
|
14
|
+
options.metaProperties &&
|
|
15
|
+
typeof options.metaProperties === 'object' &&
|
|
16
|
+
!Array.isArray(options.metaProperties)
|
|
17
|
+
) {
|
|
18
|
+
metaProperties = {
|
|
19
|
+
...metaProperties,
|
|
20
|
+
...options.metaProperties,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
return await fetch(`${url}/api/prompt/get-compiled`, {
|
|
26
|
+
method: 'POST',
|
|
27
|
+
body: JSON.stringify({
|
|
28
|
+
name: options.name,
|
|
29
|
+
version: options.version,
|
|
30
|
+
shouldCompile: !!options.shouldCompile,
|
|
31
|
+
variables: options.variables || {},
|
|
32
|
+
id: options.promptId,
|
|
33
|
+
metaProperties,
|
|
34
|
+
source: 'ts-sdk',
|
|
35
|
+
}),
|
|
36
|
+
headers: {
|
|
37
|
+
Authorization: `Bearer ${apiKey}`,
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
.then(async (response) => {
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
return {
|
|
43
|
+
err: `Openlit Error : HTTP error! Status: ${response.status}`,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return response.json();
|
|
47
|
+
})
|
|
48
|
+
.then((resp: any) => {
|
|
49
|
+
return resp;
|
|
50
|
+
});
|
|
51
|
+
} catch (e: any) {
|
|
52
|
+
if (e && typeof e.toString === 'function') {
|
|
53
|
+
return {
|
|
54
|
+
err: `Openlit Error : ${e.toString()}`,
|
|
55
|
+
data: null,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
err: `Openlit Error : ${e}`,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import OpenlitConfig from '../config';
|
|
2
|
+
import { OPENLIT_URL } from '../constant';
|
|
3
|
+
import { VaultOptions } from '../types';
|
|
4
|
+
|
|
5
|
+
export default class Vault {
|
|
6
|
+
static async getSecrets(options: VaultOptions) {
|
|
7
|
+
const url = process.env.OPENLIT_URL || options.url || OPENLIT_URL;
|
|
8
|
+
const apiKey = process.env.OPENLIT_API_KEY || options.apiKey || '';
|
|
9
|
+
|
|
10
|
+
const metaProperties = {
|
|
11
|
+
applicationName: OpenlitConfig.applicationName,
|
|
12
|
+
environment: OpenlitConfig.environment,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const vaultResponse = await fetch(`${url}/api/vault/get-secrets`, {
|
|
17
|
+
method: 'POST',
|
|
18
|
+
body: JSON.stringify({
|
|
19
|
+
key: options.key,
|
|
20
|
+
tags: options.tags,
|
|
21
|
+
metaProperties,
|
|
22
|
+
source: 'ts-sdk',
|
|
23
|
+
}),
|
|
24
|
+
headers: {
|
|
25
|
+
Authorization: `Bearer ${apiKey}`,
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
.then(async (response) => {
|
|
29
|
+
if (!response.ok) {
|
|
30
|
+
return {
|
|
31
|
+
err: `Openlit Error : HTTP error! Status: ${response.status}`,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return response.json();
|
|
35
|
+
})
|
|
36
|
+
.then((resp: any) => {
|
|
37
|
+
return resp;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const { res = {} } = vaultResponse;
|
|
41
|
+
if (!!options.shouldSetEnv) {
|
|
42
|
+
Object.entries(res).forEach(([key, value]: [string, unknown]) => {
|
|
43
|
+
process.env[key] = value as string;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return vaultResponse;
|
|
48
|
+
} catch (e: any) {
|
|
49
|
+
console.log(e);
|
|
50
|
+
if (e && typeof e.toString === 'function') {
|
|
51
|
+
return {
|
|
52
|
+
err: `Openlit Error : ${e.toString()}`,
|
|
53
|
+
data: null,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
err: `Openlit Error : ${e}`,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -9,9 +9,9 @@ import { OpenlitOptions } from './types';
|
|
|
9
9
|
import Tracing from './tracing';
|
|
10
10
|
import { DEFAULT_APPLICATION_NAME, DEFAULT_ENVIRONMENT, SDK_NAME } from './constant';
|
|
11
11
|
import { SpanExporter } from '@opentelemetry/sdk-trace-base';
|
|
12
|
-
import
|
|
12
|
+
import BaseOpenlit from './features/base';
|
|
13
13
|
|
|
14
|
-
export default class Openlit extends
|
|
14
|
+
export default class Openlit extends BaseOpenlit {
|
|
15
15
|
static resource: Resource;
|
|
16
16
|
static options: OpenlitOptions;
|
|
17
17
|
static _sdk: NodeSDK;
|
package/src/types.ts
CHANGED
|
@@ -47,13 +47,22 @@ export type SetupTracerOptions = OpenlitOptions & {
|
|
|
47
47
|
resource: Resource;
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
export
|
|
50
|
+
export interface BaseOpenlitOptions {
|
|
51
51
|
url?: string;
|
|
52
52
|
apiKey?: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface PromptHubOptions extends BaseOpenlitOptions {
|
|
53
56
|
name?: string;
|
|
54
57
|
version?: string;
|
|
55
58
|
shouldCompile?: boolean;
|
|
56
59
|
variables?: Record<string, any>;
|
|
57
60
|
promptId?: string;
|
|
58
61
|
metaProperties?: Record<string, any>;
|
|
59
|
-
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface VaultOptions extends BaseOpenlitOptions {
|
|
65
|
+
key?: string;
|
|
66
|
+
tags?: string[];
|
|
67
|
+
shouldSetEnv?: boolean;
|
|
68
|
+
}
|