Skip to content

Commit

Permalink
Merge pull request #1661 from Agenta-AI/workflow-for-cli-commands
Browse files Browse the repository at this point in the history
Workflow for cli commands for cloud
  • Loading branch information
aakrem authored May 17, 2024
2 parents f8eca2c + 898f5a2 commit 079e025
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 23 deletions.
53 changes: 50 additions & 3 deletions .github/workflows/cli-commands-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- "agenta-cli/**"

jobs:
run-agenta-cli:
serve-to-oss:
runs-on: ubuntu-latest
environment: oss
steps:
Expand All @@ -34,9 +34,56 @@ jobs:

- name: Run agenta init
run: |
APP_NAME="gh-cli-$(shuf -i 1000-9999 -n 1)"
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

- 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

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-$(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-name team
shell: bash
continue-on-error: false

Expand Down
42 changes: 23 additions & 19 deletions agenta-cli/agenta/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,15 @@ def cli():


@click.command()
@click.option("--app_name", default="")
@click.option("--backend_host", default="")
def init(app_name: str, backend_host: 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."""

Expand Down Expand Up @@ -169,28 +175,26 @@ def init(app_name: str, backend_host: str):
click.echo(click.style(f"Error: {ex}", fg="red"))
sys.exit(1)

filtered_org = None
organization = None
organization_choices = {}
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()
filtered_org = next(
(
org
for org in user_organizations
if org.name == which_organization.split(":")[0]
),
None,
)
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=list(organization_choices.keys()),
).ask()
organisation_name = which_organization

organization = organization_choices.get(organisation_name)

# Get app_id after creating new app in the backend server
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"))
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/cli/init.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<Note>You can skip the questions and initialize a new app in one line: `agenta init --app_name test --backend_host https://cloud.agenta.ai/`</Note>
<Note>You can skip the questions and initialize a new app in one line: `agenta init --app-name test --backend-host https://cloud.agenta.ai/`</Note>

<Info> In case you are running agenta enterprise, please refer to the enterprise documentation on how to set up your agenta project</Info>

Expand Down

0 comments on commit 079e025

Please sign in to comment.