mirror of
https://github.com/xming521/WeClone.git
synced 2026-08-28 18:07:28 +08:00
Merge pull request #213 from octo-patch/fix/issue-115-check-api-server-before-test
fix: check API server availability before running test-model
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import json
|
||||
import sys
|
||||
from typing import List, cast # 导入 cast
|
||||
|
||||
import openai
|
||||
@@ -8,6 +9,7 @@ from tqdm import tqdm
|
||||
|
||||
from weclone.utils.config import load_config
|
||||
from weclone.utils.config_models import TestModelArgs, WCInferConfig
|
||||
from weclone.utils.log import logger
|
||||
|
||||
infer_config = cast(WCInferConfig, load_config("web_demo"))
|
||||
test_config = cast(TestModelArgs, load_config("test_model"))
|
||||
@@ -23,6 +25,21 @@ completion_config = type("Config", (object,), completion_config)()
|
||||
client = OpenAI(api_key="""sk-test""", base_url="http://127.0.0.1:8005/v1")
|
||||
|
||||
|
||||
def _check_api_server() -> None:
|
||||
"""Verify that the API server is running before starting tests.
|
||||
|
||||
Exits with an error message if the server is not reachable.
|
||||
"""
|
||||
try:
|
||||
client.models.list()
|
||||
except openai.APIConnectionError:
|
||||
logger.error(
|
||||
f"Cannot connect to the API server at {client.base_url}. "
|
||||
"Please start the server first by running: weclone-cli server"
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def handler_text(content: str, history: list, config):
|
||||
messages = [{"role": "system", "content": f"{config.default_prompt}"}]
|
||||
for item in history:
|
||||
@@ -47,6 +64,7 @@ def handler_text(content: str, history: list, config):
|
||||
|
||||
|
||||
def main():
|
||||
_check_api_server()
|
||||
test_list = json.loads(open(test_config.test_data_path, "r", encoding="utf-8").read())["questions"]
|
||||
res = []
|
||||
for questions in tqdm(test_list, desc=" Testing..."):
|
||||
|
||||
Reference in New Issue
Block a user