Skip to content

Commit

Permalink
Merge branch 'main' into issue-1622/-Refactor-API-Endpoints-into-Serv…
Browse files Browse the repository at this point in the history
…ices-Folder
  • Loading branch information
bekossy committed May 17, 2024
2 parents c173bea + 079e025 commit 49ed7df
Show file tree
Hide file tree
Showing 226 changed files with 8,681 additions and 4,914 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,15 @@
"contributions": [
"code"
]
},
{
"login": "youcefs21",
"name": "Youcef Boumar",
"avatar_url": "https://avatars.githubusercontent.com/u/34604972?v=4",
"profile": "https://github.com/youcefs21",
"contributions": [
"doc"
]
}
],
"contributorsPerLine": 7,
Expand Down
35 changes: 35 additions & 0 deletions .github/images/we-are-hiring.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
102 changes: 102 additions & 0 deletions .github/workflows/cli-commands-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: cli commands tests

on:
pull_request:
paths:
- "agenta-backend/**"
- "agenta-cli/**"

jobs:
serve-to-oss:
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 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

- 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
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<div align="center" style="margin: 30px">
<div>
<a href="https://agentaai.notion.site/Careers-at-agenta-fb8a76d4d9044e27bd3a32678818dbc8/">
<img src="https://github.com/Agenta-AI/agenta/raw/main/.github/images/we-are-hiring.svg" alt="We are hiring! Join our team!" width="350" height="60" alt="We are hiring! Join our team!" width="350" height="60">
</a>
</div>
<a href="https://agenta.ai/">
<div align="center" >
<picture >
Expand Down Expand Up @@ -148,6 +153,11 @@ To disable anonymized telemetry, follow these steps:

After making this change, restart Agenta Compose.

# ⭐️ Join Our Team
- [Founding Lead Software Engineer Backend](https://agentaai.notion.site/Founding-Lead-Software-Engineer-Backend-d70bfefed6d543778bc4aa38b543a678)
- [Founding Product Engineer Frontend](https://agentaai.notion.site/Founding-Product-Engineer-Frontend-b6d26a3e9b254be6b6c2bfffbf0b53c5)
- [Founding Product Designer](https://agentaai.notion.site/Founding-Product-Designer-96b1e760ff0241fd96632578d533a778)

# Contributing

We warmly welcome contributions to Agenta. Feel free to submit issues, fork the repository, and send pull requests.
Expand All @@ -159,7 +169,7 @@ Check out our [Contributing Guide](https://docs.agenta.ai/contributing/getting-s
## Contributors ✨

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-43-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-44-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Expand Down Expand Up @@ -225,6 +235,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/vishalvanpariya"><img src="https://avatars.githubusercontent.com/u/27823328?v=4?s=100" width="100px;" alt="Vishal Vanpariya"/><br /><sub><b>Vishal Vanpariya</b></sub></a><br /><a href="https://github.com/Agenta-AI/agenta/commits?author=vishalvanpariya" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/youcefs21"><img src="https://avatars.githubusercontent.com/u/34604972?v=4?s=100" width="100px;" alt="Youcef Boumar"/><br /><sub><b>Youcef Boumar</b></sub></a><br /><a href="https://github.com/Agenta-AI/agenta/commits?author=youcefs21" title="Documentation">📖</a></td>
</tr>
</tbody>
</table>
Expand Down
15 changes: 15 additions & 0 deletions agenta-backend/agenta_backend/routers/variants_router.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import inspect
import logging
from typing import Any, Optional, Union, List

Expand All @@ -24,11 +25,13 @@
Image_ as Image,
AppVariantResponse_ as AppVariantResponse,
)
from agenta_backend.cloud.services import logs_manager
else:
from agenta_backend.models.api.api_models import (
Image,
AppVariantResponse,
)
from agenta_backend.services import logs_manager

from agenta_backend.models.api.api_models import (
URI,
Expand Down Expand Up @@ -312,6 +315,18 @@ async def start_variant(
return url


@router.get("/{variant_id}/logs/", operation_id="retrieve_variant_logs")
async def retrieve_variant_logs(variant_id: str, request: Request):
try:
app_variant = await db_manager.fetch_app_variant_by_id(variant_id)
deployment = await db_manager.get_deployment_by_appid(str(app_variant.app.id))
logs_result = await logs_manager.retrieve_logs(deployment.container_id)
return logs_result
except Exception as exc:
logger.exception(f"An error occurred: {str(exc)}")
raise HTTPException(500, {"message": str(exc)})


@router.get(
"/{variant_id}/",
operation_id="get_variant",
Expand Down
24 changes: 15 additions & 9 deletions agenta-backend/agenta_backend/services/db_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,17 +994,15 @@ async def check_is_last_variant_for_image(db_app_variant: AppVariantDB) -> bool:
true if it's the last variant, false otherwise
"""

query_expression = {"base.id": db_app_variant.base.id}
query = AppVariantDB.find(AppVariantDB.base.id == ObjectId(db_app_variant.base.id))

if isCloudEE():
query_expression.update(
{
"organization.id": db_app_variant.organization.id,
"workspace.id": db_app_variant.workspace.id,
}
query = query.find(
AppVariantDB.organization.id == db_app_variant.organization.id,
AppVariantDB.workspace.id == db_app_variant.workspace.id,
)

count_variants = await AppVariantDB.find(query_expression).count()
count_variants = await query.count()
return count_variants == 1


Expand All @@ -1017,7 +1015,10 @@ async def remove_deployment(deployment_db: DeploymentDB):
logger.debug("Removing deployment")
assert deployment_db is not None, "deployment_db is missing"

await deployment_db.delete()
deployment = await DeploymentDB.find_one(
DeploymentDB.id == ObjectId(deployment_db.id)
)
await deployment.delete()


async def remove_app_variant_from_db(app_variant_db: AppVariantDB):
Expand All @@ -1041,7 +1042,10 @@ async def remove_app_variant_from_db(app_variant_db: AppVariantDB):
for app_variant_revision in app_variant_revisions:
await app_variant_revision.delete()

await app_variant_db.delete()
app_variant = await AppVariantDB.find_one(
AppVariantDB.id == ObjectId(app_variant_db.id)
)
await app_variant.delete()


async def deploy_to_environment(
Expand Down Expand Up @@ -1376,6 +1380,8 @@ async def remove_image(image: ImageDB):
"""
if image is None:
raise ValueError("Image is None")

image = await ImageDB.find_one(ImageDB.id == ObjectId(image.id))
await image.delete()


Expand Down
18 changes: 18 additions & 0 deletions agenta-backend/agenta_backend/services/logs_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import aiodocker


async def retrieve_logs(container_id: str) -> str:
"""
Retrieves and returns the last 10 lines of logs (both stdout and stderr)
for a specified Docker container.
Args:
container_id (str): The docker container identifier
Returns:
the last 10 lines of logs
"""

async with aiodocker.Docker() as client:
container = await client.containers.get(container_id)
logs = await container.log(stdout=True, stderr=True)
outputs = logs[::-1][:10]
return "".join(outputs)
Loading

0 comments on commit 49ed7df

Please sign in to comment.