Merge pull request #92 from zai-org/support-bigmodel

fix format
This commit is contained in:
yongbin-buaa
2025-12-11 18:26:55 +08:00
committed by GitHub

36
main.py
View File

@@ -188,36 +188,28 @@ def check_model_api(base_url: str, model_name: str, api_key: str = "EMPTY") -> b
all_passed = True all_passed = True
# Check 1: Network connectivity # Check 1: Network connectivity using chat API
print(f"1. Checking API connectivity ({base_url})...", end=" ") print(f"1. Checking API connectivity ({base_url})...", end=" ")
try: try:
# Parse the URL to get host and port
parsed = urlparse(base_url)
# Create OpenAI client # Create OpenAI client
client = OpenAI(base_url=base_url, api_key=api_key, timeout=10.0) client = OpenAI(base_url=base_url, api_key=api_key, timeout=30.0)
# Try to list models (this tests connectivity) # Use chat completion to test connectivity (more universally supported than /models)
models_response = client.models.list() response = client.chat.completions.create(
available_models = [model.id for model in models_response.data] model=model_name,
messages=[{"role": "user", "content": "Hi"}],
max_tokens=5,
temperature=0.0,
stream=False,
)
print("✅ OK") # Check if we got a valid response
if response.choices and len(response.choices) > 0:
# Check 2: Model exists
"""
print(f"2. Checking model '{model_name}'...", end=" ")
if model_name in available_models:
print("✅ OK") print("✅ OK")
else: else:
print("❌ FAILED") print("❌ FAILED")
print(f" Error: Model '{model_name}' not found.") print(" Error: Received empty response from API")
print(f" Available models:")
for m in available_models[:10]: # Show first 10 models
print(f" - {m}")
if len(available_models) > 10:
print(f" ... and {len(available_models) - 10} more")
all_passed = False all_passed = False
"""
except Exception as e: except Exception as e:
print("❌ FAILED") print("❌ FAILED")
@@ -229,7 +221,7 @@ def check_model_api(base_url: str, model_name: str, api_key: str = "EMPTY") -> b
print(" Solution:") print(" Solution:")
print(" 1. Check if the model server is running") print(" 1. Check if the model server is running")
print(" 2. Verify the base URL is correct") print(" 2. Verify the base URL is correct")
print(f" 3. Try: curl {base_url}/models") print(f" 3. Try: curl {base_url}/chat/completions")
elif "timed out" in error_msg.lower() or "timeout" in error_msg.lower(): elif "timed out" in error_msg.lower() or "timeout" in error_msg.lower():
print(f" Error: Connection to {base_url} timed out") print(f" Error: Connection to {base_url} timed out")
print(" Solution:") print(" Solution:")