Spaces:
Running
Running
re-request jwt + retry request
Browse files- src/lib/assets/hf-logo-mono.svg +18 -0
- src/lib/chat/triggerAiCall.ts +28 -19
- src/routes/test/+page.svelte +12 -0
src/lib/assets/hf-logo-mono.svg
ADDED
|
|
src/lib/chat/triggerAiCall.ts
CHANGED
|
@@ -96,26 +96,35 @@ export async function triggerAiCall(ctx: TriggerAiCallContext): Promise<void> {
|
|
| 96 |
? null
|
| 97 |
: personasState.personas.find((p) => p.id === personasState.selectedPersona);
|
| 98 |
|
| 99 |
-
const
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
|
|
|
|
|
|
| 113 |
}
|
| 114 |
-
}
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
if (!response.ok) {
|
| 120 |
const errorBody = await response.text().catch(() => response.statusText);
|
| 121 |
throw new Error(errorBody || response.statusText);
|
|
|
|
| 96 |
? null
|
| 97 |
: personasState.personas.find((p) => p.id === personasState.selectedPersona);
|
| 98 |
|
| 99 |
+
const makeRequest = (authToken: string) =>
|
| 100 |
+
fetch('/api', {
|
| 101 |
+
method: 'POST',
|
| 102 |
+
body: JSON.stringify({
|
| 103 |
+
model: model,
|
| 104 |
+
provider: modelSettings?.provider ?? 'preferred',
|
| 105 |
+
messages: formattedMessages,
|
| 106 |
+
billingTo: billingOption,
|
| 107 |
+
...(selectedPersona ? { persona: selectedPersona } : {}),
|
| 108 |
+
...(modelSettings
|
| 109 |
+
? {
|
| 110 |
+
options: {
|
| 111 |
+
temperature: modelSettings.temperature,
|
| 112 |
+
max_tokens: modelSettings.max_tokens,
|
| 113 |
+
top_p: modelSettings.top_p
|
| 114 |
+
}
|
| 115 |
}
|
| 116 |
+
: {})
|
| 117 |
+
}),
|
| 118 |
+
headers: { Authorization: `Bearer ${authToken}` }
|
| 119 |
+
});
|
| 120 |
+
|
| 121 |
+
let response = await makeRequest(token.value);
|
| 122 |
+
if (response.status === 401) {
|
| 123 |
+
const refreshed = await token.requestTokenFromParent();
|
| 124 |
+
if (refreshed) {
|
| 125 |
+
response = await makeRequest(token.value);
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
if (!response.ok) {
|
| 129 |
const errorBody = await response.text().catch(() => response.statusText);
|
| 130 |
throw new Error(errorBody || response.statusText);
|
src/routes/test/+page.svelte
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import HFLogoMonochrome from '$lib/assets/hf-logo-mono.svg';
|
| 3 |
+
</script>
|
| 4 |
+
|
| 5 |
+
<div class="mx-auto flex h-screen max-w-7xl flex-wrap items-center justify-center gap-5">
|
| 6 |
+
<div class="flex size-56 items-center justify-center bg-black">
|
| 7 |
+
<img src={HFLogoMonochrome} alt="HF Logo" class="w-full invert" />
|
| 8 |
+
</div>
|
| 9 |
+
<div class="flex size-56 items-center justify-center bg-white">
|
| 10 |
+
<img src={HFLogoMonochrome} alt="HF Logo" class="w-full" />
|
| 11 |
+
</div>
|
| 12 |
+
</div>
|