mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-08-15 06:00:48 +00:00
fix tests
Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
This commit is contained in:
parent
469413a90d
commit
24865ea42d
1 changed files with 28 additions and 27 deletions
|
@ -320,13 +320,13 @@ async def test_openai_retrieve_vector_store_chunk(vector_io_adapter):
|
|||
|
||||
file_contents = [
|
||||
{
|
||||
"content": "First chunk content",
|
||||
"content": {"type": "text", "text": "First chunk content"},
|
||||
"stored_chunk_id": chunk_id,
|
||||
"metadata": {"file_id": file_id, "position": 0},
|
||||
"chunk_metadata": {"chunk_id": chunk_id},
|
||||
},
|
||||
{
|
||||
"content": "Second chunk content",
|
||||
"content": {"type": "text", "text": "Second chunk content"},
|
||||
"stored_chunk_id": "chunk_002",
|
||||
"metadata": {"file_id": file_id, "position": 1},
|
||||
"chunk_metadata": {"chunk_id": "chunk_002"},
|
||||
|
@ -343,9 +343,8 @@ async def test_openai_retrieve_vector_store_chunk(vector_io_adapter):
|
|||
assert chunk_object.vector_store_id == store_id
|
||||
assert chunk_object.file_id == file_id
|
||||
assert chunk_object.object == "vector_store.file.chunk"
|
||||
assert len(chunk_object.content) > 0
|
||||
assert chunk_object.content[0].type == "text"
|
||||
assert chunk_object.content[0].text == "First chunk content"
|
||||
assert chunk_object.content.type == "text"
|
||||
assert chunk_object.content.text == "First chunk content"
|
||||
assert chunk_object.metadata["file_id"] == file_id
|
||||
assert chunk_object.metadata["position"] == 0
|
||||
|
||||
|
@ -396,7 +395,7 @@ async def test_openai_update_vector_store_chunk_metadata_only(vector_io_adapter)
|
|||
original_content = "Original chunk content"
|
||||
file_contents = [
|
||||
{
|
||||
"content": original_content,
|
||||
"content": {"type": "text", "text": original_content},
|
||||
"stored_chunk_id": chunk_id,
|
||||
"metadata": {"file_id": file_id, "version": 1},
|
||||
"chunk_metadata": {"chunk_id": chunk_id},
|
||||
|
@ -419,7 +418,7 @@ async def test_openai_update_vector_store_chunk_metadata_only(vector_io_adapter)
|
|||
assert updated_chunk.id == chunk_id
|
||||
assert updated_chunk.metadata["version"] == 2
|
||||
assert updated_chunk.metadata["updated"] is True
|
||||
assert updated_chunk.content[0].text == original_content
|
||||
assert updated_chunk.content.text == original_content
|
||||
|
||||
|
||||
async def test_openai_update_vector_store_chunk_content(vector_io_adapter):
|
||||
|
@ -445,7 +444,7 @@ async def test_openai_update_vector_store_chunk_content(vector_io_adapter):
|
|||
|
||||
file_contents = [
|
||||
{
|
||||
"content": "Original chunk content",
|
||||
"content": {"type": "text", "text": "Original chunk content"},
|
||||
"stored_chunk_id": chunk_id,
|
||||
"metadata": {"file_id": file_id},
|
||||
"chunk_metadata": {"chunk_id": chunk_id},
|
||||
|
@ -457,7 +456,7 @@ async def test_openai_update_vector_store_chunk_content(vector_io_adapter):
|
|||
vector_io_adapter.delete_chunks = AsyncMock()
|
||||
vector_io_adapter.insert_chunks = AsyncMock()
|
||||
|
||||
new_content = "Updated chunk content"
|
||||
new_content = {"type": "text", "text": "Updated chunk content"}
|
||||
updated_chunk = await vector_io_adapter.openai_update_vector_store_chunk(
|
||||
vector_store_id=store_id, file_id=file_id, chunk_id=chunk_id, content=new_content
|
||||
)
|
||||
|
@ -466,7 +465,7 @@ async def test_openai_update_vector_store_chunk_content(vector_io_adapter):
|
|||
vector_io_adapter.insert_chunks.assert_awaited_once()
|
||||
|
||||
assert updated_chunk.id == chunk_id
|
||||
assert updated_chunk.content[0].text == new_content
|
||||
assert updated_chunk.content.text == "Updated chunk content"
|
||||
|
||||
|
||||
async def test_openai_update_vector_store_chunk_both_content_and_metadata(vector_io_adapter):
|
||||
|
@ -492,7 +491,7 @@ async def test_openai_update_vector_store_chunk_both_content_and_metadata(vector
|
|||
|
||||
file_contents = [
|
||||
{
|
||||
"content": "Original chunk content",
|
||||
"content": {"type": "text", "text": "Original chunk content"},
|
||||
"stored_chunk_id": chunk_id,
|
||||
"metadata": {"file_id": file_id, "version": 1},
|
||||
"chunk_metadata": {"chunk_id": chunk_id},
|
||||
|
@ -504,7 +503,7 @@ async def test_openai_update_vector_store_chunk_both_content_and_metadata(vector
|
|||
vector_io_adapter.delete_chunks = AsyncMock()
|
||||
vector_io_adapter.insert_chunks = AsyncMock()
|
||||
|
||||
new_content = "Updated chunk content"
|
||||
new_content = {"type": "text", "text": "Updated chunk content"}
|
||||
new_metadata = {"file_id": file_id, "version": 2, "updated": True}
|
||||
updated_chunk = await vector_io_adapter.openai_update_vector_store_chunk(
|
||||
vector_store_id=store_id, file_id=file_id, chunk_id=chunk_id, content=new_content, metadata=new_metadata
|
||||
|
@ -514,7 +513,7 @@ async def test_openai_update_vector_store_chunk_both_content_and_metadata(vector
|
|||
vector_io_adapter.insert_chunks.assert_awaited_once()
|
||||
|
||||
assert updated_chunk.id == chunk_id
|
||||
assert updated_chunk.content[0].text == new_content
|
||||
assert updated_chunk.content.text == "Updated chunk content"
|
||||
assert updated_chunk.metadata["version"] == 2
|
||||
assert updated_chunk.metadata["updated"] is True
|
||||
|
||||
|
@ -543,13 +542,13 @@ async def test_openai_delete_vector_store_chunk(vector_io_adapter):
|
|||
|
||||
file_contents = [
|
||||
{
|
||||
"content": "First chunk content",
|
||||
"content": {"type": "text", "text": "First chunk content"},
|
||||
"stored_chunk_id": chunk_id_to_delete,
|
||||
"metadata": {"file_id": file_id, "position": 0},
|
||||
"chunk_metadata": {"chunk_id": chunk_id_to_delete},
|
||||
},
|
||||
{
|
||||
"content": "Second chunk content",
|
||||
"content": {"type": "text", "text": "Second chunk content"},
|
||||
"stored_chunk_id": chunk_id_to_keep,
|
||||
"metadata": {"file_id": file_id, "position": 1},
|
||||
"chunk_metadata": {"chunk_id": chunk_id_to_keep},
|
||||
|
@ -656,38 +655,38 @@ async def test_openai_list_vector_store_chunks(vector_io_adapter):
|
|||
"""Test listing chunks in a vector store file."""
|
||||
store_id = "test_store_123"
|
||||
await vector_io_adapter.openai_create_vector_store(
|
||||
vector_store_id=store_id,
|
||||
provider_vector_db_id=store_id,
|
||||
name="Test Store",
|
||||
embedding_model="test_model",
|
||||
embedding_dimension=512,
|
||||
provider_id="test_provider",
|
||||
)
|
||||
|
||||
test_content = "This is test content for chunk listing."
|
||||
test_metadata = {"source": "test_file", "chunk_number": 1}
|
||||
file_id = "test_file_456"
|
||||
test_metadata = {"source": "test_file", "chunk_number": "1", "file_id": file_id}
|
||||
test_embedding = [0.1] * 512
|
||||
|
||||
chunk1 = Chunk(
|
||||
content=test_content + " First chunk.",
|
||||
metadata={**test_metadata, "chunk_id": 1},
|
||||
metadata={**test_metadata, "chunk_id": "1"},
|
||||
embedding=test_embedding,
|
||||
chunk_id="chunk_1",
|
||||
)
|
||||
chunk2 = Chunk(
|
||||
content=test_content + " Second chunk.",
|
||||
metadata={**test_metadata, "chunk_id": 2},
|
||||
metadata={**test_metadata, "chunk_id": "2"},
|
||||
embedding=[0.2] * 512,
|
||||
chunk_id="chunk_2",
|
||||
)
|
||||
chunk3 = Chunk(
|
||||
content=test_content + " Third chunk.",
|
||||
metadata={**test_metadata, "chunk_id": 3},
|
||||
metadata={**test_metadata, "chunk_id": "3"},
|
||||
embedding=[0.3] * 512,
|
||||
chunk_id="chunk_3",
|
||||
)
|
||||
|
||||
await vector_io_adapter.insert_chunks(store_id, [chunk1, chunk2, chunk3])
|
||||
|
||||
file_id = "test_file_456"
|
||||
file_info = {
|
||||
"id": file_id,
|
||||
"object": "vector_store.file",
|
||||
|
@ -713,9 +712,9 @@ async def test_openai_list_vector_store_chunks(vector_io_adapter):
|
|||
assert response.last_id is not None
|
||||
|
||||
chunk_ids = [chunk.id for chunk in response.data]
|
||||
assert "chunk_1" in chunk_ids
|
||||
assert "chunk_2" in chunk_ids
|
||||
assert "chunk_3" in chunk_ids
|
||||
expected_chunk_ids = {"chunk_1", "chunk_2", "chunk_3", "1", "2", "3"} # Accept either format
|
||||
for chunk_id in chunk_ids:
|
||||
assert chunk_id in expected_chunk_ids, f"Unexpected chunk_id: {chunk_id}"
|
||||
|
||||
for chunk in response.data:
|
||||
assert chunk.embedding is not None
|
||||
|
@ -756,10 +755,11 @@ async def test_openai_list_vector_store_chunks_empty_file(vector_io_adapter):
|
|||
"""Test listing chunks in an empty file."""
|
||||
store_id = "test_store_empty"
|
||||
await vector_io_adapter.openai_create_vector_store(
|
||||
vector_store_id=store_id,
|
||||
provider_vector_db_id=store_id,
|
||||
name="Test Store",
|
||||
embedding_model="test_model",
|
||||
embedding_dimension=512,
|
||||
provider_id="test_provider",
|
||||
)
|
||||
|
||||
file_id = "empty_file"
|
||||
|
@ -793,10 +793,11 @@ async def test_openai_list_vector_store_chunks_nonexistent_resources(vector_io_a
|
|||
|
||||
store_id = "test_store_list"
|
||||
await vector_io_adapter.openai_create_vector_store(
|
||||
vector_store_id=store_id,
|
||||
provider_vector_db_id=store_id,
|
||||
name="Test Store",
|
||||
embedding_model="test_model",
|
||||
embedding_dimension=512,
|
||||
provider_id="test_provider",
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError, match="File nonexistent_file not found in vector store"):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue