@@ -204,44 +204,43 @@ describe('Vercel SDK Instrumentation', () => {
204
204
it ( 'should observe on a given thread' , async ( ) => {
205
205
const spy = jest . spyOn ( client . api , 'sendSteps' ) ;
206
206
207
- const thread = await client . thread ( { name : 'VercelSDK Test' } ) . upsert ( ) ;
208
-
209
- const generateTextWithLiteralAI =
210
- client . instrumentation . vercel . instrument ( generateText ) ;
211
-
212
- const result = await generateTextWithLiteralAI ( {
213
- model : openai ( 'gpt-3.5-turbo' ) ,
214
- prompt : 'Write a vegetarian lasagna recipe for 4 people.' ,
215
- literalAiParent : thread
207
+ await client . thread ( { name : 'VercelSDK Test' } ) . wrap ( async ( ) => {
208
+ const generateTextWithLiteralAI =
209
+ client . instrumentation . vercel . instrument ( generateText ) ;
210
+
211
+ const result = await generateTextWithLiteralAI ( {
212
+ model : openai ( 'gpt-3.5-turbo' ) ,
213
+ prompt : 'Write a vegetarian lasagna recipe for 4 people.'
214
+ } ) ;
215
+
216
+ expect ( result . text ) . toBeTruthy ( ) ;
217
+
218
+ // Sending message is done asynchronously
219
+ await new Promise ( ( resolve ) => setTimeout ( resolve , 10 ) ) ;
220
+
221
+ expect ( spy ) . toHaveBeenCalledWith ( [
222
+ expect . objectContaining ( {
223
+ type : 'llm' ,
224
+ name : 'gpt-3.5-turbo' ,
225
+ threadId : client . _currentThread ( ) ?. id ,
226
+ generation : expect . any ( Object ) ,
227
+ input : {
228
+ content : [
229
+ {
230
+ role : 'user' ,
231
+ content : [
232
+ {
233
+ text : 'Write a vegetarian lasagna recipe for 4 people.' ,
234
+ type : 'text'
235
+ }
236
+ ]
237
+ }
238
+ ]
239
+ } ,
240
+ output : { role : 'assistant' , content : result . text }
241
+ } )
242
+ ] ) ;
216
243
} ) ;
217
-
218
- expect ( result . text ) . toBeTruthy ( ) ;
219
-
220
- // Sending message is done asynchronously
221
- await new Promise ( ( resolve ) => setTimeout ( resolve , 10 ) ) ;
222
-
223
- expect ( spy ) . toHaveBeenCalledWith ( [
224
- expect . objectContaining ( {
225
- type : 'llm' ,
226
- name : 'gpt-3.5-turbo' ,
227
- threadId : thread . id ,
228
- generation : expect . any ( Object ) ,
229
- input : {
230
- content : [
231
- {
232
- role : 'user' ,
233
- content : [
234
- {
235
- text : 'Write a vegetarian lasagna recipe for 4 people.' ,
236
- type : 'text'
237
- }
238
- ]
239
- }
240
- ]
241
- } ,
242
- output : { role : 'assistant' , content : result . text }
243
- } )
244
- ] ) ;
245
244
} ) ;
246
245
247
246
it ( 'should monitor tools' , async ( ) => {
0 commit comments