feat(tests): make inference_recorder into api_recorder (include tool_invoke)

This commit is contained in:
Ashwin Bharambe 2025-10-04 11:53:44 -07:00
parent b96640eca3
commit 9205731cd6
19 changed files with 849 additions and 666 deletions

View file

@ -7,7 +7,7 @@
import time
def new_vector_store(openai_client, name):
def new_vector_store(openai_client, name, embedding_model, embedding_dimension):
"""Create a new vector store, cleaning up any existing one with the same name."""
# Ensure we don't reuse an existing vector store
vector_stores = openai_client.vector_stores.list()
@ -16,7 +16,21 @@ def new_vector_store(openai_client, name):
openai_client.vector_stores.delete(vector_store_id=vector_store.id)
# Create a new vector store
vector_store = openai_client.vector_stores.create(name=name)
# OpenAI SDK client uses extra_body for non-standard parameters
from openai import OpenAI
if isinstance(openai_client, OpenAI):
# OpenAI SDK client - use extra_body
vector_store = openai_client.vector_stores.create(
name=name,
extra_body={"embedding_model": embedding_model, "embedding_dimension": embedding_dimension},
)
else:
# LlamaStack client - direct parameter
vector_store = openai_client.vector_stores.create(
name=name, embedding_model=embedding_model, embedding_dimension=embedding_dimension
)
return vector_store

View file

@ -16,6 +16,7 @@ import pytest
from llama_stack_client import APIStatusError
@pytest.mark.xfail(reason="Shields are not yet implemented inside responses")
def test_shields_via_extra_body(compat_client, text_model_id):
"""Test that shields parameter is received by the server and raises NotImplementedError."""

View file

@ -47,12 +47,14 @@ def test_response_text_format(compat_client, text_model_id, text_format):
@pytest.fixture
def vector_store_with_filtered_files(compat_client, text_model_id, tmp_path_factory):
"""Create a vector store with multiple files that have different attributes for filtering tests."""
def vector_store_with_filtered_files(compat_client, embedding_model_id, embedding_dimension, tmp_path_factory):
# """Create a vector store with multiple files that have different attributes for filtering tests."""
if isinstance(compat_client, LlamaStackAsLibraryClient):
pytest.skip("Responses API file search is not yet supported in library client.")
pytest.skip("upload_file() is not yet supported in library client somehow?")
vector_store = new_vector_store(compat_client, "test_vector_store_with_filters")
vector_store = new_vector_store(
compat_client, "test_vector_store_with_filters", embedding_model_id, embedding_dimension
)
tmp_path = tmp_path_factory.mktemp("filter_test_files")
# Create multiple files with different attributes

View file

@ -46,11 +46,13 @@ def test_response_non_streaming_web_search(compat_client, text_model_id, case):
@pytest.mark.parametrize("case", file_search_test_cases)
def test_response_non_streaming_file_search(compat_client, text_model_id, tmp_path, case):
def test_response_non_streaming_file_search(
compat_client, text_model_id, embedding_model_id, embedding_dimension, tmp_path, case
):
if isinstance(compat_client, LlamaStackAsLibraryClient):
pytest.skip("Responses API file search is not yet supported in library client.")
vector_store = new_vector_store(compat_client, "test_vector_store")
vector_store = new_vector_store(compat_client, "test_vector_store", embedding_model_id, embedding_dimension)
if case.file_content:
file_name = "test_response_non_streaming_file_search.txt"
@ -101,11 +103,13 @@ def test_response_non_streaming_file_search(compat_client, text_model_id, tmp_pa
assert case.expected.lower() in response.output_text.lower().strip()
def test_response_non_streaming_file_search_empty_vector_store(compat_client, text_model_id):
def test_response_non_streaming_file_search_empty_vector_store(
compat_client, text_model_id, embedding_model_id, embedding_dimension
):
if isinstance(compat_client, LlamaStackAsLibraryClient):
pytest.skip("Responses API file search is not yet supported in library client.")
vector_store = new_vector_store(compat_client, "test_vector_store")
vector_store = new_vector_store(compat_client, "test_vector_store", embedding_model_id, embedding_dimension)
# Create the response request, which should query our vector store
response = compat_client.responses.create(
@ -127,12 +131,14 @@ def test_response_non_streaming_file_search_empty_vector_store(compat_client, te
assert response.output_text
def test_response_sequential_file_search(compat_client, text_model_id, tmp_path):
def test_response_sequential_file_search(
compat_client, text_model_id, embedding_model_id, embedding_dimension, tmp_path
):
"""Test file search with sequential responses using previous_response_id."""
if isinstance(compat_client, LlamaStackAsLibraryClient):
pytest.skip("Responses API file search is not yet supported in library client.")
vector_store = new_vector_store(compat_client, "test_vector_store")
vector_store = new_vector_store(compat_client, "test_vector_store", embedding_model_id, embedding_dimension)
# Create a test file with content
file_content = "The Llama 4 Maverick model has 128 experts in its mixture of experts architecture."