Skip to content
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

fix: rename requests.py into requests_utils.py #5099

Merged
merged 6 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
AnthropicTokenStreamingHandler,
DefaultTokenStreamingHandler,
)
from haystack.utils.requests import request_with_retry
from haystack.utils.requests_utils import request_with_retry
ZanSara marked this conversation as resolved.
Show resolved Hide resolved
from haystack.environment import HAYSTACK_REMOTE_API_MAX_RETRIES, HAYSTACK_REMOTE_API_TIMEOUT_SEC

ANTHROPIC_TIMEOUT = float(os.environ.get(HAYSTACK_REMOTE_API_TIMEOUT_SEC, 30))
Expand Down
2 changes: 1 addition & 1 deletion haystack/nodes/prompt/invocation_layer/cohere.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
DefaultTokenStreamingHandler,
)
from haystack.nodes.prompt.invocation_layer.handlers import DefaultPromptHandler
from haystack.utils.requests import request_with_retry
from haystack.utils.requests_utils import request_with_retry

logger = logging.getLogger(__name__)
TIMEOUT = float(os.environ.get(HAYSTACK_REMOTE_API_TIMEOUT_SEC, 30))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
DefaultTokenStreamingHandler,
)
from haystack.nodes.prompt.invocation_layer.handlers import DefaultPromptHandler
from haystack.utils.requests import request_with_retry
from haystack.utils.requests_utils import request_with_retry

logger = logging.getLogger(__name__)
HF_TIMEOUT = float(os.environ.get(HAYSTACK_REMOTE_API_TIMEOUT_SEC, 30))
Expand Down
2 changes: 1 addition & 1 deletion haystack/preview/components/audio/whisper_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pathlib import Path
from dataclasses import dataclass

from haystack.utils.requests import request_with_retry
from haystack.utils.requests_utils import request_with_retry
from haystack.preview import component, ComponentInput, ComponentOutput, Document

logger = logging.getLogger(__name__)
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions test/preview/components/audio/test_whisper_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_run_with_path(self, preview_samples_path):
mock_response.content = '{"text": "test transcription", "other_metadata": ["other", "meta", "data"]}'
comp = RemoteWhisperTranscriber(api_key="whatever")

with patch("haystack.utils.requests.requests") as mocked_requests:
with patch("haystack.utils.requests_utils.requests") as mocked_requests:
mocked_requests.request.return_value = mock_response

result = comp.run(
Expand All @@ -67,7 +67,7 @@ def test_run_with_str(self, preview_samples_path):
mock_response.content = '{"text": "test transcription", "other_metadata": ["other", "meta", "data"]}'
comp = RemoteWhisperTranscriber(api_key="whatever")

with patch("haystack.utils.requests.requests") as mocked_requests:
with patch("haystack.utils.requests_utils.requests") as mocked_requests:
mocked_requests.request.return_value = mock_response

result = comp.run(
Expand Down Expand Up @@ -95,7 +95,7 @@ def test_transcribe_with_stream(self, preview_samples_path):
mock_response.content = '{"text": "test transcription", "other_metadata": ["other", "meta", "data"]}'
comp = RemoteWhisperTranscriber(api_key="whatever")

with patch("haystack.utils.requests.requests") as mocked_requests:
with patch("haystack.utils.requests_utils.requests") as mocked_requests:
mocked_requests.request.return_value = mock_response

with open(preview_samples_path / "audio" / "this is the content of the document.wav", "rb") as audio_stream:
Expand All @@ -113,7 +113,7 @@ def test_api_transcription(self, preview_samples_path):
mock_response.content = '{"text": "test transcription", "other_metadata": ["other", "meta", "data"]}'
comp = RemoteWhisperTranscriber(api_key="whatever")

with patch("haystack.utils.requests.requests") as mocked_requests:
with patch("haystack.utils.requests_utils.requests") as mocked_requests:
mocked_requests.request.return_value = mock_response

comp.run(
Expand All @@ -138,7 +138,7 @@ def test_api_translation(self, preview_samples_path):
mock_response.content = '{"text": "test transcription", "other_metadata": ["other", "meta", "data"]}'
comp = RemoteWhisperTranscriber(api_key="whatever")

with patch("haystack.utils.requests.requests") as mocked_requests:
with patch("haystack.utils.requests_utils.requests") as mocked_requests:
mocked_requests.request.return_value = mock_response

comp.run(
Expand Down
12 changes: 6 additions & 6 deletions test/utils/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import pytest
import requests

from haystack.utils.requests import request_with_retry
from haystack.utils.requests_utils import request_with_retry
ZanSara marked this conversation as resolved.
Show resolved Hide resolved


@pytest.mark.unit
@patch("haystack.utils.requests.requests.request")
@patch("haystack.utils.requests_utils.requests.request")
def test_request_with_retry_defaults_successfully(mock_request):
# Make requests with default retry configuration
request_with_retry(method="GET", url="https://example.com")
Expand All @@ -17,7 +17,7 @@ def test_request_with_retry_defaults_successfully(mock_request):


@pytest.mark.unit
@patch("haystack.utils.requests.requests.request")
@patch("haystack.utils.requests_utils.requests.request")
def test_request_with_retry_custom_timeout(mock_request):
# Make requests with default retry configuration
request_with_retry(method="GET", url="https://example.com", timeout=5)
Expand All @@ -27,7 +27,7 @@ def test_request_with_retry_custom_timeout(mock_request):


@pytest.mark.unit
@patch("haystack.utils.requests.requests.request")
@patch("haystack.utils.requests_utils.requests.request")
def test_request_with_retry_failing_request_and_expected_status_code(mock_request):
# Create fake failed response with status code that triggers retry
fake_response = requests.Response()
Expand All @@ -43,7 +43,7 @@ def test_request_with_retry_failing_request_and_expected_status_code(mock_reques


@pytest.mark.unit
@patch("haystack.utils.requests.requests.request")
@patch("haystack.utils.requests_utils.requests.request")
def test_request_with_retry_failing_request_and_ignored_status_code(mock_request):
# Create fake failed response with status code that doesn't trigger retry
fake_response = requests.Response()
Expand All @@ -59,7 +59,7 @@ def test_request_with_retry_failing_request_and_ignored_status_code(mock_request


@pytest.mark.unit
@patch("haystack.utils.requests.requests.request")
@patch("haystack.utils.requests_utils.requests.request")
def test_request_with_retry_timed_out_request(mock_request: Mock):
# Make request fail cause of a timeout
mock_request.side_effect = TimeoutError()
Expand Down