Skip to content

Commit a389af0

Browse files
authored
[Add] fix for router files api and example to post query to the api (#76)
Signed-off-by: ApostaC <yihua98@uchicago.edu>
1 parent eec575a commit a389af0

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import argparse
2+
3+
import httpx
4+
import requests
5+
6+
7+
def upload_file(server_url: str, file_path: str):
8+
"""Uploads a file to the production stack."""
9+
try:
10+
with open(file_path, "rb") as file:
11+
files = {"file": (file_path, file, "application/octet-stream")}
12+
data = {"purpose": "unknown"}
13+
14+
with httpx.Client() as client:
15+
response = client.post(server_url, files=files, data=data)
16+
17+
if response.status_code == 200:
18+
print("File uploaded successfully:", response.json())
19+
else:
20+
print("Failed to upload file:", response.text)
21+
except Exception as e:
22+
print(f"Error: {e}")
23+
24+
25+
def parse_args():
26+
"""Parses command line arguments."""
27+
parser = argparse.ArgumentParser(description="Uploads a file to the stack.")
28+
parser.add_argument("--path", type=str, help="Path to the file to upload.")
29+
parser.add_argument("--url", type=str, help="URL of the stack (router service).")
30+
31+
return parser.parse_args()
32+
33+
34+
if __name__ == "__main__":
35+
args = parse_args()
36+
endpoint = args.url
37+
file_to_upload = args.path
38+
upload_file(endpoint, file_to_upload)

src/vllm_router/router.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,13 @@ async def route_files(request: Request):
149149
# Unlike openai, we do not support fine-tuning, so we do not need to
150150
# check for 'purpose`.`
151151
purpose = "unknown"
152+
else:
153+
purpose = form["purpose"]
152154
if "file" not in form:
153155
return JSONResponse(
154156
status_code=400, content={"error": "Missing required parameter 'file'"}
155157
)
156158

157-
purpose = form["purpose"]
158159
file_obj: UploadFile = form["file"]
159160
file_content = await file_obj.read()
160161

0 commit comments

Comments
 (0)