Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to UV #1280

Merged
merged 23 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 6 additions & 21 deletions .github/workflows/pyright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,9 @@ jobs:
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: Install dependencies
run: poetry install --with dev,anthropic

- name: Add poetry to PATH
run: echo "$(poetry env info --path)/bin" >> $GITHUB_PATH

- uses: jakebailey/pyright-action@v2
with:
version: 1.1.373
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Install the project
run: uv sync --all-extras
- name: Run pyright
run: uv run pyright
12 changes: 6 additions & 6 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ jobs:
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: "3.10"

- name: Install Poetry
uses: snok/install-poetry@v1.3.1
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Install the project
run: uv sync --all-extras

- name: Get release version
run: echo "RELEASE_VERSION=$(poetry version | awk '{print $2}')" >> $GITHUB_ENV

- name: Build and publish Python package
run: poetry publish --build
run: uv publish
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
9 changes: 4 additions & 5 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ jobs:
with:
python-version: 3.9
cache: "pip"
- name: Install dev dependencies
run: |
python3 -m pip install --upgrade pip setuptools wheel
python3 -m pip install -r requirements.txt
python3 -m pip install -r requirements-doc.txt
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Install the project
run: uv sync --all-extras
- name: Run Continuous Integration Action
uses: astral-sh/ruff-action@v1
- name: Upload Artifacts
Expand Down
29 changes: 9 additions & 20 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,29 @@ jobs:
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: Install dependencies
run: poetry install --with dev,anthropic

- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Install the project
run: uv sync --all-extras
- name: Run tests
if: matrix.python-version != '3.11'
run: poetry run pytest tests/ -k 'not llm and not openai and not gemini and not anthropic and not cohere and not vertexai' && poetry run pytest tests/llm/test_cohere
run: uv run pytest tests/ -k 'not llm and not openai and not gemini and not anthropic and not cohere and not vertexai'
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}

- name: Run Gemini Tests
run: poetry run pytest tests/llm/test_gemini
run: uv run pytest tests/llm/test_gemini
env:
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}

- name: Generate coverage report
if: matrix.python-version == '3.11'
run: |
poetry run coverage run -m pytest tests/ -k "not docs and not anthropic and not gemini and not cohere and not vertexai and not fireworks"
poetry run coverage report
poetry run coverage html
uv run coverage run -m pytest tests/ -k "not docs and not anthropic and not gemini and not cohere and not vertexai and not fireworks"
uv run coverage report
uv run coverage html
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
16 changes: 4 additions & 12 deletions .github/workflows/test_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,10 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
cache: "poetry"

- 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 dependencies
run: poetry install --with dev,docs,test-docs,anthropic,google-generativeai

- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Install the project
run: uv sync --all-extras
- name: Run tests
run: poetry run pytest tests/llm/test_openai/docs
env:
Expand Down
8 changes: 4 additions & 4 deletions instructor/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def __init__(
self.provider = provider
self.hooks = hooks or Hooks()

async def create(
async def create( # type: ignore[override]
self,
response_model: type[T] | None,
messages: list[ChatCompletionMessageParam],
Expand All @@ -395,7 +395,7 @@ async def create(
**kwargs,
)

async def create_partial(
async def create_partial( # type: ignore[override]
self,
response_model: type[T],
messages: list[ChatCompletionMessageParam],
Expand All @@ -419,7 +419,7 @@ async def create_partial(
):
yield item

async def create_iterable(
async def create_iterable( # type: ignore[override]
self,
messages: list[ChatCompletionMessageParam],
response_model: type[T],
Expand All @@ -443,7 +443,7 @@ async def create_iterable(
):
yield item

async def create_with_completion(
async def create_with_completion( # type: ignore[override]
self,
messages: list[ChatCompletionMessageParam],
response_model: type[T],
Expand Down
11 changes: 6 additions & 5 deletions instructor/client_mistral.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@
def from_mistral(
client: Mistral,
mode: instructor.Mode = instructor.Mode.MISTRAL_TOOLS,
use_async: Literal[False] = False,
use_async: Literal[True] = True,
**kwargs: Any,
) -> instructor.Instructor: ...
) -> instructor.AsyncInstructor: ...


@overload
def from_mistral(
client: Mistral,
mode: instructor.Mode = instructor.Mode.MISTRAL_TOOLS,
use_async: Literal[True] = True,
use_async: Literal[False] = False,
**kwargs: Any,
) -> instructor.AsyncInstructor: ...

) -> instructor.Instructor: ...

def from_mistral(
client: Mistral,
Expand All @@ -35,6 +34,8 @@ def from_mistral(
instructor.Mode.MISTRAL_TOOLS,
}, "Mode be one of {instructor.Mode.MISTRAL_TOOLS}"



assert isinstance(
client, Mistral
), "Client must be an instance of mistralai.Mistral"
Expand Down
2 changes: 1 addition & 1 deletion instructor/distil.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def _distil(*args: P.args, **kwargs: P.kwargs) -> T_Retval:
return _dispatch if mode == "dispatch" else _distil

if len(args) == 1 and callable(args[0]):
return _wrap_distil(args[0])
return _wrap_distil(args[0]) # type: ignore

return _wrap_distil

Expand Down
Loading
Loading