mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-08-11 18:17:53 +00:00

* add changes for api_base * format retriever * Update haystack/nodes/retriever/dense.py Co-authored-by: bogdankostic <bogdankostic@web.de> * Update haystack/nodes/audio/whisper_transcriber.py Co-authored-by: bogdankostic <bogdankostic@web.de> * Update haystack/preview/components/audio/whisper_remote.py Co-authored-by: bogdankostic <bogdankostic@web.de> * Update haystack/nodes/answer_generator/openai.py Co-authored-by: bogdankostic <bogdankostic@web.de> * Update test_retriever.py * Update test_whisper_remote.py * Update test_generator.py * Update test_retriever.py * reformat with black * Update haystack/nodes/prompt/invocation_layer/chatgpt.py Co-authored-by: Daria Fokina <daria.f93@gmail.com> * Add unit tests * apply docstring suggestions --------- Co-authored-by: bogdankostic <bogdankostic@web.de> Co-authored-by: michaelfeil <me@michaelfeil.eu> Co-authored-by: Daria Fokina <daria.f93@gmail.com>
30 lines
1.3 KiB
Python
30 lines
1.3 KiB
Python
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
from haystack.nodes.prompt.invocation_layer import OpenAIInvocationLayer
|
|
|
|
|
|
@pytest.mark.unit
|
|
@patch("haystack.nodes.prompt.invocation_layer.open_ai.openai_request")
|
|
def test_default_api_base(mock_request):
|
|
with patch("haystack.nodes.prompt.invocation_layer.open_ai.load_openai_tokenizer"):
|
|
invocation_layer = OpenAIInvocationLayer(api_key="fake_api_key")
|
|
assert invocation_layer.api_base == "https://api.openai.com/v1"
|
|
assert invocation_layer.url == "https://api.openai.com/v1/completions"
|
|
|
|
invocation_layer.invoke(prompt="dummy_prompt")
|
|
assert mock_request.call_args.kwargs["url"] == "https://api.openai.com/v1/completions"
|
|
|
|
|
|
@pytest.mark.unit
|
|
@patch("haystack.nodes.prompt.invocation_layer.open_ai.openai_request")
|
|
def test_custom_api_base(mock_request):
|
|
with patch("haystack.nodes.prompt.invocation_layer.open_ai.load_openai_tokenizer"):
|
|
invocation_layer = OpenAIInvocationLayer(api_key="fake_api_key", api_base="https://fake_api_base.com")
|
|
assert invocation_layer.api_base == "https://fake_api_base.com"
|
|
assert invocation_layer.url == "https://fake_api_base.com/completions"
|
|
|
|
invocation_layer.invoke(prompt="dummy_prompt")
|
|
assert mock_request.call_args.kwargs["url"] == "https://fake_api_base.com/completions"
|