Skip to content

Commit

Permalink
backend: Remove metrics (#784)
Browse files Browse the repository at this point in the history
* wip

* Remove metrics code

* add workflow

* test

* test

* test

* test

* test

* fix
  • Loading branch information
tianjing-li authored Sep 26, 2024
1 parent f83b64b commit b851a07
Show file tree
Hide file tree
Showing 23 changed files with 18 additions and 1,151 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/python-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
clean: true
- name: Run lint checks
uses: chartboost/ruff-action@v1
with:
Expand Down
15 changes: 12 additions & 3 deletions .github/workflows/python-typecheck.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Typecheck
name: Typecheck newly added Python files

on:
push:
Expand All @@ -13,10 +13,19 @@ jobs:
- run: pipx install poetry
- uses: actions/setup-python@v4
with:
python-version: '3.11'
python-version: '3.11'
cache: 'poetry'
- run: poetry install
- run: echo "$(poetry env info --path)/bin" >> $GITHUB_PATH
- uses: jakebailey/pyright-action@v2
- name: Get new files added in the PR
id: get_new_files
run: |
git fetch origin main
NEW_PY_FILES=$(git diff --name-only --diff-filter=A origin/main HEAD | grep '\.py$' | tr '\n' ' ')
echo "New files: $NEW_PY_FILES"
echo "new_py_files=$NEW_PY_FILES" >> $GITHUB_OUTPUT
- name: Typecheck new files
uses: jakebailey/pyright-action@v2
with:
version: 1.1.311
extra-args: ${{ steps.get_new_files.outputs.new_py_files }}
170 changes: 0 additions & 170 deletions helper_scripts/metrics_helper.py

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ build-backend = "poetry.core.masonry.api"
include = [
"src/backend/services/metrics.py",
"src/backend/tools/google_drive/sync/actions/",
]
]
defineConstant = { DEBUG = true }
reportMissingImports = true
reportMissingTypeStubs = false
Expand Down
1 change: 0 additions & 1 deletion src/backend/config/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
Don't forget to add the implementation to this AVAILABLE_TOOLS dictionary!
"""


class ToolName(StrEnum):
Wiki_Retriever_LangChain = LangChainWikiRetriever.NAME
Search_File = SearchFileTool.NAME
Expand Down
2 changes: 0 additions & 2 deletions src/backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from backend.routers.user import router as user_router
from backend.services.context import ContextMiddleware, get_context
from backend.services.logger.middleware import LoggingMiddleware
from backend.services.metrics import MetricsMiddleware

load_dotenv()

Expand Down Expand Up @@ -81,7 +80,6 @@ def create_app():
allow_headers=["*"],
)
app.add_middleware(LoggingMiddleware)
app.add_middleware(MetricsMiddleware)
app.add_middleware(ContextMiddleware) # This should be the first middleware
app.add_exception_handler(SCIMException, scim_exception_handler)

Expand Down
3 changes: 0 additions & 3 deletions src/backend/model_deployments/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from backend.model_deployments.utils import get_model_config_var
from backend.schemas.cohere_chat import CohereChatRequest
from backend.schemas.context import Context
from backend.services.metrics import collect_metrics_chat_stream, collect_metrics_rerank

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

@collect_metrics_chat_stream
async def invoke_chat_stream(
self, chat_request: CohereChatRequest, ctx: Context, **kwargs
) -> AsyncGenerator[Any, Any]:
Expand All @@ -80,7 +78,6 @@ async def invoke_chat_stream(
for event in stream:
yield to_dict(event)

@collect_metrics_rerank
async def invoke_rerank(
self, query: str, documents: List[Dict[str, Any]], ctx: Context
) -> Any:
Expand Down
3 changes: 0 additions & 3 deletions src/backend/model_deployments/bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from backend.model_deployments.utils import get_model_config_var
from backend.schemas.cohere_chat import CohereChatRequest
from backend.schemas.context import Context
from backend.services.metrics import collect_metrics_chat_stream, collect_metrics_rerank

BEDROCK_ACCESS_KEY_ENV_VAR = "BEDROCK_ACCESS_KEY"
BEDROCK_SECRET_KEY_ENV_VAR = "BEDROCK_SECRET_KEY"
Expand Down Expand Up @@ -80,7 +79,6 @@ async def invoke_chat(self, chat_request: CohereChatRequest) -> Any:
)
yield to_dict(response)

@collect_metrics_chat_stream
async def invoke_chat_stream(
self, chat_request: CohereChatRequest, ctx: Context, **kwargs: Any
) -> AsyncGenerator[Any, Any]:
Expand All @@ -95,7 +93,6 @@ async def invoke_chat_stream(
for event in stream:
yield to_dict(event)

@collect_metrics_rerank
async def invoke_rerank(
self, query: str, documents: List[Dict[str, Any]], ctx: Context
) -> Any:
Expand Down
3 changes: 0 additions & 3 deletions src/backend/model_deployments/cohere_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from backend.schemas.cohere_chat import CohereChatRequest
from backend.schemas.context import Context
from backend.services.logger.utils import LoggerFactory
from backend.services.metrics import collect_metrics_chat_stream, collect_metrics_rerank

COHERE_API_KEY_ENV_VAR = "COHERE_API_KEY"
COHERE_ENV_VARS = [COHERE_API_KEY_ENV_VAR]
Expand Down Expand Up @@ -73,7 +72,6 @@ async def invoke_chat(
)
yield to_dict(response)

@collect_metrics_chat_stream
async def invoke_chat_stream(
self, chat_request: CohereChatRequest, ctx: Context, **kwargs: Any
) -> Any:
Expand All @@ -96,7 +94,6 @@ async def invoke_chat_stream(

yield event_dict

@collect_metrics_rerank
async def invoke_rerank(
self, query: str, documents: List[Dict[str, Any]], ctx: Context, **kwargs: Any
) -> Any:
Expand Down
3 changes: 0 additions & 3 deletions src/backend/model_deployments/sagemaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from backend.model_deployments.utils import get_model_config_var
from backend.schemas.cohere_chat import CohereChatRequest
from backend.schemas.context import Context
from backend.services.metrics import collect_metrics_chat_stream, collect_metrics_rerank

SAGE_MAKER_ACCESS_KEY_ENV_VAR = "SAGE_MAKER_ACCESS_KEY"
SAGE_MAKER_SECRET_KEY_ENV_VAR = "SAGE_MAKER_SECRET_KEY"
Expand Down Expand Up @@ -93,7 +92,6 @@ def is_available(cls) -> bool:
and SageMakerDeployment.aws_session_token is not None
)

@collect_metrics_chat_stream
async def invoke_chat_stream(
self, chat_request: CohereChatRequest, ctx: Context, **kwargs: Any
) -> AsyncGenerator[Any, Any]:
Expand All @@ -115,7 +113,6 @@ async def invoke_chat_stream(
stream_event["index"] = index
yield stream_event

@collect_metrics_rerank
async def invoke_rerank(
self, query: str, documents: List[Dict[str, Any]], ctx: Context
) -> Any:
Expand Down
3 changes: 0 additions & 3 deletions src/backend/model_deployments/single_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from backend.model_deployments.utils import get_model_config_var
from backend.schemas.cohere_chat import CohereChatRequest
from backend.schemas.context import Context
from backend.services.metrics import collect_metrics_chat_stream, collect_metrics_rerank

DEFAULT_RERANK_MODEL = "rerank-english-v2.0"
SC_URL_ENV_VAR = "SINGLE_CONTAINER_URL"
Expand Down Expand Up @@ -61,7 +60,6 @@ async def invoke_chat(self, chat_request: CohereChatRequest) -> Any:
)
yield to_dict(response)

@collect_metrics_chat_stream
async def invoke_chat_stream(
self, chat_request: CohereChatRequest, ctx: Context, **kwargs: Any
) -> AsyncGenerator[Any, Any]:
Expand All @@ -74,7 +72,6 @@ async def invoke_chat_stream(
for event in stream:
yield to_dict(event)

@collect_metrics_rerank
async def invoke_rerank(
self, query: str, documents: List[Dict[str, Any]], ctx: Context
) -> Any:
Expand Down
Loading

0 comments on commit b851a07

Please sign in to comment.