Skip to content

Commit 6929478

Browse files
authored
Fix: resolve pyright issues with PDF (#1465)
1 parent ba4c225 commit 6929478

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

instructor/multimodal.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,8 @@ def to_anthropic(self) -> dict[str, Any]:
525525
}
526526
else:
527527
if not self.data:
528-
self.data = requests.get(str(self.source)).content
529-
self.data = base64.b64encode(self.data).decode("utf-8")
528+
self.data = requests.get(str(self.source)).content # type: ignore
529+
self.data = base64.b64encode(self.data).decode("utf-8") # type: ignore
530530

531531
return {
532532
"type": "document",
@@ -586,7 +586,7 @@ def from_new_genai_file(
586586
file = client.files.upload(file=file_path)
587587
while file.state != FileState.ACTIVE:
588588
time.sleep(retry_delay)
589-
file = client.files.get(name=file.name)
589+
file = client.files.get(name=file.name) # type: ignore
590590
if max_retries > 0:
591591
max_retries -= 1
592592
else:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dependencies = [
1616
"requests<3.0.0,>=2.32.3",
1717
]
1818
name = "instructor"
19-
version = "1.7.8"
19+
version = "1.7.9"
2020
description = "structured outputs for llm"
2121
readme = "README.md"
2222

tests/llm/test_genai/test_multimodal.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ImageDescription(BaseModel):
1717

1818
pdf_path = os.path.join(curr_file, "../../assets/invoice.pdf")
1919

20-
20+
pdf_url = "https://raw.githubusercontent.com/instructor-ai/instructor/main/tests/assets/invoice.pdf"
2121
pdf_base64 = base64.b64encode(open(pdf_path, "rb").read()).decode("utf-8")
2222
pdf_base64_string = f"data:application/pdf;base64,{pdf_base64}"
2323

@@ -222,7 +222,7 @@ async def test_autodetect_images_async(client, model, mode, autodetect_images):
222222
messages=[
223223
{
224224
"role": "system",
225-
"content": "Return true if you are provided with an image that you can describe visually in your prompt. This does not include image paths or urls that might point to URLs. ",
225+
"content": "Do you see any blueberries in the context that you've been provided?. ",
226226
},
227227
{
228228
"role": "user",
@@ -243,7 +243,7 @@ class Invoice(BaseModel):
243243

244244
@pytest.mark.parametrize("model", models)
245245
@pytest.mark.parametrize("mode", modes)
246-
@pytest.mark.parametrize("pdf_source", [pdf_path, pdf_base64_string])
246+
@pytest.mark.parametrize("pdf_source", [pdf_path, pdf_base64_string, pdf_url])
247247
def test_local_pdf(client, model, mode, pdf_source):
248248
client = instructor.from_genai(client, mode=mode)
249249
response = client.chat.completions.create(
@@ -315,7 +315,7 @@ def test_upload_file_genai_pdf_integration(client, model, mode):
315315

316316
@pytest.mark.parametrize("model", models)
317317
@pytest.mark.parametrize("mode", modes)
318-
@pytest.mark.parametrize("pdf_source", [pdf_path, pdf_base64_string])
318+
@pytest.mark.parametrize("pdf_source", [pdf_path, pdf_base64_string, pdf_url])
319319
def test_local_pdf_with_genai_file(client, model, mode, pdf_source):
320320
client = instructor.from_genai(client, mode=mode)
321321
response = client.chat.completions.create(

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)