Skip to content

Commit

Permalink
Add CI
Browse files Browse the repository at this point in the history
  • Loading branch information
max-muoto committed Apr 29, 2024
1 parent 6e47c51 commit 55ac2b9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 75 deletions.
62 changes: 0 additions & 62 deletions .github/workflows/mypy.yml

This file was deleted.

47 changes: 47 additions & 0 deletions .github/workflows/pyright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Pyright

on:
push:
pull_request:
branches: [ main ]

env:
WORKING_DIRECTORY: "."
PYRIGHT_OUTPUT_FILENAME: "pyright.log"

jobs:
Pyright:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Cache Poetry virtualenv
uses: actions/cache@v2
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-
- name: Install Poetry
uses: snok/install-poetry@v1.3.1

- name: Run Static Type Checking with Pyright
run: |
set -e -o pipefail
poetry run pyright > ${{ env.WORKING_DIRECTORY }}/${{ env.PYRIGHT_OUTPUT_FILENAME }}
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: pyright-log
path: ${{ env.WORKING_DIRECTORY }}/${{ env.PYRIGHT_OUTPUT_FILENAME }}
18 changes: 6 additions & 12 deletions instructor/cli/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,7 @@ async def get_usage_for_past_n_days(n_days: int) -> list[dict[str, Any]]:


# Define the cost per unit for each model
# Add temporary body type hint here because mypy may infer the dict type
# from the first few items (?) in the dict, which may not be representative of
# the entire dict.
MODEL_COSTS: dict[
ModelNames,
Union[dict[str, float], float],
] = {
MODEL_COSTS = {
"gpt-4-0125-preview": {"prompt": 0.01 / 1000, "completion": 0.03 / 1000},
"gpt-4-turbo-preview": {"prompt": 0.01 / 1000, "completion": 0.03 / 1000},
"gpt-4-1106-preview": {"prompt": 0.01 / 1000, "completion": 0.03 / 1000},
Expand Down Expand Up @@ -114,11 +108,11 @@ def calculate_cost(

def group_and_sum_by_date_and_snapshot(usage_data: list[dict[str, Any]]) -> Table:
"""Group and sum the usage data by date and snapshot, including costs."""
summary: defaultdict[
str, defaultdict[str, dict[str, Union[int, float]]]
] = defaultdict(
lambda: defaultdict(
lambda: {"total_requests": 0, "total_tokens": 0, "total_cost": 0.0}
summary: defaultdict[str, defaultdict[str, dict[str, Union[int, float]]]] = (
defaultdict(
lambda: defaultdict(
lambda: {"total_requests": 0, "total_tokens": 0, "total_cost": 0.0}
)
)
)

Expand Down
2 changes: 1 addition & 1 deletion instructor/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ async def create_with_completion(
strict=strict,
**kwargs,
)
return response, response._raw_response # type: ignore
return response, response._raw_response


@overload
Expand Down

0 comments on commit 55ac2b9

Please sign in to comment.