Skip to content

few fixes after the refactor #9

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

Merged
merged 1 commit into from
Oct 5, 2023
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
12 changes: 6 additions & 6 deletions src/openai/azure/_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,19 +418,19 @@ async def _poll(
async def _request(self, cast_to: Type[ResponseT], options: FinalRequestOptions, **kwargs: Any) -> Any:
if options.url == "/images/generations":
options.url = "openai/images/generations:submit"
response = await super().request(httpx.Response, **kwargs)
operation_id = cast(Mapping[str, Any], getattr(response, 'model_extra')) or {}
response = await super()._request(cast_to=cast_to, options=options, **kwargs)
model_extra = cast(Mapping[str, Any], getattr(response, 'model_extra')) or {}
operation_id = cast(str, model_extra['id'])
return await self._poll(
"get", f"openai/operations/images/{operation_id}",
until=lambda response: response.json()["status"] in ["succeeded"],
failed=lambda response: response.json()["status"] in ["failed"],
)
if isinstance(options.json_data, Mapping):
model = cast(str, options.json_data["model"])
model = cast(str, options.json_data["model"])
if not options.url.startswith(f'openai/deployments/{model}'):
if options.extra_json and options.extra_json.get("dataSources"):
options.url = f'openai/deployments/{model}/extensions' + options.url
else:
else:
options.url = f'openai/deployments/{model}' + options.url
return await super().request(cast_to=cast_to, options=options, **kwargs)

return await super()._request(cast_to=cast_to, options=options, **kwargs)
8 changes: 4 additions & 4 deletions src/openai/azure/_sync_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def auth_headers(self) -> Dict[str, str]:
def _request(self, *, options: FinalRequestOptions, **kwargs: Any) -> Any:
if options.url == "/images/generations":
options.url = "openai/images/generations:submit"
response = super().request(httpx.Response, **kwargs)
response = super()._request(options=options, **kwargs)
model_extra = cast(Mapping[str, Any], getattr(response, 'model_extra')) or {}
operation_id = cast(str, model_extra['id'])
return self._poll(
Expand All @@ -393,13 +393,13 @@ def _request(self, *, options: FinalRequestOptions, **kwargs: Any) -> Any:
failed=lambda response: response.json()["status"] in ["failed"],
)
if isinstance(options.json_data, Mapping):
model = cast(str, options.json_data["model"])
model = cast(str, options.json_data["model"])
if not options.url.startswith(f'openai/deployments/{model}'):
if options.extra_json and options.extra_json.get("dataSources"):
options.url = f'openai/deployments/{model}/extensions' + options.url
else:
else:
options.url = f'openai/deployments/{model}' + options.url
return super().request(options=options, **kwargs)
return super()._request(options=options, **kwargs)

# Internal azure specific "helper" methods
def _check_polling_response(self, response: httpx.Response, predicate: Callable[[httpx.Response], bool]) -> bool:
Expand Down