From 0e0844ce00b409e8160ce36aa508017c6807bcde Mon Sep 17 00:00:00 2001 From: Nicolas Patry Date: Thu, 6 Mar 2025 16:19:37 +0100 Subject: [PATCH] Upgrade other tests. --- integration-tests/conftest.py | 4 ++ ...t_flash_llama_completion_stream_usage.json | 69 +++++++++++-------- .../models/test_completion_prompts.py | 6 +- integration-tests/models/test_tools_llama.py | 2 - 4 files changed, 48 insertions(+), 33 deletions(-) diff --git a/integration-tests/conftest.py b/integration-tests/conftest.py index ccef16b0..230d6db9 100644 --- a/integration-tests/conftest.py +++ b/integration-tests/conftest.py @@ -42,6 +42,7 @@ from syrupy.extensions.json import JSONSnapshotExtension from text_generation import AsyncClient from text_generation.types import ( + Completion, BestOfSequence, Message, ChatComplete, @@ -131,6 +132,7 @@ class ResponseComparator(JSONSnapshotExtension): or isinstance(data, ChatComplete) or isinstance(data, ChatCompletionChunk) or isinstance(data, ChatCompletionComplete) + or isinstance(data, Completion) or isinstance(data, OAIChatCompletionChunk) ): data = data.model_dump() @@ -140,6 +142,8 @@ class ResponseComparator(JSONSnapshotExtension): data = dict(data) elif isinstance(data, List): data = [self._serialize(d) for d in data] + elif isinstance(data, dict): + return data else: raise RuntimeError(f"Unexpected data {type(data)} : {data}") return data diff --git a/integration-tests/models/__snapshots__/test_completion_prompts/test_flash_llama_completion_stream_usage.json b/integration-tests/models/__snapshots__/test_completion_prompts/test_flash_llama_completion_stream_usage.json index 8c7be4cb..8564e8ce 100644 --- a/integration-tests/models/__snapshots__/test_completion_prompts/test_flash_llama_completion_stream_usage.json +++ b/integration-tests/models/__snapshots__/test_completion_prompts/test_flash_llama_completion_stream_usage.json @@ -12,11 +12,11 @@ "logprobs": null } ], - "created": 1726656043, + "created": 1741274364, "id": "", - "model": "meta-llama/Meta-Llama-3.1-8B-Instruct", + "model": "meta-llama/Llama-3.1-8B-Instruct", "object": "chat.completion.chunk", - "system_fingerprint": "2.2.1-dev0-native", + "system_fingerprint": "3.1.2-dev0-native", "usage": null }, { @@ -32,11 +32,11 @@ "logprobs": null } ], - "created": 1726656043, + "created": 1741274364, "id": "", - "model": "meta-llama/Meta-Llama-3.1-8B-Instruct", + "model": "meta-llama/Llama-3.1-8B-Instruct", "object": "chat.completion.chunk", - "system_fingerprint": "2.2.1-dev0-native", + "system_fingerprint": "3.1.2-dev0-native", "usage": null }, { @@ -52,11 +52,11 @@ "logprobs": null } ], - "created": 1726656043, + "created": 1741274364, "id": "", - "model": "meta-llama/Meta-Llama-3.1-8B-Instruct", + "model": "meta-llama/Llama-3.1-8B-Instruct", "object": "chat.completion.chunk", - "system_fingerprint": "2.2.1-dev0-native", + "system_fingerprint": "3.1.2-dev0-native", "usage": null }, { @@ -72,11 +72,11 @@ "logprobs": null } ], - "created": 1726656043, + "created": 1741274364, "id": "", - "model": "meta-llama/Meta-Llama-3.1-8B-Instruct", + "model": "meta-llama/Llama-3.1-8B-Instruct", "object": "chat.completion.chunk", - "system_fingerprint": "2.2.1-dev0-native", + "system_fingerprint": "3.1.2-dev0-native", "usage": null }, { @@ -92,11 +92,11 @@ "logprobs": null } ], - "created": 1726656043, + "created": 1741274364, "id": "", - "model": "meta-llama/Meta-Llama-3.1-8B-Instruct", + "model": "meta-llama/Llama-3.1-8B-Instruct", "object": "chat.completion.chunk", - "system_fingerprint": "2.2.1-dev0-native", + "system_fingerprint": "3.1.2-dev0-native", "usage": null }, { @@ -112,11 +112,11 @@ "logprobs": null } ], - "created": 1726656043, + "created": 1741274364, "id": "", - "model": "meta-llama/Meta-Llama-3.1-8B-Instruct", + "model": "meta-llama/Llama-3.1-8B-Instruct", "object": "chat.completion.chunk", - "system_fingerprint": "2.2.1-dev0-native", + "system_fingerprint": "3.1.2-dev0-native", "usage": null }, { @@ -132,11 +132,11 @@ "logprobs": null } ], - "created": 1726656044, + "created": 1741274364, "id": "", - "model": "meta-llama/Meta-Llama-3.1-8B-Instruct", + "model": "meta-llama/Llama-3.1-8B-Instruct", "object": "chat.completion.chunk", - "system_fingerprint": "2.2.1-dev0-native", + "system_fingerprint": "3.1.2-dev0-native", "usage": null }, { @@ -152,11 +152,11 @@ "logprobs": null } ], - "created": 1726656044, + "created": 1741274364, "id": "", - "model": "meta-llama/Meta-Llama-3.1-8B-Instruct", + "model": "meta-llama/Llama-3.1-8B-Instruct", "object": "chat.completion.chunk", - "system_fingerprint": "2.2.1-dev0-native", + "system_fingerprint": "3.1.2-dev0-native", "usage": null }, { @@ -172,11 +172,11 @@ "logprobs": null } ], - "created": 1726656044, + "created": 1741274364, "id": "", - "model": "meta-llama/Meta-Llama-3.1-8B-Instruct", + "model": "meta-llama/Llama-3.1-8B-Instruct", "object": "chat.completion.chunk", - "system_fingerprint": "2.2.1-dev0-native", + "system_fingerprint": "3.1.2-dev0-native", "usage": null }, { @@ -192,11 +192,20 @@ "logprobs": null } ], - "created": 1726656044, + "created": 1741274364, "id": "", - "model": "meta-llama/Meta-Llama-3.1-8B-Instruct", + "model": "meta-llama/Llama-3.1-8B-Instruct", "object": "chat.completion.chunk", - "system_fingerprint": "2.2.1-dev0-native", + "system_fingerprint": "3.1.2-dev0-native", + "usage": null + }, + { + "choices": [], + "created": 1741274364, + "id": "", + "model": "meta-llama/Llama-3.1-8B-Instruct", + "object": "chat.completion.chunk", + "system_fingerprint": "3.1.2-dev0-native", "usage": { "completion_tokens": 10, "prompt_tokens": 40, diff --git a/integration-tests/models/test_completion_prompts.py b/integration-tests/models/test_completion_prompts.py index 6c359f1e..e39e16a1 100644 --- a/integration-tests/models/test_completion_prompts.py +++ b/integration-tests/models/test_completion_prompts.py @@ -96,8 +96,10 @@ async def test_flash_llama_completion_stream_usage( assert not had_usage if has_usage: had_usage = True + elif c["usage"]: + had_usage = True else: - raise RuntimeError("Expected different payload") + raise RuntimeError(f"Expected different payload: {c}") assert had_usage assert ( string @@ -147,6 +149,8 @@ async def test_flash_llama_completion_stream_usage( assert not had_usage if has_usage: had_usage = True + elif c["usage"]: + had_usage = True else: raise RuntimeError("Expected different payload") assert not had_usage diff --git a/integration-tests/models/test_tools_llama.py b/integration-tests/models/test_tools_llama.py index 07a796e0..ebf69cb7 100644 --- a/integration-tests/models/test_tools_llama.py +++ b/integration-tests/models/test_tools_llama.py @@ -1,6 +1,4 @@ import pytest -import requests -import json from openai import OpenAI from huggingface_hub import InferenceClient from huggingface_hub.inference._generated.types.chat_completion import (