mirror of
https://github.com/deepset-ai/haystack.git
synced 2026-01-06 20:17:14 +00:00
fix: rename requests.py into requests_utils.py (#5099)
* requests.py -> requests_utils.py * fix tests * reimport requrests * fix more tests * review feedback
This commit is contained in:
parent
72fe43a7cc
commit
49e037a055
@ -15,7 +15,7 @@ from haystack.nodes.prompt.invocation_layer.handlers import (
|
||||
AnthropicTokenStreamingHandler,
|
||||
DefaultTokenStreamingHandler,
|
||||
)
|
||||
from haystack.utils.requests import request_with_retry
|
||||
from haystack.utils import request_with_retry
|
||||
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))
|
||||
|
||||
@ -13,7 +13,7 @@ from haystack.nodes.prompt.invocation_layer import (
|
||||
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))
|
||||
|
||||
@ -19,7 +19,7 @@ from haystack.nodes.prompt.invocation_layer import (
|
||||
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))
|
||||
|
||||
@ -6,7 +6,7 @@ import logging
|
||||
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__)
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
from haystack.utils.reflection import args_to_kwargs
|
||||
from haystack.utils.requests_utils import request_with_retry
|
||||
from haystack.utils.preprocessing import convert_files_to_docs, tika_convert_files_to_docs
|
||||
from haystack.utils.import_utils import fetch_archive_from_http
|
||||
from haystack.utils.cleaning import clean_wiki_text
|
||||
|
||||
@ -43,7 +43,7 @@ class TestRemoteWhisperTranscriber(BaseTestComponent):
|
||||
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(
|
||||
@ -67,7 +67,7 @@ class TestRemoteWhisperTranscriber(BaseTestComponent):
|
||||
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(
|
||||
@ -95,7 +95,7 @@ class TestRemoteWhisperTranscriber(BaseTestComponent):
|
||||
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:
|
||||
@ -113,7 +113,7 @@ class TestRemoteWhisperTranscriber(BaseTestComponent):
|
||||
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(
|
||||
@ -138,7 +138,7 @@ class TestRemoteWhisperTranscriber(BaseTestComponent):
|
||||
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(
|
||||
|
||||
@ -3,11 +3,11 @@ from unittest.mock import patch, Mock
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
from haystack.utils.requests import request_with_retry
|
||||
from haystack.utils.requests_utils import request_with_retry
|
||||
|
||||
|
||||
@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")
|
||||
@ -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)
|
||||
@ -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()
|
||||
@ -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()
|
||||
@ -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()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user