From 18160ca3a6d1026efb03d2fb79c1bc81bd752558 Mon Sep 17 00:00:00 2001
From: axel7083 <42176370+axel7083@users.noreply.github.com>
Date: Tue, 30 Jan 2024 12:24:43 +0100
Subject: [PATCH] feat: propagate error playground
---
packages/backend/src/managers/playground.ts | 15 ++++++++----
packages/frontend/src/lib/ErrorMessage.svelte | 23 +++++++++++++++++++
.../frontend/src/pages/ModelPlayground.svelte | 16 +++++++++++++
.../src/models/IPlaygroundQueryState.ts | 1 +
4 files changed, 50 insertions(+), 5 deletions(-)
create mode 100644 packages/frontend/src/lib/ErrorMessage.svelte
diff --git a/packages/backend/src/managers/playground.ts b/packages/backend/src/managers/playground.ts
index 596d830fa..54e017487 100644
--- a/packages/backend/src/managers/playground.ts
+++ b/packages/backend/src/managers/playground.ts
@@ -178,11 +178,11 @@ export class PlayGroundManager {
throw new Error('model is not running');
}
- const query = {
+ const query: QueryState = {
id: this.getNextQueryId(),
modelId: modelInfo.id,
prompt: prompt,
- } as QueryState;
+ };
const post_data = JSON.stringify({
model: modelInfo.file,
@@ -213,17 +213,22 @@ export class PlayGroundManager {
if (!q) {
throw new Error('query not found in state');
}
+ q.error = undefined;
q.response = result as ModelResponse;
this.queries.set(query.id, q);
- this.sendQueriesState().catch((err: unknown) => {
- console.error('playground: unable to send the response to the frontend', err);
- });
+ void this.sendQueriesState();
}
});
});
// post the data
post_req.write(post_data);
post_req.end();
+ post_req.on('error', (error) => {
+ console.error('connection on error.');
+ const q = this.queries.get(query.id);
+ q.error = `Something went wrong while trying to request model.${String(error)}`;
+ void this.sendQueriesState();
+ });
this.queries.set(query.id, query);
await this.sendQueriesState();
diff --git a/packages/frontend/src/lib/ErrorMessage.svelte b/packages/frontend/src/lib/ErrorMessage.svelte
new file mode 100644
index 000000000..7751df732
--- /dev/null
+++ b/packages/frontend/src/lib/ErrorMessage.svelte
@@ -0,0 +1,23 @@
+
+
+{#if icon}
+ {#if error !== undefined && error !== ''}
+