Skip to content

Commit b851a07

Browse files
authored
backend: Remove metrics (#784)
* wip * Remove metrics code * add workflow * test * test * test * test * test * fix
1 parent f83b64b commit b851a07

File tree

23 files changed

+18
-1151
lines changed

23 files changed

+18
-1151
lines changed

.github/workflows/python-lint.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ jobs:
99
lint:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v4
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
clean: true
1317
- name: Run lint checks
1418
uses: chartboost/ruff-action@v1
1519
with:

.github/workflows/python-typecheck.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Typecheck
1+
name: Typecheck newly added Python files
22

33
on:
44
push:
@@ -13,10 +13,19 @@ jobs:
1313
- run: pipx install poetry
1414
- uses: actions/setup-python@v4
1515
with:
16-
python-version: '3.11'
16+
python-version: '3.11'
1717
cache: 'poetry'
1818
- run: poetry install
1919
- run: echo "$(poetry env info --path)/bin" >> $GITHUB_PATH
20-
- uses: jakebailey/pyright-action@v2
20+
- name: Get new files added in the PR
21+
id: get_new_files
22+
run: |
23+
git fetch origin main
24+
NEW_PY_FILES=$(git diff --name-only --diff-filter=A origin/main HEAD | grep '\.py$' | tr '\n' ' ')
25+
echo "New files: $NEW_PY_FILES"
26+
echo "new_py_files=$NEW_PY_FILES" >> $GITHUB_OUTPUT
27+
- name: Typecheck new files
28+
uses: jakebailey/pyright-action@v2
2129
with:
2230
version: 1.1.311
31+
extra-args: ${{ steps.get_new_files.outputs.new_py_files }}

helper_scripts/metrics_helper.py

Lines changed: 0 additions & 170 deletions
This file was deleted.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ build-backend = "poetry.core.masonry.api"
109109
include = [
110110
"src/backend/services/metrics.py",
111111
"src/backend/tools/google_drive/sync/actions/",
112-
]
112+
]
113113
defineConstant = { DEBUG = true }
114114
reportMissingImports = true
115115
reportMissingTypeStubs = false

src/backend/config/tools.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
Don't forget to add the implementation to this AVAILABLE_TOOLS dictionary!
3232
"""
3333

34-
3534
class ToolName(StrEnum):
3635
Wiki_Retriever_LangChain = LangChainWikiRetriever.NAME
3736
Search_File = SearchFileTool.NAME

src/backend/main.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from backend.routers.user import router as user_router
3030
from backend.services.context import ContextMiddleware, get_context
3131
from backend.services.logger.middleware import LoggingMiddleware
32-
from backend.services.metrics import MetricsMiddleware
3332

3433
load_dotenv()
3534

@@ -81,7 +80,6 @@ def create_app():
8180
allow_headers=["*"],
8281
)
8382
app.add_middleware(LoggingMiddleware)
84-
app.add_middleware(MetricsMiddleware)
8583
app.add_middleware(ContextMiddleware) # This should be the first middleware
8684
app.add_exception_handler(SCIMException, scim_exception_handler)
8785

src/backend/model_deployments/azure.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from backend.model_deployments.utils import get_model_config_var
99
from backend.schemas.cohere_chat import CohereChatRequest
1010
from backend.schemas.context import Context
11-
from backend.services.metrics import collect_metrics_chat_stream, collect_metrics_rerank
1211

1312
AZURE_API_KEY_ENV_VAR = "AZURE_API_KEY"
1413
# Example URL: "https://<endpoint>.<region>.inference.ai.azure.com/v1"
@@ -69,7 +68,6 @@ async def invoke_chat(self, chat_request: CohereChatRequest) -> Any:
6968
)
7069
yield to_dict(response)
7170

72-
@collect_metrics_chat_stream
7371
async def invoke_chat_stream(
7472
self, chat_request: CohereChatRequest, ctx: Context, **kwargs
7573
) -> AsyncGenerator[Any, Any]:
@@ -80,7 +78,6 @@ async def invoke_chat_stream(
8078
for event in stream:
8179
yield to_dict(event)
8280

83-
@collect_metrics_rerank
8481
async def invoke_rerank(
8582
self, query: str, documents: List[Dict[str, Any]], ctx: Context
8683
) -> Any:

src/backend/model_deployments/bedrock.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from backend.model_deployments.utils import get_model_config_var
99
from backend.schemas.cohere_chat import CohereChatRequest
1010
from backend.schemas.context import Context
11-
from backend.services.metrics import collect_metrics_chat_stream, collect_metrics_rerank
1211

1312
BEDROCK_ACCESS_KEY_ENV_VAR = "BEDROCK_ACCESS_KEY"
1413
BEDROCK_SECRET_KEY_ENV_VAR = "BEDROCK_SECRET_KEY"
@@ -80,7 +79,6 @@ async def invoke_chat(self, chat_request: CohereChatRequest) -> Any:
8079
)
8180
yield to_dict(response)
8281

83-
@collect_metrics_chat_stream
8482
async def invoke_chat_stream(
8583
self, chat_request: CohereChatRequest, ctx: Context, **kwargs: Any
8684
) -> AsyncGenerator[Any, Any]:
@@ -95,7 +93,6 @@ async def invoke_chat_stream(
9593
for event in stream:
9694
yield to_dict(event)
9795

98-
@collect_metrics_rerank
9996
async def invoke_rerank(
10097
self, query: str, documents: List[Dict[str, Any]], ctx: Context
10198
) -> Any:

src/backend/model_deployments/cohere_platform.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from backend.schemas.cohere_chat import CohereChatRequest
1111
from backend.schemas.context import Context
1212
from backend.services.logger.utils import LoggerFactory
13-
from backend.services.metrics import collect_metrics_chat_stream, collect_metrics_rerank
1413

1514
COHERE_API_KEY_ENV_VAR = "COHERE_API_KEY"
1615
COHERE_ENV_VARS = [COHERE_API_KEY_ENV_VAR]
@@ -73,7 +72,6 @@ async def invoke_chat(
7372
)
7473
yield to_dict(response)
7574

76-
@collect_metrics_chat_stream
7775
async def invoke_chat_stream(
7876
self, chat_request: CohereChatRequest, ctx: Context, **kwargs: Any
7977
) -> Any:
@@ -96,7 +94,6 @@ async def invoke_chat_stream(
9694

9795
yield event_dict
9896

99-
@collect_metrics_rerank
10097
async def invoke_rerank(
10198
self, query: str, documents: List[Dict[str, Any]], ctx: Context, **kwargs: Any
10299
) -> Any:

src/backend/model_deployments/sagemaker.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from backend.model_deployments.utils import get_model_config_var
1010
from backend.schemas.cohere_chat import CohereChatRequest
1111
from backend.schemas.context import Context
12-
from backend.services.metrics import collect_metrics_chat_stream, collect_metrics_rerank
1312

1413
SAGE_MAKER_ACCESS_KEY_ENV_VAR = "SAGE_MAKER_ACCESS_KEY"
1514
SAGE_MAKER_SECRET_KEY_ENV_VAR = "SAGE_MAKER_SECRET_KEY"
@@ -93,7 +92,6 @@ def is_available(cls) -> bool:
9392
and SageMakerDeployment.aws_session_token is not None
9493
)
9594

96-
@collect_metrics_chat_stream
9795
async def invoke_chat_stream(
9896
self, chat_request: CohereChatRequest, ctx: Context, **kwargs: Any
9997
) -> AsyncGenerator[Any, Any]:
@@ -115,7 +113,6 @@ async def invoke_chat_stream(
115113
stream_event["index"] = index
116114
yield stream_event
117115

118-
@collect_metrics_rerank
119116
async def invoke_rerank(
120117
self, query: str, documents: List[Dict[str, Any]], ctx: Context
121118
) -> Any:

0 commit comments

Comments
 (0)