File size: 1,523 Bytes
7450b4b
 
 
 
 
 
cca76bd
7450b4b
8170758
 
 
7450b4b
 
 
 
 
 
8170758
7450b4b
 
 
8170758
 
7450b4b
cca76bd
7450b4b
 
8170758
cca76bd
8170758
7450b4b
 
 
 
 
 
 
cca76bd
7450b4b
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
45
46
47
48
49
import subprocess
import os
import sys

# --- Configuration ---
PORT = int(os.environ.get("PORT", 7860))
BIND_ADDRESS = "0.0.0.0" # Listen on all interfaces within the container

# Combine address and port for the --bind argument
COMBINED_BIND = f"{BIND_ADDRESS}:{PORT}"

# Choose the g4f install variant (ensure it matches requirements.txt)
G4F_VARIANT = "all" # Change to 'slim' or 'base' if needed

# --- --- --- --- ---

print(f"--- Starting gpt4free API Server (variant: {G4F_VARIANT}) ---")
print(f"Attempting to bind to: {COMBINED_BIND}") # Updated print statement
print(f"Python version: {sys.version}")
print("-" * 30)

# Construct the command using the combined --bind "<address>:<port>" format
# Remove the separate --port argument
command = [
    sys.executable,
    "-m",
    "g4f",
    "--bind", COMBINED_BIND, # Use the combined address and port string
    "--debug"
    # No separate --port argument needed here
]

print(f"Executing command: {' '.join(command)}")
print("-" * 30, flush=True)

try:
    process = subprocess.Popen(command, stdout=sys.stdout, stderr=sys.stderr)
    process.wait()

except FileNotFoundError:
    print("\nERROR: Could not find the python interpreter or the 'g4f' module.")
    print("Please ensure Python is installed correctly and 'g4f' is in requirements.txt")
    sys.exit(1)
except Exception as e:
    print(f"\nERROR: An unexpected error occurred while trying to start the server: {e}")
    sys.exit(1)

print("-" * 30)
print("--- gpt4free API Server process exited. ---")