Skip to content

Commit ce3b93e

Browse files
ArkaD171717claude
andcommitted
fix: move imports to top level, use async callback in async test
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent db9a56a commit ce3b93e

2 files changed

Lines changed: 25 additions & 23 deletions

File tree

integrations/mistral/tests/test_mistral_chat_generator.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,24 +1185,26 @@ def test_run_empty_messages(self, monkeypatch):
11851185
assert response == {"replies": []}
11861186

11871187
def test_convert_response_from_json_string(self):
1188-
json_str = json.dumps({
1189-
"id": "test",
1190-
"model": "mistral-small-latest",
1191-
"choices": [
1192-
{
1193-
"finish_reason": "stop",
1194-
"index": 0,
1195-
"message": {
1196-
"role": "assistant",
1197-
"content": [
1198-
{"type": "thinking", "thinking": [{"type": "text", "text": "Thinking."}]},
1199-
{"type": "text", "text": "Answer."},
1200-
],
1201-
},
1202-
}
1203-
],
1204-
"usage": {"prompt_tokens": 5, "completion_tokens": 10, "total_tokens": 15},
1205-
})
1188+
json_str = json.dumps(
1189+
{
1190+
"id": "test",
1191+
"model": "mistral-small-latest",
1192+
"choices": [
1193+
{
1194+
"finish_reason": "stop",
1195+
"index": 0,
1196+
"message": {
1197+
"role": "assistant",
1198+
"content": [
1199+
{"type": "thinking", "thinking": [{"type": "text", "text": "Thinking."}]},
1200+
{"type": "text", "text": "Answer."},
1201+
],
1202+
},
1203+
}
1204+
],
1205+
"usage": {"prompt_tokens": 5, "completion_tokens": 10, "total_tokens": 15},
1206+
}
1207+
)
12061208
messages = _convert_mistral_response_to_chat_messages(json_str)
12071209
assert len(messages) == 1
12081210
assert messages[0].text == "Answer."

integrations/mistral/tests/test_mistral_chat_generator_async.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import logging
23
import os
34
from datetime import datetime
45
from unittest.mock import AsyncMock, patch
@@ -318,15 +319,14 @@ async def test_run_async_empty_messages(self, monkeypatch):
318319

319320
@pytest.mark.asyncio
320321
async def test_run_async_streaming_with_reasoning_logs_warning(self, monkeypatch, caplog):
321-
import logging
322+
monkeypatch.setenv("MISTRAL_API_KEY", "fake-api-key")
322323

323-
from haystack.components.generators.utils import print_streaming_chunk
324-
from haystack.dataclasses import ChatMessage
324+
async def async_callback(chunk: StreamingChunk):
325+
pass
325326

326-
monkeypatch.setenv("MISTRAL_API_KEY", "fake-api-key")
327327
component = MistralChatGenerator(
328328
generation_kwargs={"reasoning_effort": "high"},
329-
streaming_callback=print_streaming_chunk,
329+
streaming_callback=async_callback,
330330
)
331331

332332
with (

0 commit comments

Comments
 (0)