Skip to content

Commit

Permalink
Updating Deps and removing some bits
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulKinlan committed Nov 25, 2023
1 parent ef0d992 commit 3e7f0b1
Show file tree
Hide file tree
Showing 19 changed files with 86 additions and 492 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions samples/TheCritic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" href="/styles/global.css" />
<title>Breadboard Playground</title>
<title>The Critic</title>
</head>
<body>
<header>
<a href="/"><h1 id="title">Breadboard Playground</h1></a>
<a href="/"><h1 id="title">The Critic</h1></a>
</header>
<bb-ui></bb-ui>
<script type="module">
Expand Down
115 changes: 0 additions & 115 deletions samples/TheCritic/src/async-gen.ts

This file was deleted.

2 changes: 1 addition & 1 deletion samples/TheCritic/src/boards/the-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ export class Panel {
}
}
}
}
}
35 changes: 0 additions & 35 deletions samples/TheCritic/src/events.ts

This file was deleted.

154 changes: 0 additions & 154 deletions samples/TheCritic/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,158 +5,4 @@
*/

import * as BreadboardUI from "./ui";
import type * as Breadboard from "@google-labs/breadboard";
import { type RunResult, HostRuntime } from "@google-labs/breadboard/worker";
import { ProxyReceiver } from "./receiver.js";

const localBoards = await (await fetch("/local-boards.json")).json();
const PROXY_NODES = [
"palm-generateText",
"embedText",
"secrets",
"fetch",
"credentials",
"driveList",
"math-min"
];
const WORKER_URL =
import.meta.env.MODE === "development" ? "/src/worker.ts" : "/worker.js";
const config = {
boards: [
...localBoards,
],
};

export class Main {
#ui = BreadboardUI.get();
#runtime = new HostRuntime(WORKER_URL);
#receiver = new ProxyReceiver();
#hasActiveBoard = false;

constructor() {
BreadboardUI.register();

this.#ui.addEventListener(
BreadboardUI.StartEvent.eventName,
async (evt) => {
if (this.#hasActiveBoard) {
if (
!confirm("You already have an active board. Do you want to change?")
) {
return;
}
}
this.#hasActiveBoard = true;

const startEvent = evt as BreadboardUI.StartEvent;
this.#ui.setActiveBreadboard(startEvent.url);

for await (const result of this.#runtime.run(
startEvent.url,
PROXY_NODES
)) {
this.#handleEvent(result);
}
}
);

this.#ui.addEventListener(BreadboardUI.ToastEvent.eventName, (evt) => {
const toastEvent = evt as BreadboardUI.ToastEvent;
this.#ui.toast(toastEvent.message, toastEvent.toastType);
});

this.#ui.start(config);
}

async #handleEvent(result: RunResult) {
const { data, type } = result.message;
switch (type) {
case "load": {
const loadData = data as BreadboardUI.LoadArgs;
this.#ui.load(loadData);
break;
}

case "output": {
const outputData = data as { outputs: BreadboardUI.OutputArgs };
await this.#ui.output(outputData.outputs);
break;
}

case "input": {
const inputData = data as {
node: { id: string };
inputArguments: BreadboardUI.InputArgs;
};
result.reply(
await this.#ui.input(inputData.node.id, inputData.inputArguments)
);
break;
}

case "beforehandler": {
const progressData = data as { node: { id: unknown } };
this.#ui.progress(`Running "${progressData.node.id}" ...`);
break;
}

case "error": {
const errorData = data as { error: string };
this.#ui.error(errorData.error);
break;
}

case "proxy":
{
try {
const proxyData = data as {
node: Breadboard.NodeDescriptor;
inputs: Breadboard.InputValues;
};
for await (const handledResult of this.#receiver.handle(
proxyData
)) {
const receiverResult = handledResult as {
type: "secret" | "result";
name: string;
value: string | { completion: string };
nodeType: Breadboard.NodeTypeIdentifier;
};

switch (receiverResult.type) {
case "secret":
receiverResult.value = await this.#ui.secret(
receiverResult.name
);
break;
case "result":
if (receiverResult.nodeType === "palm-generateText") {
const resultValue = receiverResult.value as {
completion: string;
};
this.#ui.result({
title: "LLM response",
result: resultValue.completion,
});
}
result.reply(receiverResult.value);
break;
}
}
} catch (e) {
const err = e as Error;
this.#ui.error(err.message);
}
}
break;

case "end":
this.#ui.done();
this.#hasActiveBoard = false;
break;

case "shutdown":
break;
}
}
}
Loading

0 comments on commit 3e7f0b1

Please sign in to comment.