Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
machineuser
commited on
Commit
·
575ec75
1
Parent(s):
b6c4534
Sync widgets demo
Browse files
packages/widgets/src/lib/components/InferenceWidget/widgets/ConversationalWidget/ConversationalWidget.svelte
CHANGED
|
@@ -203,8 +203,15 @@
|
|
| 203 |
} else {
|
| 204 |
error = `Something went wrong with the request.`;
|
| 205 |
}
|
|
|
|
|
|
|
| 206 |
}
|
| 207 |
} finally {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
isLoading = false;
|
| 209 |
abort = undefined;
|
| 210 |
}
|
|
@@ -224,10 +231,14 @@
|
|
| 224 |
}
|
| 225 |
|
| 226 |
async function applyWidgetExample(example: Example, opts: ExampleRunOpts = {}): Promise<void> {
|
| 227 |
-
|
| 228 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
} else {
|
| 230 |
-
messages = [...example.messages];
|
| 231 |
}
|
| 232 |
if (opts.isPreview) {
|
| 233 |
return;
|
|
|
|
| 203 |
} else {
|
| 204 |
error = `Something went wrong with the request.`;
|
| 205 |
}
|
| 206 |
+
} else {
|
| 207 |
+
clearConversation();
|
| 208 |
}
|
| 209 |
} finally {
|
| 210 |
+
const isLastMsgFromUser = messages.at(-1)?.role === "user";
|
| 211 |
+
if (error && isLastMsgFromUser) {
|
| 212 |
+
// roles should alternate. therefore, if there was an error, we should remove last user message so that user can submit new user message afterwards
|
| 213 |
+
messages = messages.slice(0, -1);
|
| 214 |
+
}
|
| 215 |
isLoading = false;
|
| 216 |
abort = undefined;
|
| 217 |
}
|
|
|
|
| 231 |
}
|
| 232 |
|
| 233 |
async function applyWidgetExample(example: Example, opts: ExampleRunOpts = {}): Promise<void> {
|
| 234 |
+
clearConversation();
|
| 235 |
+
if (opts.inferenceOpts?.isOnLoadCall) {
|
| 236 |
+
// if isOnLoadCall do NOT trigger svelte UI update, the UI update will be triggered by getOutput if the example succeeds
|
| 237 |
+
// otherwise, error will be suppressed so that user doesn't come to errored page on load
|
| 238 |
+
// however, the user will still get the error after manually interacting with the widget if it is not isOnLoadCall
|
| 239 |
+
"text" in example ? messages.push({ role: "user", content: example.text }) : messages.push(...example.messages);
|
| 240 |
} else {
|
| 241 |
+
"text" in example ? (messages = [{ role: "user", content: example.text }]) : (messages = [...example.messages]);
|
| 242 |
}
|
| 243 |
if (opts.isPreview) {
|
| 244 |
return;
|