Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .turbo/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"team": "agenta", "apiUrl": "http://localhost:3040"}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ def create_default_project_for_workspaces(session: Connection):
for workspace in workspaces:
# Create a new default project for each workspace
get_or_create_workspace_default_project(
session=session,
workspace=workspace, # type: ignore
session=session, workspace=workspace # type: ignore
)

# Commit the changes for the current batch
Expand Down
10 changes: 4 additions & 6 deletions api/ee/databases/postgres/migrations/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ async def get_current_migration_head_from_db(engine: AsyncEngine):

async with engine.connect() as connection:
try:
result = await connection.execute(
text("SELECT version_num FROM alembic_version")
) # type: ignore
result = await connection.execute(text("SELECT version_num FROM alembic_version")) # type: ignore
except (asyncpg.exceptions.UndefinedTableError, ProgrammingError):
# Note: If the alembic_version table does not exist, it will result in raising an UndefinedTableError exception.
# We need to suppress the error and return a list with the alembic_version table name to inform the user that there is a pending migration \
Expand All @@ -85,9 +83,9 @@ async def get_current_migration_head_from_db(engine: AsyncEngine):
return "alembic_version"

migration_heads = [row[0] for row in result.fetchall()]
assert len(migration_heads) == 1, (
"There can only be one migration head stored in the database."
)
assert (
len(migration_heads) == 1
), "There can only be one migration head stored in the database."
return migration_heads[0]


Expand Down
10 changes: 4 additions & 6 deletions api/ee/databases/postgres/migrations/tracing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ async def get_current_migration_head_from_db(engine: AsyncEngine):

async with engine.connect() as connection:
try:
result = await connection.execute(
text("SELECT version_num FROM alembic_version")
) # type: ignore
result = await connection.execute(text("SELECT version_num FROM alembic_version")) # type: ignore
except (asyncpg.exceptions.UndefinedTableError, ProgrammingError):
# Note: If the alembic_version table does not exist, it will result in raising an UndefinedTableError exception.
# We need to suppress the error and return a list with the alembic_version table name to inform the user that there is a pending migration \
Expand All @@ -78,9 +76,9 @@ async def get_current_migration_head_from_db(engine: AsyncEngine):
return "alembic_version"

migration_heads = [row[0] for row in result.fetchall()]
assert len(migration_heads) == 1, (
"There can only be one migration head stored in the database."
)
assert (
len(migration_heads) == 1
), "There can only be one migration head stored in the database."
return migration_heads[0]


Expand Down
2 changes: 1 addition & 1 deletion api/ee/src/apis/fastapi/billing/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

stripe.api_key = environ.get("STRIPE_API_KEY")

MAC_ADDRESS = ":".join(f"{(getnode() >> ele) & 0xFF:02x}" for ele in range(40, -1, -8))
MAC_ADDRESS = ":".join(f"{(getnode() >> ele) & 0xff:02x}" for ele in range(40, -1, -8))
STRIPE_WEBHOOK_SECRET = environ.get("STRIPE_WEBHOOK_SECRET")
STRIPE_TARGET = environ.get("STRIPE_TARGET") or MAC_ADDRESS
AGENTA_PRICING = loads(environ.get("AGENTA_PRICING") or "{}")
Expand Down
2 changes: 1 addition & 1 deletion api/ee/src/core/subscriptions/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

stripe.api_key = environ.get("STRIPE_SECRET_KEY")

MAC_ADDRESS = ":".join(f"{(getnode() >> ele) & 0xFF:02x}" for ele in range(40, -1, -8))
MAC_ADDRESS = ":".join(f"{(getnode() >> ele) & 0xff:02x}" for ele in range(40, -1, -8))
STRIPE_TARGET = environ.get("STRIPE_TARGET") or MAC_ADDRESS
AGENTA_PRICING = loads(environ.get("AGENTA_PRICING") or "{}")

Expand Down
4 changes: 3 additions & 1 deletion api/ee/src/services/db_manager_ee.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,9 @@ async def remove_user_from_workspace(
project = await db_manager.get_project_by_id(project_id=project_id)

async with engine.core_session() as session:
if not user: # User is an invited user who has not yet created an account and therefore does not have a user object
if (
not user
): # User is an invited user who has not yet created an account and therefore does not have a user object
pass
else:
# Ensure that a user can not remove the owner of the workspace
Expand Down
6 changes: 3 additions & 3 deletions api/ee/src/services/workspace_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ async def accept_workspace_invitation(

invitation = await check_valid_invitation(project_id, user.email, token)
if invitation is not None:
assert invitation.role is not None, (
"Invitation does not have any workspace role"
)
assert (
invitation.role is not None
), "Invitation does not have any workspace role"
await db_manager_ee.add_user_to_workspace_and_org(
organization, workspace, user, project_id, invitation.role
)
Expand Down
36 changes: 18 additions & 18 deletions api/ee/src/utils/entitlements.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,25 @@ class EntitlementsException(Exception):
pass


NOT_ENTITLED_RESPONSE: Callable[[Tracker], JSONResponse] = (
lambda tracker=None: JSONResponse(
status_code=403,
content={
"detail": (
"You have reached your monthly quota limit. Please upgrade your plan to continue."
if tracker == Tracker.COUNTERS
NOT_ENTITLED_RESPONSE: Callable[
[Tracker], JSONResponse
] = lambda tracker=None: JSONResponse(
status_code=403,
content={
"detail": (
"You have reached your monthly quota limit. Please upgrade your plan to continue."
if tracker == Tracker.COUNTERS
else (
"You have reached your quota limit. Please upgrade your plan to continue."
if tracker == Tracker.GAUGES
else (
"You have reached your quota limit. Please upgrade your plan to continue."
if tracker == Tracker.GAUGES
else (
"You do not have access to this feature. Please upgrade your plan to continue."
if tracker == Tracker.FLAGS
else "You do not have access to this feature."
)
"You do not have access to this feature. Please upgrade your plan to continue."
if tracker == Tracker.FLAGS
else "You do not have access to this feature."
)
),
},
)
)
),
},
)


Expand Down Expand Up @@ -163,7 +163,7 @@ async def check_entitlements(

# TODO: remove this line
log.info(
f"adjusting: {organization_id} | {(('0' if (meter.month != 0 and meter.month < 10) else '') + str(meter.month)) if meter.month != 0 else ' '}.{meter.year if meter.year else ' '} | {'allow' if check else 'deny '} | {meter.key}: {meter.value - meter.synced} [{meter.value}]"
f"adjusting: {organization_id} | {(('0' if (meter.month != 0 and meter.month < 10) else '') + str(meter.month)) if meter.month != 0 else ' '}.{meter.year if meter.year else ' '} | {'allow' if check else 'deny '} | {meter.key}: {meter.value-meter.synced} [{meter.value}]"
)

return check is True, meter, _
24 changes: 12 additions & 12 deletions api/ee/src/utils/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,17 @@ async def check_rbac_permission(
bool: True if the user belongs to the workspace and has the specified permission, False otherwise.
"""

assert project_id is not None, (
"Project_ID is required to check object-level permissions"
)
assert (
project_id is not None
), "Project_ID is required to check object-level permissions"

# Assert that either permission or role is provided, but not both
assert (permission is not None) or (role is not None), (
"Either 'permission' or 'role' must be provided, but neither is provided"
)
assert not ((permission is not None) and (role is not None)), (
"'permission' and 'role' cannot both be provided at the same time"
)
assert (permission is not None) or (
role is not None
), "Either 'permission' or 'role' must be provided, but neither is provided"
assert not (
(permission is not None) and (role is not None)
), "'permission' and 'role' cannot both be provided at the same time"

if project_id is not None:
project = await db_manager.get_project_by_id(project_id)
Expand Down Expand Up @@ -281,9 +281,9 @@ async def check_project_has_role_or_permission(
if not check:
return True

assert role is not None or permission is not None, (
"Either role or permission must be provided"
)
assert (
role is not None or permission is not None
), "Either role or permission must be provided"

project_members = await db_manager_ee.get_project_members(
project_id=str(project.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ def add_default_evaluators_to_project(session: Session, project_id: str):
}

for setting_name, default_value in settings_values.items():
assert default_value != "", (
f"Default value for ground truth key '{setting_name}' in Evaluator is empty"
)
assert (
default_value != ""
), f"Default value for ground truth key '{setting_name}' in Evaluator is empty"

assert hasattr(evaluator, "name") and hasattr(evaluator, "key"), (
f"'name' and 'key' does not exist in the evaluator: {evaluator}"
)
assert hasattr(evaluator, "name") and hasattr(
evaluator, "key"
), f"'name' and 'key' does not exist in the evaluator: {evaluator}"

evaluator_config = EvaluatorConfigDB(
project_id=uuid.UUID(project_id),
Expand Down
10 changes: 4 additions & 6 deletions api/oss/databases/postgres/migrations/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ async def get_current_migration_head_from_db(engine: AsyncEngine):

async with engine.connect() as connection:
try:
result = await connection.execute(
text("SELECT version_num FROM alembic_version")
) # type: ignore
result = await connection.execute(text("SELECT version_num FROM alembic_version")) # type: ignore
except (asyncpg.exceptions.UndefinedTableError, ProgrammingError):
# Note: If the alembic_version table does not exist, it will result in raising an UndefinedTableError exception.
# We need to suppress the error and return a list with the alembic_version table name to inform the user that there is a pending migration \
Expand All @@ -85,9 +83,9 @@ async def get_current_migration_head_from_db(engine: AsyncEngine):
return "alembic_version"

migration_heads = [row[0] for row in result.fetchall()]
assert len(migration_heads) == 1, (
"There can only be one migration head stored in the database."
)
assert (
len(migration_heads) == 1
), "There can only be one migration head stored in the database."
return migration_heads[0]


Expand Down
10 changes: 4 additions & 6 deletions api/oss/databases/postgres/migrations/tracing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ async def get_current_migration_head_from_db(engine: AsyncEngine):

async with engine.connect() as connection:
try:
result = await connection.execute(
text("SELECT version_num FROM alembic_version")
) # type: ignore
result = await connection.execute(text("SELECT version_num FROM alembic_version")) # type: ignore
except (asyncpg.exceptions.UndefinedTableError, ProgrammingError):
# Note: If the alembic_version table does not exist, it will result in raising an UndefinedTableError exception.
# We need to suppress the error and return a list with the alembic_version table name to inform the user that there is a pending migration \
Expand All @@ -77,9 +75,9 @@ async def get_current_migration_head_from_db(engine: AsyncEngine):
return "alembic_version"

migration_heads = [row[0] for row in result.fetchall()]
assert len(migration_heads) == 1, (
"There can only be one migration head stored in the database."
)
assert (
len(migration_heads) == 1
), "There can only be one migration head stored in the database."
return migration_heads[0]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def process(self, attributes: CanonicalAttributes, features: SpanFeatures) -> No

# Exceptions - Rebuilt from attributes.events to match previous output structure
exception_events = attributes.get_events_by_name("exception")
if exception_events: # Process the first one if multiple exist, or adapt if all should be processed
if (
exception_events
): # Process the first one if multiple exist, or adapt if all should be processed
event_data = exception_events[0]
# Ensure timestamp is decoded and formatted as previously (likely to string by decode_value if it's datetime)
decoded_ts = decode_value(event_data.timestamp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ def process(self, bag: CanonicalAttributes, features: SpanFeatures) -> None:
and transformed_attributes.get("ag.metrics.unit.tokens.completion")
and not transformed_attributes.get("ag.metrics.unit.tokens.total")
):
transformed_attributes["ag.metrics.unit.tokens.total"] = (
transformed_attributes.get("ag.metrics.unit.tokens.prompt")
+ transformed_attributes.get("ag.metrics.unit.tokens.completion")
transformed_attributes[
"ag.metrics.unit.tokens.total"
] = transformed_attributes.get(
"ag.metrics.unit.tokens.prompt"
) + transformed_attributes.get(
"ag.metrics.unit.tokens.completion"
)
if not has_logfire_data:
return
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions api/oss/src/apis/fastapi/shared/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ def parse_metadata(
flags: Optional[str] = None,
tags: Optional[str] = None,
meta: Optional[str] = None,
) -> Tuple[
Optional[Flags],
Optional[Tags],
Optional[Meta],
]:
) -> Tuple[Optional[Flags], Optional[Tags], Optional[Meta],]:
_flags = None
try:
_flags = loads(flags) if flags else None
Expand Down
20 changes: 8 additions & 12 deletions api/oss/src/apis/fastapi/testsets/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,23 +1162,19 @@ async def fetch_simple_testset(
if testset is None:
return SimpleTestsetResponse()

testset_variant = (
await self.simple_testsets_service.testsets_service.fetch_testset_variant(
project_id=UUID(request.state.project_id),
#
testset_ref=Reference(id=testset.id),
)
testset_variant = await self.simple_testsets_service.testsets_service.fetch_testset_variant(
project_id=UUID(request.state.project_id),
#
testset_ref=Reference(id=testset.id),
)

if testset_variant is None:
return SimpleTestsetResponse()

testset_revision = (
await self.simple_testsets_service.testsets_service.fetch_testset_revision(
project_id=UUID(request.state.project_id),
#
testset_variant_ref=Reference(id=testset_variant.id),
)
testset_revision = await self.simple_testsets_service.testsets_service.fetch_testset_revision(
project_id=UUID(request.state.project_id),
#
testset_variant_ref=Reference(id=testset_variant.id),
)

if testset_revision is None:
Expand Down
20 changes: 8 additions & 12 deletions api/oss/src/core/annotations/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,10 @@ async def create(
)

if simple_evaluator:
evaluator_revision = (
await self.evaluators_service.fetch_evaluator_revision(
project_id=project_id,
#
evaluator_ref=Reference(id=simple_evaluator.id),
)
evaluator_revision = await self.evaluators_service.fetch_evaluator_revision(
project_id=project_id,
#
evaluator_ref=Reference(id=simple_evaluator.id),
)
elif evaluator_revision.evaluator_id:
simple_evaluator = await self.simple_evaluators_service.fetch(
Expand Down Expand Up @@ -335,12 +333,10 @@ async def edit(
)

if simple_evaluator:
evaluator_revision = (
await self.evaluators_service.fetch_evaluator_revision(
project_id=project_id,
#
evaluator_ref=Reference(id=simple_evaluator.id),
)
evaluator_revision = await self.evaluators_service.fetch_evaluator_revision(
project_id=project_id,
#
evaluator_ref=Reference(id=simple_evaluator.id),
)

if not evaluator_revision or not evaluator_revision.data:
Expand Down
Loading
Loading