Make API Key OpenAI-compatible (#917)
This commit is contained in:
@@ -391,7 +391,11 @@ def get_call_select(args: argparse.Namespace):
|
||||
|
||||
|
||||
def popen_launch_server(
|
||||
model: str, base_url: str, timeout: float, other_args: tuple = ()
|
||||
model: str,
|
||||
base_url: str,
|
||||
timeout: float,
|
||||
api_key: Optional[str] = None,
|
||||
other_args: tuple = (),
|
||||
):
|
||||
_, host, port = base_url.split(":")
|
||||
host = host[2:]
|
||||
@@ -408,12 +412,19 @@ def popen_launch_server(
|
||||
port,
|
||||
*other_args,
|
||||
]
|
||||
if api_key:
|
||||
command += ["--api-key", api_key]
|
||||
|
||||
process = subprocess.Popen(command, stdout=None, stderr=None)
|
||||
|
||||
start_time = time.time()
|
||||
while time.time() - start_time < timeout:
|
||||
try:
|
||||
response = requests.get(f"{base_url}/v1/models")
|
||||
headers = {
|
||||
"Content-Type": "application/json; charset=utf-8",
|
||||
"Authorization": f"Bearer {api_key}",
|
||||
}
|
||||
response = requests.get(f"{base_url}/v1/models", headers=headers)
|
||||
if response.status_code == 200:
|
||||
return process
|
||||
except requests.RequestException:
|
||||
|
||||
Reference in New Issue
Block a user