Skip to content

Commit

Permalink
small changes for perf test on new transaction storing system
Browse files Browse the repository at this point in the history
  • Loading branch information
sliwaszymon committed Jul 14, 2024
1 parent d38a719 commit 894f061
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 5 additions & 3 deletions backend/src/app/web_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1123,15 +1123,17 @@ async def mock_transactions(
:return: A dictionary containing the status and message (code and latency).
"""
time_start = datetime.now(tz=timezone.utc)
repo = ctx["transaction_repository"]
transactions_repo = ctx["transaction_repository"]
raw_transactions_repo = ctx["raw_transaction_repository"]

# Delete all transactions for project-test in order to avoid duplicates transactions keys
repo.delete_cascade(project_id="project-test")
transactions_repo.delete_cascade(project_id="project-test")

# generate random transactions, with different models and providers
mocked_transactions = utils.generate_mock_transactions(count, date_from, date_to)
for transaction in mocked_transactions:
repo.add(transaction)

transactions_repo.add(transaction)
time_stop = datetime.now(tz=timezone.utc)

return {
Expand Down
9 changes: 6 additions & 3 deletions backend/src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1619,13 +1619,13 @@ def generate_mock_transactions(n: int, date_from: datetime, date_to: datetime):
else 0
)
output_tokens = output_tokens if status == 200 else 0

input_cost, output_cost = random.uniform(0.00005, 0.05), random.uniform(
0.00005, 0.05
)
transactions.append(
Transaction(
id=transaction_id,
project_id="project-test",
request={},
response={},
tags=["tag1", "tag2", "tag3"],
provider=random.choice(providers),
model=random.choice(models),
Expand All @@ -1642,6 +1642,9 @@ def generate_mock_transactions(n: int, date_from: datetime, date_to: datetime):
request_time=start_date,
response_time=stop_date,
generation_speed=generation_speed,
input_cost=input_cost,
output_cost=output_cost,
total_cost=input_cost + output_cost,
)
)

Expand Down

0 comments on commit 894f061

Please sign in to comment.