@@ -19,75 +19,85 @@ export default (client: LiteralClient) => ({
19
19
* @param options.metadata Metadata to attach to all generations.
20
20
* @returns
21
21
*/
22
- openai : ( options ?: OpenAIGlobalOptions ) => {
23
- try {
24
- // eslint-disable-next-line @typescript-eslint/no-var-requires
25
- const { default : instrumentOpenAI } = require ( './openai' ) ;
26
- return instrumentOpenAI ( client , options ) ;
27
- } catch ( error ) {
28
- throw new Error (
29
- 'Failed to load OpenAI. Please ensure openai is installed.'
30
- ) ;
31
- }
32
- } ,
33
-
34
- langchain : {
35
- literalCallback : ( params ?: {
36
- threadId ?: string ;
37
- chainTypesToIgnore ?: string [ ] ;
38
- } ) => {
22
+ get openai ( ) {
23
+ return ( options ?: OpenAIGlobalOptions ) => {
39
24
try {
40
25
// eslint-disable-next-line @typescript-eslint/no-var-requires
41
- const { LiteralCallbackHandler } = require ( './langchain' ) ;
42
- return new LiteralCallbackHandler (
43
- client ,
44
- params ?. threadId ,
45
- params ?. chainTypesToIgnore
46
- ) ;
26
+ const { default : instrumentOpenAI } = require ( './openai' ) ;
27
+ return instrumentOpenAI ( client , options ) ;
47
28
} catch ( error ) {
48
29
throw new Error (
49
- 'Failed to load langchain . Please ensure langchain is installed.'
30
+ 'Failed to load OpenAI . Please ensure openai is installed.'
50
31
) ;
51
32
}
52
- }
33
+ } ;
53
34
} ,
54
35
55
- vercel : {
56
- instrument : < TFunction extends AllVercelFn > ( fn : TFunction ) => {
57
- try {
58
- // eslint-disable-next-line @typescript-eslint/no-var-requires
59
- const { makeInstrumentVercelSDK } = require ( './vercel-sdk' ) ;
60
- return makeInstrumentVercelSDK ( client ) ( fn ) ;
61
- } catch ( error ) {
62
- throw new Error (
63
- 'Failed to load Vercel SDK. Please ensure @vercel/ai is installed.'
64
- ) ;
36
+ get langchain ( ) {
37
+ return {
38
+ literalCallback : ( params ?: {
39
+ threadId ?: string ;
40
+ chainTypesToIgnore ?: string [ ] ;
41
+ } ) => {
42
+ try {
43
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
44
+ const { LiteralCallbackHandler } = require ( './langchain' ) ;
45
+ return new LiteralCallbackHandler (
46
+ client ,
47
+ params ?. threadId ,
48
+ params ?. chainTypesToIgnore
49
+ ) ;
50
+ } catch ( error ) {
51
+ throw new Error (
52
+ 'Failed to load langchain. Please ensure langchain is installed.'
53
+ ) ;
54
+ }
65
55
}
66
- }
56
+ } ;
67
57
} ,
68
58
69
- llamaIndex : {
70
- instrument : ( ) => {
71
- try {
72
- // eslint-disable-next-line @typescript-eslint/no-var-requires
73
- const { instrumentLlamaIndex } = require ( './llamaindex' ) ;
74
- return instrumentLlamaIndex ( client ) ;
75
- } catch ( error ) {
76
- throw new Error (
77
- 'Failed to load LlamaIndex. Please ensure llamaindex is installed.'
78
- ) ;
59
+ get vercel ( ) {
60
+ return {
61
+ instrument : < TFunction extends AllVercelFn > ( fn : TFunction ) => {
62
+ try {
63
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
64
+ const { makeInstrumentVercelSDK } = require ( './vercel-sdk' ) ;
65
+ return makeInstrumentVercelSDK ( client ) ( fn ) ;
66
+ } catch ( error ) {
67
+ throw new Error (
68
+ 'Failed to load Vercel SDK. Please ensure @vercel/ai is installed.'
69
+ ) ;
70
+ }
79
71
}
72
+ } ;
73
+ } ,
74
+
75
+ llamaIndex : {
76
+ get instrument ( ) {
77
+ return ( ) => {
78
+ try {
79
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
80
+ const { instrumentLlamaIndex } = require ( './llamaindex' ) ;
81
+ return instrumentLlamaIndex ( client ) ;
82
+ } catch ( error ) {
83
+ throw new Error (
84
+ 'Failed to load LlamaIndex. Please ensure llamaindex is installed.'
85
+ ) ;
86
+ }
87
+ } ;
80
88
} ,
81
- withThread : < R > ( thread : Thread , callback : ( ) => R ) => {
82
- try {
83
- // eslint-disable-next-line @typescript-eslint/no-var-requires
84
- const { withThread } = require ( './llamaindex' ) ;
85
- return withThread ( thread , callback ) ;
86
- } catch ( error ) {
87
- throw new Error (
88
- 'Failed to load LlamaIndex. Please ensure llamaindex is installed.'
89
- ) ;
90
- }
89
+ get withThread ( ) {
90
+ return < R > ( thread : Thread , callback : ( ) => R ) => {
91
+ try {
92
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
93
+ const { withThread } = require ( './llamaindex' ) ;
94
+ return withThread ( thread , callback ) ;
95
+ } catch ( error ) {
96
+ throw new Error (
97
+ 'Failed to load LlamaIndex. Please ensure llamaindex is installed.'
98
+ ) ;
99
+ }
100
+ } ;
91
101
}
92
102
}
93
103
} ) ;
0 commit comments