File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed
Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments