openlit 1.1.0 → 1.3.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 +1 -1
- package/package.json +1 -1
- package/src/constant.ts +6 -5
- package/src/features/base.ts +7 -0
- package/src/features/prompt-hub.ts +64 -0
- package/src/features/vault.ts +54 -0
- package/src/index.ts +2 -1
- package/src/prompt-hub.ts +64 -0
- package/src/types.ts +20 -0
package/README.md
CHANGED
|
@@ -132,7 +132,7 @@ export OTEL_EXPORTER_OTLP_HEADERS = "YOUR_OTEL_ENDPOINT_AUTH"
|
|
|
132
132
|
|
|
133
133
|
With the LLM Observability data now being collected and sent to OpenLIT, the next step is to visualize and analyze this data to get insights into your LLM application’s performance, behavior, and identify areas of improvement.
|
|
134
134
|
|
|
135
|
-
To begin exploring your LLM Application's performance data within the OpenLIT
|
|
135
|
+
To begin exploring your LLM Application's performance data within the OpenLIT, please see the [Quickstart Guide](https://docs.openlit.io/latest/quickstart).
|
|
136
136
|
|
|
137
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.
|
|
138
138
|
|
package/package.json
CHANGED
package/src/constant.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export const SDK_NAME =
|
|
2
|
-
export const DEFAULT_ENVIRONMENT =
|
|
3
|
-
export const DEFAULT_APPLICATION_NAME =
|
|
4
|
-
export const INSTRUMENTATION_PREFIX =
|
|
5
|
-
export const TELEMETRY_SDK_NAME = 'opentelemetry';
|
|
1
|
+
export const SDK_NAME = 'openlit';
|
|
2
|
+
export const DEFAULT_ENVIRONMENT = 'default';
|
|
3
|
+
export const DEFAULT_APPLICATION_NAME = 'default';
|
|
4
|
+
export const INSTRUMENTATION_PREFIX = '@openlit';
|
|
5
|
+
export const TELEMETRY_SDK_NAME = 'opentelemetry';
|
|
6
|
+
export const OPENLIT_URL = 'http://127.0.0.1:3000';
|
|
@@ -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,54 @@
|
|
|
1
|
+
import { OPENLIT_URL } from '../constant';
|
|
2
|
+
import { VaultOptions } from '../types';
|
|
3
|
+
|
|
4
|
+
export default class Vault {
|
|
5
|
+
static async getSecrets(options: VaultOptions) {
|
|
6
|
+
const url = process.env.OPENLIT_URL || options.url || OPENLIT_URL;
|
|
7
|
+
const apiKey = process.env.OPENLIT_API_KEY || options.apiKey || '';
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
const vaultResponse = await fetch(`${url}/api/vault/get-secrets`, {
|
|
11
|
+
method: 'POST',
|
|
12
|
+
body: JSON.stringify({
|
|
13
|
+
key: options.key,
|
|
14
|
+
tags: options.tags,
|
|
15
|
+
}),
|
|
16
|
+
headers: {
|
|
17
|
+
Authorization: `Bearer ${apiKey}`,
|
|
18
|
+
},
|
|
19
|
+
})
|
|
20
|
+
.then(async (response) => {
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
return {
|
|
23
|
+
err: `Openlit Error : HTTP error! Status: ${response.status}`,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return response.json();
|
|
27
|
+
})
|
|
28
|
+
.then((resp: any) => {
|
|
29
|
+
return resp;
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const { res = {} } = vaultResponse;
|
|
33
|
+
if (!!options.shouldSetEnv) {
|
|
34
|
+
Object.entries(res).forEach(([key, value]: [string, unknown]) => {
|
|
35
|
+
process.env[key] = value as string;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return vaultResponse;
|
|
40
|
+
} catch (e: any) {
|
|
41
|
+
console.log(e);
|
|
42
|
+
if (e && typeof e.toString === 'function') {
|
|
43
|
+
return {
|
|
44
|
+
err: `Openlit Error : ${e.toString()}`,
|
|
45
|
+
data: null,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
err: `Openlit Error : ${e}`,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -9,8 +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 BaseOpenlit from './features/base';
|
|
12
13
|
|
|
13
|
-
export default class Openlit {
|
|
14
|
+
export default class Openlit extends BaseOpenlit {
|
|
14
15
|
static resource: Resource;
|
|
15
16
|
static options: OpenlitOptions;
|
|
16
17
|
static _sdk: NodeSDK;
|
|
@@ -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
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -46,3 +46,23 @@ export type OpenlitOptions = {
|
|
|
46
46
|
export type SetupTracerOptions = OpenlitOptions & {
|
|
47
47
|
resource: Resource;
|
|
48
48
|
};
|
|
49
|
+
|
|
50
|
+
export interface BaseOpenlitOptions {
|
|
51
|
+
url?: string;
|
|
52
|
+
apiKey?: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface PromptHubOptions extends BaseOpenlitOptions {
|
|
56
|
+
name?: string;
|
|
57
|
+
version?: string;
|
|
58
|
+
shouldCompile?: boolean;
|
|
59
|
+
variables?: Record<string, any>;
|
|
60
|
+
promptId?: string;
|
|
61
|
+
metaProperties?: Record<string, any>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface VaultOptions extends BaseOpenlitOptions {
|
|
65
|
+
key?: string;
|
|
66
|
+
tags?: string[];
|
|
67
|
+
shouldSetEnv?: boolean;
|
|
68
|
+
}
|