Spaces:
Sleeping
Sleeping
Add debug logging
Browse files- document-authoring.js +3 -3
- nginx.conf +1 -1
- service-config.yml +1 -1
- start-services.sh +23 -34
document-authoring.js
CHANGED
|
@@ -178,7 +178,7 @@ let retryCount = 0;
|
|
| 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'
|
|
@@ -287,7 +287,7 @@ script.onload = async () => {
|
|
| 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',
|
|
@@ -421,7 +421,7 @@ ${targetLang}: "Las empresas usan Nutrient para..."`
|
|
| 421 |
// Add language detection function
|
| 422 |
async function detectLanguage(text) {
|
| 423 |
try {
|
| 424 |
-
const response = await fetch('/
|
| 425 |
method: 'POST',
|
| 426 |
headers: {
|
| 427 |
'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('/inference/api/v1/chat/completions', {
|
| 182 |
method: 'POST',
|
| 183 |
headers: {
|
| 184 |
'Content-Type': 'application/json'
|
|
|
|
| 287 |
|
| 288 |
async function translate(content, targetLang, sourceLang = 'English') {
|
| 289 |
try {
|
| 290 |
+
const response = await fetch('/inference/api/v1/chat/completions', {
|
| 291 |
method: 'POST',
|
| 292 |
headers: {
|
| 293 |
'Content-Type': 'application/json',
|
|
|
|
| 421 |
// Add language detection function
|
| 422 |
async function detectLanguage(text) {
|
| 423 |
try {
|
| 424 |
+
const response = await fetch('/inference/api/v1/chat/completions', {
|
| 425 |
method: 'POST',
|
| 426 |
headers: {
|
| 427 |
'Content-Type': 'application/json',
|
nginx.conf
CHANGED
|
@@ -15,7 +15,7 @@ http {
|
|
| 15 |
proxy_pass http://127.0.0.1:4000/healthcheck;
|
| 16 |
}
|
| 17 |
|
| 18 |
-
location /
|
| 19 |
proxy_pass http://127.0.0.1:4000;
|
| 20 |
}
|
| 21 |
|
|
|
|
| 15 |
proxy_pass http://127.0.0.1:4000/healthcheck;
|
| 16 |
}
|
| 17 |
|
| 18 |
+
location /inference/api/v1/ {
|
| 19 |
proxy_pass http://127.0.0.1:4000;
|
| 20 |
}
|
| 21 |
|
service-config.yml
CHANGED
|
@@ -11,7 +11,7 @@ aiServices:
|
|
| 11 |
name: 'openai-compat'
|
| 12 |
baseUrl: http://127.0.0.1:7861/v1
|
| 13 |
model: 'all-MiniLM-L6-v2'
|
| 14 |
-
|
| 15 |
- provider:
|
| 16 |
name: 'openai-compat'
|
| 17 |
baseUrl: http://127.0.0.1:7861/v1
|
|
|
|
| 11 |
name: 'openai-compat'
|
| 12 |
baseUrl: http://127.0.0.1:7861/v1
|
| 13 |
model: 'all-MiniLM-L6-v2'
|
| 14 |
+
inference:
|
| 15 |
- provider:
|
| 16 |
name: 'openai-compat'
|
| 17 |
baseUrl: http://127.0.0.1:7861/v1
|
start-services.sh
CHANGED
|
@@ -25,61 +25,50 @@ if ! ps aux | grep nginx | grep -v grep > /dev/null; then
|
|
| 25 |
fi
|
| 26 |
echo "Nginx started successfully"
|
| 27 |
|
| 28 |
-
# Start AI Assistant
|
| 29 |
-
echo "Starting AI Assistant..."
|
| 30 |
-
cd $HOME/app/aia
|
| 31 |
-
PORT=4000 node app/main.bundle.js &
|
| 32 |
-
AIA_PID=$!
|
| 33 |
-
|
| 34 |
# Start the models
|
| 35 |
-
echo "Starting
|
| 36 |
TMPDIR=/tmp/llamafiler /usr/local/bin/llamafiler --model $HOME/models/gemma-2b.gguf -ngl 999 --listen 0.0.0.0:8082 &
|
| 37 |
GEMMA_PID=$!
|
| 38 |
|
| 39 |
-
|
| 40 |
-
TMPDIR=/tmp/llamafiler /usr/local/bin/llamafiler --model $HOME/models/embeddings.gguf -ngl 999 --listen 0.0.0.0:8081 &
|
| 41 |
EMBEDDINGS_PID=$!
|
| 42 |
|
| 43 |
-
# Wait for
|
| 44 |
echo "Waiting for models to be ready..."
|
| 45 |
-
TIMEOUT=600 # 10 minutes timeout
|
| 46 |
START_TIME=$SECONDS
|
|
|
|
| 47 |
|
| 48 |
-
|
| 49 |
-
curl -s
|
| 50 |
-H "Content-Type: application/json" \
|
| 51 |
-
-d '{"model":
|
| 52 |
-
|
|
|
|
| 53 |
-H "Content-Type: application/json" \
|
| 54 |
-
-d '{"input":"test"}'
|
|
|
|
|
|
|
| 55 |
}
|
| 56 |
|
| 57 |
-
until
|
| 58 |
ELAPSED=$((SECONDS - START_TIME))
|
| 59 |
if [ $ELAPSED -gt $TIMEOUT ]; then
|
| 60 |
-
echo "Timeout
|
| 61 |
exit 1
|
| 62 |
fi
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
if ! kill -0 $GEMMA_PID 2>/dev/null; then
|
| 66 |
-
echo "Gemma model process died"
|
| 67 |
exit 1
|
| 68 |
fi
|
| 69 |
-
|
| 70 |
-
echo "Embeddings model process died"
|
| 71 |
-
exit 1
|
| 72 |
-
fi
|
| 73 |
-
if ! kill -0 $AIA_PID 2>/dev/null; then
|
| 74 |
-
echo "AI Assistant process died"
|
| 75 |
-
exit 1
|
| 76 |
-
fi
|
| 77 |
-
|
| 78 |
-
echo "Waiting for services... (${ELAPSED}s elapsed, PIDs: Gemma=$GEMMA_PID, Embeddings=$EMBEDDINGS_PID, AIA=$AIA_PID)"
|
| 79 |
sleep 2
|
| 80 |
done
|
| 81 |
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
-
# Keep
|
| 85 |
wait $GEMMA_PID
|
|
|
|
| 25 |
fi
|
| 26 |
echo "Nginx started successfully"
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
# Start the models
|
| 29 |
+
echo "Starting models..."
|
| 30 |
TMPDIR=/tmp/llamafiler /usr/local/bin/llamafiler --model $HOME/models/gemma-2b.gguf -ngl 999 --listen 0.0.0.0:8082 &
|
| 31 |
GEMMA_PID=$!
|
| 32 |
|
| 33 |
+
TMPDIR=/tmp/llamafiler /usr/local/bin/llamafiler --model $HOME/models/embeddings.gguf -ngl 999 --listen 0.0.0.0:8081 &
|
|
|
|
| 34 |
EMBEDDINGS_PID=$!
|
| 35 |
|
| 36 |
+
# Wait for models to be ready
|
| 37 |
echo "Waiting for models to be ready..."
|
|
|
|
| 38 |
START_TIME=$SECONDS
|
| 39 |
+
TIMEOUT=600 # 10 minutes
|
| 40 |
|
| 41 |
+
wait_for_models() {
|
| 42 |
+
CHAT_TEST=$(curl -s -X POST http://127.0.0.1:8082/v1/chat/completions \
|
| 43 |
-H "Content-Type: application/json" \
|
| 44 |
+
-d '{"model":"gemma-2b","messages":[{"role":"user","content":"test"}]}')
|
| 45 |
+
|
| 46 |
+
EMBED_TEST=$(curl -s -X POST http://127.0.0.1:8081/v1/embeddings \
|
| 47 |
-H "Content-Type: application/json" \
|
| 48 |
+
-d '{"input":"test"}')
|
| 49 |
+
|
| 50 |
+
[[ "$CHAT_TEST" == *"content"* ]] && [[ "$EMBED_TEST" == *"embedding"* ]]
|
| 51 |
}
|
| 52 |
|
| 53 |
+
until wait_for_models; do
|
| 54 |
ELAPSED=$((SECONDS - START_TIME))
|
| 55 |
if [ $ELAPSED -gt $TIMEOUT ]; then
|
| 56 |
+
echo "Timeout after ${TIMEOUT} seconds"
|
| 57 |
exit 1
|
| 58 |
fi
|
| 59 |
+
if ! kill -0 $GEMMA_PID 2>/dev/null || ! kill -0 $EMBEDDINGS_PID 2>/dev/null; then
|
| 60 |
+
echo "Model process died"
|
|
|
|
|
|
|
| 61 |
exit 1
|
| 62 |
fi
|
| 63 |
+
echo "Waiting for models... (${ELAPSED}s elapsed)"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
sleep 2
|
| 65 |
done
|
| 66 |
|
| 67 |
+
# Start AI Assistant
|
| 68 |
+
echo "Models ready after ${ELAPSED}s. Starting AI Assistant..."
|
| 69 |
+
cd $HOME/app/aia
|
| 70 |
+
PORT=4000 node app/main.bundle.js &
|
| 71 |
+
AIA_PID=$!
|
| 72 |
|
| 73 |
+
# Keep container running
|
| 74 |
wait $GEMMA_PID
|