dmartincy commited on
Commit
b90ec9f
·
1 Parent(s): 9b094c9

Connect to llamafile

Browse files
Files changed (4) hide show
  1. document-authoring.js +17 -4
  2. index.html +65 -0
  3. nginx.conf +0 -4
  4. service-config.yml +3 -3
document-authoring.js CHANGED
@@ -178,18 +178,31 @@ let retryCount = 0;
178
  const MAX_RETRIES = 10; // Will try for 20 seconds (10 attempts * 2 second interval)
179
 
180
  function checkServicesStatus() {
181
- fetch('/healthcheck')
 
 
 
 
 
 
 
 
 
182
  .then(response => {
183
  if (response.ok) {
184
  window.servicesReady = true;
185
  const translationControls = document.getElementById('translationControls');
186
  const statusIndicator = document.getElementById('statusIndicator');
 
187
  if (translationControls) {
188
  translationControls.style.display = 'block';
189
  }
190
  if (statusIndicator) {
191
  statusIndicator.style.display = 'none';
192
  }
 
 
 
193
  return true;
194
  }
195
  throw new Error('Services not ready');
@@ -199,11 +212,11 @@ function checkServicesStatus() {
199
  const statusIndicator = document.getElementById('statusIndicator');
200
  if (statusIndicator) {
201
  if (retryCount >= MAX_RETRIES) {
202
- statusIndicator.innerHTML = '❌ Failed to initialize translation services. Try restarting the space.';
203
  statusIndicator.style.color = '#dc3545';
204
  clearInterval(statusInterval);
205
  } else {
206
- statusIndicator.innerHTML = `<span class="spinner"></span> Initializing translation services...`;
207
  }
208
  }
209
  console.log('Waiting for services...', error);
@@ -274,7 +287,7 @@ script.onload = async () => {
274
 
275
  async function translate(content, targetLang, sourceLang = 'English') {
276
  try {
277
- const response = await fetch('/client/inference/api/v1/chat/completions', {
278
  method: 'POST',
279
  headers: {
280
  'Content-Type': 'application/json',
 
178
  const MAX_RETRIES = 10; // Will try for 20 seconds (10 attempts * 2 second interval)
179
 
180
  function checkServicesStatus() {
181
+ fetch('/v1/chat/completions', {
182
+ method: 'POST',
183
+ headers: {
184
+ 'Content-Type': 'application/json'
185
+ },
186
+ body: JSON.stringify({
187
+ model: 'gemma-2b',
188
+ messages: [{role: 'user', content: 'hi'}]
189
+ })
190
+ })
191
  .then(response => {
192
  if (response.ok) {
193
  window.servicesReady = true;
194
  const translationControls = document.getElementById('translationControls');
195
  const statusIndicator = document.getElementById('statusIndicator');
196
+ const loadingOverlay = document.getElementById('loadingOverlay');
197
  if (translationControls) {
198
  translationControls.style.display = 'block';
199
  }
200
  if (statusIndicator) {
201
  statusIndicator.style.display = 'none';
202
  }
203
+ if (loadingOverlay) {
204
+ loadingOverlay.classList.add('hidden');
205
+ }
206
  return true;
207
  }
208
  throw new Error('Services not ready');
 
212
  const statusIndicator = document.getElementById('statusIndicator');
213
  if (statusIndicator) {
214
  if (retryCount >= MAX_RETRIES) {
215
+ statusIndicator.innerHTML = '❌ Failed to initialize AI services. Try restarting the space.';
216
  statusIndicator.style.color = '#dc3545';
217
  clearInterval(statusInterval);
218
  } else {
219
+ statusIndicator.innerHTML = `<span class="spinner"></span> Initializing AI services...`;
220
  }
221
  }
222
  console.log('Waiting for services...', error);
 
287
 
288
  async function translate(content, targetLang, sourceLang = 'English') {
289
  try {
290
+ const response = await fetch('/v1/chat/completions', {
291
  method: 'POST',
292
  headers: {
293
  'Content-Type': 'application/json',
index.html CHANGED
@@ -56,10 +56,75 @@
56
  border-radius: 4px;
57
  font-size: 16px;
58
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  </style>
60
  </head>
61
  <body>
 
 
 
 
62
  <div id="app"></div>
63
  <script src="/document-authoring.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  </body>
65
  </html>
 
56
  border-radius: 4px;
57
  font-size: 16px;
58
  }
59
+
60
+ #loadingOverlay {
61
+ position: fixed;
62
+ top: 0;
63
+ left: 0;
64
+ width: 100%;
65
+ height: 100%;
66
+ background: rgba(255, 255, 255, 0.9);
67
+ display: flex;
68
+ flex-direction: column;
69
+ justify-content: center;
70
+ align-items: center;
71
+ z-index: 1000;
72
+ }
73
+
74
+ #loadingSpinner {
75
+ width: 50px;
76
+ height: 50px;
77
+ border: 5px solid #f3f3f3;
78
+ border-top: 5px solid #3498db;
79
+ border-radius: 50%;
80
+ animation: spin 1s linear infinite;
81
+ margin-bottom: 20px;
82
+ }
83
+
84
+ #loadingMessage {
85
+ font-size: 18px;
86
+ color: #333;
87
+ }
88
+
89
+ .hidden {
90
+ display: none !important;
91
+ }
92
  </style>
93
  </head>
94
  <body>
95
+ <div id="loadingOverlay">
96
+ <div id="loadingSpinner"></div>
97
+ <div id="loadingMessage">Initializing AI models... This may take up to 10 minutes.</div>
98
+ </div>
99
  <div id="app"></div>
100
  <script src="/document-authoring.js"></script>
101
+ <script>
102
+ // Check if services are ready
103
+ function checkServices() {
104
+ fetch('/v1/chat/completions', {
105
+ method: 'POST',
106
+ headers: {
107
+ 'Content-Type': 'application/json'
108
+ },
109
+ body: JSON.stringify({
110
+ model: 'gemma-2b',
111
+ messages: [{role: 'user', content: 'hi'}]
112
+ })
113
+ })
114
+ .then(response => {
115
+ if (response.ok) {
116
+ document.getElementById('loadingOverlay').classList.add('hidden');
117
+ } else {
118
+ setTimeout(checkServices, 5000); // retry every 5 seconds
119
+ }
120
+ })
121
+ .catch(() => {
122
+ setTimeout(checkServices, 5000); // retry on error
123
+ });
124
+ }
125
+
126
+ // Start checking when page loads
127
+ checkServices();
128
+ </script>
129
  </body>
130
  </html>
nginx.conf CHANGED
@@ -22,9 +22,5 @@ http {
22
  location /v1/embeddings {
23
  proxy_pass http://127.0.0.1:8081;
24
  }
25
-
26
- location /v1 {
27
- proxy_pass http://127.0.0.1:8082;
28
- }
29
  }
30
  }
 
22
  location /v1/embeddings {
23
  proxy_pass http://127.0.0.1:8081;
24
  }
 
 
 
 
25
  }
26
  }
service-config.yml CHANGED
@@ -4,17 +4,17 @@ aiServices:
4
  chat:
5
  provider:
6
  name: 'openai-compat'
7
- baseUrl: http://127.0.0.1:7861/v1
8
  model: 'gemma-2b'
9
  textEmbeddings:
10
  provider:
11
  name: 'openai-compat'
12
- baseUrl: http://127.0.0.1:7861/v1
13
  model: 'all-MiniLM-L6-v2'
14
  headless:
15
  - provider:
16
  name: 'openai-compat'
17
- baseUrl: http://127.0.0.1:7861/v1
18
  model:
19
  name: 'gemma-2b'
20
  id: 'gemma-2b'
 
4
  chat:
5
  provider:
6
  name: 'openai-compat'
7
+ baseUrl: http://127.0.0.1:8082/v1
8
  model: 'gemma-2b'
9
  textEmbeddings:
10
  provider:
11
  name: 'openai-compat'
12
+ baseUrl: http://127.0.0.1:8081/v1
13
  model: 'all-MiniLM-L6-v2'
14
  headless:
15
  - provider:
16
  name: 'openai-compat'
17
+ baseUrl: http://127.0.0.1:8082/v1
18
  model:
19
  name: 'gemma-2b'
20
  id: 'gemma-2b'