litellm/tests/local_testing/test_supabase_integration.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

80 lines
2.0 KiB
Python
Raw Normal View History

#### What this tests ####
# This tests if logging to the supabase integration actually works
import sys, os
import traceback
import pytest
2023-12-25 16:40:38 +08:00
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm
from litellm import embedding, completion
litellm.input_callback = ["supabase"]
litellm.success_callback = ["supabase"]
litellm.failure_callback = ["supabase"]
litellm.set_verbose = False
2023-12-25 16:40:38 +08:00
def test_supabase_logging():
try:
response = completion(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "Hello tell me hi"}],
user="ishaanRegular",
max_tokens=10,
)
print(response)
except Exception as e:
print(e)
2023-12-25 16:40:38 +08:00
# test_supabase_logging()
2023-12-25 16:40:38 +08:00
def test_acompletion_sync():
import asyncio
import time
2023-12-25 16:40:38 +08:00
async def completion_call():
try:
response = await litellm.acompletion(
2023-12-25 16:40:38 +08:00
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "write a poem"}],
max_tokens=10,
stream=True,
2023-11-18 09:46:49 +08:00
user="ishaanStreamingUser",
2023-12-25 16:40:38 +08:00
timeout=5,
)
complete_response = ""
start_time = time.time()
async for chunk in response:
chunk_time = time.time()
2023-12-25 16:40:38 +08:00
# print(chunk)
complete_response += chunk["choices"][0]["delta"].get("content", "")
2023-12-25 16:40:38 +08:00
# print(complete_response)
# print(f"time since initial request: {chunk_time - start_time:.5f}")
if chunk["choices"][0].get("finish_reason", None) != None:
print("🤗🤗🤗 DONE")
return
2023-12-25 16:40:38 +08:00
except litellm.Timeout as e:
2023-11-18 09:46:49 +08:00
pass
except Exception:
print(f"error occurred: {traceback.format_exc()}")
pass
asyncio.run(completion_call())
2023-12-25 16:40:38 +08:00
# test_acompletion_sync()
2023-11-16 10:14:09 +08:00
# reset callbacks
litellm.input_callback = []
litellm.success_callback = []
litellm.failure_callback = []