From 873dcd9a4a24baa33244786728da1333e676f1bc Mon Sep 17 00:00:00 2001 From: John Smith Date: Sun, 1 Dec 2024 17:03:08 +1030 Subject: [PATCH] Revert "chore: Cleanup runConfigId / input merging (#179)" (#181) This reverts commit 05fbcfa9922ded09e736ff85008e9de04d2d2f2e. --- 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, 40 insertions(+), 33 deletions(-) diff --git a/control-plane/src/modules/contract.ts b/control-plane/src/modules/contract.ts index 95f875c2..98cc5888 100644 --- a/control-plane/src/modules/contract.ts +++ b/control-plane/src/modules/contract.ts @@ -524,29 +524,17 @@ 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("DEPRECATED"), + id: z.string().describe("The run configuration ID"), input: z .object({}) .passthrough() .describe( - "DEPRECATED", + "The run configuration input arguments, the schema must match the run configuration input schema", ) .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 2598e7b3..44154ba4 100644 --- a/control-plane/src/modules/prompt-templates.test.ts +++ b/control-plane/src/modules/prompt-templates.test.ts @@ -196,5 +196,34 @@ 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 e178502f..9e5bdc88 100644 --- a/control-plane/src/modules/prompt-templates.ts +++ b/control-plane/src/modules/prompt-templates.ts @@ -442,6 +442,10 @@ 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 ec01b0e8..585422e6 100644 --- a/control-plane/src/modules/workflows/router.ts +++ b/control-plane/src/modules/workflows/router.ts @@ -70,21 +70,12 @@ 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.configId = body.configId ?? body.template.id; - body.input = body.input ?? body.template.input; + body.config = body.template; } - if (!body.initialPrompt && !body.configId) { + if (!body.initialPrompt && !body.config) { return { status: 400, body: { @@ -133,13 +124,13 @@ export const runsRouter = initServer().router( callSummarization: body.callSummarization, reasoningTraces: body.reasoningTraces, - input: body.input, + input: body.config?.input, }; - const runConfig = body.configId + const runConfig = body.config ? await getRunConfig({ clusterId, - id: body.configId, + id: body.config.id, }) : undefined; @@ -157,11 +148,6 @@ 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"); }