Skip to content
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
30 changes: 0 additions & 30 deletions integrations/meta_llama/tests/test_llama_chat_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,36 +239,6 @@ def test_run_with_params(self, chat_messages, mock_chat_completion, monkeypatch)
assert len(response["replies"]) == 1
assert [isinstance(reply, ChatMessage) for reply in response["replies"]]

def test_check_abnormal_completions(self, caplog):
component = MetaLlamaChatGenerator(api_key=Secret.from_token("test-api-key"))
messages = [
ChatMessage.from_assistant(
"",
meta={
"finish_reason": "content_filter" if i % 2 == 0 else "length",
"index": i,
},
)
for i, _ in enumerate(range(4))
]

for m in messages:
component._check_finish_reason(m.meta)

# check truncation warning
message_template = (
"The completion for index {index} has been truncated before reaching a natural stopping point. "
"Increase the max_tokens parameter to allow for longer completions."
)

for index in [1, 3]:
assert caplog.records[index].message == message_template.format(index=index)

# check content filter warning
message_template = "The completion for index {index} has been truncated due to the content filter."
for index in [0, 2]:
assert caplog.records[index].message == message_template.format(index=index)

@pytest.mark.skipif(
not os.environ.get("LLAMA_API_KEY", None),
reason="Export an env var called LLAMA_API_KEY containing the OpenAI API key to run this test.",
Expand Down
26 changes: 0 additions & 26 deletions integrations/mistral/tests/test_mistral_chat_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,32 +208,6 @@ def test_run_with_params(self, chat_messages, mock_chat_completion, monkeypatch)
assert len(response["replies"]) == 1
assert [isinstance(reply, ChatMessage) for reply in response["replies"]]

def test_check_abnormal_completions(self, caplog):
component = MistralChatGenerator(api_key=Secret.from_token("test-api-key"))
messages = [
ChatMessage.from_assistant(
"", meta={"finish_reason": "content_filter" if i % 2 == 0 else "length", "index": i}
)
for i, _ in enumerate(range(4))
]

for m in messages:
component._check_finish_reason(m.meta)

# check truncation warning
message_template = (
"The completion for index {index} has been truncated before reaching a natural stopping point. "
"Increase the max_tokens parameter to allow for longer completions."
)

for index in [1, 3]:
assert caplog.records[index].message == message_template.format(index=index)

# check content filter warning
message_template = "The completion for index {index} has been truncated due to the content filter."
for index in [0, 2]:
assert caplog.records[index].message == message_template.format(index=index)

@pytest.mark.skipif(
not os.environ.get("MISTRAL_API_KEY", None),
reason="Export an env var called MISTRAL_API_KEY containing the OpenAI API key to run this test.",
Expand Down
26 changes: 0 additions & 26 deletions integrations/openrouter/tests/test_openrouter_chat_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,32 +240,6 @@ def test_run_with_params(self, chat_messages, mock_chat_completion, monkeypatch)
assert len(response["replies"]) == 1
assert [isinstance(reply, ChatMessage) for reply in response["replies"]]

def test_check_abnormal_completions(self, caplog):
component = OpenRouterChatGenerator(api_key=Secret.from_token("test-api-key"))
messages = [
ChatMessage.from_assistant(
"", meta={"finish_reason": "content_filter" if i % 2 == 0 else "length", "index": i}
)
for i, _ in enumerate(range(4))
]

for m in messages:
component._check_finish_reason(m.meta)

# check truncation warning
message_template = (
"The completion for index {index} has been truncated before reaching a natural stopping point. "
"Increase the max_tokens parameter to allow for longer completions."
)

for index in [1, 3]:
assert caplog.records[index].message == message_template.format(index=index)

# check content filter warning
message_template = "The completion for index {index} has been truncated due to the content filter."
for index in [0, 2]:
assert caplog.records[index].message == message_template.format(index=index)

@pytest.mark.skipif(
not os.environ.get("OPENROUTER_API_KEY", None),
reason="Export an env var called OPENROUTER_API_KEY containing the OpenRouter API key to run this test.",
Expand Down
33 changes: 0 additions & 33 deletions integrations/stackit/tests/test_stackit_chat_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,39 +199,6 @@ def test_run_with_params(self, chat_messages, mock_chat_completion, monkeypatch)
assert len(response["replies"]) == 1
assert [isinstance(reply, ChatMessage) for reply in response["replies"]]

def test_check_abnormal_completions(self, caplog):
component = STACKITChatGenerator(
model="neuralmagic/Meta-Llama-3.1-8B-Instruct-FP8", api_key=Secret.from_token("test-api-key")
)
messages = [
ChatMessage.from_assistant(
"", meta={"finish_reason": "content_filter" if i % 2 == 0 else "length", "index": i}
)
for i, _ in enumerate(range(4))
]

for m in messages:
try:
# Haystack >= 2.9.0
component._check_finish_reason(m.meta)
except AttributeError:
# Haystack < 2.9.0
component._check_finish_reason(m)

# check truncation warning
message_template = (
"The completion for index {index} has been truncated before reaching a natural stopping point. "
"Increase the max_tokens parameter to allow for longer completions."
)

for index in [1, 3]:
assert caplog.records[index].message == message_template.format(index=index)

# check content filter warning
message_template = "The completion for index {index} has been truncated due to the content filter."
for index in [0, 2]:
assert caplog.records[index].message == message_template.format(index=index)

@pytest.mark.skipif(
not os.environ.get("STACKIT_API_KEY", None),
reason="Export an env var called STACKIT_API_KEY containing the API key to run this test.",
Expand Down
Loading