From e5b331efb8b7cbb67fde5acf09dd73a16eec01c1 Mon Sep 17 00:00:00 2001 From: Abram Date: Wed, 14 Aug 2024 20:24:31 +0100 Subject: [PATCH 01/25] feat (backend): created AppType enum and introduce new column 'app_type' to AppDB model --- agenta-backend/agenta_backend/models/db_models.py | 3 ++- agenta-backend/agenta_backend/models/shared_models.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/agenta-backend/agenta_backend/models/db_models.py b/agenta-backend/agenta_backend/models/db_models.py index 374d2a80e4..2cf0529437 100644 --- a/agenta-backend/agenta_backend/models/db_models.py +++ b/agenta-backend/agenta_backend/models/db_models.py @@ -15,7 +15,7 @@ from sqlalchemy.dialects.postgresql import UUID, JSONB from agenta_backend.models.base import Base -from agenta_backend.models.shared_models import TemplateType +from agenta_backend.models.shared_models import TemplateType, AppType class UserDB(Base): @@ -76,6 +76,7 @@ class AppDB(Base): nullable=False, ) app_name = Column(String) + app_type = Column(Enum(AppType), nullable=True) user_id = Column(UUID(as_uuid=True), ForeignKey("users.id")) created_at = Column( DateTime(timezone=True), default=lambda: datetime.now(timezone.utc) diff --git a/agenta-backend/agenta_backend/models/shared_models.py b/agenta-backend/agenta_backend/models/shared_models.py index 56affd84f8..8ba5f737bb 100644 --- a/agenta-backend/agenta_backend/models/shared_models.py +++ b/agenta-backend/agenta_backend/models/shared_models.py @@ -65,3 +65,9 @@ class HumanEvaluationScenarioOutput(BaseModel): class TemplateType(enum.Enum): IMAGE = "image" ZIP = "zip" + + +class AppType(enum.Enum): + CHAT_PROMPT = "chat_prompt" + SINGLE_PROMPT = "single_prompt" + CUSTOM = "custom" From 501841d3be550ad536388f37be57ffbf218a0bfb Mon Sep 17 00:00:00 2001 From: Abram Date: Wed, 14 Aug 2024 23:42:27 +0100 Subject: [PATCH 02/25] feat (migration): generate and apply schema migration script with Alembic --- ...dded_the_app_type_column_to_the_app_db_.py | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 agenta-backend/agenta_backend/migrations/postgres/versions/1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py diff --git a/agenta-backend/agenta_backend/migrations/postgres/versions/1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py b/agenta-backend/agenta_backend/migrations/postgres/versions/1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py new file mode 100644 index 0000000000..b7ad9232ea --- /dev/null +++ b/agenta-backend/agenta_backend/migrations/postgres/versions/1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py @@ -0,0 +1,54 @@ +"""Added the 'app_type' column to the 'app_db' table + +Revision ID: 1abfef8ed0ef +Revises: b80c708c21bb +Create Date: 2024-08-14 19:44:23.707519 + +""" + +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = "1abfef8ed0ef" +down_revision: Union[str, None] = "b80c708c21bb" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + + # Create the enum type first + app_enumtype = sa.Enum( + "CHAT_PROMPT", "SINGLE_PROMPT", "RAG", "CUSTOM", name="app_enumtype" + ) + app_enumtype.create(op.get_bind(), checkfirst=True) + + # Then add the column using the enum type + op.add_column( + "app_db", + sa.Column( + "app_type", + app_enumtype, + nullable=True, + ), + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + + # Drop the column first + op.drop_column("app_db", "app_type") + + # Then drop the enum type + app_enumtype = sa.Enum( + "CHAT_PROMPT", "SINGLE_PROMPT", "RAG", "CUSTOM", name="app_enumtype" + ) + app_enumtype.drop(op.get_bind(), checkfirst=True) + # ### end Alembic commands ### From 474e5341a241b6eb9d41d8797c8f5b4d395e2348 Mon Sep 17 00:00:00 2001 From: Abram Date: Thu, 15 Aug 2024 22:47:26 +0100 Subject: [PATCH 03/25] feat (backend): specify enum type for 'app_type' column, extend AppType enum with RAG, and update App API response --- agenta-backend/agenta_backend/models/api/api_models.py | 1 + agenta-backend/agenta_backend/models/converters.py | 4 +++- agenta-backend/agenta_backend/models/db_models.py | 2 +- agenta-backend/agenta_backend/models/shared_models.py | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/agenta-backend/agenta_backend/models/api/api_models.py b/agenta-backend/agenta_backend/models/api/api_models.py index 540b754dbc..7f11cbd126 100644 --- a/agenta-backend/agenta_backend/models/api/api_models.py +++ b/agenta-backend/agenta_backend/models/api/api_models.py @@ -211,6 +211,7 @@ class URI(BaseModel): class App(BaseModel): app_id: str app_name: str + app_type: Optional[str] = None class RemoveApp(BaseModel): diff --git a/agenta-backend/agenta_backend/models/converters.py b/agenta-backend/agenta_backend/models/converters.py index 72a0d174dc..8ec36a01a8 100644 --- a/agenta-backend/agenta_backend/models/converters.py +++ b/agenta-backend/agenta_backend/models/converters.py @@ -466,7 +466,9 @@ def base_db_to_pydantic(base_db: VariantBaseDB) -> BaseOutput: def app_db_to_pydantic(app_db: AppDB) -> App: - return App(app_name=app_db.app_name, app_id=str(app_db.id)) + return App( + app_name=app_db.app_name, app_id=str(app_db.id), app_type=app_db.app_type + ) def image_db_to_pydantic(image_db: ImageDB) -> ImageExtended: diff --git a/agenta-backend/agenta_backend/models/db_models.py b/agenta-backend/agenta_backend/models/db_models.py index 2cf0529437..3dd7e69381 100644 --- a/agenta-backend/agenta_backend/models/db_models.py +++ b/agenta-backend/agenta_backend/models/db_models.py @@ -76,7 +76,7 @@ class AppDB(Base): nullable=False, ) app_name = Column(String) - app_type = Column(Enum(AppType), nullable=True) + app_type = Column(Enum(AppType, name="app_enumtype"), nullable=True) user_id = Column(UUID(as_uuid=True), ForeignKey("users.id")) created_at = Column( DateTime(timezone=True), default=lambda: datetime.now(timezone.utc) diff --git a/agenta-backend/agenta_backend/models/shared_models.py b/agenta-backend/agenta_backend/models/shared_models.py index 8ba5f737bb..3eb4889a4d 100644 --- a/agenta-backend/agenta_backend/models/shared_models.py +++ b/agenta-backend/agenta_backend/models/shared_models.py @@ -70,4 +70,5 @@ class TemplateType(enum.Enum): class AppType(enum.Enum): CHAT_PROMPT = "chat_prompt" SINGLE_PROMPT = "single_prompt" + RAG = "rag" CUSTOM = "custom" From 4296c8d6d77f9c69260baefcd055d8ace6fadbe3 Mon Sep 17 00:00:00 2001 From: Abram Date: Fri, 16 Aug 2024 07:51:26 +0100 Subject: [PATCH 04/25] feat (backend): implement the following: - Create DB function to get 'app_type' from template - Update DB function 'create_app_and_envs' to include 'app_type' --- .../agenta_backend/routers/app_router.py | 24 ++++++++------- .../agenta_backend/services/db_manager.py | 30 ++++++++++++++++++- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/agenta-backend/agenta_backend/routers/app_router.py b/agenta-backend/agenta_backend/routers/app_router.py index 094a30cf7f..cf4367bfca 100644 --- a/agenta-backend/agenta_backend/routers/app_router.py +++ b/agenta-backend/agenta_backend/routers/app_router.py @@ -277,6 +277,7 @@ async def create_app( request.state.user_id, organization_id if isCloudEE() else None, str(workspace.id) if isCloudEE() else None, + template_id=None ) return CreateAppOutput(app_id=str(app_db.id), app_name=str(app_db.app_name)) except Exception as e: @@ -503,9 +504,16 @@ async def create_app_and_variant_from_template( ) logger.debug( - "Step 5: Creating new app and initializing environments" + "Step 5: Retrieve template from db" if isCloudEE() - else "Step 2: Creating new app and initializing environments" + else "Step 2: Retrieve template from db" + ) + template_db = await db_manager.get_template(payload.template_id) + + logger.debug( + "Step 6: Creating new app and initializing environments" + if isCloudEE() + else "Step 3: Creating new app and initializing environments" ) if app is None: app = await db_manager.create_app_and_envs( @@ -513,22 +521,16 @@ async def create_app_and_variant_from_template( request.state.user_id, payload.organization_id if isCloudEE() else None, # type: ignore payload.workspace_id if isCloudEE() else None, # type: ignore + str(template_db.id), ) - logger.debug( - "Step 6: Retrieve template from db" - if isCloudEE() - else "Step 3: Retrieve template from db" - ) - template_db = await db_manager.get_template(payload.template_id) - repo_name = os.environ.get("AGENTA_TEMPLATE_REPO", "agentaai/templates_v2") - image_name = f"{repo_name}:{template_db.name}" - logger.debug( "Step 7: Creating image instance and adding variant based on image" if isCloudEE() else "Step 4: Creating image instance and adding variant based on image" ) + repo_name = os.environ.get("AGENTA_TEMPLATE_REPO", "agentaai/templates_v2") + image_name = f"{repo_name}:{template_db.name}" app_variant_db = await app_manager.add_variant_based_on_image( app=app, variant_name="app.default", diff --git a/agenta-backend/agenta_backend/services/db_manager.py b/agenta-backend/agenta_backend/services/db_manager.py index 08ac7b00f9..87421ab764 100644 --- a/agenta-backend/agenta_backend/services/db_manager.py +++ b/agenta-backend/agenta_backend/services/db_manager.py @@ -1,6 +1,7 @@ import os import uuid import logging +from enum import Enum from pathlib import Path from urllib.parse import urlparse from typing import Any, Dict, List, Optional @@ -73,6 +74,7 @@ from agenta_backend.models.shared_models import ( Result, + AppType, ConfigDB, TemplateType, CorrectAnswer, @@ -616,11 +618,35 @@ async def create_deployment( raise Exception(f"Error while creating deployment: {e}") +async def get_app_type_from_template(template_id: Optional[str]) -> Enum: + """Get the application type from the specified template. + + Args: + template_id (Optional[str]): The ID of the template + + Returns: + AppType (Enum): The determined application type. Defaults to AppType.CUSTOM. + """ + + if template_id is None: + return AppType.CUSTOM + + template_db = await get_template(template_id=template_id) + if "Single Prompt" in template_db.title: + return AppType.SINGLE_PROMPT + elif "Chat Application" in template_db.title: + return AppType.CHAT_PROMPT + elif "RAG" in template_db.title: + return AppType.RAG + return AppType.CUSTOM + + async def create_app_and_envs( app_name: str, user_uid: str, organization_id: Optional[str] = None, workspace_id: Optional[str] = None, + template_id: Optional[str] = None, ) -> AppDB: """ Create a new app with the given name and organization ID. @@ -630,6 +656,7 @@ async def create_app_and_envs( user_uid (str): The UID of the user that the app belongs to. organization_id (str): The ID of the organization that the app belongs to. workspace_id (str): The ID of the workspace that the app belongs to. + template_id (str): The ID of the template Returns: AppDB: The created app. @@ -648,8 +675,9 @@ async def create_app_and_envs( if app is not None: raise ValueError("App with the same name already exists") + app_type = await get_app_type_from_template(template_id) async with db_engine.get_session() as session: - app = AppDB(app_name=app_name, user_id=user.id) + app = AppDB(app_name=app_name, user_id=user.id, app_type=app_type) if isCloudEE(): # assert that if organization_id is provided, workspace_id is also provided, and vice versa From a41d3d9f3fde68cad605d82449ed59b7989cb3cd Mon Sep 17 00:00:00 2001 From: Abram Date: Fri, 16 Aug 2024 08:02:58 +0100 Subject: [PATCH 05/25] style (backend): format code with prettier@23.12.0 --- agenta-backend/agenta_backend/routers/app_router.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agenta-backend/agenta_backend/routers/app_router.py b/agenta-backend/agenta_backend/routers/app_router.py index cf4367bfca..3481985b80 100644 --- a/agenta-backend/agenta_backend/routers/app_router.py +++ b/agenta-backend/agenta_backend/routers/app_router.py @@ -277,7 +277,7 @@ async def create_app( request.state.user_id, organization_id if isCloudEE() else None, str(workspace.id) if isCloudEE() else None, - template_id=None + template_id=None, ) return CreateAppOutput(app_id=str(app_db.id), app_name=str(app_db.app_name)) except Exception as e: From ad41e91edbb95973565980561de46eca5a5ea2b4 Mon Sep 17 00:00:00 2001 From: Abram Date: Thu, 22 Aug 2024 02:32:35 +0100 Subject: [PATCH 06/25] chore (backend): rename function 'get_app_type_from_template' to 'get_app_type_from_template_by_id' --- agenta-backend/agenta_backend/services/db_manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agenta-backend/agenta_backend/services/db_manager.py b/agenta-backend/agenta_backend/services/db_manager.py index 2514c0fb58..1fa5e9643b 100644 --- a/agenta-backend/agenta_backend/services/db_manager.py +++ b/agenta-backend/agenta_backend/services/db_manager.py @@ -619,7 +619,7 @@ async def create_deployment( raise Exception(f"Error while creating deployment: {e}") -async def get_app_type_from_template(template_id: Optional[str]) -> Enum: +async def get_app_type_from_template_by_id(template_id: Optional[str]) -> Enum: """Get the application type from the specified template. Args: @@ -676,7 +676,7 @@ async def create_app_and_envs( if app is not None: raise ValueError("App with the same name already exists") - app_type = await get_app_type_from_template(template_id) + app_type = await get_app_type_from_template_by_id(template_id) async with db_engine.get_session() as session: app = AppDB(app_name=app_name, user_id=user.id, app_type=app_type) From 61ad8c688e1f01ffd085d0074a4a6f10ca18cf90 Mon Sep 17 00:00:00 2001 From: Abram Date: Thu, 22 Aug 2024 02:35:38 +0100 Subject: [PATCH 07/25] refactor (backend): update AppType enum to use opaque template strings for app categorization --- ...ed0ef_added_the_app_type_column_to_the_app_db_.py | 12 ++++++++++-- .../agenta_backend/models/shared_models.py | 8 ++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/agenta-backend/agenta_backend/migrations/postgres/versions/1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py b/agenta-backend/agenta_backend/migrations/postgres/versions/1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py index b7ad9232ea..e338329f3d 100644 --- a/agenta-backend/agenta_backend/migrations/postgres/versions/1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py +++ b/agenta-backend/agenta_backend/migrations/postgres/versions/1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py @@ -24,7 +24,11 @@ def upgrade() -> None: # Create the enum type first app_enumtype = sa.Enum( - "CHAT_PROMPT", "SINGLE_PROMPT", "RAG", "CUSTOM", name="app_enumtype" + "TEMPLATE:CONVERSATION:Simple_Chat", + "TEMPLATE:GENERATION:Simple_Prompt", + "TEMPLATE:CHAIN:RAG:Simple_RAG", + "CUSTOM", + name="app_enumtype", ) app_enumtype.create(op.get_bind(), checkfirst=True) @@ -48,7 +52,11 @@ def downgrade() -> None: # Then drop the enum type app_enumtype = sa.Enum( - "CHAT_PROMPT", "SINGLE_PROMPT", "RAG", "CUSTOM", name="app_enumtype" + "TEMPLATE:CONVERSATION:Simple_Chat", + "TEMPLATE:GENERATION:Simple_Prompt", + "TEMPLATE:CHAIN:RAG:Simple_RAG", + "CUSTOM", + name="app_enumtype", ) app_enumtype.drop(op.get_bind(), checkfirst=True) # ### end Alembic commands ### diff --git a/agenta-backend/agenta_backend/models/shared_models.py b/agenta-backend/agenta_backend/models/shared_models.py index 3eb4889a4d..3a47aad029 100644 --- a/agenta-backend/agenta_backend/models/shared_models.py +++ b/agenta-backend/agenta_backend/models/shared_models.py @@ -68,7 +68,7 @@ class TemplateType(enum.Enum): class AppType(enum.Enum): - CHAT_PROMPT = "chat_prompt" - SINGLE_PROMPT = "single_prompt" - RAG = "rag" - CUSTOM = "custom" + CHAT_PROMPT = "TEMPLATE:CONVERSATION:Simple_Chat" + SINGLE_PROMPT = "TEMPLATE:GENERATION:Simple_Prompt" + RAG = "TEMPLATE:CHAIN:RAG:Simple_RAG" + CUSTOM = "CUSTOM" From 5161ccc9304e571a99a69c645c37e81cf4b6ca2d Mon Sep 17 00:00:00 2001 From: Abram Date: Thu, 22 Aug 2024 02:36:27 +0100 Subject: [PATCH 08/25] chore (style): format cookbook with black@23.12.0 --- website/scripts/generate_cookbooks.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/website/scripts/generate_cookbooks.py b/website/scripts/generate_cookbooks.py index b84cd2ee3d..6b8a809224 100644 --- a/website/scripts/generate_cookbooks.py +++ b/website/scripts/generate_cookbooks.py @@ -5,6 +5,7 @@ import os import sys + def make_header(notebook_path): github_uri = "Agenta-AI/agenta/blob/main/cookbook" github_path = f"https://github.com/{github_uri}/{os.path.basename(notebook_path)}" @@ -52,11 +53,11 @@ def export_notebook(notebook_path, output_path): title = convert_to_title_case(os.path.basename(notebook_path)) # Add the title to the top of the markdown file - title_header = f"---\ntitle: \"{title}\"\n---\n\n" - + title_header = f'---\ntitle: "{title}"\n---\n\n' + # Add the header below the title header = make_header(notebook_path) - + # Combine the title, header, and the output markdown content output = title_header + header + output @@ -103,4 +104,4 @@ def main(notebook_filename=None): if __name__ == "__main__": # Get the filename argument from the command line notebook_filename = sys.argv[1] if len(sys.argv) > 1 else None - main(notebook_filename) \ No newline at end of file + main(notebook_filename) From cae8a980b2ef14c9ac0557050099b29d94ce86ed Mon Sep 17 00:00:00 2001 From: Abram Date: Thu, 22 Aug 2024 15:54:07 +0100 Subject: [PATCH 09/25] refactor (backend): improve migration handling by checking only the latest migration head - Refactored the migration check to compare the current database migration head against the latest migration script head. - Enhanced `get_current_migration_head_from_db` to ensure only one migration head is tracked. - Updated logic in `get_pending_migration_head` to reduce unnecessary checks and handle first-time setup more efficiently. - Improved error handling and clarified logging messages for better debugging. --- .../migrations/postgres/utils.py | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/agenta-backend/agenta_backend/migrations/postgres/utils.py b/agenta-backend/agenta_backend/migrations/postgres/utils.py index 3666175a3e..5914d780f1 100644 --- a/agenta-backend/agenta_backend/migrations/postgres/utils.py +++ b/agenta-backend/agenta_backend/migrations/postgres/utils.py @@ -55,15 +55,15 @@ def is_initial_setup(engine) -> bool: return not all_tables_exist -async def get_applied_migrations(engine: AsyncEngine): +async def get_current_migration_head_from_db(engine: AsyncEngine): """ - Checks the alembic_version table to get all the migrations that has been applied. + Checks the alembic_version table to get the current migration head that has been applied. Args: engine (Engine): The engine that connects to an sqlalchemy pool Returns: - a list of strings + the current migration head (where 'head' is the revision stored in the migration script) """ async with engine.connect() as connection: @@ -75,32 +75,37 @@ async def get_applied_migrations(engine: AsyncEngine): # to make Alembic start tracking the migration changes. # -------------------------------------------------------------------------------------- # This effect (the exception raising) happens for both users (first-time and returning) - return ["alembic_version"] + return "alembic_version" - applied_migrations = [row[0] for row in result.fetchall()] - return applied_migrations + 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." + return migration_heads[0] -async def get_pending_migrations(): +async def get_pending_migration_head(): """ - Gets the migrations that have not been applied. + Gets the migration head that have not been applied. Returns: - the number of pending migrations + the pending migration head """ engine = create_async_engine(url=os.environ["POSTGRES_URI"]) try: - applied_migrations = await get_applied_migrations(engine=engine) - migration_files = [script.revision for script in script.walk_revisions()] - pending_migrations = [m for m in migration_files if m not in applied_migrations] - - if "alembic_version" in applied_migrations: - pending_migrations.append("alembic_version") + current_migration_script_head = script.get_current_head() + migration_head_from_db = await get_current_migration_head_from_db(engine=engine) + + pending_migration_head = [] + if current_migration_script_head != migration_head_from_db: + pending_migration_head.append(current_migration_script_head) + if "alembic_version" == migration_head_from_db: + pending_migration_head.append("alembic_version") finally: await engine.dispose() - return pending_migrations + return pending_migration_head def run_alembic_migration(): @@ -109,9 +114,9 @@ def run_alembic_migration(): """ try: - pending_migrations = asyncio.run(get_pending_migrations()) + pending_migration_head = asyncio.run(get_pending_migration_head()) APPLY_AUTO_MIGRATIONS = os.environ.get("AGENTA_AUTO_MIGRATIONS") - FIRST_TIME_USER = True if "alembic_version" in pending_migrations else False + FIRST_TIME_USER = True if "alembic_version" in pending_migration_head else False if FIRST_TIME_USER or APPLY_AUTO_MIGRATIONS == "true": command.upgrade(alembic_cfg, "head") @@ -133,7 +138,7 @@ def run_alembic_migration(): except Exception as e: click.echo( click.style( - f"\nAn ERROR occured while applying migration: {traceback.format_exc()}\nThe container will now exit.", + f"\nAn ERROR occurred while applying migration: {traceback.format_exc()}\nThe container will now exit.", fg="red", ), color=True, @@ -146,11 +151,11 @@ async def check_for_new_migrations(): Checks for new migrations and notify the user. """ - pending_migrations = await get_pending_migrations() - if len(pending_migrations) >= 1: + pending_migration_head = await get_pending_migration_head() + if len(pending_migration_head) >= 1 and isinstance(pending_migration_head[0], str): click.echo( click.style( - f"\nWe have detected that there are pending database migrations {pending_migrations} that need to be applied to keep the application up to date. To ensure the application functions correctly with the latest updates, please follow the guide here => https://docs.agenta.ai/self-host/migration/applying-schema-migration\n", + f"\nWe have detected that there are pending database migrations {pending_migration_head} that need to be applied to keep the application up to date. To ensure the application functions correctly with the latest updates, please follow the guide here => https://docs.agenta.ai/self-host/migration/applying-schema-migration\n", fg="yellow", ), color=True, From 1a51c59dc53956748962536b46bd36ce4a50f772 Mon Sep 17 00:00:00 2001 From: Abram Date: Thu, 22 Aug 2024 16:52:28 +0100 Subject: [PATCH 10/25] refactor (backend): update AppType and enums in migration script --- ...ed0ef_added_the_app_type_column_to_the_app_db_.py | 12 ++++++------ .../agenta_backend/models/shared_models.py | 2 +- agenta-backend/agenta_backend/services/db_manager.py | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/agenta-backend/agenta_backend/migrations/postgres/versions/1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py b/agenta-backend/agenta_backend/migrations/postgres/versions/1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py index e338329f3d..f614ab8a74 100644 --- a/agenta-backend/agenta_backend/migrations/postgres/versions/1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py +++ b/agenta-backend/agenta_backend/migrations/postgres/versions/1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py @@ -24,9 +24,9 @@ def upgrade() -> None: # Create the enum type first app_enumtype = sa.Enum( - "TEMPLATE:CONVERSATION:Simple_Chat", - "TEMPLATE:GENERATION:Simple_Prompt", - "TEMPLATE:CHAIN:RAG:Simple_RAG", + "CHAT_PROMPT", + "SINGLE_PROMPT", + "RAG", "CUSTOM", name="app_enumtype", ) @@ -52,9 +52,9 @@ def downgrade() -> None: # Then drop the enum type app_enumtype = sa.Enum( - "TEMPLATE:CONVERSATION:Simple_Chat", - "TEMPLATE:GENERATION:Simple_Prompt", - "TEMPLATE:CHAIN:RAG:Simple_RAG", + "CHAT_PROMPT", + "SINGLE_PROMPT", + "RAG", "CUSTOM", name="app_enumtype", ) diff --git a/agenta-backend/agenta_backend/models/shared_models.py b/agenta-backend/agenta_backend/models/shared_models.py index 3a47aad029..17c75a8f14 100644 --- a/agenta-backend/agenta_backend/models/shared_models.py +++ b/agenta-backend/agenta_backend/models/shared_models.py @@ -67,7 +67,7 @@ class TemplateType(enum.Enum): ZIP = "zip" -class AppType(enum.Enum): +class AppType(str, enum.Enum): CHAT_PROMPT = "TEMPLATE:CONVERSATION:Simple_Chat" SINGLE_PROMPT = "TEMPLATE:GENERATION:Simple_Prompt" RAG = "TEMPLATE:CHAIN:RAG:Simple_RAG" diff --git a/agenta-backend/agenta_backend/services/db_manager.py b/agenta-backend/agenta_backend/services/db_manager.py index 1fa5e9643b..69d0927f91 100644 --- a/agenta-backend/agenta_backend/services/db_manager.py +++ b/agenta-backend/agenta_backend/services/db_manager.py @@ -619,14 +619,14 @@ async def create_deployment( raise Exception(f"Error while creating deployment: {e}") -async def get_app_type_from_template_by_id(template_id: Optional[str]) -> Enum: +async def get_app_type_from_template_by_id(template_id: Optional[str]) -> str: """Get the application type from the specified template. Args: template_id (Optional[str]): The ID of the template Returns: - AppType (Enum): The determined application type. Defaults to AppType.CUSTOM. + AppType (str): The determined application type. Defaults to AppType.CUSTOM. """ if template_id is None: @@ -677,6 +677,7 @@ async def create_app_and_envs( raise ValueError("App with the same name already exists") app_type = await get_app_type_from_template_by_id(template_id) + print("App Type: ", app_type) async with db_engine.get_session() as session: app = AppDB(app_name=app_name, user_id=user.id, app_type=app_type) From c29c90f364d7fa59149913a751992ceaa0273fb4 Mon Sep 17 00:00:00 2001 From: Abram Date: Mon, 26 Aug 2024 15:34:56 +0100 Subject: [PATCH 11/25] refactor (web): add app_type to ListAppsItem interface and AppCard component --- agenta-web/src/components/AppSelector/AppCard.tsx | 2 +- agenta-web/src/lib/Types.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/agenta-web/src/components/AppSelector/AppCard.tsx b/agenta-web/src/components/AppSelector/AppCard.tsx index bab8dc9e7b..298d031ccc 100644 --- a/agenta-web/src/components/AppSelector/AppCard.tsx +++ b/agenta-web/src/components/AppSelector/AppCard.tsx @@ -133,7 +133,7 @@ const AppCard: React.FC<{
Type - Template + {app.app_type}
Last modified: diff --git a/agenta-web/src/lib/Types.ts b/agenta-web/src/lib/Types.ts index 127643d793..5b14760f53 100644 --- a/agenta-web/src/lib/Types.ts +++ b/agenta-web/src/lib/Types.ts @@ -21,6 +21,7 @@ export interface TestSet { export interface ListAppsItem { app_id: string app_name: string + app_type: string } export interface AppVariant { From 264422017fb42dfeb43c1a19704c5556006dae1c Mon Sep 17 00:00:00 2001 From: Abram Date: Mon, 26 Aug 2024 16:23:06 +0100 Subject: [PATCH 12/25] refactor (backend): simplify AppType enums --- ...ed0ef_added_the_app_type_column_to_the_app_db_.py | 12 ++++++------ .../agenta_backend/models/shared_models.py | 6 +++--- agenta-backend/agenta_backend/services/db_manager.py | 7 +++---- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/agenta-backend/agenta_backend/migrations/postgres/versions/1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py b/agenta-backend/agenta_backend/migrations/postgres/versions/1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py index f614ab8a74..b85d7e7f3b 100644 --- a/agenta-backend/agenta_backend/migrations/postgres/versions/1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py +++ b/agenta-backend/agenta_backend/migrations/postgres/versions/1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py @@ -24,9 +24,9 @@ def upgrade() -> None: # Create the enum type first app_enumtype = sa.Enum( - "CHAT_PROMPT", - "SINGLE_PROMPT", - "RAG", + "CHAT_TEMPLATE", + "PROMPT_TEMPLATE", + "RAG_TEMPLATE", "CUSTOM", name="app_enumtype", ) @@ -52,9 +52,9 @@ def downgrade() -> None: # Then drop the enum type app_enumtype = sa.Enum( - "CHAT_PROMPT", - "SINGLE_PROMPT", - "RAG", + "CHAT_TEMPLATE", + "PROMPT_TEMPLATE", + "RAG_TEMPLATE", "CUSTOM", name="app_enumtype", ) diff --git a/agenta-backend/agenta_backend/models/shared_models.py b/agenta-backend/agenta_backend/models/shared_models.py index 17c75a8f14..085e6fa909 100644 --- a/agenta-backend/agenta_backend/models/shared_models.py +++ b/agenta-backend/agenta_backend/models/shared_models.py @@ -68,7 +68,7 @@ class TemplateType(enum.Enum): class AppType(str, enum.Enum): - CHAT_PROMPT = "TEMPLATE:CONVERSATION:Simple_Chat" - SINGLE_PROMPT = "TEMPLATE:GENERATION:Simple_Prompt" - RAG = "TEMPLATE:CHAIN:RAG:Simple_RAG" + CHAT_TEMPLATE = "TEMPLATE:simple_chat" + PROMPT_TEMPLATE = "TEMPLATE:single_prompt" + RAG_TEMPLATE = "TEMPLATE:RAG" CUSTOM = "CUSTOM" diff --git a/agenta-backend/agenta_backend/services/db_manager.py b/agenta-backend/agenta_backend/services/db_manager.py index 69d0927f91..5f88c3cee8 100644 --- a/agenta-backend/agenta_backend/services/db_manager.py +++ b/agenta-backend/agenta_backend/services/db_manager.py @@ -634,11 +634,11 @@ async def get_app_type_from_template_by_id(template_id: Optional[str]) -> str: template_db = await get_template(template_id=template_id) if "Single Prompt" in template_db.title: - return AppType.SINGLE_PROMPT + return AppType.PROMPT_TEMPLATE elif "Chat Application" in template_db.title: - return AppType.CHAT_PROMPT + return AppType.CHAT_TEMPLATE elif "RAG" in template_db.title: - return AppType.RAG + return AppType.RAG_TEMPLATE return AppType.CUSTOM @@ -677,7 +677,6 @@ async def create_app_and_envs( raise ValueError("App with the same name already exists") app_type = await get_app_type_from_template_by_id(template_id) - print("App Type: ", app_type) async with db_engine.get_session() as session: app = AppDB(app_name=app_name, user_id=user.id, app_type=app_type) From 0b708526f77a4bed7c7475fe31d1f87b63244007 Mon Sep 17 00:00:00 2001 From: Abram Date: Mon, 26 Aug 2024 16:30:07 +0100 Subject: [PATCH 13/25] minor refactor (backend): ensure that app_type field in ListAppsItem interface is optional --- agenta-web/src/lib/Types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agenta-web/src/lib/Types.ts b/agenta-web/src/lib/Types.ts index 5b14760f53..d934e57b94 100644 --- a/agenta-web/src/lib/Types.ts +++ b/agenta-web/src/lib/Types.ts @@ -21,7 +21,7 @@ export interface TestSet { export interface ListAppsItem { app_id: string app_name: string - app_type: string + app_type?: string } export interface AppVariant { From 1c40fc23bc742c1c17be2913407cd40521ceb245 Mon Sep 17 00:00:00 2001 From: Abram Date: Thu, 29 Aug 2024 22:36:40 +0100 Subject: [PATCH 14/25] feat (backend): add class method for mapping AppType enum to user-friendly tags --- agenta-backend/agenta_backend/models/converters.py | 7 ++++--- agenta-backend/agenta_backend/models/shared_models.py | 10 ++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/agenta-backend/agenta_backend/models/converters.py b/agenta-backend/agenta_backend/models/converters.py index 4568ae020c..4dbd548f90 100644 --- a/agenta-backend/agenta_backend/models/converters.py +++ b/agenta-backend/agenta_backend/models/converters.py @@ -2,14 +2,13 @@ """ import uuid -import json import logging from typing import List, Tuple, Any from agenta_backend.services import db_manager from agenta_backend.utils.common import isCloudEE from agenta_backend.models.api.user_models import User -from agenta_backend.models.shared_models import ConfigDB +from agenta_backend.models.shared_models import ConfigDB, AppType from agenta_backend.models.api.evaluation_model import ( CorrectAnswer, Evaluation, @@ -470,7 +469,9 @@ def base_db_to_pydantic(base_db: VariantBaseDB) -> BaseOutput: def app_db_to_pydantic(app_db: AppDB) -> App: return App( - app_name=app_db.app_name, app_id=str(app_db.id), app_type=app_db.app_type + app_name=app_db.app_name, + app_id=str(app_db.id), + app_type=AppType.friendly_name(app_db.app_type), ) diff --git a/agenta-backend/agenta_backend/models/shared_models.py b/agenta-backend/agenta_backend/models/shared_models.py index 085e6fa909..06df7f0fbe 100644 --- a/agenta-backend/agenta_backend/models/shared_models.py +++ b/agenta-backend/agenta_backend/models/shared_models.py @@ -72,3 +72,13 @@ class AppType(str, enum.Enum): PROMPT_TEMPLATE = "TEMPLATE:single_prompt" RAG_TEMPLATE = "TEMPLATE:RAG" CUSTOM = "CUSTOM" + + @classmethod + def friendly_name(cls, app_type: str): + mappings = { + cls.CHAT_TEMPLATE: "chat", + cls.PROMPT_TEMPLATE: "completion", + cls.RAG_TEMPLATE: "rag", + cls.CUSTOM: "custom", + } + return mappings.get(app_type, None) From acdc6adf3b39fb4b1a27e5d1158923dbf3f02fad Mon Sep 17 00:00:00 2001 From: Abram Date: Thu, 29 Aug 2024 22:38:50 +0100 Subject: [PATCH 15/25] minor refactor (backend): rename AppType class method to 'friendly_tag' --- agenta-backend/agenta_backend/models/converters.py | 2 +- agenta-backend/agenta_backend/models/shared_models.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/agenta-backend/agenta_backend/models/converters.py b/agenta-backend/agenta_backend/models/converters.py index 4dbd548f90..8d7b4cb4d4 100644 --- a/agenta-backend/agenta_backend/models/converters.py +++ b/agenta-backend/agenta_backend/models/converters.py @@ -471,7 +471,7 @@ def app_db_to_pydantic(app_db: AppDB) -> App: return App( app_name=app_db.app_name, app_id=str(app_db.id), - app_type=AppType.friendly_name(app_db.app_type), + app_type=AppType.friendly_tag(app_db.app_type), ) diff --git a/agenta-backend/agenta_backend/models/shared_models.py b/agenta-backend/agenta_backend/models/shared_models.py index 06df7f0fbe..0184599fbf 100644 --- a/agenta-backend/agenta_backend/models/shared_models.py +++ b/agenta-backend/agenta_backend/models/shared_models.py @@ -74,7 +74,7 @@ class AppType(str, enum.Enum): CUSTOM = "CUSTOM" @classmethod - def friendly_name(cls, app_type: str): + def friendly_tag(cls, app_type: str): mappings = { cls.CHAT_TEMPLATE: "chat", cls.PROMPT_TEMPLATE: "completion", From ab4c6378cea6a09dbd92d89b0923f3d38d95b782 Mon Sep 17 00:00:00 2001 From: Abram Date: Thu, 29 Aug 2024 23:03:34 +0100 Subject: [PATCH 16/25] feat (backend): generate alembic migration script to resolve conflicting heads --- .../78cde3fc549c_merge_conflicting_heads.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 agenta-backend/agenta_backend/migrations/postgres/versions/78cde3fc549c_merge_conflicting_heads.py diff --git a/agenta-backend/agenta_backend/migrations/postgres/versions/78cde3fc549c_merge_conflicting_heads.py b/agenta-backend/agenta_backend/migrations/postgres/versions/78cde3fc549c_merge_conflicting_heads.py new file mode 100644 index 0000000000..570c7286fb --- /dev/null +++ b/agenta-backend/agenta_backend/migrations/postgres/versions/78cde3fc549c_merge_conflicting_heads.py @@ -0,0 +1,27 @@ +"""Merge conflicting heads + +Revision ID: 78cde3fc549c +Revises: 1abfef8ed0ef, 5c29a64204f4 +Create Date: 2024-08-29 22:01:35.030820 + +""" + +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = "78cde3fc549c" +down_revision: Union[str, None] = ("1abfef8ed0ef", "5c29a64204f4") +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + pass + + +def downgrade() -> None: + pass From f956e40137da2cc7f5396833d13b859be48038d2 Mon Sep 17 00:00:00 2001 From: Abram Date: Mon, 9 Sep 2024 08:42:37 +0100 Subject: [PATCH 17/25] refactor (backend): remove RAG_TEMPLATE from application types --- .../1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py | 2 -- agenta-backend/agenta_backend/models/shared_models.py | 2 -- agenta-backend/agenta_backend/services/db_manager.py | 2 -- 3 files changed, 6 deletions(-) diff --git a/agenta-backend/agenta_backend/migrations/postgres/versions/1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py b/agenta-backend/agenta_backend/migrations/postgres/versions/1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py index b85d7e7f3b..b21a7cb928 100644 --- a/agenta-backend/agenta_backend/migrations/postgres/versions/1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py +++ b/agenta-backend/agenta_backend/migrations/postgres/versions/1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py @@ -26,7 +26,6 @@ def upgrade() -> None: app_enumtype = sa.Enum( "CHAT_TEMPLATE", "PROMPT_TEMPLATE", - "RAG_TEMPLATE", "CUSTOM", name="app_enumtype", ) @@ -54,7 +53,6 @@ def downgrade() -> None: app_enumtype = sa.Enum( "CHAT_TEMPLATE", "PROMPT_TEMPLATE", - "RAG_TEMPLATE", "CUSTOM", name="app_enumtype", ) diff --git a/agenta-backend/agenta_backend/models/shared_models.py b/agenta-backend/agenta_backend/models/shared_models.py index 0184599fbf..19bb5d997f 100644 --- a/agenta-backend/agenta_backend/models/shared_models.py +++ b/agenta-backend/agenta_backend/models/shared_models.py @@ -70,7 +70,6 @@ class TemplateType(enum.Enum): class AppType(str, enum.Enum): CHAT_TEMPLATE = "TEMPLATE:simple_chat" PROMPT_TEMPLATE = "TEMPLATE:single_prompt" - RAG_TEMPLATE = "TEMPLATE:RAG" CUSTOM = "CUSTOM" @classmethod @@ -78,7 +77,6 @@ def friendly_tag(cls, app_type: str): mappings = { cls.CHAT_TEMPLATE: "chat", cls.PROMPT_TEMPLATE: "completion", - cls.RAG_TEMPLATE: "rag", cls.CUSTOM: "custom", } return mappings.get(app_type, None) diff --git a/agenta-backend/agenta_backend/services/db_manager.py b/agenta-backend/agenta_backend/services/db_manager.py index 5096ab1aae..23dd11b636 100644 --- a/agenta-backend/agenta_backend/services/db_manager.py +++ b/agenta-backend/agenta_backend/services/db_manager.py @@ -637,8 +637,6 @@ async def get_app_type_from_template_by_id(template_id: Optional[str]) -> str: return AppType.PROMPT_TEMPLATE elif "Chat Application" in template_db.title: return AppType.CHAT_TEMPLATE - elif "RAG" in template_db.title: - return AppType.RAG_TEMPLATE return AppType.CUSTOM From 4d8b5dccb2ed06afde6949489019f561abe6f715 Mon Sep 17 00:00:00 2001 From: Abram Date: Mon, 9 Sep 2024 11:13:02 +0100 Subject: [PATCH 18/25] refactor (migration): regenerate alembic migration to add app_type column to the app_db table --- ...bc2f82_added_the_app_type_column_to_the_app_db_.py} | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) rename agenta-backend/agenta_backend/migrations/postgres/versions/{1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py => 0f086ebc2f82_added_the_app_type_column_to_the_app_db_.py} (88%) diff --git a/agenta-backend/agenta_backend/migrations/postgres/versions/1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py b/agenta-backend/agenta_backend/migrations/postgres/versions/0f086ebc2f82_added_the_app_type_column_to_the_app_db_.py similarity index 88% rename from agenta-backend/agenta_backend/migrations/postgres/versions/1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py rename to agenta-backend/agenta_backend/migrations/postgres/versions/0f086ebc2f82_added_the_app_type_column_to_the_app_db_.py index b21a7cb928..b614f25009 100644 --- a/agenta-backend/agenta_backend/migrations/postgres/versions/1abfef8ed0ef_added_the_app_type_column_to_the_app_db_.py +++ b/agenta-backend/agenta_backend/migrations/postgres/versions/0f086ebc2f82_added_the_app_type_column_to_the_app_db_.py @@ -1,8 +1,8 @@ """Added the 'app_type' column to the 'app_db' table -Revision ID: 1abfef8ed0ef -Revises: b80c708c21bb -Create Date: 2024-08-14 19:44:23.707519 +Revision ID: 0f086ebc2f82 +Revises: 78cde3fc549c +Create Date: 2024-09-09 10:11:05.429116 """ @@ -13,8 +13,8 @@ # revision identifiers, used by Alembic. -revision: str = "1abfef8ed0ef" -down_revision: Union[str, None] = "b80c708c21bb" +revision: str = "0f086ebc2f82" +down_revision: Union[str, None] = "78cde3fc549c" branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None From 436f85a20dbbe64da09de3e8c745e56fc174fcf2 Mon Sep 17 00:00:00 2001 From: Abram Date: Mon, 9 Sep 2024 11:18:50 +0100 Subject: [PATCH 19/25] refactor (backend): remove conflicting head that is now redundant --- .../postgres/versions/78cde3fc549c_merge_conflicting_heads.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agenta-backend/agenta_backend/migrations/postgres/versions/78cde3fc549c_merge_conflicting_heads.py b/agenta-backend/agenta_backend/migrations/postgres/versions/78cde3fc549c_merge_conflicting_heads.py index 570c7286fb..40c2340af3 100644 --- a/agenta-backend/agenta_backend/migrations/postgres/versions/78cde3fc549c_merge_conflicting_heads.py +++ b/agenta-backend/agenta_backend/migrations/postgres/versions/78cde3fc549c_merge_conflicting_heads.py @@ -1,7 +1,7 @@ """Merge conflicting heads Revision ID: 78cde3fc549c -Revises: 1abfef8ed0ef, 5c29a64204f4 +Revises: 5c29a64204f4 Create Date: 2024-08-29 22:01:35.030820 """ @@ -14,7 +14,7 @@ # revision identifiers, used by Alembic. revision: str = "78cde3fc549c" -down_revision: Union[str, None] = ("1abfef8ed0ef", "5c29a64204f4") +down_revision: Union[str, None] = "5c29a64204f4" branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None From be5f19d01e8b26dbb0faca1b74e24d29d8020768 Mon Sep 17 00:00:00 2001 From: Abram Date: Thu, 14 Nov 2024 09:16:15 +0100 Subject: [PATCH 20/25] refactor (backend): remove redundant migration script and set `down_revision` to `add_nodes_dbe` migration head --- ...dded_the_app_type_column_to_the_app_db_.py | 2 +- .../78cde3fc549c_merge_conflicting_heads.py | 27 ------------------- 2 files changed, 1 insertion(+), 28 deletions(-) delete mode 100644 agenta-backend/agenta_backend/migrations/postgres/versions/78cde3fc549c_merge_conflicting_heads.py diff --git a/agenta-backend/agenta_backend/migrations/postgres/versions/0f086ebc2f82_added_the_app_type_column_to_the_app_db_.py b/agenta-backend/agenta_backend/migrations/postgres/versions/0f086ebc2f82_added_the_app_type_column_to_the_app_db_.py index b614f25009..33390edf63 100644 --- a/agenta-backend/agenta_backend/migrations/postgres/versions/0f086ebc2f82_added_the_app_type_column_to_the_app_db_.py +++ b/agenta-backend/agenta_backend/migrations/postgres/versions/0f086ebc2f82_added_the_app_type_column_to_the_app_db_.py @@ -14,7 +14,7 @@ # revision identifiers, used by Alembic. revision: str = "0f086ebc2f82" -down_revision: Union[str, None] = "78cde3fc549c" +down_revision: Union[str, None] = "847972cfa14a" branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None diff --git a/agenta-backend/agenta_backend/migrations/postgres/versions/78cde3fc549c_merge_conflicting_heads.py b/agenta-backend/agenta_backend/migrations/postgres/versions/78cde3fc549c_merge_conflicting_heads.py deleted file mode 100644 index 40c2340af3..0000000000 --- a/agenta-backend/agenta_backend/migrations/postgres/versions/78cde3fc549c_merge_conflicting_heads.py +++ /dev/null @@ -1,27 +0,0 @@ -"""Merge conflicting heads - -Revision ID: 78cde3fc549c -Revises: 5c29a64204f4 -Create Date: 2024-08-29 22:01:35.030820 - -""" - -from typing import Sequence, Union - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision: str = "78cde3fc549c" -down_revision: Union[str, None] = "5c29a64204f4" -branch_labels: Union[str, Sequence[str], None] = None -depends_on: Union[str, Sequence[str], None] = None - - -def upgrade() -> None: - pass - - -def downgrade() -> None: - pass From 6ca04dad59dfe9618b46b92d06ac93e1d6e61549 Mon Sep 17 00:00:00 2001 From: Abram Date: Fri, 15 Nov 2024 09:14:08 +0100 Subject: [PATCH 21/25] refactor (migrations): ensure `55bdd2e9a465` migration head makes use of an extended app_db model --- .../postgres/data_migrations/projects.py | 2 +- .../agenta_backend/models/deprecated_models.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/agenta-backend/agenta_backend/migrations/postgres/data_migrations/projects.py b/agenta-backend/agenta_backend/migrations/postgres/data_migrations/projects.py index 5ba0acc0f6..b2ba4be98b 100644 --- a/agenta-backend/agenta_backend/migrations/postgres/data_migrations/projects.py +++ b/agenta-backend/agenta_backend/migrations/postgres/data_migrations/projects.py @@ -8,9 +8,9 @@ from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker, Session +from agenta_backend.models.deprecated_models import ProjectScopedAppDB as AppDB from agenta_backend.models.db_models import ( ProjectDB, - AppDB, AppVariantDB, AppVariantRevisionsDB, VariantBaseDB, diff --git a/agenta-backend/agenta_backend/models/deprecated_models.py b/agenta-backend/agenta_backend/models/deprecated_models.py index 4bd4373b4e..80c3c04f65 100644 --- a/agenta-backend/agenta_backend/models/deprecated_models.py +++ b/agenta-backend/agenta_backend/models/deprecated_models.py @@ -15,6 +15,23 @@ DeprecatedBase = declarative_base() +class ProjectScopedAppDB(DeprecatedBase): + __tablename__ = "app_db" + __table_args__ = {"extend_existing": True} + + id = Column( + UUID(as_uuid=True), + primary_key=True, + default=uuid.uuid7, + unique=True, + nullable=False, + ) + app_name = Column(String) + project_id = Column( + UUID(as_uuid=True), ForeignKey("projects.id", ondelete="CASCADE") + ) + + class DeprecatedAppDB(DeprecatedBase): __tablename__ = "app_db" __table_args__ = {"extend_existing": True} From 38828ffd72611cc3b523e057ccb2c71a96613d7d Mon Sep 17 00:00:00 2001 From: jp-agenta Date: Mon, 18 Nov 2024 11:08:43 +0100 Subject: [PATCH 22/25] PROMPT -> COMPLETION --- .../0f086ebc2f82_added_the_app_type_column_to_the_app_db_.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agenta-backend/agenta_backend/migrations/postgres/versions/0f086ebc2f82_added_the_app_type_column_to_the_app_db_.py b/agenta-backend/agenta_backend/migrations/postgres/versions/0f086ebc2f82_added_the_app_type_column_to_the_app_db_.py index 33390edf63..aed4283756 100644 --- a/agenta-backend/agenta_backend/migrations/postgres/versions/0f086ebc2f82_added_the_app_type_column_to_the_app_db_.py +++ b/agenta-backend/agenta_backend/migrations/postgres/versions/0f086ebc2f82_added_the_app_type_column_to_the_app_db_.py @@ -25,7 +25,7 @@ def upgrade() -> None: # Create the enum type first app_enumtype = sa.Enum( "CHAT_TEMPLATE", - "PROMPT_TEMPLATE", + "COMPLETION_TEMPLATE", "CUSTOM", name="app_enumtype", ) @@ -52,7 +52,7 @@ def downgrade() -> None: # Then drop the enum type app_enumtype = sa.Enum( "CHAT_TEMPLATE", - "PROMPT_TEMPLATE", + "COMPLETION_TEMPLATE", "CUSTOM", name="app_enumtype", ) From d108da405cabc71ed5cb04a30175b71d19ce4a9f Mon Sep 17 00:00:00 2001 From: jp-agenta Date: Mon, 18 Nov 2024 11:09:32 +0100 Subject: [PATCH 23/25] prompt -> completion --- agenta-backend/agenta_backend/models/shared_models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agenta-backend/agenta_backend/models/shared_models.py b/agenta-backend/agenta_backend/models/shared_models.py index 19bb5d997f..d14ea22140 100644 --- a/agenta-backend/agenta_backend/models/shared_models.py +++ b/agenta-backend/agenta_backend/models/shared_models.py @@ -69,14 +69,14 @@ class TemplateType(enum.Enum): class AppType(str, enum.Enum): CHAT_TEMPLATE = "TEMPLATE:simple_chat" - PROMPT_TEMPLATE = "TEMPLATE:single_prompt" + COMPLETION_TEMPLATE = "TEMPLATE:simple_completion" CUSTOM = "CUSTOM" @classmethod def friendly_tag(cls, app_type: str): mappings = { cls.CHAT_TEMPLATE: "chat", - cls.PROMPT_TEMPLATE: "completion", + cls.COMPLETION_TEMPLATE: "completion", cls.CUSTOM: "custom", } return mappings.get(app_type, None) From fb37a4503261f0428d4762c9a2108f5368926810 Mon Sep 17 00:00:00 2001 From: jp-agenta Date: Mon, 18 Nov 2024 11:10:15 +0100 Subject: [PATCH 24/25] prompt -> completion --- agenta-backend/agenta_backend/services/db_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agenta-backend/agenta_backend/services/db_manager.py b/agenta-backend/agenta_backend/services/db_manager.py index 6c59b88972..73983b87b4 100644 --- a/agenta-backend/agenta_backend/services/db_manager.py +++ b/agenta-backend/agenta_backend/services/db_manager.py @@ -701,7 +701,7 @@ async def get_app_type_from_template_by_id(template_id: Optional[str]) -> str: template_db = await get_template(template_id=template_id) if "Completion Prompt" in template_db.title: - return AppType.PROMPT_TEMPLATE + return AppType.COMPLETION_TEMPLATE elif "Chat Prompt" in template_db.title: return AppType.CHAT_TEMPLATE return AppType.CUSTOM From 03d4695d551372ea86cbeefeb90dd37fb24ab144 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vega Date: Fri, 22 Nov 2024 16:33:12 +0100 Subject: [PATCH 25/25] pre-release --- agenta-cli/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agenta-cli/pyproject.toml b/agenta-cli/pyproject.toml index 81dc67dae7..04eb9ce188 100644 --- a/agenta-cli/pyproject.toml +++ b/agenta-cli/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "agenta" -version = "0.27.3" +version = "0.27.7a1" description = "The SDK for agenta is an open-source LLMOps platform." readme = "README.md" authors = ["Mahmoud Mabrouk "]