File size: 1,479 Bytes
ea4670b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import requests
import time

base_url = "https://rulga-doc-chat.hf.space"
max_retries = 10  # Максимальное количество попыток
retry_delay = 30  # Задержка между попытками в секундах

def wait_for_service():
    print("Waiting for the service to start...")
    for attempt in range(max_retries):
        try:
            response = requests.get(base_url)
            if response.status_code == 200 and "Could not parse JSON" not in response.text:
                print(f"Service is ready after {attempt + 1} attempts!")
                return True
        except requests.exceptions.RequestException:
            pass
        
        print(f"Attempt {attempt + 1}/{max_retries}. Service is still starting. Waiting {retry_delay} seconds...")
        time.sleep(retry_delay)
    
    return False

if wait_for_service():
    # Запуск создания базы знаний
    print("\nSending rebuild request...")
    rebuild_url = f"{base_url}/rebuild-kb"
    response = requests.post(rebuild_url, params={"force": True})
    print(f"Status code: {response.status_code}")
    print(f"Response: {response.text}")

    # Проверка статуса
    print("\nChecking status...")
    status_url = f"{base_url}/kb-status"
    status = requests.get(status_url)
    print(f"Status code: {status.status_code}")
    print(f"Status: {status.text}")
else:
    print("Service failed to start after maximum retries")