From 598b94b8547ecfd7b67b422cbe49b087c293a79e Mon Sep 17 00:00:00 2001 From: John Smith Date: Sun, 1 Dec 2024 17:03:49 +1030 Subject: [PATCH] Revert "Revert "chore: Cleanup runConfigId / input merging (#179)" (#181)" This reverts commit 873dcd9a4a24baa33244786728da1333e676f1bc. --- control-plane/src/modules/contract.ts | 16 ++++++++-- .../src/modules/prompt-templates.test.ts | 29 ------------------- control-plane/src/modules/prompt-templates.ts | 4 --- control-plane/src/modules/workflows/router.ts | 24 +++++++++++---- 4 files changed, 33 insertions(+), 40 deletions(-) diff --git a/control-plane/src/modules/contract.ts b/control-plane/src/modules/contract.ts index 98cc5888..95f875c2 100644 --- a/control-plane/src/modules/contract.ts +++ b/control-plane/src/modules/contract.ts @@ -524,17 +524,29 @@ export const definition = { .describe( "When provided, the run will be marked as as a test / evaluation", ), + configId: z + .string() + .optional() + .describe("The run configuration ID to use"), + input: z + .object({}) + .passthrough() + .describe( + "Structured input arguments to merge with the initial prompt. The schema must match the run configuration input schema if defined", + ) + .optional(), config: z .object({ - id: z.string().describe("The run configuration ID"), + id: z.string().describe("DEPRECATED"), input: z .object({}) .passthrough() .describe( - "The run configuration input arguments, the schema must match the run configuration input schema", + "DEPRECATED", ) .optional(), }) + .describe("DEPRECATED") .optional(), context: anyObject .optional() diff --git a/control-plane/src/modules/prompt-templates.test.ts b/control-plane/src/modules/prompt-templates.test.ts index 44154ba4..2598e7b3 100644 --- a/control-plane/src/modules/prompt-templates.test.ts +++ b/control-plane/src/modules/prompt-templates.test.ts @@ -196,34 +196,5 @@ describe("prompt-templates", () => { }, }); }); - - it("should merge initialPrompt with run input", () => { - const options = { - input: { - name: "World", - }, - }; - - const runConfig = { - id: "test-id", - name: "test-template", - initialPrompt: "Hello: ", - inputSchema: { - type: "object", - required: ["name"], - properties: { - name: { type: "string" }, - extra: { type: "string" }, - }, - }, - versions: [], - } as any; - - const result = mergeRunConfigOptions(options, runConfig); - - expect(result.error).toBeNull(); - expect(result.options?.initialPrompt).toContain("Hello"); - expect(result.options?.initialPrompt).toContain("World"); - }); }); }); diff --git a/control-plane/src/modules/prompt-templates.ts b/control-plane/src/modules/prompt-templates.ts index 9e5bdc88..e178502f 100644 --- a/control-plane/src/modules/prompt-templates.ts +++ b/control-plane/src/modules/prompt-templates.ts @@ -442,10 +442,6 @@ export const mergeRunConfigOptions = ( } } - if (options.input) { - mergedOptions.initialPrompt = `${mergedOptions.initialPrompt}\n\n\n${JSON.stringify(options.input, null, 2)}\n`; - } - mergedOptions.messageMetadata = { displayable: { templateName: runConfig.name, diff --git a/control-plane/src/modules/workflows/router.ts b/control-plane/src/modules/workflows/router.ts index 585422e6..ec01b0e8 100644 --- a/control-plane/src/modules/workflows/router.ts +++ b/control-plane/src/modules/workflows/router.ts @@ -70,12 +70,21 @@ export const runsRouter = initServer().router( await auth.canAccess({ cluster: { clusterId } }); auth.canCreate({ run: true }); + // TODO: Remove once use of deprecated fields is removed + if (body.config) { + logger.info("Depreacted `run.config` provided in call to createRun"); + body.configId = body.configId ?? body.config.id; + body.input = body.input ?? body.config.input; + } + + // TODO: Remove once use of deprecated fields is removed if (body.template) { logger.info("Depreacted `run.template` provided in call to createRun"); - body.config = body.template; + body.configId = body.configId ?? body.template.id; + body.input = body.input ?? body.template.input; } - if (!body.initialPrompt && !body.config) { + if (!body.initialPrompt && !body.configId) { return { status: 400, body: { @@ -124,13 +133,13 @@ export const runsRouter = initServer().router( callSummarization: body.callSummarization, reasoningTraces: body.reasoningTraces, - input: body.config?.input, + input: body.input, }; - const runConfig = body.config + const runConfig = body.configId ? await getRunConfig({ clusterId, - id: body.config.id, + id: body.configId, }) : undefined; @@ -148,6 +157,11 @@ export const runsRouter = initServer().router( runOptions = merged.options; } + if (runOptions.input) { + runOptions.initialPrompt = `${runOptions.initialPrompt}\n\n\n${JSON.stringify(runOptions.input, null, 2)}\n`; + } + + if (!runOptions.initialPrompt) { throw new Error("Failed to construct initialPrompt"); }