Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/ai/src/protocols/openai-decisions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion packages/ai/src/protocols/system-one.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const encodeQuestions = (questions: ReadonlyArray<DecisionQuestion>) =>
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)
Expand Down
11 changes: 7 additions & 4 deletions packages/ai/test/decision.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -199,7 +199,7 @@ describe("Decision", () => {
greeting: {
type: "choice",
instructions: "Is this a greeting?",
criteria: { true: null, false: null },
criteria: { true: "", false: "" },
},
},
})
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Loading