From 67f73f5013f7a37e17df7df9a7d0db0e255d9d50 Mon Sep 17 00:00:00 2001 From: Ezzeri Esa Date: Sat, 3 Feb 2024 11:52:45 -0800 Subject: [PATCH] Include types to most upstream modules (#391) --- .github/workflows/mypy.yml | 7 ++++++- instructor/cli/files.py | 22 ++++++++++++---------- instructor/cli/usage.py | 2 +- instructor/exceptions.py | 5 +++-- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index 3e76d25..48fe24d 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -9,7 +9,12 @@ env: WORKING_DIRECTORY: "." MYPY_OUTPUT_FILENAME: "mypy.log" CUSTOM_FLAGS: "--python-version=3.9 --color-output --no-pretty --follow-imports=skip" - CUSTOM_PACKAGES: "instructor/cli/cli.py instructor/cli/usage.py" + CUSTOM_PACKAGES: | + instructor/_types/_alias.py + instructor/cli/cli.py + instructor/cli/files.py + instructor/cli/usage.py + instructor/exceptions.py jobs: MyPy: diff --git a/instructor/cli/files.py b/instructor/cli/files.py index df91acf..4e8f254 100644 --- a/instructor/cli/files.py +++ b/instructor/cli/files.py @@ -51,12 +51,12 @@ def get_file_status(file_id: str) -> str: @app.command( help="Upload a file to OpenAI's servers, will monitor the upload status until it is processed", -) +) # type: ignore[misc] def upload( filepath: str = typer.Argument(..., help="Path to the file to upload"), purpose: str = typer.Option("fine-tune", help="Purpose of the file"), poll: int = typer.Option(5, help="Polling interval in seconds"), -): +) -> None: with open(filepath, "rb") as file: response = client.files.create(file=file, purpose=purpose) file_id = response["id"] @@ -72,11 +72,11 @@ def upload( @app.command( help="Download a file from OpenAI's servers", -) +) # type: ignore[misc] def download( file_id: str = typer.Argument(..., help="ID of the file to download"), output: str = typer.Argument(..., help="Output path for the downloaded file"), -): +) -> None: with console.status(f"[bold green]Downloading file {file_id}...", spinner="dots"): content = client.files.download(file_id) with open(output, "wb") as file: @@ -86,8 +86,8 @@ def download( @app.command( help="Delete a file from OpenAI's servers", -) -def delete(file_id: str = typer.Argument(..., help="ID of the file to delete")): +) # type: ignore[misc] +def delete(file_id: str = typer.Argument(..., help="ID of the file to delete")) -> None: with console.status(f"[bold red]Deleting file {file_id}...", spinner="dots"): try: client.files.delete(file_id) @@ -99,10 +99,10 @@ def delete(file_id: str = typer.Argument(..., help="ID of the file to delete")): @app.command( help="Monitor the status of a file on OpenAI's servers", -) +) # type: ignore[misc] def status( file_id: str = typer.Argument(..., help="ID of the file to check the status of"), -): +) -> None: with console.status(f"Monitoring status of file {file_id}...") as status: while True: file_status = get_file_status(file_id) @@ -114,7 +114,9 @@ def status( @app.command( help="List the files on OpenAI's servers", -) -def list(limit: int = typer.Option(5, help="Limit the number of files to list")): +) # type: ignore[misc] +def list( + limit: int = typer.Option(5, help="Limit the number of files to list"), +) -> None: files = get_files(limit=limit) console.log(generate_file_table(files)) diff --git a/instructor/cli/usage.py b/instructor/cli/usage.py index 6d58b48..3e1dc74 100644 --- a/instructor/cli/usage.py +++ b/instructor/cli/usage.py @@ -146,7 +146,7 @@ def group_and_sum_by_date_and_snapshot(usage_data: List[Dict[str, Any]]) -> Tabl return table -@app.command(help="Displays OpenAI API usage data for the past N days.") # type: ignore +@app.command(help="Displays OpenAI API usage data for the past N days.") # type: ignore[misc] def list( n: int = typer.Option(0, help="Number of days."), ) -> None: diff --git a/instructor/exceptions.py b/instructor/exceptions.py index 815a265..9ff9396 100644 --- a/instructor/exceptions.py +++ b/instructor/exceptions.py @@ -2,7 +2,8 @@ class IncompleteOutputException(Exception): """Exception raised when the output from LLM is incomplete due to max tokens limit reached.""" def __init__( - self, message="The output is incomplete due to a max_tokens length limit." - ): + self, + message: str = "The output is incomplete due to a max_tokens length limit.", + ) -> None: self.message = message super().__init__(self.message)