From c29afeef8162953c866f232a8762feb99f8ab286 Mon Sep 17 00:00:00 2001 From: Damien BUTY Date: Fri, 6 Sep 2024 17:26:57 +0200 Subject: [PATCH 1/3] feat(prompt): add url to getPrompt --- src/api.ts | 2 ++ src/prompt-engineering/prompt.ts | 1 + tests/api.test.ts | 9 +++++++++ 3 files changed, 12 insertions(+) diff --git a/src/api.ts b/src/api.ts index 677a013..470a0e5 100644 --- a/src/api.ts +++ b/src/api.ts @@ -2033,6 +2033,7 @@ export class API { variables variablesDefaultValues version + url lineage { name } @@ -2064,6 +2065,7 @@ export class API { variables variablesDefaultValues version + url lineage { name } diff --git a/src/prompt-engineering/prompt.ts b/src/prompt-engineering/prompt.ts index c03a32c..bee2abe 100644 --- a/src/prompt-engineering/prompt.ts +++ b/src/prompt-engineering/prompt.ts @@ -35,6 +35,7 @@ class PromptFields extends Utils { createdAt!: string; name!: string; version!: number; + url?: Maybe; versionDesc?: Maybe; metadata!: Record; items!: Array>; diff --git a/tests/api.test.ts b/tests/api.test.ts index fbe318b..2f2eec9 100644 --- a/tests/api.test.ts +++ b/tests/api.test.ts @@ -597,6 +597,15 @@ describe('End to end tests for the SDK', function () { expect(fetchedPrompt?.version).toBe(0); }); + it('should get the URL for the prompt', async () => { + const prompt = await client.api.getPrompt('Default', 0); + const projectId = await client.api.getProjectId(); + + expect(prompt?.url).toContain( + `projects/${projectId}/playground?name=Default&version=0` + ); + }); + it('should format a prompt with default values', async () => { const prompt = await client.api.getPrompt('Default'); From e3801f4014962ed28f25831d550834bfae3ad5c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Sirieix?= Date: Wed, 11 Sep 2024 14:48:03 +0200 Subject: [PATCH 2/3] fix: fix test --- tests/api.test.ts | 8 ++++---- tests/attachments.test.ts | 4 ++-- tests/integration/openai.test.ts | 6 ++++-- tests/wrappers.test.ts | 22 +++++++++++----------- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/tests/api.test.ts b/tests/api.test.ts index 2f2eec9..ede3b50 100644 --- a/tests/api.test.ts +++ b/tests/api.test.ts @@ -175,7 +175,7 @@ describe('End to end tests for the SDK', function () { }) .send(); - await new Promise((resolve) => setTimeout(resolve, 1000)); + await new Promise((resolve) => setTimeout(resolve, 2000)); const fetchedStep = await client.api.getStep(step.id!); expect(fetchedStep?.id).toBe(step.id); @@ -209,7 +209,7 @@ describe('End to end tests for the SDK', function () { }) .send(); - await new Promise((resolve) => setTimeout(resolve, 1000)); + await new Promise((resolve) => setTimeout(resolve, 2000)); const fetchedStep = await client.api.getStep(step.id!); expect(fetchedStep?.id).toBe(step.id); @@ -237,7 +237,7 @@ describe('End to end tests for the SDK', function () { expect(step.id).not.toBeNull(); - await new Promise((resolve) => setTimeout(resolve, 1000)); + await new Promise((resolve) => setTimeout(resolve, 2000)); const steps = await client.api.getSteps({ filters: [ @@ -269,7 +269,7 @@ describe('End to end tests for the SDK', function () { }) .send(); - await new Promise((resolve) => setTimeout(resolve, 1000)); + await new Promise((resolve) => setTimeout(resolve, 2000)); const score = await client.api.createScore({ stepId: step.id!, diff --git a/tests/attachments.test.ts b/tests/attachments.test.ts index ccb277d..3db3135 100644 --- a/tests/attachments.test.ts +++ b/tests/attachments.test.ts @@ -48,7 +48,7 @@ describe('Attachments', () => { }) .send(); - await new Promise((resolve) => setTimeout(resolve, 1000)); + await new Promise((resolve) => setTimeout(resolve, 2000)); const fetchedStep = await client.api.getStep(step.id!); @@ -86,7 +86,7 @@ describe('Attachments', () => { }); }); - await new Promise((resolve) => setTimeout(resolve, 1000)); + await new Promise((resolve) => setTimeout(resolve, 2000)); const fetchedStep = await client.api.getStep(stepId!); diff --git a/tests/integration/openai.test.ts b/tests/integration/openai.test.ts index a8954c9..d16f179 100644 --- a/tests/integration/openai.test.ts +++ b/tests/integration/openai.test.ts @@ -318,6 +318,8 @@ describe('OpenAI Instrumentation', () => { }) ]); + await new Promise((resolve) => setTimeout(resolve, 3000)); + const { data: [firstGeneration] } = await client.api.getSteps({ @@ -366,7 +368,7 @@ describe('OpenAI Instrumentation', () => { }); }); - await new Promise((resolve) => setTimeout(resolve, 2000)); + await new Promise((resolve) => setTimeout(resolve, 4000)); const { data: [step] @@ -409,7 +411,7 @@ describe('OpenAI Instrumentation', () => { }); }); - await new Promise((resolve) => setTimeout(resolve, 3000)); + await new Promise((resolve) => setTimeout(resolve, 5000)); const { data: [step] diff --git a/tests/wrappers.test.ts b/tests/wrappers.test.ts index a578f3c..d4c28ee 100644 --- a/tests/wrappers.test.ts +++ b/tests/wrappers.test.ts @@ -64,7 +64,7 @@ describe('Wrapper', () => { }); }); - await sleep(1000); + await sleep(2000); const thread = await client.api.getThread(threadId!); const step = await client.api.getStep(stepId!); @@ -120,7 +120,7 @@ describe('Wrapper', () => { }); }); - await sleep(1000); + await sleep(2000); const thread = await client.api.getThread(threadId!); const run = await client.api.getStep(runId!); const retrieveStep = await client.api.getStep(retrieveStepId!); @@ -162,7 +162,7 @@ describe('Wrapper', () => { }); }); - await sleep(1000); + await sleep(2000); const run = await client.api.getStep(runId!); const createdStep = await client.api.getStep(stepId!); @@ -187,7 +187,7 @@ describe('Wrapper', () => { }); }); - await sleep(1000); + await sleep(2000); const run = await client.api.getStep(runId!); const step = await client.api.getStep(stepId!); @@ -246,7 +246,7 @@ describe('Wrapper', () => { { metadata: { key: 'thread-value' } } ); - await sleep(1000); + await sleep(2000); const thread = await client.api.getThread(threadId!); const step = await client.api.getStep(stepId!); @@ -279,7 +279,7 @@ describe('Wrapper', () => { (output) => ({ metadata: { assistantMessage: output.content } }) ); - await sleep(1000); + await sleep(2000); const thread = await client.api.getThread(threadId!); const step = await client.api.getStep(stepId!); @@ -310,7 +310,7 @@ describe('Wrapper', () => { }); }); - await sleep(1000); + await sleep(2000); const thread = await client.api.getThread(threadId!); const step = await client.api.getStep(stepId!); @@ -338,7 +338,7 @@ describe('Wrapper', () => { }); }); - await sleep(1000); + await sleep(2000); const thread = await client.api.getThread(threadId!); const step = await client.api.getStep(stepId!); @@ -353,7 +353,7 @@ describe('Wrapper', () => { .thread({ name: 'Test Wrappers Thread' }) .upsert(); - await sleep(1000); + await sleep(2000); const thread = await client.api.getThread(threadId); const wrappedThreadId = await thread!.wrap(async () => { @@ -368,7 +368,7 @@ describe('Wrapper', () => { .run({ name: 'Test Wrappers Thread' }) .send(); - await sleep(1000); + await sleep(2000); const step = await client.api.getStep(stepId!); const wrappedStepId = await step!.wrap(async () => { @@ -406,7 +406,7 @@ describe('Wrapper', () => { }); expect(persistedExperimentItem).toBeTruthy(); - await sleep(1000); + await sleep(2000); const experimentRunId = persistedExperimentItem!.experimentRunId; expect(experimentRunId).toBeTruthy(); From 0f4716bf11a89b2f68363272537eeec24b655a4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Sirieix?= Date: Wed, 11 Sep 2024 17:14:49 +0200 Subject: [PATCH 3/3] fix: fix store --- src/index.ts | 20 ++++++++++---------- tests/integration/openai.test.ts | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/index.ts b/src/index.ts index 89e985a..7bde18b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,7 +20,6 @@ type StoredContext = { rootRun: Step | null; }; -const storage = new AsyncLocalStorage(); /** * The LiteralClient class provides an interface to interact with the Literal AI API. * It offers methods for creating threads and steps, as well as instrumentation for various AI services. @@ -40,7 +39,8 @@ export class LiteralClient { api: API; openai: ReturnType; instrumentation: ReturnType; - store: AsyncLocalStorage = storage; + store: AsyncLocalStorage = + new AsyncLocalStorage(); /** * Initialize a new Literal AI Client. @@ -115,7 +115,7 @@ export class LiteralClient { * @returns The current thread, if any. */ _currentThread(): Thread | null { - const store = storage.getStore(); + const store = this.store.getStore(); return store?.currentThread || null; } @@ -125,7 +125,7 @@ export class LiteralClient { * @returns The current step, if any. */ _currentStep(): Step | null { - const store = storage.getStore(); + const store = this.store.getStore(); return store?.currentStep || null; } @@ -135,7 +135,7 @@ export class LiteralClient { * @returns The current experiment, if any. */ _currentExperimentItemRunId(): string | null { - const store = storage.getStore(); + const store = this.store.getStore(); return store?.currentExperimentItemRunId || null; } @@ -145,7 +145,7 @@ export class LiteralClient { * @returns The root run, if any. */ _rootRun(): Step | null { - const store = storage.getStore(); + const store = this.store.getStore(); return store?.rootRun || null; } @@ -156,7 +156,7 @@ export class LiteralClient { * @returns The current thread, if any. */ getCurrentThread(): Thread { - const store = storage.getStore(); + const store = this.store.getStore(); if (!store?.currentThread) { throw new Error( @@ -173,7 +173,7 @@ export class LiteralClient { * @returns The current step, if any. */ getCurrentStep(): Step { - const store = storage.getStore(); + const store = this.store.getStore(); if (!store?.currentStep) { throw new Error( @@ -190,7 +190,7 @@ export class LiteralClient { * @returns The current experiment, if any. */ getCurrentExperimentItemRunId(): string { - const store = storage.getStore(); + const store = this.store.getStore(); if (!store?.currentExperimentItemRunId) { throw new Error( @@ -207,7 +207,7 @@ export class LiteralClient { * @returns The current step, if any. */ getRootRun(): Step { - const store = storage.getStore(); + const store = this.store.getStore(); if (!store?.rootRun) { throw new Error( diff --git a/tests/integration/openai.test.ts b/tests/integration/openai.test.ts index d16f179..59fdad7 100644 --- a/tests/integration/openai.test.ts +++ b/tests/integration/openai.test.ts @@ -256,7 +256,7 @@ describe('OpenAI Instrumentation', () => { }); }); - await new Promise((resolve) => setTimeout(resolve, 1000)); + await new Promise((resolve) => setTimeout(resolve, 2000)); const { data: [step]