Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement]: Backend Improvements Based on CLI-SDK Testing #2431

Merged
merged 17 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
0ae5ea4
Merge 'feat/AGE-1430-new-playground' into dev branch
aybruhm Jan 24, 2025
9af4213
refactor (backend): fix anomalies when running cli & sdk tests
aybruhm Jan 27, 2025
162bd17
feat (sdk): create app manager
aybruhm Jan 28, 2025
2ea2354
refactor (sdk): include AppManager in __init__ and remove deprecating…
aybruhm Jan 30, 2025
4105da4
minor refactor (backend): resolve anomalies while running sdk tests
aybruhm Jan 30, 2025
3fc28c6
Merge branch 'feat/AGE-1430-new-playground' into feat/cli-sdk-testing…
aybruhm Jan 31, 2025
7f04b54
chore (backend): format code
aybruhm Jan 31, 2025
59cd046
chore (backend): update poetry.lock to resolve lock conflicts
aybruhm Feb 4, 2025
3fdcef3
refactor (sdk): regenerate sdk client backend based on new fern changes
aybruhm Feb 4, 2025
0f2dd92
chore (backend): resolve Duplicate Attribute error
aybruhm Feb 4, 2025
05c863b
Merge branch 'feat/AGE-1430-new-playground' into feat/cli-sdk-testing…
aybruhm Feb 4, 2025
118d9ee
cleanup (sdk): remove hack to disable cache from query_params ;-)
aybruhm Feb 4, 2025
1854a25
chore (backend): sync new-playground branch into feat/cli-sdk-testing…
aybruhm Feb 4, 2025
1e277a7
chore (sdk): revert baggage change
aybruhm Feb 4, 2025
d1eb21f
refactor (backend): revert db function to not raise http exceptions
aybruhm Feb 4, 2025
f2d4af0
Merge branch 'feat/cli-sdk-testing-w-coverage' into chore/regenerate-…
aybruhm Feb 4, 2025
557637f
Merge pull request #2450 from Agenta-AI/chore/regenerate-sdk-client-b…
aybruhm Feb 4, 2025
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
60 changes: 47 additions & 13 deletions agenta-backend/agenta_backend/routers/app_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,18 @@ async def create_app(
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))

app_db = await db_manager.create_app_and_envs(
payload.app_name,
project_id=request.state.project_id,
template_key=payload.template_key,
)
try:
app_db = await db_manager.create_app_and_envs(
payload.app_name,
project_id=request.state.project_id,
template_key=payload.template_key,
)
except ValueError:
raise HTTPException(
status_code=400,
detail="App with the same name already exists",
)

return CreateAppOutput(app_id=str(app_db.id), app_name=str(app_db.app_name))


Expand All @@ -265,7 +272,13 @@ async def update_app(
HTTPException: If there is an error creating the app or the user does not have permission to access the app.
"""

app = await db_manager.fetch_app_by_id(app_id)
try:
app = await db_manager.fetch_app_by_id(app_id)
except db_manager.NoResultFound:
raise HTTPException(
status_code=404, detail=f"No application with ID '{app_id}' found"
)

if isCloudEE():
has_permission = await check_action_access(
user_uid=request.state.user_id,
Expand Down Expand Up @@ -357,7 +370,13 @@ async def add_variant_from_image(
elif await deployment_manager.validate_image(image) is False:
raise HTTPException(status_code=404, detail="Image not found")

app = await db_manager.fetch_app_by_id(app_id)
try:
app = await db_manager.fetch_app_by_id(app_id)
except db_manager.NoResultFound:
raise HTTPException(
status_code=404, detail=f"No application with ID '{app_id}' found"
)

if isCloudEE():
has_permission = await check_action_access(
user_uid=request.state.user_id,
Expand Down Expand Up @@ -415,6 +434,10 @@ async def add_variant_from_url(

try:
app = await db_manager.fetch_app_by_id(app_id)
except db_manager.NoResultFound:
raise HTTPException(
status_code=404, detail=f"No application with ID '{app_id}' found"
)

if isCloudEE():
has_permission = await check_action_access(
Expand Down Expand Up @@ -503,7 +526,12 @@ async def remove_app(
app -- App to remove
"""

app = await db_manager.fetch_app_by_id(app_id)
try:
app = await db_manager.fetch_app_by_id(app_id)
except db_manager.NoResultFound:
raise HTTPException(
status_code=404, detail=f"No application with ID '{app_id}' found"
)

if isCloudEE():
has_permission = await check_action_access(
Expand Down Expand Up @@ -604,11 +632,17 @@ async def create_app_and_variant_from_template(
else "Step 3: Creating new app and initializing environments"
)
if app is None:
app = await db_manager.create_app_and_envs(
app_name=app_name,
template_id=str(template_db.id),
project_id=request.state.project_id,
)
try:
app = await db_manager.create_app_and_envs(
app_name=app_name,
template_id=str(template_db.id),
project_id=request.state.project_id,
)
except ValueError:
raise HTTPException(
status_code=400,
detail="App with the same name already exists",
)

logger.debug(
"Step 7: Creating image instance and adding variant based on image"
Expand Down
1,566 changes: 808 additions & 758 deletions agenta-backend/poetry.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions agenta-backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pytest = "^7.3.1"
httpx = "^0.24.0"
pytest-asyncio = "^0.21.1"
faker = "^23.2.0"
pexpect = "^4.9.0"
pytest-xdist = "^3.6.1"
pytz = "^2024.2"

[build-system]
Expand Down
2 changes: 2 additions & 0 deletions agenta-cli/agenta/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
from .sdk.utils.costs import calculate_token_usage
from .sdk.client import Agenta
from .sdk.litellm import litellm as callbacks
from .sdk.managers.apps import AppManager
from .sdk.managers.vault import VaultManager
from .sdk.managers.secrets import SecretsManager
from .sdk.managers.config import ConfigManager
from .sdk.managers.variant import VariantManager
from .sdk.managers.deployment import DeploymentManager
from .sdk import assets as assets
from .sdk import tracer
from .client.exceptions import APIRequestError

config = PreInitObject("agenta.config", Config)
DEFAULT_AGENTA_SINGLETON_INSTANCE = AgentaSingleton()
Expand Down
58 changes: 35 additions & 23 deletions agenta-cli/agenta/client/backend/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file was auto-generated by Fern from our API Definition.

from .types import (
AccountResponse,
AgentaNodeDto,
AgentaNodeDtoNodesValue,
AgentaNodesResponse,
Expand All @@ -23,8 +24,6 @@
ConfigResponseModel,
CorrectAnswer,
CreateAppOutput,
CreateSpan,
CreateTraceResponse,
DeleteEvaluation,
DockerEnvVars,
EnvironmentOutput,
Expand Down Expand Up @@ -54,11 +53,14 @@
InviteRequest,
LegacyAnalyticsResponse,
LegacyDataPoint,
LegacyScopeRequest,
LegacyScopesResponse,
LegacyUserRequest,
LegacyUserResponse,
LifecycleDto,
LinkDto,
ListApiKeysResponse,
LlmRunRateLimit,
LlmTokens,
MetricsDto,
NewTestset,
NodeDto,
Expand All @@ -72,54 +74,59 @@
OTelSpansResponse,
OTelStatusCode,
Organization,
OrganizationMembershipRequest,
OrganizationOutput,
Outputs,
OrganizationRequest,
ParentDto,
Permission,
ProjectMembershipRequest,
ProjectRequest,
ProjectScope,
ProjectsResponse,
ProviderKeyDto,
ProviderKind,
Reference,
ReferenceDto,
ReferenceRequestModel,
Result,
Role,
RootDto,
ScopesResponseModel,
Score,
SecretDto,
SecretKind,
SecretResponseDto,
SimpleEvaluationOutput,
Span,
SpanDetail,
SpanDto,
SpanDtoNodesValue,
SpanStatusCode,
SpanVariant,
StatusCode,
StatusDto,
Template,
TemplateImageInfo,
TestSetOutputResponse,
TestSetSimpleResponse,
TimeDto,
TraceDetail,
TreeDto,
TreeType,
UpdateAppOutput,
Uri,
UserRequest,
ValidationError,
ValidationErrorLocItem,
VariantAction,
VariantActionEnum,
WithPagination,
WorkspaceMemberResponse,
WorkspaceMembershipRequest,
WorkspacePermission,
WorkspaceRequest,
WorkspaceResponse,
WorkspaceRole,
WorkspaceRoleResponse,
)
from .errors import UnprocessableEntityError
from . import (
access_control,
admin,
apps,
bases,
configs,
Expand All @@ -129,18 +136,18 @@
evaluators,
human_evaluations,
observability,
observability_v_1,
scopes,
testsets,
variants,
vault,
)
from .client import AgentaApi, AsyncAgentaApi
from .containers import ContainerTemplatesResponse
from .observability_v_1 import Format, QueryAnalyticsResponse, QueryTracesResponse
from .observability import Format, QueryAnalyticsResponse, QueryTracesResponse
from .variants import AddVariantFromBaseAndConfigResponse

__all__ = [
"AccountResponse",
"AddVariantFromBaseAndConfigResponse",
"AgentaApi",
"AgentaNodeDto",
Expand All @@ -167,8 +174,6 @@
"ContainerTemplatesResponse",
"CorrectAnswer",
"CreateAppOutput",
"CreateSpan",
"CreateTraceResponse",
"DeleteEvaluation",
"DockerEnvVars",
"EnvironmentOutput",
Expand Down Expand Up @@ -199,11 +204,14 @@
"InviteRequest",
"LegacyAnalyticsResponse",
"LegacyDataPoint",
"LegacyScopeRequest",
"LegacyScopesResponse",
"LegacyUserRequest",
"LegacyUserResponse",
"LifecycleDto",
"LinkDto",
"ListApiKeysResponse",
"LlmRunRateLimit",
"LlmTokens",
"MetricsDto",
"NewTestset",
"NodeDto",
Expand All @@ -217,54 +225,59 @@
"OTelSpansResponse",
"OTelStatusCode",
"Organization",
"OrganizationMembershipRequest",
"OrganizationOutput",
"Outputs",
"OrganizationRequest",
"ParentDto",
"Permission",
"ProjectMembershipRequest",
"ProjectRequest",
"ProjectScope",
"ProjectsResponse",
"ProviderKeyDto",
"ProviderKind",
"QueryAnalyticsResponse",
"QueryTracesResponse",
"Reference",
"ReferenceDto",
"ReferenceRequestModel",
"Result",
"Role",
"RootDto",
"ScopesResponseModel",
"Score",
"SecretDto",
"SecretKind",
"SecretResponseDto",
"SimpleEvaluationOutput",
"Span",
"SpanDetail",
"SpanDto",
"SpanDtoNodesValue",
"SpanStatusCode",
"SpanVariant",
"StatusCode",
"StatusDto",
"Template",
"TemplateImageInfo",
"TestSetOutputResponse",
"TestSetSimpleResponse",
"TimeDto",
"TraceDetail",
"TreeDto",
"TreeType",
"UnprocessableEntityError",
"UpdateAppOutput",
"Uri",
"UserRequest",
"ValidationError",
"ValidationErrorLocItem",
"VariantAction",
"VariantActionEnum",
"WithPagination",
"WorkspaceMemberResponse",
"WorkspaceMembershipRequest",
"WorkspacePermission",
"WorkspaceRequest",
"WorkspaceResponse",
"WorkspaceRole",
"WorkspaceRoleResponse",
"access_control",
"admin",
"apps",
"bases",
"configs",
Expand All @@ -274,7 +287,6 @@
"evaluators",
"human_evaluations",
"observability",
"observability_v_1",
"scopes",
"testsets",
"variants",
Expand Down
1 change: 1 addition & 0 deletions agenta-cli/agenta/client/backend/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This file was auto-generated by Fern from our API Definition.
Loading
Loading