Skip to content

Commit e701533

Browse files
committed
fix: move imports to top level, fix logprobs test schema
logprobs Choice requires top_logprobs field, was missing. Inline imports in test methods trigger PLC0415 lint error.
1 parent a1d503b commit e701533

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

integrations/openrouter/tests/test_openrouter_chat_generator.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
from haystack_integrations.components.generators.openrouter.chat.chat_generator import (
2424
OpenRouterChatGenerator,
25+
_convert_openrouter_chunk_to_streaming_chunk,
2526
_convert_openrouter_completion_to_chat_message,
2627
_extract_reasoning,
2728
)
@@ -1410,7 +1411,11 @@ def test_convert_completion_with_logprobs(self):
14101411
choices=[
14111412
Choice(
14121413
finish_reason="stop",
1413-
logprobs={"content": [{"token": "Hello", "logprob": -0.5}]},
1414+
logprobs={
1415+
"content": [
1416+
{"token": "Hello", "logprob": -0.5, "top_logprobs": [], "bytes": [72, 101, 108, 108, 111]}
1417+
]
1418+
},
14141419
index=0,
14151420
message=ChatCompletionMessage(content="Hello!", role="assistant"),
14161421
)
@@ -1458,10 +1463,6 @@ def test_convert_completion_malformed_tool_call_json(self):
14581463
assert result.tool_calls[0].id == "call_good"
14591464

14601465
def test_convert_chunk_empty_choices(self):
1461-
from haystack_integrations.components.generators.openrouter.chat.chat_generator import (
1462-
_convert_openrouter_chunk_to_streaming_chunk,
1463-
)
1464-
14651466
chunk = ChatCompletionChunk(
14661467
id="gen-empty",
14671468
choices=[],

integrations/openrouter/tests/test_openrouter_chat_generator_async.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
StreamingChunk,
1111
)
1212
from haystack.tools import Tool, Toolset
13+
from haystack.utils.auth import Secret
1314
from openai import AsyncOpenAI
14-
from openai.types.chat import ChatCompletion, ChatCompletionMessage
15+
from openai.types.chat import ChatCompletion, ChatCompletionChunk, ChatCompletionMessage
1516
from openai.types.chat.chat_completion import Choice
17+
from openai.types.chat.chat_completion_chunk import Choice as ChoiceChunk
18+
from openai.types.chat.chat_completion_chunk import ChoiceDelta
19+
from openai.types.completion_usage import CompletionUsage
1620

1721
from haystack_integrations.components.generators.openrouter.chat.chat_generator import (
1822
OpenRouterChatGenerator,
@@ -384,12 +388,6 @@ async def test_run_async_empty_messages(self, monkeypatch):
384388
@pytest.mark.asyncio
385389
async def test_handle_async_stream_response_with_reasoning(self, monkeypatch):
386390
monkeypatch.setenv("OPENROUTER_API_KEY", "fake-api-key")
387-
from openai.types.chat import ChatCompletionChunk
388-
from openai.types.chat.chat_completion_chunk import Choice as ChoiceChunk
389-
from openai.types.chat.chat_completion_chunk import ChoiceDelta
390-
from openai.types.completion_usage import CompletionUsage
391-
392-
from haystack.utils.auth import Secret
393391

394392
chunks = [
395393
ChatCompletionChunk(

0 commit comments

Comments
 (0)