From d78136b65f157de57eaf4f298d477b927d8b619d Mon Sep 17 00:00:00 2001 From: aakrem Date: Thu, 16 May 2024 19:20:30 +0200 Subject: [PATCH 1/8] add organisation as cli option --- agenta-cli/agenta/cli/main.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/agenta-cli/agenta/cli/main.py b/agenta-cli/agenta/cli/main.py index 7bb43b6831..d1170adc1f 100644 --- a/agenta-cli/agenta/cli/main.py +++ b/agenta-cli/agenta/cli/main.py @@ -80,7 +80,8 @@ def cli(): @click.command() @click.option("--app_name", default="") @click.option("--backend_host", default="") -def init(app_name: str, backend_host: str): +@click.option("--organisation", default="") +def init(app_name: str, backend_host: str, organisation: str): init_option = "Blank App" if backend_host != "" and app_name != "" else "" """Initialize a new Agenta app with the template files.""" @@ -171,18 +172,17 @@ def init(app_name: str, backend_host: str): filtered_org = None if where_question == "On agenta cloud": - which_organization = questionary.select( - "Which organization do you want to create the app for?", - choices=[ - f"{org.name}: {org.description}" for org in user_organizations - ], - ).ask() + if not organisation: + which_organization = questionary.select( + "Which organization do you want to create the app for?", + choices=[ + f"{org.name}: {org.description}" for org in user_organizations + ], + ).ask() + organisation = which_organization.split(":")[0] + filtered_org = next( - ( - org - for org in user_organizations - if org.name == which_organization.split(":")[0] - ), + (org for org in user_organizations if org.name == organisation), None, ) From aa5a0ec849a7d19f8e2b8f777209dfb0cda16241 Mon Sep 17 00:00:00 2001 From: aakrem Date: Thu, 16 May 2024 19:21:17 +0200 Subject: [PATCH 2/8] add cli commands for cloud --- .github/workflows/cli-commands-tests.yml | 55 ++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cli-commands-tests.yml b/.github/workflows/cli-commands-tests.yml index 12312e6107..c666b49b8d 100644 --- a/.github/workflows/cli-commands-tests.yml +++ b/.github/workflows/cli-commands-tests.yml @@ -2,12 +2,12 @@ name: cli commands tests on: pull_request: - paths: - - "agenta-backend/**" - - "agenta-cli/**" + # paths: + # - "agenta-backend/**" + # - "agenta-cli/**" jobs: - run-agenta-cli: + serve-to-oss: runs-on: ubuntu-latest environment: oss steps: @@ -53,3 +53,50 @@ jobs: agenta variant serve --file_name app.py --overwrite shell: bash continue-on-error: false + + serve-to-cloud: + runs-on: ubuntu-latest + environment: oss + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up python + id: setup-python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip setuptools + pip install poetry + cd agenta-cli + pip install -e . + + - name: Create .env file + run: | + echo "OPENAI_API_KEY=${{ secrets.NEXT_PUBLIC_OPENAI_API_KEY }}" > .env + working-directory: examples/baby_name_generator + + - name: Run agenta init + run: | + APP_NAME="gh-cli-$(shuf -i 1000-9999 -n 1)" + cd examples/baby_name_generator + AGENTA_API_KEY=${{ secrets.AGENTA_API_KEY }} agenta init --app_name $APP_NAME --backend_host https://cloud.agenta.ai --organisation team + shell: bash + continue-on-error: false + + - name: Run agenta variant serve + run: | + cd examples/baby_name_generator + agenta variant serve --file_name app.py + shell: bash + continue-on-error: false + + - name: Run agenta variant serve with overwrite + run: | + cd examples/baby_name_generator + agenta variant serve --file_name app.py --overwrite + shell: bash + continue-on-error: false From ec7146c12d98a7b0a1610fd959a24791193953ae Mon Sep 17 00:00:00 2001 From: aakrem Date: Thu, 16 May 2024 20:36:17 +0200 Subject: [PATCH 3/8] rename app name --- .github/workflows/cli-commands-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cli-commands-tests.yml b/.github/workflows/cli-commands-tests.yml index c666b49b8d..66183726ff 100644 --- a/.github/workflows/cli-commands-tests.yml +++ b/.github/workflows/cli-commands-tests.yml @@ -34,7 +34,7 @@ jobs: - name: Run agenta init run: | - APP_NAME="gh-cli-$(shuf -i 1000-9999 -n 1)" + APP_NAME="gh-cli-$(date +'%y-%m-%d_%H-%M-%S')" cd examples/baby_name_generator agenta init --app_name $APP_NAME --backend_host ${{ secrets.BACKEND_HOST }} shell: bash @@ -81,7 +81,7 @@ jobs: - name: Run agenta init run: | - APP_NAME="gh-cli-$(shuf -i 1000-9999 -n 1)" + APP_NAME="gh-cli-$(date +'%y-%m-%d_%H-%M-%S')" cd examples/baby_name_generator AGENTA_API_KEY=${{ secrets.AGENTA_API_KEY }} agenta init --app_name $APP_NAME --backend_host https://cloud.agenta.ai --organisation team shell: bash From f2d51cf9acc9d3428f026c409eab4e1dc52a9fe1 Mon Sep 17 00:00:00 2001 From: aakrem Date: Thu, 16 May 2024 20:39:29 +0200 Subject: [PATCH 4/8] remove temp commented code --- .github/workflows/cli-commands-tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cli-commands-tests.yml b/.github/workflows/cli-commands-tests.yml index 66183726ff..7a9d7fb852 100644 --- a/.github/workflows/cli-commands-tests.yml +++ b/.github/workflows/cli-commands-tests.yml @@ -2,9 +2,9 @@ name: cli commands tests on: pull_request: - # paths: - # - "agenta-backend/**" - # - "agenta-cli/**" + paths: + - "agenta-backend/**" + - "agenta-cli/**" jobs: serve-to-oss: From 6a3717dd58f0171b02247b32140b96b7bb75b873 Mon Sep 17 00:00:00 2001 From: aakrem Date: Thu, 16 May 2024 20:45:41 +0200 Subject: [PATCH 5/8] adjust date format --- .github/workflows/cli-commands-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cli-commands-tests.yml b/.github/workflows/cli-commands-tests.yml index 7a9d7fb852..95168f5923 100644 --- a/.github/workflows/cli-commands-tests.yml +++ b/.github/workflows/cli-commands-tests.yml @@ -34,7 +34,7 @@ jobs: - name: Run agenta init run: | - APP_NAME="gh-cli-$(date +'%y-%m-%d_%H-%M-%S')" + APP_NAME="gh-cli-$(date +'%d-%m-%y_%H-%M-%S')" cd examples/baby_name_generator agenta init --app_name $APP_NAME --backend_host ${{ secrets.BACKEND_HOST }} shell: bash @@ -81,7 +81,7 @@ jobs: - name: Run agenta init run: | - APP_NAME="gh-cli-$(date +'%y-%m-%d_%H-%M-%S')" + APP_NAME="gh-cli-$(date +'%d-%m-%y_%H-%M-%S')" cd examples/baby_name_generator AGENTA_API_KEY=${{ secrets.AGENTA_API_KEY }} agenta init --app_name $APP_NAME --backend_host https://cloud.agenta.ai --organisation team shell: bash From 68d4f37a99670143a5ec1f4c89ed064816b7350e Mon Sep 17 00:00:00 2001 From: aakrem Date: Fri, 17 May 2024 10:56:14 +0200 Subject: [PATCH 6/8] adjust cli from camel_case to kebab-case and rename variables --- agenta-cli/agenta/cli/main.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/agenta-cli/agenta/cli/main.py b/agenta-cli/agenta/cli/main.py index d1170adc1f..e4e088aa83 100644 --- a/agenta-cli/agenta/cli/main.py +++ b/agenta-cli/agenta/cli/main.py @@ -78,10 +78,10 @@ def cli(): @click.command() -@click.option("--app_name", default="") -@click.option("--backend_host", default="") -@click.option("--organisation", default="") -def init(app_name: str, backend_host: str, organisation: str): +@click.option("--app-name", "--app_name", default=None) +@click.option("--backend-host", "backend_host", default=None) +@click.option("--organisation-name", "organisation_name", default=None, help="The name of the organisation") +def init(app_name: str, backend_host: str, organisation_name: str): init_option = "Blank App" if backend_host != "" and app_name != "" else "" """Initialize a new Agenta app with the template files.""" @@ -170,19 +170,19 @@ def init(app_name: str, backend_host: str, organisation: str): click.echo(click.style(f"Error: {ex}", fg="red")) sys.exit(1) - filtered_org = None + organization = None if where_question == "On agenta cloud": - if not organisation: + if not organisation_name: which_organization = questionary.select( "Which organization do you want to create the app for?", choices=[ f"{org.name}: {org.description}" for org in user_organizations ], ).ask() - organisation = which_organization.split(":")[0] + organisation_name = which_organization.split(":")[0] - filtered_org = next( - (org for org in user_organizations if org.name == organisation), + organization = next( + (org for org in user_organizations if org.name == organisation_name), None, ) @@ -190,7 +190,7 @@ def init(app_name: str, backend_host: str, organisation: str): try: app_id = client.apps.create_app( app_name=app_name, - organization_id=filtered_org.id if filtered_org else None, + organization_id=organization.id if organization else None, ).app_id except Exception as ex: click.echo(click.style(f"Error: {ex}", fg="red")) From 2c23bc5af46f5eecef08b657b1af744a92d55a3f Mon Sep 17 00:00:00 2001 From: aakrem Date: Fri, 17 May 2024 10:57:02 +0200 Subject: [PATCH 7/8] adjust workflow and docs with new kebab-case convention --- .github/workflows/cli-commands-tests.yml | 4 ++-- docs/reference/cli/init.mdx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cli-commands-tests.yml b/.github/workflows/cli-commands-tests.yml index 95168f5923..3740c2e72a 100644 --- a/.github/workflows/cli-commands-tests.yml +++ b/.github/workflows/cli-commands-tests.yml @@ -36,7 +36,7 @@ jobs: run: | APP_NAME="gh-cli-$(date +'%d-%m-%y_%H-%M-%S')" cd examples/baby_name_generator - agenta init --app_name $APP_NAME --backend_host ${{ secrets.BACKEND_HOST }} + agenta init --app-name $APP_NAME --backend-host ${{ secrets.BACKEND_HOST }} shell: bash continue-on-error: false @@ -83,7 +83,7 @@ jobs: run: | APP_NAME="gh-cli-$(date +'%d-%m-%y_%H-%M-%S')" cd examples/baby_name_generator - AGENTA_API_KEY=${{ secrets.AGENTA_API_KEY }} agenta init --app_name $APP_NAME --backend_host https://cloud.agenta.ai --organisation team + AGENTA_API_KEY=${{ secrets.AGENTA_API_KEY }} agenta init --app-name $APP_NAME --backend-host https://cloud.agenta.ai --organisation-name team shell: bash continue-on-error: false diff --git a/docs/reference/cli/init.mdx b/docs/reference/cli/init.mdx index a141a15d94..2b13bf96ca 100644 --- a/docs/reference/cli/init.mdx +++ b/docs/reference/cli/init.mdx @@ -41,7 +41,7 @@ Here you can select where the agenta platform is hosted. - Select local machine if you are running the OSS version of agenta on your local machine ([http://localhost](http://localhost)) - Select remote machine, in case you are running the OSS version of agenta on a remote machine. In that case you will prompted to enter the remote machine URL. -You can skip the questions and initialize a new app in one line: `agenta init --app_name test --backend_host https://cloud.agenta.ai/` +You can skip the questions and initialize a new app in one line: `agenta init --app-name test --backend-host https://cloud.agenta.ai/` In case you are running agenta enterprise, please refer to the enterprise documentation on how to set up your agenta project From 898f5a2015e5ca1effebec977822a9b5310bb098 Mon Sep 17 00:00:00 2001 From: aakrem Date: Fri, 17 May 2024 11:18:35 +0200 Subject: [PATCH 8/8] small refactor --- agenta-cli/agenta/cli/main.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/agenta-cli/agenta/cli/main.py b/agenta-cli/agenta/cli/main.py index e4e088aa83..ab3bf4a7ba 100644 --- a/agenta-cli/agenta/cli/main.py +++ b/agenta-cli/agenta/cli/main.py @@ -79,8 +79,13 @@ def cli(): @click.command() @click.option("--app-name", "--app_name", default=None) -@click.option("--backend-host", "backend_host", default=None) -@click.option("--organisation-name", "organisation_name", default=None, help="The name of the organisation") +@click.option("--backend-host", "backend_host", default=None) +@click.option( + "--organisation-name", + "organisation_name", + default=None, + help="The name of the organisation", +) def init(app_name: str, backend_host: str, organisation_name: str): init_option = "Blank App" if backend_host != "" and app_name != "" else "" """Initialize a new Agenta app with the template files.""" @@ -171,20 +176,19 @@ def init(app_name: str, backend_host: str, organisation_name: str): sys.exit(1) organization = None + organization_choices = {} if where_question == "On agenta cloud": if not organisation_name: + organization_choices = { + f"{org.name}": org for org in user_organizations + } which_organization = questionary.select( "Which organization do you want to create the app for?", - choices=[ - f"{org.name}: {org.description}" for org in user_organizations - ], + choices=list(organization_choices.keys()), ).ask() - organisation_name = which_organization.split(":")[0] + organisation_name = which_organization - organization = next( - (org for org in user_organizations if org.name == organisation_name), - None, - ) + organization = organization_choices.get(organisation_name) # Get app_id after creating new app in the backend server try: