2727logger = get_logger (__name__ )
2828
2929PREVIEW_API_VERSION = "2024-10-02-preview"
30- SESSION_API_VERSION = "2024-02-02-preview"
3130POLLING_TIMEOUT = 1500 # how many seconds before exiting
3231POLLING_SECONDS = 2 # how many seconds between requests
3332POLLING_TIMEOUT_FOR_MANAGED_CERTIFICATE = 1500 # how many seconds before exiting
@@ -1158,11 +1157,11 @@ def list_by_subscription(cls, cmd, formatter=lambda x: x):
11581157
11591158
11601159class SessionCodeInterpreterPreviewClient ():
1161- api_version = SESSION_API_VERSION
1160+ api_version = PREVIEW_API_VERSION
11621161
11631162 @classmethod
11641163 def execute (cls , cmd , identifier , code_interpreter_envelope , session_pool_endpoint , no_wait = False ):
1165- url_fmt = "{}/code/execute ?identifier={}&api-version={}"
1164+ url_fmt = "{}/executions ?identifier={}&api-version={}"
11661165 request_url = url_fmt .format (
11671166 session_pool_endpoint ,
11681167 identifier ,
@@ -1181,10 +1180,11 @@ def execute(cls, cmd, identifier, code_interpreter_envelope, session_pool_endpoi
11811180 return r .json ()
11821181
11831182 @classmethod
1184- def upload (cls , cmd , identifier , filepath , session_pool_endpoint , no_wait = False ):
1185- url_fmt = "{}/files/upload? identifier={}&api-version={}"
1183+ def upload (cls , cmd , identifier , filepath , path , session_pool_endpoint , no_wait = False ):
1184+ url_fmt = "{}/files?{} identifier={}&api-version={}"
11861185 request_url = url_fmt .format (
11871186 session_pool_endpoint ,
1187+ f"path={ path } &" if path is not None else "" ,
11881188 identifier ,
11891189 cls .api_version )
11901190
@@ -1221,11 +1221,13 @@ def upload(cls, cmd, identifier, filepath, session_pool_endpoint, no_wait=False)
12211221 return r .json ()
12221222
12231223 @classmethod
1224- def show_file_content (cls , cmd , identifier , filename , session_pool_endpoint ):
1225- url_fmt = "{}/files/content/{}?identifier={}&api-version={}"
1224+ def show_file_content (cls , cmd , identifier , filename , path , session_pool_endpoint ):
1225+ path , filename = cls .extract_path_from_filename (path , filename )
1226+ url_fmt = "{}/files/{}/content?{}identifier={}&api-version={}"
12261227 request_url = url_fmt .format (
12271228 session_pool_endpoint ,
12281229 filename ,
1230+ f"path={ path } &" if path is not None else "" ,
12291231 identifier ,
12301232 cls .api_version )
12311233
@@ -1236,11 +1238,13 @@ def show_file_content(cls, cmd, identifier, filename, session_pool_endpoint):
12361238 return json .dumps (r .content .decode ())
12371239
12381240 @classmethod
1239- def show_file_metadata (cls , cmd , identifier , filename , session_pool_endpoint ):
1240- url_fmt = "{}/files/{}?identifier={}&api-version={}"
1241+ def show_file_metadata (cls , cmd , identifier , filename , path , session_pool_endpoint ):
1242+ path , filename = cls .extract_path_from_filename (path , filename )
1243+ url_fmt = "{}/files/{}?{}identifier={}&api-version={}"
12411244 request_url = url_fmt .format (
12421245 session_pool_endpoint ,
12431246 filename ,
1247+ f"path={ path } &" if path is not None else "" ,
12441248 identifier ,
12451249 cls .api_version )
12461250 logger .warning (request_url )
@@ -1249,11 +1253,13 @@ def show_file_metadata(cls, cmd, identifier, filename, session_pool_endpoint):
12491253 return r .json ()
12501254
12511255 @classmethod
1252- def delete_file (cls , cmd , identifier , filename , session_pool_endpoint , no_wait = False ):
1253- url_fmt = "{}/files/{}?identifier={}&api-version={}"
1256+ def delete_file (cls , cmd , identifier , filename , path , session_pool_endpoint , no_wait = False ):
1257+ path , filename = cls .extract_path_from_filename (path , filename )
1258+ url_fmt = "{}/files/{}?{}identifier={}&api-version={}"
12541259 request_url = url_fmt .format (
12551260 session_pool_endpoint ,
12561261 filename ,
1262+ f"path={ path } &" if path is not None else "" ,
12571263 identifier ,
12581264 cls .api_version )
12591265
@@ -1282,6 +1288,16 @@ def list_files(cls, cmd, identifier, path, session_pool_endpoint):
12821288 r = send_raw_request (cmd .cli_ctx , "GET" , request_url , resource = SESSION_RESOURCE )
12831289 return r .json ()
12841290
1291+ @staticmethod
1292+ def extract_path_from_filename (path , filename ):
1293+ if '/' not in filename :
1294+ return path , filename
1295+ path_in_filename , filename = filename .rsplit ('/' , 1 )
1296+ if path is None :
1297+ return path_in_filename , filename
1298+ else :
1299+ return path .rstrip ("/" ) + "/" + path_in_filename .lstrip ('/' ), filename
1300+
12851301
12861302class DotNetComponentPreviewClient ():
12871303 api_version = PREVIEW_API_VERSION
0 commit comments