openlit 1.1.0 → 1.2.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/package.json +1 -1
- package/src/constant.ts +6 -5
- package/src/index.ts +2 -1
- package/src/prompt-hub.ts +64 -0
- package/src/types.ts +11 -0
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';
|
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 PromptHub from './prompt-hub';
|
|
12
13
|
|
|
13
|
-
export default class Openlit {
|
|
14
|
+
export default class Openlit extends PromptHub {
|
|
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,14 @@ export type OpenlitOptions = {
|
|
|
46
46
|
export type SetupTracerOptions = OpenlitOptions & {
|
|
47
47
|
resource: Resource;
|
|
48
48
|
};
|
|
49
|
+
|
|
50
|
+
export type PromptHubOptions = {
|
|
51
|
+
url?: string;
|
|
52
|
+
apiKey?: string;
|
|
53
|
+
name?: string;
|
|
54
|
+
version?: string;
|
|
55
|
+
shouldCompile?: boolean;
|
|
56
|
+
variables?: Record<string, any>;
|
|
57
|
+
promptId?: string;
|
|
58
|
+
metaProperties?: Record<string, any>;
|
|
59
|
+
};
|