Skip to content

Commit

Permalink
Include types to most upstream modules (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
savarin committed Feb 3, 2024
1 parent 95fe774 commit 67f73f5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 12 additions & 10 deletions instructor/cli/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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))
2 changes: 1 addition & 1 deletion instructor/cli/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions instructor/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 67f73f5

Please sign in to comment.