enzostvs HF Staff commited on
Commit
6bba0f8
·
1 Parent(s): dc766b5

re-request jwt + retry request

Browse files
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 response = await fetch('/api', {
100
- method: 'POST',
101
- body: JSON.stringify({
102
- model: model,
103
- provider: modelSettings?.provider ?? 'preferred',
104
- messages: formattedMessages,
105
- billingTo: billingOption,
106
- ...(selectedPersona ? { persona: selectedPersona } : {}),
107
- ...(modelSettings
108
- ? {
109
- options: {
110
- temperature: modelSettings.temperature,
111
- max_tokens: modelSettings.max_tokens,
112
- top_p: modelSettings.top_p
 
 
113
  }
114
- }
115
- : {})
116
- }),
117
- headers: { Authorization: `Bearer ${token.value}` }
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>