mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-06-26 22:00:13 +00:00
fix: handle async tests inHuggingFaceAPIChatGenerator
to prevent error (#8986)
* add missing asyncio * explicitly close connection in the test
This commit is contained in:
parent
40798bc4f2
commit
ae26e7580b
@ -822,6 +822,7 @@ class TestHuggingFaceAPIChatGenerator:
|
||||
reason="Export an env var called HF_API_TOKEN containing the Hugging Face token to run this test.",
|
||||
)
|
||||
@pytest.mark.flaky(reruns=3, reruns_delay=10)
|
||||
@pytest.mark.asyncio
|
||||
async def test_live_run_async_serverless(self):
|
||||
generator = HuggingFaceAPIChatGenerator(
|
||||
api_type=HFGenerationAPIType.SERVERLESS_INFERENCE_API,
|
||||
@ -829,17 +830,18 @@ class TestHuggingFaceAPIChatGenerator:
|
||||
generation_kwargs={"max_tokens": 20},
|
||||
)
|
||||
|
||||
# No need for instruction tokens here since we use the chat_completion endpoint which handles the chat
|
||||
# templating for us.
|
||||
messages = [
|
||||
ChatMessage.from_user("What is the capital of France? Be concise only provide the capital, nothing else.")
|
||||
]
|
||||
response = await generator.run_async(messages=messages)
|
||||
try:
|
||||
response = await generator.run_async(messages=messages)
|
||||
|
||||
assert "replies" in response
|
||||
assert isinstance(response["replies"], list)
|
||||
assert len(response["replies"]) > 0
|
||||
assert [isinstance(reply, ChatMessage) for reply in response["replies"]]
|
||||
assert "usage" in response["replies"][0].meta
|
||||
assert "prompt_tokens" in response["replies"][0].meta["usage"]
|
||||
assert "completion_tokens" in response["replies"][0].meta["usage"]
|
||||
assert "replies" in response
|
||||
assert isinstance(response["replies"], list)
|
||||
assert len(response["replies"]) > 0
|
||||
assert [isinstance(reply, ChatMessage) for reply in response["replies"]]
|
||||
assert "usage" in response["replies"][0].meta
|
||||
assert "prompt_tokens" in response["replies"][0].meta["usage"]
|
||||
assert "completion_tokens" in response["replies"][0].meta["usage"]
|
||||
finally:
|
||||
await generator._async_client.close()
|
||||
|
Loading…
x
Reference in New Issue
Block a user