Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boolean input type error when passing to invoke or passthrough #2324

Open
TinaNikou opened this issue Jun 27, 2024 · 0 comments
Open

Boolean input type error when passing to invoke or passthrough #2324

TinaNikou opened this issue Jun 27, 2024 · 0 comments

Comments

@TinaNikou
Copy link
Contributor

Came across this error when migrating the 'Text Generator' (./packages/breadboard-web/src/boards/text-generator.ts) board to the build API.

The useStreaming input is boolean type, defaulting to false.

const useStreaming = input({
  type: "boolean",
  default: false,
});

const invoker = invoke({
  $board: switchModel.outputs.path,
  text,
  useStreaming
});

const passer = passthrough({
  useStreaming
});

I get the following error when passing it into the invoke or passthrough nodes:
Type 'InputWithDefault<boolean>' is not assignable to type '(InputWithDefault<boolean> & string) | (InputWithDefault<boolean> & number) | (InputWithDefault<boolean> & false) | ... 27 more ... | (InputWithDefault<...> & Convergence<...>)'. Type 'InputWithDefault<boolean>' is not assignable to type '(InputWithDefault<boolean> & string) | (InputWithDefault<boolean> & number) | (InputWithDefault<boolean> & false) | ... 23 more ... | (InputWithDefault<...> & Convergence<...>)'. Type 'InputWithDefault<boolean>' is not assignable to type 'InputWithDefault<boolean> & Convergence<{ [K: string]: JsonSerializable; }>'. Type 'InputWithDefault<boolean>' is missing the following properties from type 'Convergence<{ [K: string]: JsonSerializable; }>': __isConvergence, portsts(2322)

Full code example here:

import { board, enumeration, input, output } from "@breadboard-ai/build";
import { invoke, code, passthrough } from "@google-labs/core-kit";

const text = input({ type: "string" });

const MODEL = input({ type: enumeration("Gemini Pro", "GPT 3.5 Turbo"), examples: ["Gemini Pro"] });

const switchModel = code({ MODEL }, { path: "string" }, ({ MODEL }) => {
    const models: Record<string, string> = { "Gemini Pro": "gemini-generator.json", "GPT 3.5 Turbo": "openai-gpt-35-turbo.json" };
    const path = models[MODEL];
    if (!path) throw new Error(`Unsupported model: ${MODEL}`);
    return { path };
  }
);

const useStreaming = input({
  type: "boolean",
  default: false,
});

const invoker = invoke({
  $board: switchModel.outputs.path,
  text,
  useStreaming
});

const passer = passthrough({
  useStreaming
});

const textOutput = output(invoker.unsafeOutput("text"));
const streamOutput = output(invoker.unsafeOutput("stream"));
const passthroughOutput = output(passer.outputs.useStreaming);

export default board({
  inputs: { text, useStreaming, MODEL },
  outputs: { textOutput, streamOutput, passthroughOutput }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant