Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobiichi-Origami committed Jan 11, 2024
1 parent a6573dd commit 007f51b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/qianfan/resources/console/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def inner(*args: Any, **kwargs: Any) -> QfResponse:
),
)
req = func(*args, **kwargs)
return ConsoleAPIRequestor(**kwargs)._request_console_api(req, ak, sk, retry_config)
return ConsoleAPIRequestor(**kwargs)._request_console_api(
req, ak, sk, retry_config
)

return inner

Expand Down
21 changes: 15 additions & 6 deletions src/qianfan/resources/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import AsyncIterator, Iterator, Tuple
from typing import Any, AsyncIterator, Iterator, Tuple

import aiohttp
import requests
Expand All @@ -25,7 +25,7 @@ class HTTPClient(object):
object used to make http request
"""

def __init__(self, ssl: bool = True, **kwargs) -> None:
def __init__(self, ssl: bool = True, **kwargs: Any) -> None:
"""
init sync and async request session
Expand All @@ -44,7 +44,9 @@ def request(self, req: QfRequest) -> requests.Response:
sync request
"""
resp = self._session.request(
**req.requests_args(), timeout=req.retry_config.timeout, verify=self.ssl,
**req.requests_args(),
timeout=req.retry_config.timeout,
verify=self.ssl,
)
return resp

Expand All @@ -55,7 +57,10 @@ def request_stream(
sync stream request
"""
resp = self._session.request(
**req.requests_args(), stream=True, timeout=req.retry_config.timeout, verify=self.ssl
**req.requests_args(),
stream=True,
timeout=req.retry_config.timeout,
verify=self.ssl,
)
for line in resp.iter_lines():
yield line, resp
Expand All @@ -68,7 +73,9 @@ async def arequest(
"""
session = aiohttp.ClientSession()
timeout = aiohttp.ClientTimeout(total=req.retry_config.timeout)
response = await session.request(**req.requests_args(), timeout=timeout, ssl=self.ssl)
response = await session.request(
**req.requests_args(), timeout=timeout, ssl=self.ssl
)
return response, session

async def arequest_stream(
Expand All @@ -79,6 +86,8 @@ async def arequest_stream(
"""
async with aiohttp.ClientSession() as session:
timeout = aiohttp.ClientTimeout(total=req.retry_config.timeout)
async with session.request(**req.requests_args(), timeout=timeout, ssl=self.ssl) as resp:
async with session.request(
**req.requests_args(), timeout=timeout, ssl=self.ssl
) as resp:
async for line in resp.content:
yield line, resp
2 changes: 1 addition & 1 deletion src/qianfan/tests/chat_completion_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,4 +646,4 @@ def test_auth_using_iam():

def test_keyword_arguments_passing():
cc = qianfan.ChatCompletion(ssl=False)
assert not cc._client._client.ssl
assert not cc._client._client.ssl

0 comments on commit 007f51b

Please sign in to comment.