mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-08-15 06:00:48 +00:00
test: generate unique chat completion IDs for replayed responses
When replaying recorded chat completion responses, the original chat IDs cause conflicts due to SQLite unique constraints. Generate new UUIDs for both ChatCompletion and ChatCompletionChunk objects to ensure each replayed response has a unique identifier. This fixes test failures when running integration tests in replay mode with recorded chat completion responses.
This commit is contained in:
parent
6358d0a478
commit
711735891a
1 changed files with 17 additions and 0 deletions
|
@ -10,12 +10,15 @@ import hashlib
|
|||
import json
|
||||
import os
|
||||
import sqlite3
|
||||
import uuid
|
||||
from collections.abc import Generator
|
||||
from contextlib import contextmanager
|
||||
from enum import StrEnum
|
||||
from pathlib import Path
|
||||
from typing import Any, Literal, cast
|
||||
|
||||
from openai.types.chat import ChatCompletion, ChatCompletionChunk
|
||||
|
||||
from llama_stack.log import get_logger
|
||||
|
||||
logger = get_logger(__name__, category="testing")
|
||||
|
@ -248,6 +251,20 @@ async def _patched_inference_method(original_method, self, client_type, endpoint
|
|||
recording = _current_storage.find_recording(request_hash)
|
||||
if recording:
|
||||
response_body = recording["response"]["body"]
|
||||
if (
|
||||
isinstance(response_body, list)
|
||||
and len(response_body) > 0
|
||||
and isinstance(response_body[0], ChatCompletionChunk)
|
||||
):
|
||||
# We can't replay chatcompletions with the same id and we store them in a sqlite database with a unique constraint on the id.
|
||||
# So we generate a new id and replace the old one.
|
||||
newid = uuid.uuid4().hex
|
||||
response_body[0].id = "chatcmpl-" + newid
|
||||
elif isinstance(response_body, ChatCompletion):
|
||||
# We can't replay chatcompletions with the same id and we store them in a sqlite database with a unique constraint on the id.
|
||||
# So we generate a new id and replace the old one.
|
||||
newid = uuid.uuid4().hex
|
||||
response_body.id = "chatcmpl-" + newid
|
||||
|
||||
if recording["response"].get("is_streaming", False):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue