🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat: allow fetching specific prompt version (#781)
Max Deichmann71a1f81b4dbe
diff --git a/src/__tests__/prompts.servertest.ts b/src/__tests__/prompts.servertest.tsindex cbe7da0a37..70d27531c6 100644--- a/src/__tests__/prompts.servertest.ts+++ b/src/__tests__/prompts.servertest.ts@@ -45,7 +45,7 @@ describe("/api/public/prompts API Endpoint", () => {expect(fetchedObservations.body.createdBy).toBe("user-1");});- it("should fetch active prompt only", async () => {+ it("should fetch active prompt only if no prompt version is given", async () => {const promptId = uuidv4();await prisma.prompt.create({@@ -64,13 +64,65 @@ describe("/api/public/prompts API Endpoint", () => {const fetchedObservations = await makeAPICall("GET",- "/api/public/prompts?name=prompt-name&version=1",+ "/api/public/prompts?name=prompt-name",undefined,);expect(fetchedObservations.status).toBe(404);});+ it("should fetch inactive prompt if prompt version is given", async () => {+ const promptId = uuidv4();+ const promptTwoId = uuidv4();++ await prisma.prompt.create({+ data: {+ id: promptId,+ name: "prompt-name",+ prompt: "prompt-one",+ isActive: false,+ version: 1,+ project: {+ connect: { id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a" },+ },+ createdBy: "user-1",+ },+ });++ await prisma.prompt.create({+ data: {+ id: promptTwoId,+ name: "prompt-name",+ prompt: "prompt",+ isActive: true,+ version: 2,+ project: {+ connect: { id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a" },+ },+ createdBy: "user-1",+ },+ });++ const fetchedObservations = await makeAPICall(+ "GET",+ "/api/public/prompts?name=prompt-name&version=1",+ undefined,+ );++ expect(fetchedObservations.status).toBe(200);++ if (!isPrompt(fetchedObservations.body)) {+ throw new Error("Expected body to be a prompt");+ }++ expect(fetchedObservations.body.id).toBe(promptId);+ expect(fetchedObservations.body.name).toBe("prompt-name");+ expect(fetchedObservations.body.prompt).toBe("prompt-one");+ expect(fetchedObservations.body.version).toBe(1);+ expect(fetchedObservations.body.isActive).toBe(false);+ expect(fetchedObservations.body.createdBy).toBe("user-1");+ });+it("should fetch active prompt when multiple exist", async () => {const promptIdOne = uuidv4();const promptIdTwo = uuidv4();diff --git a/src/pages/api/public/prompts.ts b/src/pages/api/public/prompts.tsindex b158a66da3..72e475101b 100644--- a/src/pages/api/public/prompts.ts+++ b/src/pages/api/public/prompts.ts@@ -55,7 +55,9 @@ export default async function handler(projectId: authCheck.scope.projectId,name: searchParams.name,version: searchParams.version ?? undefined,- isActive: true,+ // if no version is given, we take the latest active prompt+ // if no prompt is active, there will no prompt be available+ isActive: !searchParams.version ? true : undefined,},});