Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit b820548

Browse files
committed
Merge branch 'main' into issue-1020
2 parents 0fd96dc + a9951dd commit b820548

File tree

9 files changed

+203
-62
lines changed

9 files changed

+203
-62
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ wheels/
2222

2323
# Virtual Environment
2424
venv/
25+
.venv/
2526
env/
2627
ENV/
2728

poetry.lock

Lines changed: 175 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ PyYAML = "==6.0.2"
1414
fastapi = "==0.115.11"
1515
uvicorn = "==0.34.0"
1616
structlog = "==25.1.0"
17-
litellm = "==1.61.20"
17+
litellm = "==1.62.1"
1818
llama_cpp_python = "==0.3.5"
1919
cryptography = "==44.0.2"
2020
sqlalchemy = "==2.0.38"
@@ -50,7 +50,7 @@ ruff = "==0.9.9"
5050
bandit = "==1.8.3"
5151
build = "==1.2.2.post1"
5252
wheel = "==0.45.1"
53-
litellm = "==1.61.20"
53+
litellm = "==1.62.1"
5454
pytest-asyncio = "==0.25.3"
5555
llama_cpp_python = "==0.3.5"
5656
scikit-learn = "==1.6.1"

src/codegate/api/v1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, List, Optional
1+
from typing import List, Optional
22
from uuid import UUID
33

44
import requests
@@ -8,10 +8,10 @@
88
from fastapi.routing import APIRoute
99
from pydantic import BaseModel, ValidationError
1010

11-
from codegate.config import API_DEFAULT_PAGE_SIZE, API_MAX_PAGE_SIZE
1211
import codegate.muxing.models as mux_models
1312
from codegate import __version__
1413
from codegate.api import v1_models, v1_processing
14+
from codegate.config import API_DEFAULT_PAGE_SIZE, API_MAX_PAGE_SIZE
1515
from codegate.db.connection import AlreadyExistsError, DbReader
1616
from codegate.db.models import AlertSeverity, WorkspaceWithModel
1717
from codegate.providers import crud as provendcrud

src/codegate/db/connection.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
import json
33
import uuid
44
from pathlib import Path
5-
from typing import Dict, List, Optional, Tuple, Type
5+
from typing import Dict, List, Optional, Type
66

77
import structlog
88
from alembic import command as alembic_command
99
from alembic.config import Config as AlembicConfig
1010
from pydantic import BaseModel
11-
from sqlalchemy import CursorResult, TextClause, bindparam, event, text
11+
from sqlalchemy import CursorResult, TextClause, event, text
1212
from sqlalchemy.engine import Engine
1313
from sqlalchemy.exc import IntegrityError, OperationalError
1414
from sqlalchemy.ext.asyncio import create_async_engine
@@ -627,10 +627,10 @@ async def get_prompts_with_output_alerts_usage_by_workspace_id(
627627
conditions["limit"] = limit
628628
conditions["offset"] = offset
629629

630-
fetched_rows: List[IntermediatePromptWithOutputUsageAlerts] = (
631-
await self._exec_select_conditions_to_pydantic(
632-
IntermediatePromptWithOutputUsageAlerts, sql, conditions, should_raise=True
633-
)
630+
fetched_rows: List[
631+
IntermediatePromptWithOutputUsageAlerts
632+
] = await self._exec_select_conditions_to_pydantic(
633+
IntermediatePromptWithOutputUsageAlerts, sql, conditions, should_raise=True
634634
)
635635
prompts_dict: Dict[str, GetPromptWithOutputsRow] = {}
636636
for row in fetched_rows:
@@ -668,7 +668,7 @@ async def get_prompts_with_output_alerts_usage_by_workspace_id(
668668
async def get_total_messages_count_by_workspace_id(
669669
self, workspace_id: str, trigger_category: Optional[str] = None
670670
) -> int:
671-
"""Get total count of messages for a given workspace_id, considering trigger_category if provided."""
671+
"""Get total count of messages for a given workspace_id, considering trigger_category."""
672672
sql = text(
673673
"""
674674
SELECT COUNT(*)

src/codegate/muxing/rulematcher.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import copy
2+
import fnmatch
23
from abc import ABC, abstractmethod
34
from asyncio import Lock
45
from typing import Dict, List, Optional
@@ -116,16 +117,16 @@ def _extract_request_filenames(self, detected_client: ClientType, data: dict) ->
116117
def _is_matcher_in_filenames(self, detected_client: ClientType, data: dict) -> bool:
117118
"""
118119
Check if the matcher is in the request filenames.
120+
The matcher is treated as a glob pattern and matched against the filenames.
119121
"""
120122
# Empty matcher_blob means we match everything
121123
if not self._mux_rule.matcher:
122124
return True
123125
filenames_to_match = self._extract_request_filenames(detected_client, data)
124-
# _mux_rule.matcher can be a filename or a file extension. We match if any of the filenames
125-
# match the rule.
126+
# _mux_rule.matcher is a glob pattern. We match if any of the filenames
127+
# match the pattern.
126128
is_filename_match = any(
127-
self._mux_rule.matcher == filename or filename.endswith(self._mux_rule.matcher)
128-
for filename in filenames_to_match
129+
fnmatch.fnmatch(filename, self._mux_rule.matcher) for filename in filenames_to_match
129130
)
130131
return is_filename_match
131132

src/codegate/providers/crud/crud.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ async def try_update_to_provider(
401401
dbprovend.endpoint, authm.auth_type, authm.auth_blob, prov
402402
)
403403
except Exception as err:
404-
logger.error(
404+
logger.info(
405405
"Unable to get models from provider. Skipping",
406406
provider=dbprovend.name,
407407
err=str(err),

tests/integration/integration_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ async def _setup_muxing(
231231
provider_endpoint = muxing_config.get("provider_endpoint")
232232
try:
233233
data_with_api_keys = self.replace_env_variables(provider_endpoint["data"], os.environ)
234-
response_create_provider = self.call_codegate(
234+
response_create_provider = self.call_provider(
235235
provider=provider,
236236
url=provider_endpoint["url"],
237237
headers=provider_endpoint["headers"],
@@ -250,7 +250,7 @@ async def _setup_muxing(
250250
mux["provider_id"] = created_provider_endpoint["id"]
251251

252252
# The endpoint actually takes a list
253-
self.call_codegate(
253+
self.call_provider(
254254
provider=provider,
255255
url=muxes_rules["url"],
256256
headers=muxes_rules["headers"],

tests/muxing/test_rulematcher.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ def test_catch_all(matcher_blob, thing_to_match):
5151
[
5252
(None, [], True), # Empty filenames and no blob
5353
(None, ["main.py"], True), # Empty blob should match
54-
(".py", ["main.py"], True), # Extension match
54+
("*.py", ["main.py"], True), # Extension match
5555
("main.py", ["main.py"], True), # Full name match
56-
(".py", ["main.py", "test.py"], True), # Extension match
56+
("*.py", ["main.py", "test.py"], True), # Extension match
5757
("main.py", ["main.py", "test.py"], True), # Full name match
5858
("main.py", ["test.py"], False), # Full name no match
59-
(".js", ["main.py", "test.py"], False), # Extension no match
60-
(".ts", ["main.tsx", "test.tsx"], False), # Extension no match
59+
("*.js", ["main.py", "test.py"], False), # Extension no match
60+
("*.ts", ["main.tsx", "test.tsx"], False), # Extension no match
6161
],
6262
)
6363
def test_file_matcher(
@@ -89,13 +89,13 @@ def test_file_matcher(
8989
[
9090
(None, [], True), # Empty filenames and no blob
9191
(None, ["main.py"], True), # Empty blob should match
92-
(".py", ["main.py"], True), # Extension match
92+
("*.py", ["main.py"], True), # Extension match
9393
("main.py", ["main.py"], True), # Full name match
94-
(".py", ["main.py", "test.py"], True), # Extension match
94+
("*.py", ["main.py", "test.py"], True), # Extension match
9595
("main.py", ["main.py", "test.py"], True), # Full name match
9696
("main.py", ["test.py"], False), # Full name no match
97-
(".js", ["main.py", "test.py"], False), # Extension no match
98-
(".ts", ["main.tsx", "test.tsx"], False), # Extension no match
97+
("*.js", ["main.py", "test.py"], False), # Extension no match
98+
("*.ts", ["main.tsx", "test.tsx"], False), # Extension no match
9999
],
100100
)
101101
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)