Skip to content

Commit

Permalink
feat: support new streaming mechanism in the playground (#601)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Jul 28, 2024
1 parent bbfdbec commit 633d6fe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/react-playground/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@assistant-ui/react-playground",
"version": "0.0.11",
"version": "0.0.12",
"license": "MIT",
"exports": {
".": {
Expand Down
28 changes: 19 additions & 9 deletions packages/react-playground/src/lib/playground-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,21 +193,31 @@ export class PlaygroundThreadRuntime implements ReactThreadRuntime {
};

try {
const result = await this.adapter.run({
const promiseOrGenerator = this.adapter.run({
messages,
abortSignal: this.abortController.signal,
config: this.configProvider.getModelConfig(),
onUpdate: updateMessage,
});
if (result.status?.type === "running")
throw new Error(
"Unexpected running status returned from ChatModelAdapter",
);

if (Symbol.asyncIterator in promiseOrGenerator) {
for await (const r of promiseOrGenerator) {
updateMessage(r);
}
} else {
updateMessage(await promiseOrGenerator);
}

this.abortController = null;
updateMessage({
status: { type: "complete", reason: "unknown" },
...result,
});

if (message.status.type === "running") {
updateMessage({
status: { type: "complete", reason: "unknown" },
});
} else {
// notify subscribers that isRunning is now false
this.notifySubscribers();
}
} catch (e) {
this.abortController = null;

Expand Down

0 comments on commit 633d6fe

Please sign in to comment.