Skip to content

Fix next-pylint issue #39632

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
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
11 changes: 8 additions & 3 deletions sdk/ai/azure-ai-inference/azure/ai/inference/models/_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
"""
import asyncio
import base64
import json
import logging
Expand Down Expand Up @@ -464,6 +463,9 @@ def _read_next_block(self) -> bool:
return True
return self._deserialize_and_add_to_queue(element)

def __enter__(self):
return self

def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: # type: ignore
self.close()

Expand Down Expand Up @@ -503,8 +505,11 @@ async def _read_next_block_async(self) -> bool:
return True
return self._deserialize_and_add_to_queue(element)

def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: # type: ignore
asyncio.run(self.aclose())
async def __aenter__(self):
return self

async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: # type: ignore
await self.aclose()

async def aclose(self) -> None:
await self._response.close()
Expand Down
19 changes: 9 additions & 10 deletions sdk/ai/azure-ai-inference/tests/test_chat_completions_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,16 +389,15 @@ def test_chat_completions_with_bytes_input(self, **kwargs):
@ServicePreparerChatCompletions()
@recorded_by_proxy
def test_chat_completions_streaming(self, **kwargs):
client = self._create_chat_client(**kwargs)
response = client.complete(
stream=True,
messages=[
sdk.models.SystemMessage("You are a helpful assistant."),
sdk.models.UserMessage("Give me 3 good reasons why I should exercise every day."),
],
)
self._validate_chat_completions_streaming_result(response)
client.close()
with self._create_chat_client(**kwargs) as client:
with client.complete(
stream=True,
messages=[
sdk.models.SystemMessage("You are a helpful assistant."),
sdk.models.UserMessage("Give me 3 good reasons why I should exercise every day."),
],
) as response:
self._validate_chat_completions_streaming_result(response)

@ServicePreparerChatCompletions()
@recorded_by_proxy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,16 +371,15 @@ async def test_async_chat_completions_with_model_extras(self, **kwargs):
@ServicePreparerChatCompletions()
@recorded_by_proxy_async
async def test_async_chat_completions_streaming(self, **kwargs):
client = self._create_async_chat_client(Sync=False, **kwargs)
response = await client.complete(
stream=True,
messages=[
sdk.models.SystemMessage(content="You are a helpful assistant."),
sdk.models.UserMessage(content="Give me 3 good reasons why I should exercise every day."),
],
)
await self._validate_async_chat_completions_streaming_result(response)
await client.close()
async with self._create_async_chat_client(Sync=False, **kwargs) as client:
async with await client.complete(
stream=True,
messages=[
sdk.models.SystemMessage(content="You are a helpful assistant."),
sdk.models.UserMessage(content="Give me 3 good reasons why I should exercise every day."),
],
) as response:
await self._validate_async_chat_completions_streaming_result(response)

@ServicePreparerChatCompletions()
@recorded_by_proxy_async
Expand Down