mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-06-28 10:54:19 +00:00
# What does this PR do? ## Test Plan LLAMA_STACK_CONFIG=fireworks pytest -s -v tests/integration/files/test_files.py::test_openai_client_basic_operations
57 lines
2 KiB
Python
57 lines
2 KiB
Python
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
# All rights reserved.
|
|
#
|
|
# This source code is licensed under the terms described in the LICENSE file in
|
|
# the root directory of this source tree.
|
|
|
|
from io import BytesIO
|
|
|
|
import pytest
|
|
|
|
from llama_stack.distribution.library_client import LlamaStackAsLibraryClient
|
|
|
|
|
|
def test_openai_client_basic_operations(openai_client, client_with_models):
|
|
"""Test basic file operations through OpenAI client."""
|
|
if isinstance(client_with_models, LlamaStackAsLibraryClient):
|
|
pytest.skip("OpenAI files are not supported when testing with library client yet.")
|
|
client = openai_client
|
|
|
|
test_content = b"files test content"
|
|
|
|
try:
|
|
# Upload file using OpenAI client
|
|
with BytesIO(test_content) as file_buffer:
|
|
file_buffer.name = "openai_test.txt"
|
|
uploaded_file = client.files.create(file=file_buffer, purpose="assistants")
|
|
|
|
# Verify basic response structure
|
|
assert uploaded_file.id.startswith("file-")
|
|
assert hasattr(uploaded_file, "filename")
|
|
|
|
# List files
|
|
files_list = client.files.list()
|
|
file_ids = [f.id for f in files_list.data]
|
|
assert uploaded_file.id in file_ids
|
|
|
|
# Retrieve file info
|
|
retrieved_file = client.files.retrieve(uploaded_file.id)
|
|
assert retrieved_file.id == uploaded_file.id
|
|
|
|
# Retrieve file content - OpenAI client returns httpx Response object
|
|
content_response = client.files.content(uploaded_file.id)
|
|
# The response is an httpx Response object with .content attribute containing bytes
|
|
content = content_response.content
|
|
assert content == test_content
|
|
|
|
# Delete file
|
|
delete_response = client.files.delete(uploaded_file.id)
|
|
assert delete_response.deleted is True
|
|
|
|
except Exception as e:
|
|
# Cleanup in case of failure
|
|
try:
|
|
client.files.delete(uploaded_file.id)
|
|
except Exception:
|
|
pass
|
|
raise e
|