Skip to content
This repository was archived by the owner on Aug 5, 2025. It is now read-only.

Commit 96b6971

Browse files
authored
Merge pull request #58 from Chainlit/willy/update-vercel-integration
Willy/update vercel integration
2 parents e0c811e + 28ee60e commit 96b6971

File tree

3 files changed

+44
-43
lines changed

3 files changed

+44
-43
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@literalai/client",
3-
"version": "0.0.513",
3+
"version": "0.0.514",
44
"description": "",
55
"exports": {
66
".": {

src/instrumentation/vercel-sdk.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,14 @@ export const makeInstrumentVercelSDK = (
256256
type TOptions = Options<TFunction>;
257257
type TResult = Result<TFunction>;
258258

259-
return async (
260-
options: TOptions & { literalAiParent?: Step | Thread }
261-
): Promise<TResult> => {
262-
const { literalAiParent: parent, ...originalOptions } = options;
259+
return async (options: TOptions): Promise<TResult> => {
263260
const startTime = Date.now();
264-
const result: TResult = await (fn as any)(originalOptions);
261+
const result: TResult = await (fn as any)(options);
262+
263+
const threadFromStore = client._currentThread();
264+
const stepFromStore = client._currentStep();
265+
266+
const parent = stepFromStore || threadFromStore;
265267

266268
// Fork the stream to compute metrics
267269
let stream: ReadableStream<OriginalStreamPart>;

tests/integration/vercel-sdk.test.ts

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -204,44 +204,43 @@ describe('Vercel SDK Instrumentation', () => {
204204
it('should observe on a given thread', async () => {
205205
const spy = jest.spyOn(client.api, 'sendSteps');
206206

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+
]);
216243
});
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-
]);
245244
});
246245

247246
it('should monitor tools', async () => {

0 commit comments

Comments
 (0)