From 659b4e9731196b3ff45184345a94704a19df94c3 Mon Sep 17 00:00:00 2001 From: Katie Wu Date: Fri, 21 Jul 2023 02:06:30 -0700 Subject: [PATCH 01/10] File API functions --- clients/python/llmengine/__init__.py | 12 ++ clients/python/llmengine/api_engine.py | 15 ++ clients/python/llmengine/data_types.py | 41 ++++++ clients/python/llmengine/file.py | 192 +++++++++++++++++++++++++ docs/api/data_types.md | 10 ++ docs/api/python_client.md | 9 ++ 6 files changed, 279 insertions(+) create mode 100644 clients/python/llmengine/file.py diff --git a/clients/python/llmengine/__init__.py b/clients/python/llmengine/__init__.py index d7567145..a1144127 100644 --- a/clients/python/llmengine/__init__.py +++ b/clients/python/llmengine/__init__.py @@ -25,12 +25,18 @@ CompletionSyncResponse, CreateFineTuneRequest, CreateFineTuneResponse, + DeleteFileResponse, DeleteLLMEndpointResponse, + GetFileContentResponse, + GetFileResponse, GetFineTuneResponse, GetLLMEndpointResponse, + ListFilesResponse, ListFineTunesResponse, ListLLMEndpointsResponse, + UploadFileResponse, ) +from llmengine.file import File from llmengine.fine_tuning import FineTune from llmengine.model import Model @@ -43,11 +49,17 @@ "CompletionSyncResponse", "CreateFineTuneRequest", "CreateFineTuneResponse", + "DeleteFileResponse", "DeleteLLMEndpointResponse", + "File", "FineTune", + "GetFileContentResponse", + "GetFileResponse", "GetFineTuneResponse", "GetLLMEndpointResponse", + "ListFilesResponse", "ListFineTunesResponse", "ListLLMEndpointsResponse", "Model", + "UploadFileResponse", ) diff --git a/clients/python/llmengine/api_engine.py b/clients/python/llmengine/api_engine.py index 0d82c184..d85c287e 100644 --- a/clients/python/llmengine/api_engine.py +++ b/clients/python/llmengine/api_engine.py @@ -1,5 +1,6 @@ # NOTICE - per Apache 2.0 license: # This file was copied and modified from the OpenAI Python client library: https://github.com/openai/openai-python +from io import BufferedReader import json import os from functools import wraps @@ -124,6 +125,20 @@ def post_stream( except json.JSONDecodeError: raise ValueError(f"Invalid JSON payload: {payload_data}") + @classmethod + def post_file(cls, resource_name: str, files: BufferedReader, timeout: int) -> Dict[str, Any]: + api_key = get_api_key() + response = requests.post( + os.path.join(LLM_ENGINE_BASE_PATH, resource_name), + files=files, + timeout=timeout, + headers={"x-api-key": api_key}, + ) + if response.status_code != 200: + raise parse_error(response.status_code, response.content) + payload = response.json() + return payload + @classmethod async def apost_sync( cls, resource_name: str, data: Dict[str, Any], timeout: int diff --git a/clients/python/llmengine/data_types.py b/clients/python/llmengine/data_types.py index ffcd4f5c..362b52d0 100644 --- a/clients/python/llmengine/data_types.py +++ b/clients/python/llmengine/data_types.py @@ -440,3 +440,44 @@ class GetFineTuneEventsResponse(BaseModel): """ events: List[LLMFineTuneEvent] = Field(..., description="List of fine-tuning events.") + + +class UploadFileResponse(BaseModel): + """Response object for uploading a file.""" + + id: str = Field(..., description="ID of the uploaded file.") + """ID of the uploaded file.""" + + +class GetFileResponse(BaseModel): + """Response object for retrieving a file.""" + + id: str = Field(..., description="ID of the requested file.") + """ID of the requested file.""" + filename: str = Field(..., description="File name.") + """File name.""" + size: int = Field(..., description="Length of the file, in characters.") + """Length of the file, in characters.""" + + +class ListFilesResponse(BaseModel): + """Response object for listing files.""" + + files: List[GetFileResponse] = Field(..., description="List of file IDs, names, and sizes.") + """List of file IDs, names, and sizes.""" + + +class DeleteFileResponse(BaseModel): + """Response object for deleting a file.""" + + deleted: bool = Field(..., description="Whether deletion was successful.") + """Whether deletion was successful.""" + + +class GetFileContentResponse(BaseModel): + """Response object for retrieving a file's content.""" + + id: str = Field(..., description="ID of the requested file.") + """ID of the requested file.""" + content: str = Field(..., description="File content.") + """File content.""" diff --git a/clients/python/llmengine/file.py b/clients/python/llmengine/file.py new file mode 100644 index 00000000..2757b76e --- /dev/null +++ b/clients/python/llmengine/file.py @@ -0,0 +1,192 @@ +from llmengine.api_engine import DEFAULT_TIMEOUT, APIEngine +from llmengine.data_types import ( + DeleteFileResponse, + GetFileContentResponse, + GetFileResponse, + ListFilesResponse, + UploadFileResponse, +) + + +class File(APIEngine): + """ + File API. This API is used to upload private files to Scale so that fine-tunes can access them for training and validation data. + + Functions are provided to upload, get, list, and delete files, as well as to get the contents of a file. + """ + + @classmethod + def upload(cls, file_path: str) -> UploadFileResponse: + """ + Uploads a local file to Scale. + + Args: + file_path (`str`): + The local path to the file. + + Returns: + UploadFileResponse: an object that contains the ID of the uploaded file + + === "Uploading file in Python" + ```python + from llmengine import File + + response = File.upload("training_dataset.csv") + + print(response.json()) + ``` + + === "Response in JSON" + ```json + { + "id": "file-abc123" + } + ``` + """ + with open(file_path, "rb") as file: + files = {"file": file} + response = cls.post_file( + resource_name="v1/files", + files=files, + timeout=DEFAULT_TIMEOUT, + ) + return UploadFileResponse.parse_obj(response) + + @classmethod + def get(cls, file_id: str) -> GetFileResponse: + """ + Get filename and size of a file. + + Args: + file_id (`str`): + ID of the file + + Returns: + GetFileResponse: an object that contains the ID, filename, and size of the requested file + + === "Getting metadata about file in Python" + ```python + from llmengine import File + + response = File.get( + file_id="file-abc123", + ) + + print(response.json()) + ``` + + === "Response in JSON" + ```json + { + "id": "file-abc123", + "filename": "training_dataset.csv", + "size": 100 + } + ``` + """ + response = cls._get(f"v1/files/{file_id}", timeout=DEFAULT_TIMEOUT) + return GetFileResponse.parse_obj(response) + + @classmethod + def list(cls) -> ListFilesResponse: + """ + List all files, with information about their filenames and sizes. + + Returns: + ListFilesResponse: an object that contains a list of all files and their filenames and sizes + + === "Listing files in Python" + ```python + from llmengine import File + + response = File.list() + print(response.json()) + ``` + + === "Response in JSON" + ```json + { + "files": [ + { + "id": "file-abc123", + "filename": "training_dataset.csv", + "size": 100 + }, + { + "id": "file-def456", + "filename": "validation_dataset.csv", + "size": 50 + } + ] + } + ``` + """ + response = cls._get("v1/files", timeout=30) + return ListFilesResponse.parse_obj(response) + + @classmethod + def delete(cls, file_id: str) -> DeleteFileResponse: + """ + Deletes a file. + + Args: + file_id (`str`): + ID of the file + + Returns: + DeleteFileResponse: an object that contains whether the deletion was successful + + === "Deleting file in Python" + ```python + from llmengine import File + + response = File.delete(file_id="file-abc123") + print(response.json()) + ``` + + === "Response in JSON" + ```json + { + "deleted": true + } + ``` + """ + response = cls._delete( + f"v1/files/{file_id}", + timeout=DEFAULT_TIMEOUT, + ) + return DeleteFileResponse.parse_obj(response) + + @classmethod + def get_content(cls, file_id: str) -> GetFileContentResponse: + """ + Get contents of a file. + + Args: + file_id (`str`): + ID of the file + + Returns: + GetFileContentResponse: an object that contains the ID and content of the file + + === "Getting file content in Python" + ```python + from llmengine import File + + response = File.get_content(file_id="file-abc123") + print(response.json()) + ``` + + === "Response in JSON" + ```json + { + "id": "file-abc123", + "content": "Hello world!" + } + ``` + """ + response = cls._get( + f"v1/files/{file_id}/content", + timeout=DEFAULT_TIMEOUT, + ) + return GetFileContentResponse.parse_obj(response) diff --git a/docs/api/data_types.md b/docs/api/data_types.md index 55f33028..2d53a3bf 100644 --- a/docs/api/data_types.md +++ b/docs/api/data_types.md @@ -43,3 +43,13 @@ ::: llmengine.ListLLMEndpointsResponse ::: llmengine.DeleteLLMEndpointResponse + +::: llmengine.UploadFileResponse + +::: llmengine.GetFileResponse + +::: llmengine.GetFileContentResponse + +::: llmengine.ListFilesResponse + +::: llmengine.DeleteFileResponse diff --git a/docs/api/python_client.md b/docs/api/python_client.md index 820b2e56..e1a8b1f2 100644 --- a/docs/api/python_client.md +++ b/docs/api/python_client.md @@ -21,3 +21,12 @@ - get - list - delete + +::: llmengine.File + selection: + members: + - upload + - get + - get_content + - list + - delete From e4a62e599da6f95bbb49824824cd831c81a53dd9 Mon Sep 17 00:00:00 2001 From: Katie Wu Date: Mon, 31 Jul 2023 12:39:22 -0700 Subject: [PATCH 02/10] upload file, not path --- clients/python/llmengine/file.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/clients/python/llmengine/file.py b/clients/python/llmengine/file.py index 2757b76e..25b99a80 100644 --- a/clients/python/llmengine/file.py +++ b/clients/python/llmengine/file.py @@ -1,3 +1,5 @@ +from io import BufferedReader + from llmengine.api_engine import DEFAULT_TIMEOUT, APIEngine from llmengine.data_types import ( DeleteFileResponse, @@ -16,13 +18,13 @@ class File(APIEngine): """ @classmethod - def upload(cls, file_path: str) -> UploadFileResponse: + def upload(cls, file: BufferedReader) -> UploadFileResponse: """ - Uploads a local file to Scale. + Uploads a file to Scale. Args: - file_path (`str`): - The local path to the file. + file (`BufferedReader`): + A file opened with open(file_path, "r") Returns: UploadFileResponse: an object that contains the ID of the uploaded file @@ -31,7 +33,7 @@ def upload(cls, file_path: str) -> UploadFileResponse: ```python from llmengine import File - response = File.upload("training_dataset.csv") + response = File.upload(open("training_dataset.csv", "r")) print(response.json()) ``` @@ -43,13 +45,12 @@ def upload(cls, file_path: str) -> UploadFileResponse: } ``` """ - with open(file_path, "rb") as file: - files = {"file": file} - response = cls.post_file( - resource_name="v1/files", - files=files, - timeout=DEFAULT_TIMEOUT, - ) + files = {"file": file} + response = cls.post_file( + resource_name="v1/files", + files=files, + timeout=DEFAULT_TIMEOUT, + ) return UploadFileResponse.parse_obj(response) @classmethod From 31000caba1936903618f673e395c1e17f11ab6a8 Mon Sep 17 00:00:00 2001 From: Katie Wu Date: Mon, 31 Jul 2023 12:50:15 -0700 Subject: [PATCH 03/10] address comments --- clients/python/llmengine/data_types.py | 3 +++ clients/python/llmengine/file.py | 12 ++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/clients/python/llmengine/data_types.py b/clients/python/llmengine/data_types.py index 6e596d10..1016bef8 100644 --- a/clients/python/llmengine/data_types.py +++ b/clients/python/llmengine/data_types.py @@ -454,8 +454,10 @@ class GetFileResponse(BaseModel): id: str = Field(..., description="ID of the requested file.") """ID of the requested file.""" + filename: str = Field(..., description="File name.") """File name.""" + size: int = Field(..., description="Length of the file, in characters.") """Length of the file, in characters.""" @@ -479,5 +481,6 @@ class GetFileContentResponse(BaseModel): id: str = Field(..., description="ID of the requested file.") """ID of the requested file.""" + content: str = Field(..., description="File content.") """File content.""" diff --git a/clients/python/llmengine/file.py b/clients/python/llmengine/file.py index 25b99a80..c3e7ae48 100644 --- a/clients/python/llmengine/file.py +++ b/clients/python/llmengine/file.py @@ -12,7 +12,7 @@ class File(APIEngine): """ - File API. This API is used to upload private files to Scale so that fine-tunes can access them for training and validation data. + File API. This API is used to upload private files to LLM engine so that fine-tunes can access them for training and validation data. Functions are provided to upload, get, list, and delete files, as well as to get the contents of a file. """ @@ -20,7 +20,7 @@ class File(APIEngine): @classmethod def upload(cls, file: BufferedReader) -> UploadFileResponse: """ - Uploads a file to Scale. + Uploads a file to LLM engine. Args: file (`BufferedReader`): @@ -56,7 +56,7 @@ def upload(cls, file: BufferedReader) -> UploadFileResponse: @classmethod def get(cls, file_id: str) -> GetFileResponse: """ - Get filename and size of a file. + Get file metadata, including filename and size. Args: file_id (`str`): @@ -91,7 +91,7 @@ def get(cls, file_id: str) -> GetFileResponse: @classmethod def list(cls) -> ListFilesResponse: """ - List all files, with information about their filenames and sizes. + List metadata about all files, e.g. their filenames and sizes. Returns: ListFilesResponse: an object that contains a list of all files and their filenames and sizes @@ -159,9 +159,9 @@ def delete(cls, file_id: str) -> DeleteFileResponse: return DeleteFileResponse.parse_obj(response) @classmethod - def get_content(cls, file_id: str) -> GetFileContentResponse: + def download(cls, file_id: str) -> GetFileContentResponse: """ - Get contents of a file. + Get contents of a file, as a string. (If the uploaded file is in binary, a string encoding will be returned.) Args: file_id (`str`): From c951a1b12fd4ca831bc86a3613ed5bfa51fe99c3 Mon Sep 17 00:00:00 2001 From: Katie Wu Date: Mon, 31 Jul 2023 18:43:54 -0700 Subject: [PATCH 04/10] rename to DownloadFileResponse --- clients/python/llmengine/__init__.py | 4 ++-- clients/python/llmengine/data_types.py | 2 +- clients/python/llmengine/file.py | 8 ++++---- docs/api/data_types.md | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/clients/python/llmengine/__init__.py b/clients/python/llmengine/__init__.py index 994e1e09..485a0b1b 100644 --- a/clients/python/llmengine/__init__.py +++ b/clients/python/llmengine/__init__.py @@ -27,7 +27,7 @@ CreateFineTuneResponse, DeleteFileResponse, DeleteLLMEndpointResponse, - GetFileContentResponse, + DownloadFileResponse, GetFileResponse, GetFineTuneResponse, GetLLMEndpointResponse, @@ -51,9 +51,9 @@ "CreateFineTuneResponse", "DeleteFileResponse", "DeleteLLMEndpointResponse", + "DownloadFileResponse", "File", "FineTune", - "GetFileContentResponse", "GetFileResponse", "GetFineTuneResponse", "GetLLMEndpointResponse", diff --git a/clients/python/llmengine/data_types.py b/clients/python/llmengine/data_types.py index 63aefbbd..1590e602 100644 --- a/clients/python/llmengine/data_types.py +++ b/clients/python/llmengine/data_types.py @@ -489,7 +489,7 @@ class DeleteFileResponse(BaseModel): """Whether deletion was successful.""" -class GetFileContentResponse(BaseModel): +class DownloadFileResponse(BaseModel): """Response object for retrieving a file's content.""" id: str = Field(..., description="ID of the requested file.") diff --git a/clients/python/llmengine/file.py b/clients/python/llmengine/file.py index c3e7ae48..9a950f6b 100644 --- a/clients/python/llmengine/file.py +++ b/clients/python/llmengine/file.py @@ -3,7 +3,7 @@ from llmengine.api_engine import DEFAULT_TIMEOUT, APIEngine from llmengine.data_types import ( DeleteFileResponse, - GetFileContentResponse, + DownloadFileResponse, GetFileResponse, ListFilesResponse, UploadFileResponse, @@ -159,7 +159,7 @@ def delete(cls, file_id: str) -> DeleteFileResponse: return DeleteFileResponse.parse_obj(response) @classmethod - def download(cls, file_id: str) -> GetFileContentResponse: + def download(cls, file_id: str) -> DownloadFileResponse: """ Get contents of a file, as a string. (If the uploaded file is in binary, a string encoding will be returned.) @@ -168,7 +168,7 @@ def download(cls, file_id: str) -> GetFileContentResponse: ID of the file Returns: - GetFileContentResponse: an object that contains the ID and content of the file + DownloadFileResponse: an object that contains the ID and content of the file === "Getting file content in Python" ```python @@ -190,4 +190,4 @@ def download(cls, file_id: str) -> GetFileContentResponse: f"v1/files/{file_id}/content", timeout=DEFAULT_TIMEOUT, ) - return GetFileContentResponse.parse_obj(response) + return DownloadFileResponse.parse_obj(response) diff --git a/docs/api/data_types.md b/docs/api/data_types.md index 2d53a3bf..2a2d4626 100644 --- a/docs/api/data_types.md +++ b/docs/api/data_types.md @@ -48,7 +48,7 @@ ::: llmengine.GetFileResponse -::: llmengine.GetFileContentResponse +::: llmengine.DownloadFileResponse ::: llmengine.ListFilesResponse From e6a531b200e81351b68b4b794c7f709502bce9d2 Mon Sep 17 00:00:00 2001 From: Katie Wu Date: Mon, 31 Jul 2023 18:45:54 -0700 Subject: [PATCH 05/10] bump version to 0.0.0.b8 --- clients/python/llmengine/__init__.py | 2 +- clients/python/pyproject.toml | 2 +- clients/python/setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clients/python/llmengine/__init__.py b/clients/python/llmengine/__init__.py index 485a0b1b..6d994098 100644 --- a/clients/python/llmengine/__init__.py +++ b/clients/python/llmengine/__init__.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.0.0.beta7" +__version__ = "0.0.0.beta8" from typing import Sequence diff --git a/clients/python/pyproject.toml b/clients/python/pyproject.toml index 0b9759db..6f229a8b 100644 --- a/clients/python/pyproject.toml +++ b/clients/python/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "scale-llm-engine" -version = "0.0.0.beta7" +version = "0.0.0.beta8" description = "Scale LLM Engine Python client" license = "Apache-2.0" authors = ["Phil Chen "] diff --git a/clients/python/setup.py b/clients/python/setup.py index 67b6d4f0..625c8984 100644 --- a/clients/python/setup.py +++ b/clients/python/setup.py @@ -3,6 +3,6 @@ setup( name="scale-llm-engine", python_requires=">=3.7", - version="0.0.0.beta7", + version="0.0.0.beta8", packages=find_packages(), ) From 3bb0f39eabb731fa3088f6d1e44a298b238e64ba Mon Sep 17 00:00:00 2001 From: Katie Wu Date: Mon, 31 Jul 2023 18:51:36 -0700 Subject: [PATCH 06/10] is this the right place to add CNAME --- docs/CNAME | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/CNAME diff --git a/docs/CNAME b/docs/CNAME new file mode 100644 index 00000000..4f4ed6e6 --- /dev/null +++ b/docs/CNAME @@ -0,0 +1 @@ +llm-engine.scale.com \ No newline at end of file From c100be7f875cbced3e307c0d195828b75adf5945 Mon Sep 17 00:00:00 2001 From: Katie Wu Date: Tue, 1 Aug 2023 11:32:25 -0700 Subject: [PATCH 07/10] change name back --- clients/python/llmengine/__init__.py | 4 ++-- clients/python/llmengine/data_types.py | 2 +- clients/python/llmengine/file.py | 8 ++++---- docs/api/data_types.md | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/clients/python/llmengine/__init__.py b/clients/python/llmengine/__init__.py index 6d994098..25dd9652 100644 --- a/clients/python/llmengine/__init__.py +++ b/clients/python/llmengine/__init__.py @@ -27,7 +27,7 @@ CreateFineTuneResponse, DeleteFileResponse, DeleteLLMEndpointResponse, - DownloadFileResponse, + GetFileContentResponse, GetFileResponse, GetFineTuneResponse, GetLLMEndpointResponse, @@ -51,7 +51,7 @@ "CreateFineTuneResponse", "DeleteFileResponse", "DeleteLLMEndpointResponse", - "DownloadFileResponse", + "GetFileContentResponse", "File", "FineTune", "GetFileResponse", diff --git a/clients/python/llmengine/data_types.py b/clients/python/llmengine/data_types.py index 1590e602..63aefbbd 100644 --- a/clients/python/llmengine/data_types.py +++ b/clients/python/llmengine/data_types.py @@ -489,7 +489,7 @@ class DeleteFileResponse(BaseModel): """Whether deletion was successful.""" -class DownloadFileResponse(BaseModel): +class GetFileContentResponse(BaseModel): """Response object for retrieving a file's content.""" id: str = Field(..., description="ID of the requested file.") diff --git a/clients/python/llmengine/file.py b/clients/python/llmengine/file.py index 9a950f6b..c3e7ae48 100644 --- a/clients/python/llmengine/file.py +++ b/clients/python/llmengine/file.py @@ -3,7 +3,7 @@ from llmengine.api_engine import DEFAULT_TIMEOUT, APIEngine from llmengine.data_types import ( DeleteFileResponse, - DownloadFileResponse, + GetFileContentResponse, GetFileResponse, ListFilesResponse, UploadFileResponse, @@ -159,7 +159,7 @@ def delete(cls, file_id: str) -> DeleteFileResponse: return DeleteFileResponse.parse_obj(response) @classmethod - def download(cls, file_id: str) -> DownloadFileResponse: + def download(cls, file_id: str) -> GetFileContentResponse: """ Get contents of a file, as a string. (If the uploaded file is in binary, a string encoding will be returned.) @@ -168,7 +168,7 @@ def download(cls, file_id: str) -> DownloadFileResponse: ID of the file Returns: - DownloadFileResponse: an object that contains the ID and content of the file + GetFileContentResponse: an object that contains the ID and content of the file === "Getting file content in Python" ```python @@ -190,4 +190,4 @@ def download(cls, file_id: str) -> DownloadFileResponse: f"v1/files/{file_id}/content", timeout=DEFAULT_TIMEOUT, ) - return DownloadFileResponse.parse_obj(response) + return GetFileContentResponse.parse_obj(response) diff --git a/docs/api/data_types.md b/docs/api/data_types.md index 2a2d4626..2d53a3bf 100644 --- a/docs/api/data_types.md +++ b/docs/api/data_types.md @@ -48,7 +48,7 @@ ::: llmengine.GetFileResponse -::: llmengine.DownloadFileResponse +::: llmengine.GetFileContentResponse ::: llmengine.ListFilesResponse From a2d9dd6eb97542f4a20c6f376edfdc2b3e63729a Mon Sep 17 00:00:00 2001 From: Katie Wu Date: Tue, 1 Aug 2023 15:56:14 -0700 Subject: [PATCH 08/10] typecheck --- clients/python/llmengine/api_engine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/python/llmengine/api_engine.py b/clients/python/llmengine/api_engine.py index ec2306fe..85713160 100644 --- a/clients/python/llmengine/api_engine.py +++ b/clients/python/llmengine/api_engine.py @@ -140,7 +140,7 @@ def post_stream( raise ValueError(f"Invalid JSON payload: {payload_data}") @classmethod - def post_file(cls, resource_name: str, files: BufferedReader, timeout: int) -> Dict[str, Any]: + def post_file(cls, resource_name: str, files: Dict[str, BufferedReader], timeout: int) -> Dict[str, Any]: api_key = get_api_key() response = requests.post( os.path.join(LLM_ENGINE_BASE_PATH, resource_name), From 69c0c4c3d07de6184bec18638f146f49eab04a95 Mon Sep 17 00:00:00 2001 From: Katie Wu Date: Tue, 1 Aug 2023 16:00:15 -0700 Subject: [PATCH 09/10] black reformat --- clients/python/llmengine/api_engine.py | 4 +++- server/llm_engine_server/api/batch_jobs_v1.py | 1 - .../llm_engine_server/domain/use_cases/batch_job_use_cases.py | 1 - .../live_streaming_model_endpoint_inference_gateway.py | 1 - .../test_db_docker_image_batch_job_bundle_repository.py | 1 - 5 files changed, 3 insertions(+), 5 deletions(-) diff --git a/clients/python/llmengine/api_engine.py b/clients/python/llmengine/api_engine.py index 85713160..dce5d09e 100644 --- a/clients/python/llmengine/api_engine.py +++ b/clients/python/llmengine/api_engine.py @@ -140,7 +140,9 @@ def post_stream( raise ValueError(f"Invalid JSON payload: {payload_data}") @classmethod - def post_file(cls, resource_name: str, files: Dict[str, BufferedReader], timeout: int) -> Dict[str, Any]: + def post_file( + cls, resource_name: str, files: Dict[str, BufferedReader], timeout: int + ) -> Dict[str, Any]: api_key = get_api_key() response = requests.post( os.path.join(LLM_ENGINE_BASE_PATH, resource_name), diff --git a/server/llm_engine_server/api/batch_jobs_v1.py b/server/llm_engine_server/api/batch_jobs_v1.py index 86f46ff9..ac83425f 100644 --- a/server/llm_engine_server/api/batch_jobs_v1.py +++ b/server/llm_engine_server/api/batch_jobs_v1.py @@ -125,7 +125,6 @@ async def create_docker_image_batch_job( auth: User = Depends(verify_authentication), external_interfaces: ExternalInterfaces = Depends(get_external_interfaces), ) -> CreateDockerImageBatchJobV1Response: - add_trace_resource_name("batch_jobs_di_create") logger.info(f"POST /docker-image-batch-jobs with {request} for {auth}") try: diff --git a/server/llm_engine_server/domain/use_cases/batch_job_use_cases.py b/server/llm_engine_server/domain/use_cases/batch_job_use_cases.py index e6710313..7b5f7520 100644 --- a/server/llm_engine_server/domain/use_cases/batch_job_use_cases.py +++ b/server/llm_engine_server/domain/use_cases/batch_job_use_cases.py @@ -175,7 +175,6 @@ def __init__( async def execute( self, user: User, request: CreateDockerImageBatchJobV1Request ) -> CreateDockerImageBatchJobV1Response: - if request.docker_image_batch_job_bundle_id is not None: batch_bundle = await self.docker_image_batch_job_bundle_repository.get_docker_image_batch_job_bundle( request.docker_image_batch_job_bundle_id diff --git a/server/llm_engine_server/infra/gateways/live_streaming_model_endpoint_inference_gateway.py b/server/llm_engine_server/infra/gateways/live_streaming_model_endpoint_inference_gateway.py index 0c812e8f..1bbcbc11 100644 --- a/server/llm_engine_server/infra/gateways/live_streaming_model_endpoint_inference_gateway.py +++ b/server/llm_engine_server/infra/gateways/live_streaming_model_endpoint_inference_gateway.py @@ -72,7 +72,6 @@ def __init__(self, use_asyncio: bool): async def make_single_request(self, request_url: str, payload_json: Dict[str, Any]): errored = False if self.use_asyncio: - async with aiohttp.ClientSession(json_serialize=_serialize_json) as aioclient: aio_resp = await aioclient.post( request_url, diff --git a/server/tests/unit/infra/repositories/test_db_docker_image_batch_job_bundle_repository.py b/server/tests/unit/infra/repositories/test_db_docker_image_batch_job_bundle_repository.py index 81d172ad..579d13d0 100644 --- a/server/tests/unit/infra/repositories/test_db_docker_image_batch_job_bundle_repository.py +++ b/server/tests/unit/infra/repositories/test_db_docker_image_batch_job_bundle_repository.py @@ -106,7 +106,6 @@ async def test_list_docker_image_batch_job_bundles( test_api_key: str, test_api_key_team: str, ): - orm_docker_image_batch_job_bundle_1_v2.created_by = test_api_key_team orm_docker_image_batch_job_bundle_1_v2.owner = test_api_key_team docker_image_batch_job_bundle_1_v2.created_by = test_api_key_team From b0c27612902406a07d3bcd96985f933bb344f683 Mon Sep 17 00:00:00 2001 From: Katie Wu Date: Tue, 1 Aug 2023 16:21:54 -0700 Subject: [PATCH 10/10] isort --- clients/python/llmengine/api_engine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/python/llmengine/api_engine.py b/clients/python/llmengine/api_engine.py index dce5d09e..089138b7 100644 --- a/clients/python/llmengine/api_engine.py +++ b/clients/python/llmengine/api_engine.py @@ -1,9 +1,9 @@ # NOTICE - per Apache 2.0 license: # This file was copied and modified from the OpenAI Python client library: https://github.com/openai/openai-python -from io import BufferedReader import json import os from functools import wraps +from io import BufferedReader from typing import Any, AsyncIterable, Dict, Iterator, Optional import requests