Skip to content

Commit d6561c7

Browse files
jxnlclaude
andauthored
Fix/ci uv migration (#1886)
Co-authored-by: Claude <[email protected]>
1 parent 0c2aff2 commit d6561c7

File tree

21 files changed

+76
-69
lines changed

21 files changed

+76
-69
lines changed

.github/workflows/evals.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,18 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v2
1818

19-
- name: Set up Python 3.11
20-
uses: actions/setup-python@v4
19+
- name: Install uv
20+
uses: astral-sh/setup-uv@v4
2121
with:
22-
python-version: 3.11
23-
cache: "poetry"
22+
enable-cache: true
2423

25-
- name: Install Poetry
26-
uses: snok/install[email protected]
24+
- name: Set up Python
25+
run: uv python install 3.11
2726

2827
- name: Install dependencies
29-
run: poetry install --with dev,anthropic
28+
run: uv sync --all-extras --dev
3029

3130
- name: Run all tests
32-
run: poetry run pytest tests/
31+
run: uv run pytest tests/
3332
env:
3433
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

.github/workflows/pyright.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ jobs:
2424
- name: Install the project
2525
run: uv sync --all-extras
2626
- name: Run type check with ty
27-
run: uv run ty check
27+
run: uv run ty check instructor/

.github/workflows/scheduled-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333

3434
- name: Install dependencies
3535
run: |
36-
uv sync --dev
36+
uv sync --all-extras --dev
3737
3838
- name: Run linting
3939
run: |

instructor/batch/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"""
77

88
from __future__ import annotations
9-
from typing import Any, Union, TypeVar, Generic, TypeAlias
9+
from typing import Any, Union, TypeVar, Generic
10+
from typing_extensions import TypeAlias
1011
from pydantic import BaseModel, Field, ConfigDict
1112
from datetime import datetime, timezone
1213
from enum import Enum

instructor/dsl/iterable.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ async def from_streaming_response_async(
5454
json_chunks = extract_json_from_stream_async(json_chunks)
5555

5656
if mode in {Mode.MISTRAL_TOOLS, Mode.VERTEXAI_TOOLS}:
57-
return cls.tasks_from_mistral_chunks(json_chunks, **kwargs)
58-
59-
return cls.tasks_from_chunks_async(json_chunks, **kwargs)
57+
async for item in cls.tasks_from_mistral_chunks(json_chunks, **kwargs):
58+
yield item
59+
else:
60+
async for item in cls.tasks_from_chunks_async(json_chunks, **kwargs):
61+
yield item
6062

6163
@classmethod
6264
async def tasks_from_mistral_chunks(

instructor/dsl/partial.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,13 @@ async def from_streaming_response_async(
177177

178178
if mode == Mode.MD_JSON:
179179
json_chunks = extract_json_from_stream_async(json_chunks)
180-
elif mode == Mode.WRITER_TOOLS:
181-
return cls.writer_model_from_chunks_async(json_chunks, **kwargs)
182180

183-
return cls.model_from_chunks_async(json_chunks, **kwargs)
181+
if mode == Mode.WRITER_TOOLS:
182+
async for item in cls.writer_model_from_chunks_async(json_chunks, **kwargs):
183+
yield item
184+
else:
185+
async for item in cls.model_from_chunks_async(json_chunks, **kwargs):
186+
yield item
184187

185188
@classmethod
186189
def writer_model_from_chunks(

instructor/processing/multimodal.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,14 @@ def from_raw_base64(cls, data: str) -> Image:
155155
# Detect image type from file signature (magic bytes)
156156
# This replaces imghdr which was removed in Python 3.13
157157
img_type = None
158-
if decoded.startswith(b'\xff\xd8\xff'):
159-
img_type = 'jpeg'
160-
elif decoded.startswith(b'\x89PNG\r\n\x1a\n'):
161-
img_type = 'png'
162-
elif decoded.startswith(b'GIF87a') or decoded.startswith(b'GIF89a'):
163-
img_type = 'gif'
164-
elif decoded.startswith(b'RIFF') and decoded[8:12] == b'WEBP':
165-
img_type = 'webp'
158+
if decoded.startswith(b"\xff\xd8\xff"):
159+
img_type = "jpeg"
160+
elif decoded.startswith(b"\x89PNG\r\n\x1a\n"):
161+
img_type = "png"
162+
elif decoded.startswith(b"GIF87a") or decoded.startswith(b"GIF89a"):
163+
img_type = "gif"
164+
elif decoded.startswith(b"RIFF") and decoded[8:12] == b"WEBP":
165+
img_type = "webp"
166166

167167
if img_type:
168168
media_type = f"image/{img_type}"

instructor/processing/response.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class User(BaseModel):
3737

3838
import inspect
3939
import logging
40-
from typing import Any, TypeVar, TYPE_CHECKING
40+
from typing import Any, TypeVar, TYPE_CHECKING, cast
41+
from collections.abc import AsyncGenerator
4142

4243
from openai.types.chat import ChatCompletion
4344
from pydantic import BaseModel
@@ -229,15 +230,12 @@ async def process_response_async(
229230
and stream
230231
):
231232
# from_streaming_response_async returns an AsyncGenerator
232-
# Collect all yielded values into a list
233+
# Yield each item as it comes in
233234
# Note: response type varies by mode (ChatCompletion, AsyncGenerator, etc.)
234-
tasks = []
235-
async for task in response_model.from_streaming_response_async( # type: ignore[arg-type]
235+
return response_model.from_streaming_response_async( # type: ignore[return-value]
236236
cast(AsyncGenerator[Any, None], response), # type: ignore[arg-type]
237237
mode=mode,
238-
):
239-
tasks.append(task)
240-
return tasks # type: ignore
238+
)
241239

242240
model = response_model.from_response( # type: ignore
243241
response,

instructor/providers/anthropic/utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
from textwrap import dedent
1010
from typing import Any, TypedDict, Union
1111

12-
from pydantic import ValidationError
13-
from ...core.exceptions import ValidationError as InstructorValidationError
1412

1513
from ...mode import Mode
1614
from ...processing.schema import generate_anthropic_schema

instructor/providers/bedrock/client.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from typing import Any, Literal, overload
44
import warnings
55

6-
import boto3
76
from botocore.client import BaseClient
87

98
import instructor
@@ -12,7 +11,7 @@
1211

1312
@overload # type: ignore
1413
def from_bedrock(
15-
client: boto3.client,
14+
client: BaseClient,
1615
mode: instructor.Mode = instructor.Mode.BEDROCK_TOOLS,
1716
async_client: Literal[False] = False,
1817
**kwargs: Any,
@@ -21,7 +20,7 @@ def from_bedrock(
2120

2221
@overload # type: ignore
2322
def from_bedrock(
24-
client: boto3.client,
23+
client: BaseClient,
2524
mode: instructor.Mode = instructor.Mode.BEDROCK_TOOLS,
2625
async_client: Literal[True] = True,
2726
**kwargs: Any,

0 commit comments

Comments
 (0)