Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
46 changes: 29 additions & 17 deletions src/vws/async_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

import json
from http import HTTPMethod, HTTPStatus
from typing import Any, Self
from typing import Self

from beartype import BeartypeConf, beartype
from urllib3.fields import RequestField
from urllib3.filepost import encode_multipart_formdata
from vws_auth_tools import authorization_header, rfc_1123_date

Expand Down Expand Up @@ -131,23 +132,34 @@ async def query(
targets.
"""
image_content = _get_image_data(image=image)
body: dict[str, Any] = { # pyrefly: ignore [explicit-any]
"image": (
"image.jpeg",
image_content,
"image/jpeg",
),
"max_num_results": (
None,
max_num_results,
"text/plain",
),
"include_target_data": (
None,
include_target_data.value,
"text/plain",
max_num_results_field = RequestField(
name="max_num_results",
data=str(object=max_num_results),
)
max_num_results_field.make_multipart(
content_disposition="form-data",
content_type="text/plain",
)
include_target_data_field = RequestField(
name="include_target_data",
data=include_target_data.value,
)
include_target_data_field.make_multipart(
content_disposition="form-data",
content_type="text/plain",
)
body = [
RequestField.from_tuples(
fieldname="image",
value=(
"image.jpeg",
image_content,
"image/jpeg",
),
),
}
max_num_results_field,
include_target_data_field,
]
date = rfc_1123_date()
request_path = "/v1/query"
content, content_type_header = encode_multipart_formdata(fields=body)
Expand Down
33 changes: 24 additions & 9 deletions src/vws/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import json
from http import HTTPMethod, HTTPStatus
from typing import Any

from beartype import BeartypeConf, beartype
from urllib3.fields import RequestField
from urllib3.filepost import encode_multipart_formdata
from vws_auth_tools import authorization_header, rfc_1123_date

Expand Down Expand Up @@ -112,15 +112,30 @@ def query(
An ordered list of target details of matching targets.
"""
image_content = _get_image_data(image=image)
body: dict[str, Any] = { # pyrefly: ignore [explicit-any]
"image": ("image.jpeg", image_content, "image/jpeg"),
"max_num_results": (None, max_num_results, "text/plain"),
"include_target_data": (
None,
include_target_data.value,
"text/plain",
max_num_results_field = RequestField(
name="max_num_results",
data=str(object=max_num_results),
)
max_num_results_field.make_multipart(
content_disposition="form-data",
content_type="text/plain",
)
include_target_data_field = RequestField(
name="include_target_data",
data=include_target_data.value,
)
include_target_data_field.make_multipart(
content_disposition="form-data",
content_type="text/plain",
)
body = [
RequestField.from_tuples(
fieldname="image",
value=("image.jpeg", image_content, "image/jpeg"),
),
}
max_num_results_field,
include_target_data_field,
]
date = rfc_1123_date()
request_path = "/v1/query"
content, content_type_header = encode_multipart_formdata(fields=body)
Expand Down