mirror of
https://github.com/vllm-project/vllm.git
synced 2025-10-20 14:53:52 +08:00
Signed-off-by: wang.yuqi <noooop@126.com> Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
# SPDX-License-Identifier: Apache-2.0
|
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
|
"""Example Python client for classification API using vLLM API server
|
|
NOTE:
|
|
start a supported classification model server with `vllm serve`, e.g.
|
|
vllm serve jason9693/Qwen2.5-1.5B-apeach
|
|
"""
|
|
|
|
import argparse
|
|
import pprint
|
|
|
|
import requests
|
|
|
|
|
|
def post_http_request(payload: dict, api_url: str) -> requests.Response:
|
|
headers = {"User-Agent": "Test Client"}
|
|
response = requests.post(api_url, headers=headers, json=payload)
|
|
return response
|
|
|
|
|
|
def parse_args():
|
|
parse = argparse.ArgumentParser()
|
|
parse.add_argument("--host", type=str, default="localhost")
|
|
parse.add_argument("--port", type=int, default=8000)
|
|
parse.add_argument("--model", type=str, default="jason9693/Qwen2.5-1.5B-apeach")
|
|
return parse.parse_args()
|
|
|
|
|
|
def main(args):
|
|
host = args.host
|
|
port = args.port
|
|
model_name = args.model
|
|
|
|
api_url = f"http://{host}:{port}/classify"
|
|
prompts = [
|
|
"Hello, my name is",
|
|
"The president of the United States is",
|
|
"The capital of France is",
|
|
"The future of AI is",
|
|
]
|
|
|
|
payload = {
|
|
"model": model_name,
|
|
"input": prompts,
|
|
}
|
|
|
|
classify_response = post_http_request(payload=payload, api_url=api_url)
|
|
pprint.pprint(classify_response.json())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
args = parse_args()
|
|
main(args)
|