dmpantiu commited on
Commit
eac2f98
·
verified ·
1 Parent(s): 4001c18

Upload folder using huggingface_hub

Browse files
web/agent_wrapper.py CHANGED
@@ -61,6 +61,7 @@ class AgentSession:
61
  # Resolve API keys: user-provided take priority over env vars
62
  openai_key = self._api_keys.get("openai_api_key") or os.environ.get("OPENAI_API_KEY")
63
  arraylake_key = self._api_keys.get("arraylake_api_key") or os.environ.get("ARRAYLAKE_API_KEY")
 
64
 
65
  if not arraylake_key:
66
  logger.warning("ARRAYLAKE_API_KEY not found")
@@ -69,6 +70,9 @@ class AgentSession:
69
  # server-configured keys with user-provided ones in multi-user scenarios)
70
  os.environ["ARRAYLAKE_API_KEY"] = arraylake_key
71
 
 
 
 
72
  if not openai_key:
73
  logger.error("OPENAI_API_KEY not found")
74
  return
 
61
  # Resolve API keys: user-provided take priority over env vars
62
  openai_key = self._api_keys.get("openai_api_key") or os.environ.get("OPENAI_API_KEY")
63
  arraylake_key = self._api_keys.get("arraylake_api_key") or os.environ.get("ARRAYLAKE_API_KEY")
64
+ hf_token = self._api_keys.get("hf_token") or os.environ.get("HF_TOKEN")
65
 
66
  if not arraylake_key:
67
  logger.warning("ARRAYLAKE_API_KEY not found")
 
70
  # server-configured keys with user-provided ones in multi-user scenarios)
71
  os.environ["ARRAYLAKE_API_KEY"] = arraylake_key
72
 
73
+ if hf_token and not os.environ.get("HF_TOKEN"):
74
+ os.environ["HF_TOKEN"] = hf_token
75
+
76
  if not openai_key:
77
  logger.error("OPENAI_API_KEY not found")
78
  return
web/routes/api.py CHANGED
@@ -60,6 +60,7 @@ async def keys_status():
60
  return {
61
  "openai": bool(os.environ.get("OPENAI_API_KEY")),
62
  "arraylake": bool(os.environ.get("ARRAYLAKE_API_KEY")),
 
63
  }
64
 
65
 
 
60
  return {
61
  "openai": bool(os.environ.get("OPENAI_API_KEY")),
62
  "arraylake": bool(os.environ.get("ARRAYLAKE_API_KEY")),
63
+ "hf": bool(os.environ.get("HF_TOKEN")),
64
  }
65
 
66
 
web/routes/websocket.py CHANGED
@@ -64,6 +64,7 @@ async def websocket_chat(websocket: WebSocket):
64
  api_keys = {
65
  "openai_api_key": data.get("openai_api_key", ""),
66
  "arraylake_api_key": data.get("arraylake_api_key", ""),
 
67
  }
68
  session = create_session(connection_id, api_keys=api_keys)
69
  ready = session.is_ready()
 
64
  api_keys = {
65
  "openai_api_key": data.get("openai_api_key", ""),
66
  "arraylake_api_key": data.get("arraylake_api_key", ""),
67
+ "hf_token": data.get("hf_token", ""),
68
  }
69
  session = create_session(connection_id, api_keys=api_keys)
70
  ready = session.is_ready()
web/static/js/chat.js CHANGED
@@ -26,6 +26,7 @@ class EurusChat {
26
  this.saveKeysBtn = document.getElementById('save-keys-btn');
27
  this.openaiKeyInput = document.getElementById('openai-key');
28
  this.arraylakeKeyInput = document.getElementById('arraylake-key');
 
29
 
30
  marked.setOptions({
31
  highlight: (code, lang) => {
@@ -80,7 +81,7 @@ class EurusChat {
80
  this.saveKeysBtn.addEventListener('click', () => this.saveAndSendKeys());
81
 
82
  // Allow Enter in key fields to submit
83
- [this.openaiKeyInput, this.arraylakeKeyInput].forEach(input => {
84
  input.addEventListener('keydown', (e) => {
85
  if (e.key === 'Enter') {
86
  e.preventDefault();
@@ -88,25 +89,69 @@ class EurusChat {
88
  }
89
  });
90
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  }
92
 
93
  saveAndSendKeys() {
94
  const openaiKey = this.openaiKeyInput.value.trim();
95
  const arraylakeKey = this.arraylakeKeyInput.value.trim();
 
96
 
97
  if (!openaiKey) {
98
  this.openaiKeyInput.focus();
99
  return;
100
  }
101
 
102
- // Send keys via WebSocket (never saved to storage)
 
 
 
 
 
 
 
 
103
  if (this.ws && this.ws.readyState === WebSocket.OPEN) {
104
  this.saveKeysBtn.disabled = true;
105
  this.saveKeysBtn.textContent = 'Connecting...';
106
  this.ws.send(JSON.stringify({
107
  type: 'configure_keys',
108
- openai_api_key: openaiKey,
109
- arraylake_api_key: arraylakeKey,
110
  }));
111
  }
112
  }
@@ -154,6 +199,9 @@ class EurusChat {
154
 
155
  if (this.serverKeysPresent.openai || this.keysConfigured) {
156
  this.sendBtn.disabled = false;
 
 
 
157
  }
158
  };
159
 
 
26
  this.saveKeysBtn = document.getElementById('save-keys-btn');
27
  this.openaiKeyInput = document.getElementById('openai-key');
28
  this.arraylakeKeyInput = document.getElementById('arraylake-key');
29
+ this.hfKeyInput = document.getElementById('hf-key');
30
 
31
  marked.setOptions({
32
  highlight: (code, lang) => {
 
81
  this.saveKeysBtn.addEventListener('click', () => this.saveAndSendKeys());
82
 
83
  // Allow Enter in key fields to submit
84
+ [this.openaiKeyInput, this.arraylakeKeyInput, this.hfKeyInput].forEach(input => {
85
  input.addEventListener('keydown', (e) => {
86
  if (e.key === 'Enter') {
87
  e.preventDefault();
 
89
  }
90
  });
91
  });
92
+
93
+ // Restore keys from sessionStorage (survives refresh, cleared on browser close)
94
+ this.restoreSessionKeys();
95
+ }
96
+
97
+ restoreSessionKeys() {
98
+ const saved = sessionStorage.getItem('eurus-keys');
99
+ if (!saved) return;
100
+ try {
101
+ const keys = JSON.parse(saved);
102
+ if (keys.openai_api_key) this.openaiKeyInput.value = keys.openai_api_key;
103
+ if (keys.arraylake_api_key) this.arraylakeKeyInput.value = keys.arraylake_api_key;
104
+ if (keys.hf_token) this.hfKeyInput.value = keys.hf_token;
105
+ } catch (e) {
106
+ sessionStorage.removeItem('eurus-keys');
107
+ }
108
+ }
109
+
110
+ autoSendSessionKeys() {
111
+ // After WS connects, if we have session-stored keys and server has none, auto-send them
112
+ if (this.serverKeysPresent.openai || this.keysConfigured) return;
113
+ const saved = sessionStorage.getItem('eurus-keys');
114
+ if (!saved) return;
115
+ try {
116
+ const keys = JSON.parse(saved);
117
+ if (keys.openai_api_key && this.ws && this.ws.readyState === WebSocket.OPEN) {
118
+ this.ws.send(JSON.stringify({
119
+ type: 'configure_keys',
120
+ openai_api_key: keys.openai_api_key,
121
+ arraylake_api_key: keys.arraylake_api_key || '',
122
+ hf_token: keys.hf_token || '',
123
+ }));
124
+ }
125
+ } catch (e) {
126
+ sessionStorage.removeItem('eurus-keys');
127
+ }
128
  }
129
 
130
  saveAndSendKeys() {
131
  const openaiKey = this.openaiKeyInput.value.trim();
132
  const arraylakeKey = this.arraylakeKeyInput.value.trim();
133
+ const hfKey = this.hfKeyInput.value.trim();
134
 
135
  if (!openaiKey) {
136
  this.openaiKeyInput.focus();
137
  return;
138
  }
139
 
140
+ // Save to sessionStorage (cleared when browser closes, survives refresh)
141
+ const keysPayload = {
142
+ openai_api_key: openaiKey,
143
+ arraylake_api_key: arraylakeKey,
144
+ hf_token: hfKey,
145
+ };
146
+ sessionStorage.setItem('eurus-keys', JSON.stringify(keysPayload));
147
+
148
+ // Send keys via WebSocket
149
  if (this.ws && this.ws.readyState === WebSocket.OPEN) {
150
  this.saveKeysBtn.disabled = true;
151
  this.saveKeysBtn.textContent = 'Connecting...';
152
  this.ws.send(JSON.stringify({
153
  type: 'configure_keys',
154
+ ...keysPayload,
 
155
  }));
156
  }
157
  }
 
199
 
200
  if (this.serverKeysPresent.openai || this.keysConfigured) {
201
  this.sendBtn.disabled = false;
202
+ } else {
203
+ // Auto-send keys from sessionStorage on reconnect/refresh
204
+ this.autoSendSessionKeys();
205
  }
206
  };
207
 
web/templates/index.html CHANGED
@@ -10,8 +10,8 @@
10
  <span>API Keys Required</span>
11
  </div>
12
  <div class="api-keys-body">
13
- <p class="api-keys-note">Enter your API keys to use Eurus. Keys are stored in your browser only and never
14
- saved on the server.</p>
15
  <div class="api-key-field">
16
  <label for="openai-key">OpenAI API Key <span class="required">*</span></label>
17
  <input type="password" id="openai-key" placeholder="sk-..." autocomplete="off">
@@ -20,6 +20,10 @@
20
  <label for="arraylake-key">Arraylake API Key</label>
21
  <input type="password" id="arraylake-key" placeholder="ema_..." autocomplete="off">
22
  </div>
 
 
 
 
23
  <button id="save-keys-btn" class="save-keys-btn">Connect</button>
24
  </div>
25
  </div>
@@ -60,5 +64,5 @@
60
  {% endblock %}
61
 
62
  {% block scripts %}
63
- <script src="/static/js/chat.js?v=20260218"></script>
64
  {% endblock %}
 
10
  <span>API Keys Required</span>
11
  </div>
12
  <div class="api-keys-body">
13
+ <p class="api-keys-note">Enter your API keys to use Eurus. Keys are kept in your browser session only
14
+ they are cleared when you close the browser.</p>
15
  <div class="api-key-field">
16
  <label for="openai-key">OpenAI API Key <span class="required">*</span></label>
17
  <input type="password" id="openai-key" placeholder="sk-..." autocomplete="off">
 
20
  <label for="arraylake-key">Arraylake API Key</label>
21
  <input type="password" id="arraylake-key" placeholder="ema_..." autocomplete="off">
22
  </div>
23
+ <div class="api-key-field">
24
+ <label for="hf-key">HuggingFace Token</label>
25
+ <input type="password" id="hf-key" placeholder="hf_..." autocomplete="off">
26
+ </div>
27
  <button id="save-keys-btn" class="save-keys-btn">Connect</button>
28
  </div>
29
  </div>
 
64
  {% endblock %}
65
 
66
  {% block scripts %}
67
+ <script src="/static/js/chat.js?v=20260218b"></script>
68
  {% endblock %}