mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 11:14:04 +00:00
(test) proxy use fixtures
This commit is contained in:
parent
3e908bf507
commit
c2f0a5c76a
2 changed files with 19 additions and 20 deletions
|
@ -29,9 +29,10 @@ python_file_path = f"{filepath}/test_configs/custom_callbacks.py"
|
||||||
|
|
||||||
# Use the app fixture in your client fixture
|
# Use the app fixture in your client fixture
|
||||||
|
|
||||||
def get_client(config_fp):
|
@pytest.fixture
|
||||||
|
def client():
|
||||||
filepath = os.path.dirname(os.path.abspath(__file__))
|
filepath = os.path.dirname(os.path.abspath(__file__))
|
||||||
config_fp = f"{filepath}/test_configs/{config_fp}"
|
config_fp = f"{filepath}/test_configs/test_custom_logger.yaml"
|
||||||
initialize(config=config_fp)
|
initialize(config=config_fp)
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
app.include_router(router) # Include your router in the test app
|
app.include_router(router) # Include your router in the test app
|
||||||
|
@ -49,9 +50,8 @@ headers = {
|
||||||
|
|
||||||
print("Testing proxy custom logger")
|
print("Testing proxy custom logger")
|
||||||
|
|
||||||
def test_embedding():
|
def test_embedding(client):
|
||||||
try:
|
try:
|
||||||
client = get_client(config_fp="test_custom_logger.yaml")
|
|
||||||
litellm.set_verbose=False
|
litellm.set_verbose=False
|
||||||
from litellm.proxy.utils import get_instance_fn
|
from litellm.proxy.utils import get_instance_fn
|
||||||
my_custom_logger = get_instance_fn(
|
my_custom_logger = get_instance_fn(
|
||||||
|
@ -96,10 +96,10 @@ def test_embedding():
|
||||||
pytest.fail(f"LiteLLM Proxy test failed. Exception {str(e)}")
|
pytest.fail(f"LiteLLM Proxy test failed. Exception {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
def test_chat_completion():
|
def test_chat_completion(client):
|
||||||
try:
|
try:
|
||||||
# Your test data
|
# Your test data
|
||||||
client = get_client(config_fp="test_custom_logger.yaml")
|
|
||||||
print("initialized proxy")
|
print("initialized proxy")
|
||||||
litellm.set_verbose=False
|
litellm.set_verbose=False
|
||||||
from litellm.proxy.utils import get_instance_fn
|
from litellm.proxy.utils import get_instance_fn
|
||||||
|
@ -160,10 +160,9 @@ def test_chat_completion():
|
||||||
pytest.fail(f"LiteLLM Proxy test failed. Exception {str(e)}")
|
pytest.fail(f"LiteLLM Proxy test failed. Exception {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
def test_chat_completion_stream():
|
def test_chat_completion_stream(client):
|
||||||
try:
|
try:
|
||||||
# Your test data
|
# Your test data
|
||||||
client = get_client(config_fp="test_custom_logger.yaml")
|
|
||||||
litellm.set_verbose=False
|
litellm.set_verbose=False
|
||||||
from litellm.proxy.utils import get_instance_fn
|
from litellm.proxy.utils import get_instance_fn
|
||||||
my_custom_logger = get_instance_fn(
|
my_custom_logger = get_instance_fn(
|
||||||
|
|
|
@ -23,22 +23,22 @@ from concurrent.futures import ThreadPoolExecutor
|
||||||
# test /chat/completion request to the proxy
|
# test /chat/completion request to the proxy
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from litellm.proxy.proxy_server import router, save_worker_config, startup_event # Replace with the actual module where your FastAPI router is defined
|
from litellm.proxy.proxy_server import router, save_worker_config, initialize, startup_event # Replace with the actual module where your FastAPI router is defined
|
||||||
filepath = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
config_fp = f"{filepath}/test_configs/test_config.yaml"
|
|
||||||
save_worker_config(config=config_fp, model=None, alias=None, api_base=None, api_version=None, debug=False, temperature=None, max_tokens=None, request_timeout=600, max_budget=None, telemetry=False, drop_params=True, add_function_to_prompt=False, headers=None, save=False, use_queue=False)
|
|
||||||
app = FastAPI()
|
|
||||||
app.include_router(router) # Include your router in the test app
|
|
||||||
@app.on_event("startup")
|
|
||||||
async def wrapper_startup_event():
|
|
||||||
await startup_event()
|
|
||||||
|
|
||||||
# Here you create a fixture that will be used by your tests
|
# Here you create a fixture that will be used by your tests
|
||||||
# Make sure the fixture returns TestClient(app)
|
# Make sure the fixture returns TestClient(app)
|
||||||
@pytest.fixture(autouse=True)
|
|
||||||
|
@pytest.fixture(scope="module")
|
||||||
def client():
|
def client():
|
||||||
with TestClient(app) as client:
|
filepath = os.path.dirname(os.path.abspath(__file__))
|
||||||
yield client
|
config_fp = f"{filepath}/test_configs/test_config.yaml"
|
||||||
|
save_worker_config(config=config_fp, model=None, alias=None, api_base=None, api_version=None, debug=False, temperature=None, max_tokens=None, request_timeout=600, max_budget=None, telemetry=False, drop_params=True, add_function_to_prompt=False, headers=None, save=False, use_queue=False)
|
||||||
|
initialize(config=config_fp)
|
||||||
|
app = FastAPI()
|
||||||
|
app.include_router(router) # Include your router in the test app
|
||||||
|
import asyncio
|
||||||
|
asyncio.run(startup_event())
|
||||||
|
return TestClient(app)
|
||||||
|
|
||||||
def test_add_new_key(client):
|
def test_add_new_key(client):
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue