breadboard-ai / breadboard

A library for prototyping generative AI applications.
Apache License 2.0
183 stars 25 forks source link

Schema mismatch on fetch node #2498

Open paullewis opened 3 months ago

paullewis commented 3 months ago

According to our schema a port's default value should be string|undefined

However in the fetch component we set the default for the headers property to be an object

Not sure which is more correct, but the net result is that the Visual Editor is expecting string|undefined but in this case gets {} which then gets serialized to [object Object]

dglazkov commented 3 months ago

This is my bug. I defined default as "string", because that's what examples type is, but actually, JSON schema doesn't have a strong opinion here, and having default be of the same type of as its port seems more logical.

The fix here is likely to change default to be of unknown type and rely on Build API to infer the proper type. Right?

aomarks commented 3 months ago

Fetch headers are a string->string mapping, so I believe the headers port should have type:

JSON Schema:

{
  "type": "object",
  "additionalProperties": {
    "type": "string"
  }
}

Breadboard Type Expression:

import {object} from "@breadboard-ai/build";
object({}, "string")

TypeScript:

Record<string, string>
aomarks commented 3 months ago

The fix here is likely to change default to be of unknown type and rely on Build API to infer the proper type. Right?

Yeah, I agree the default type for a Breadboard port should be any JSON value which is:

JSON Schema:

{}

OR identically JSON Schema:

{"type": ["array", "boolean", "null", "number", "object", "string"]}

Breadboard Type Expression:

"unknown";

TypeScript:

type JsonSerializable =
  | string
  | number
  | boolean
  | null
  | Array<JsonSerializable>
  | { [K: string]: JsonSerializable };