Skip to content

Commit

Permalink
Merge pull request #26 from PromptSail/dev
Browse files Browse the repository at this point in the history
Enhancements: Error handlings, UI/UX Updates, and New Features
  • Loading branch information
ksopyla authored Apr 11, 2024
2 parents d5414cc + e25d9e3 commit 44b2fc9
Show file tree
Hide file tree
Showing 23 changed files with 1,065 additions and 555 deletions.
38 changes: 30 additions & 8 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ jobs:
steps:
- name: set datetime env
run: echo "NOW=$(date +'%Y.%m.%d')" >> $GITHUB_ENV

- name: Set RELEASE_TAG based on branch name and release tag
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "RELEASE_TAG=release_candidate" >> $GITHUB_ENV
elif [[ "${{ github.event.release.tag_name }}" != "" ]]; then
echo "RELEASE_TAG=latest" >> $GITHUB_ENV
else
echo "RELEASE_TAG=non-release" >> $GITHUB_ENV
fi
- name: Use RELEASE_TAG
run: echo "RELEASE_TAG is ${{ env.RELEASE_TAG }}"

- name: Checkout repository
uses: actions/checkout@v3
Expand Down Expand Up @@ -142,10 +155,8 @@ jobs:
tags: |
${{ env.IMAGE_URI }}/${{ env.IMAGE_NAME_BACKEND }}:${{ github.sha }}
${{ env.IMAGE_URI }}/${{ env.IMAGE_NAME_BACKEND }}:${{ github.run_number }}
${{ env.IMAGE_URI }}/${{ env.IMAGE_NAME_BACKEND }}:${{ env.NOW }}
${{ env.IMAGE_URI }}/${{ env.IMAGE_NAME_BACKEND }}:${{ github.event.release.tag_name || 'non-release' }}
${{ env.IMAGE_URI }}/${{ env.IMAGE_NAME_BACKEND }}:${{ github.event.release.tag_name && 'latest'|| 'non-release' }}
${{ env.IMAGE_URI }}/${{ env.IMAGE_NAME_BACKEND }}:${{ github.ref == 'refs/heads/main' && 'latest' || 'dev' }}
${{ env.IMAGE_URI }}/${{ env.IMAGE_NAME_BACKEND }}:${{ github.event.release.tag_name || env.RELEASE_TAG }}
${{ env.IMAGE_URI }}/${{ env.IMAGE_NAME_BACKEND }}:${{ env.RELEASE_TAG }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
Expand Down Expand Up @@ -183,6 +194,19 @@ jobs:

- name: set datetime env
run: echo "NOW=$(date +'%Y.%m.%d')" >> $GITHUB_ENV

- name: Set RELEASE_TAG based on branch name and release tag
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "RELEASE_TAG=release_candidate" >> $GITHUB_ENV
elif [[ "${{ github.event.release.tag_name }}" != "" ]]; then
echo "RELEASE_TAG=latest" >> $GITHUB_ENV
else
echo "RELEASE_TAG=non-release" >> $GITHUB_ENV
fi
- name: Use RELEASE_TAG
run: echo "RELEASE_TAG is ${{ env.RELEASE_TAG }}"
- name: Checkout repository
uses: actions/checkout@v3

Expand Down Expand Up @@ -232,10 +256,8 @@ jobs:
tags: |
${{ env.IMAGE_URI }}/${{ env.IMAGE_NAME_UI }}:${{ github.sha }}
${{ env.IMAGE_URI }}/${{ env.IMAGE_NAME_UI }}:${{ github.run_number }}
${{ env.IMAGE_URI }}/${{ env.IMAGE_NAME_UI }}:${{ env.NOW }}
${{ env.IMAGE_URI }}/${{ env.IMAGE_NAME_UI }}:${{ github.event.release.tag_name || 'non-release' }}
${{ env.IMAGE_URI }}/${{ env.IMAGE_NAME_UI }}:${{ github.event.release.tag_name && 'latest'|| 'non-release' }}
${{ env.IMAGE_URI }}/${{ env.IMAGE_NAME_UI }}:${{ github.ref == 'refs/heads/main' && 'latest' || 'dev' }}
${{ env.IMAGE_URI }}/${{ env.IMAGE_NAME_UI }}:${{ github.event.release.tag_name || env.RELEASE_TAG }}
${{ env.IMAGE_URI }}/${{ env.IMAGE_NAME_UI }}:${{ env.RELEASE_TAG }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,6 @@ cython_debug/
.python-version
.vscode/launch.json
.vscode/settings.json
poetry.lock
backend/poetry.lock
**/.env
private_examples/*
24 changes: 8 additions & 16 deletions backend/provider_price_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,24 +179,24 @@
"model_name": "gpt-3.5-turbo",
"start_date": "2023-11-06",
"match_pattern": "(?i)^(gpt-)(35|3.5)(-turbo)$",
"input_price": 0.0005,
"output_price": 0.0015,
"input_price": 0.0010,
"output_price": 0.0020,
"total_price": 0
},
{
"model_name": "gpt-3.5-turbo",
"start_date": "2023-06-27",
"match_pattern": "(?i)^(gpt-)(35|3.5)(-turbo)$",
"input_price": 0.0005,
"output_price": 0.0015,
"input_price": 0.0015,
"output_price": 0.0020,
"total_price": 0
},
{
"model_name": "gpt-3.5-turbo",
"start_date": "",
"match_pattern": "(?i)^(gpt-)(35|3.5)(-turbo)$",
"input_price": 0.0005,
"output_price": 0.0015,
"input_price": 0.0015,
"output_price": 0.0020,
"total_price": 0
},
{
Expand All @@ -211,8 +211,8 @@
"model_name": "gpt-3.5-turbo-0301",
"start_date": "",
"match_pattern": "(?i)^(gpt-)(35|3.5)(-turbo-0301)$",
"input_price": 0.002,
"output_price": 0.002,
"input_price": 0.0015,
"output_price": 0.0020,
"total_price": 0
},
{
Expand All @@ -231,14 +231,6 @@
"output_price": 0.002,
"total_price": 0
},
{
"model_name": "gpt-3.5-turbo-16k",
"start_date": "2024-02-16",
"match_pattern": "(?i)^(gpt-)(35|3.5)(-turbo-16k)$",
"input_price": 0.0005,
"output_price": 0.0015,
"total_price": 0
},
{
"model_name": "gpt-3.5-turbo-16k",
"start_date": "",
Expand Down
2 changes: 1 addition & 1 deletion backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ authors = ["Przemysław Górecki <[email protected]>, Krzysztof Sopy

[tool.poetry.dependencies]
python = "^3.10"
fastapi = "^0.103.2"
uvicorn = {extras = ["stable"], version = "^0.23.2"}
httpx = "^0.25.0"
python-dotenv = "^1.0.0"
Expand All @@ -18,6 +17,7 @@ brotli = "^1.1.0"
pandas = "^2.2.1"
lato = "^0.8.0"
python-slugify = "^8.0.4"
fastapi = "^0.110.1"



Expand Down
30 changes: 26 additions & 4 deletions backend/src/app/web_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
from slugify import slugify
from transactions.models import generate_uuid
from transactions.schemas import (
GetTransactionLatencyStatisticsSchema,
GetTransactionPageResponseSchema,
GetTransactionStatusStatisticsSchema,
GetTransactionsUsageStatisticsSchema,
GetTransactionUsageStatisticsWithoutDateSchema,
GetTransactionWithProjectSlugSchema,
StatisticTransactionSchema,
StatisticTransactionSchema, GetTransactionsLatencyStatisticsSchema,
GetTransactionLatencyStatisticsWithoutDateSchema,
)
from transactions.use_cases import (
count_token_usage_for_project,
Expand Down Expand Up @@ -446,6 +446,7 @@ async def get_transaction_usage_statistics_over_time(
project_id=project_id,
date_from=date_from,
date_to=date_to,
status_code=200
)
transactions = [
StatisticTransactionSchema(
Expand Down Expand Up @@ -590,7 +591,7 @@ async def get_transaction_latency_statistics_over_time(
date_from: datetime | str | None = None,
date_to: datetime | str | None = None,
period: utils.PeriodEnum = utils.PeriodEnum.day,
) -> list[GetTransactionLatencyStatisticsSchema]:
) -> list[GetTransactionsLatencyStatisticsSchema]:
"""
Compute mean transactions generation speed and latency statistics over a specified time period.\n
Expand Down Expand Up @@ -623,6 +624,7 @@ async def get_transaction_latency_statistics_over_time(
project_id=project_id,
date_from=date_from,
date_to=date_to,
status_code=200
)
transactions = [
StatisticTransactionSchema(
Expand All @@ -644,8 +646,28 @@ async def get_transaction_latency_statistics_over_time(
stats = utils.speed_counter_for_transactions(
transactions, period, date_from, date_to
)

dates = [stat.date for stat in stats]
new_stats = []
for date in set(dates):
for_date = []
for stat in stats:
if stat.date == date:
for_date.append(
GetTransactionLatencyStatisticsWithoutDateSchema(
provider=stat.provider,
model=stat.model,
mean_latency=stat.mean_latency,
tokens_per_second=stat.tokens_per_second,
total_transactions=stat.total_transactions
)
)
new_stats.append(
GetTransactionsLatencyStatisticsSchema(date=date, records=for_date)
)
new_stats.sort(key=lambda statistic: statistic.date)

return stats
return new_stats


@app.get("/api/statistics/pricelist", response_class=JSONResponse)
Expand Down
15 changes: 14 additions & 1 deletion backend/src/transactions/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class GetTransactionStatusStatisticsSchema(BaseModel):
status_500: int
total_transactions: int


class GetTransactionLatencyStatisticsSchema(BaseModel):
provider: str
model: str
Expand All @@ -113,6 +113,19 @@ class GetTransactionLatencyStatisticsSchema(BaseModel):
total_transactions: int


class GetTransactionLatencyStatisticsWithoutDateSchema(BaseModel):
provider: str
model: str
mean_latency: timedelta | int | float
tokens_per_second: int | float
total_transactions: int


class GetTransactionsLatencyStatisticsSchema(BaseModel):
date: datetime
records: list[GetTransactionLatencyStatisticsWithoutDateSchema]


class GetTransactionPageResponseSchema(BaseModel):
items: list[GetTransactionWithProjectSlugSchema]
page_index: int
Expand Down
4 changes: 3 additions & 1 deletion backend/src/transactions/use_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ def get_list_of_filtered_transactions(
date_from: datetime,
date_to: datetime,
transaction_repository: TransactionRepository,
status_code: int | None = None,
) -> list[Transaction]:
"""
Retrieve a list of transactions filtered by project ID and date range.
Expand All @@ -226,10 +227,11 @@ def get_list_of_filtered_transactions(
:param date_from: The starting date for the filter.
:param date_to: The ending date for the filter.
:param transaction_repository: An instance of TransactionRepository for data retrieval.
:param status_code: The transactions' status code.
:return: A list of Transaction objects that meet the specified criteria.
"""
query = create_transaction_query_from_filters(
date_from=date_from, date_to=date_to, project_id=project_id
date_from=date_from, date_to=date_to, project_id=project_id, status_code=status_code
)
transactions = transaction_repository.get_filtered(query)
return transactions
Loading

0 comments on commit 44b2fc9

Please sign in to comment.