mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-24 10:14:26 +00:00
(test) load test router
This commit is contained in:
parent
18d9222945
commit
8560794963
1 changed files with 25 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
|||
import time, asyncio
|
||||
from openai import AsyncOpenAI
|
||||
import uuid
|
||||
import traceback
|
||||
|
||||
|
||||
litellm_client = AsyncOpenAI(
|
||||
|
@ -8,20 +9,41 @@ litellm_client = AsyncOpenAI(
|
|||
base_url="http://0.0.0.0:8000"
|
||||
)
|
||||
|
||||
|
||||
async def litellm_completion():
|
||||
return await litellm_client.chat.completions.create(
|
||||
# Your existing code for litellm_completion goes here
|
||||
try:
|
||||
return await litellm_client.chat.completions.create(
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[{"role": "user", "content": f"This is a test: {uuid.uuid4()}"}],
|
||||
)
|
||||
except Exception as e:
|
||||
# If there's an exception, log the error message
|
||||
with open("error_log.txt", "a") as error_log:
|
||||
error_log.write(f"Error during completion: {str(e)}. Tracbeack {traceback.format_exc()}\n, load_test ")
|
||||
pass
|
||||
|
||||
|
||||
|
||||
async def main():
|
||||
start = time.time()
|
||||
n = 1 # Number of concurrent tasks
|
||||
n = 500 # Number of concurrent tasks
|
||||
tasks = [litellm_completion() for _ in range(n)]
|
||||
|
||||
chat_completions = await asyncio.gather(*tasks)
|
||||
|
||||
successful_completions = [c for c in chat_completions if c is not None]
|
||||
|
||||
# Write errors to error_log.txt
|
||||
with open("error_log.txt", "a") as error_log:
|
||||
for completion in chat_completions:
|
||||
if isinstance(completion, str):
|
||||
error_log.write(completion + "\n")
|
||||
|
||||
print(n, time.time() - start, len(successful_completions))
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
# Blank out contents of error_log.txt
|
||||
open("error_log.txt", "w").close()
|
||||
|
||||
asyncio.run(main())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue