diff --git a/packages/ai/src/protocols/openai-decisions.ts b/packages/ai/src/protocols/openai-decisions.ts index ac5313d392a1..4e9abc698bb3 100644 --- a/packages/ai/src/protocols/openai-decisions.ts +++ b/packages/ai/src/protocols/openai-decisions.ts @@ -67,6 +67,12 @@ const fromRequest = Effect.fn("OpenAIDecisions.fromRequest")(function* (request: model: request.model.id, input: [{ role: "user", content: yield* Effect.forEach(request.input, (part) => inputPart(request, part)) }], questions: request.questions.map((question) => { + // Some hosts (Parallel) reject a choice option without a description; an empty one answers the same. + if (question.type === "choice") + return { + ...question, + choices: question.choices.map((choice) => ({ ...choice, description: choice.description ?? "" })), + } if (question.type !== "predicate") return question // Predicates have no criteria field, so what true and false mean is appended to the instructions. const meanings = [ diff --git a/packages/ai/src/protocols/system-one.ts b/packages/ai/src/protocols/system-one.ts index 66a1333e1243..b57c34c8c3d8 100644 --- a/packages/ai/src/protocols/system-one.ts +++ b/packages/ai/src/protocols/system-one.ts @@ -102,7 +102,7 @@ const encodeQuestions = (questions: ReadonlyArray) => type: "choice", instructions: question.instructions, criteria: Object.fromEntries( - question.choices.map((choice) => [String(choice.value), choice.description ?? null]), + question.choices.map((choice) => [String(choice.value), choice.description ?? ""]), ), }, ] as const) diff --git a/packages/ai/test/decision.test.ts b/packages/ai/test/decision.test.ts index 986b2bb4e763..2a3f04a61f7d 100644 --- a/packages/ai/test/decision.test.ts +++ b/packages/ai/test/decision.test.ts @@ -127,7 +127,7 @@ describe("Decision", () => { department: { type: "choice", instructions: "Which team should handle this?", - criteria: { billing: "Payments and refunds", technical: null }, + criteria: { billing: "Payments and refunds", technical: "" }, }, urgency: { type: "score", @@ -199,7 +199,7 @@ describe("Decision", () => { greeting: { type: "choice", instructions: "Is this a greeting?", - criteria: { true: null, false: null }, + criteria: { true: "", false: "" }, }, }, }) @@ -455,7 +455,10 @@ describe("Decision", () => { name: "department", type: "choice", instructions: "Which team should handle this?", - choices: [{ value: "billing", description: "Payments and refunds" }, { value: "technical" }], + choices: [ + { value: "billing", description: "Payments and refunds" }, + { value: "technical", description: "" }, + ], }, { name: "urgency", @@ -618,7 +621,7 @@ describe("Decision", () => { department: { type: "choice", instructions: "Which team should handle this?", - criteria: { billing: "Payments and refunds", technical: null }, + criteria: { billing: "Payments and refunds", technical: "" }, }, urgency: { type: "score",