Skip to content

Commit

Permalink
Merge pull request #25 from Agenta-AI/evaluation_dynamic
Browse files Browse the repository at this point in the history
Evaluation dynamic
  • Loading branch information
mmabrouk authored May 24, 2023
2 parents 8d28bf0 + 6bbbd8a commit 0db1868
Show file tree
Hide file tree
Showing 55 changed files with 493 additions and 214 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ agenta-cli/tests/
examples/pitch_genius/config.toml
examples/pitch_genius/agenta.py
examples/pitch_genius/main.py
agenta-deploy-server/db/deploy.db
agenta-backend/db/deploy.db

.vscode
6 changes: 3 additions & 3 deletions agenta-deploy-server/Dockerfile → agenta-backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ RUN pip install --upgrade pip \
COPY pyproject.toml poetry.lock* README.md sleep.py /app/

# This is a hack to create a dummy module so that poetry install doesn't fail
RUN mkdir -p /app/deploy_server
RUN touch /app/deploy_server/__init__.py
RUN mkdir -p /app/agenta_backend
RUN touch /app/agenta_backend/__init__.py

# Project initialization:
RUN poetry config virtualenvs.create false \
&& poetry install --no-interaction --no-ansi
# remove dummy module
RUN rm -r /app/deploy_server
RUN rm -r /app/agenta_backend
EXPOSE 8000
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import toml

# Load the settings from the .toml file
toml_config = toml.load("deploy_server/config.toml")
toml_config = toml.load("agenta_backend/config.toml")

# Set the environment variables from the TOML configurations
os.environ["DOCKER_REGISTRY_URL"] = toml_config["docker_registry_url"]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from deploy_server.routers import app_variant
from deploy_server.routers import app_evaluation_router
from deploy_server.routers import dataset_router
from agenta_backend.routers import app_variant
from agenta_backend.routers import app_evaluation_router
from agenta_backend.routers import dataset_router

origins = [
"http://localhost:3000",
Expand All @@ -22,6 +22,7 @@
allow_headers=["*"],
)


@app.on_event("startup")
async def startup_event():
# TOOD:: Add connection to registry
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Converts db models to pydantic models
"""
from deploy_server.models.db_models import AppVariantDB, ImageDB
from deploy_server.models.api.api_models import AppVariant, Image
from agenta_backend.models.db_models import AppVariantDB, ImageDB
from agenta_backend.models.api.api_models import AppVariant, Image


def app_variant_db_to_pydantic(app_variant_db: AppVariantDB) -> AppVariant:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi import HTTPException, APIRouter
from deploy_server.models.api.app_evaluation_model import ComparisonTable, EvaluationRow, EvaluationRowUpdate, ComparisonTableUpdate
from deploy_server.services.db_mongo import comparison_tables, evaluation_rows
from agenta_backend.models.api.app_evaluation_model import ComparisonTable, EvaluationRow, EvaluationRowUpdate, ComparisonTableUpdate
from agenta_backend.services.db_mongo import comparison_tables, evaluation_rows
from datetime import datetime
from bson import ObjectId
from typing import List
Expand Down Expand Up @@ -142,7 +142,7 @@ async def fetch_results(comparison_table_id: str):
'comparison_table_id': comparison_table_id
})

results["votes"].append({"0" : flag_votes_nb});
results["votes"].append({"0": flag_votes_nb})

comparison_table_rows_nb = await evaluation_rows.count_documents({
'comparison_table_id': comparison_table_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
"""
from typing import List

from deploy_server.models.api.api_models import AppVariant, Image, URI, App
from deploy_server.services import docker_utils
from deploy_server.services import db_manager
from agenta_backend.models.api.api_models import AppVariant, Image, URI, App
from agenta_backend.services import docker_utils
from agenta_backend.services import db_manager
from fastapi import APIRouter, HTTPException
from deploy_server.config import settings
from agenta_backend.config import settings
from typing import Optional

router = APIRouter()

# Add route handlers for image-related operations


@router.get("/list/", response_model=List[AppVariant]) # deprecated
@router.get("/list_variants/", response_model=List[AppVariant])
async def list_app_variants(app_name: Optional[str] = None):
"""Lists the app variants from our repository.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
from fastapi import HTTPException, APIRouter, UploadFile, File
from deploy_server.services.db_mongo import datasets
from deploy_server.models.api.dataset_model import DatasetModel, UploadResponse
from deploy_server.services.db_mongo import datasets
from agenta_backend.services.db_mongo import datasets
from agenta_backend.models.api.dataset_model import DatasetModel, UploadResponse
from agenta_backend.services.db_mongo import datasets
from datetime import datetime
from bson import ObjectId
import csv
Expand Down Expand Up @@ -95,6 +95,7 @@ async def get_datasets():
document['_id'] = str(document['_id'])
return documents


@router.get("/{dataset_id}", tags=["datasets"])
async def get_dataset(dataset_id: str):
"""
Expand All @@ -112,4 +113,4 @@ async def get_dataset(dataset_id: str):
dataset["_id"] = str(dataset["_id"])
return dataset
else:
raise HTTPException(status_code=404, detail=f"dataset with id {dataset_id} not found")
raise HTTPException(status_code=404, detail=f"dataset with id {dataset_id} not found")
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from sqlmodel import Session, SQLModel, create_engine
from deploy_server.models.api.api_models import AppVariant, Image, App
from deploy_server.models.db_models import AppVariantDB, ImageDB
from deploy_server.models.converters import app_variant_db_to_pydantic, image_db_to_pydantic
from agenta_backend.models.api.api_models import AppVariant, Image, App
from agenta_backend.models.db_models import AppVariantDB, ImageDB
from agenta_backend.models.converters import app_variant_db_to_pydantic, image_db_to_pydantic
from typing import List
import os

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import List

import docker
from deploy_server.config import settings
from deploy_server.models.api.api_models import AppVariant, Image, URI
from agenta_backend.config import settings
from agenta_backend.models.api.api_models import AppVariant, Image, URI


client = docker.from_env()
Expand All @@ -20,7 +20,7 @@ def port_generator(start_port=9000):

def list_images() -> List[Image]:
"""Lists all the images from our repository
These are tagged with the registry name (config in both deploy_server and agenta-cli)
These are tagged with the registry name (config in both agenta_backend and agenta-cli)
Returns:
List[Image]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[tool.poetry]
name = "deploy_server"
name = "agenta_backend"
version = "0.1.0"
description = ""
authors = ["Mahmoud Mabrouk <mahmoudmabrouk.mail@gmail.com>"]
readme = "README.md"
packages = [{include = "deploy_server"}]
packages = [{include = "agenta_backend"}]

[tool.poetry.dependencies]
python = "^3.9"
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions agenta-backend/start_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uvicorn agenta_backend.main:app --reload --host 0.0.0.0 --port 8881
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from fastapi.testclient import TestClient
from deploy_server.main import app
from agenta_backend.main import app


@pytest.fixture(scope="session", autouse=True)
Expand Down
12 changes: 12 additions & 0 deletions agenta-backend/tests/manual_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os
import docker
from agenta_backend.config import settings

from agenta_backend.services.docker_utils import list_images, start_container, stop_container, delete_container
from agenta_backend.services.db_manager import add_app_variant, list_app_variants, get_image
from agenta_backend.models.api_models import AppVariant, Image, URI

client = docker.from_env()
uri = start_container("agenta-server/clitest", "clitest")

print(uri)
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest
from deploy_server.models.api.api_models import AppVariant, Image, App
from agenta_backend.models.api.api_models import AppVariant, Image, App
from random import choice
from string import ascii_letters
from deploy_server.services.db_manager import get_session, list_app_variants, add_app_variant, remove_app_variant, engine, get_image, list_app_names
from agenta_backend.services.db_manager import get_session, list_app_variants, add_app_variant, remove_app_variant, engine, get_image, list_app_names
from sqlmodel import Session


Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pytest
from unittest.mock import MagicMock, patch
# replace with your actual module name
from deploy_server.services.docker_utils import start_container, stop_container, delete_container, list_images
from agenta_backend.services.docker_utils import start_container, stop_container, delete_container, list_images
# replace with your actual module name
from deploy_server.models.api_models import Image, Container
from agenta_backend.models.api_models import Image, Container


@pytest.fixture
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
from sqlmodel import Session
from deploy_server.services.db_manager import get_session, list_app_variants, add_app_variant, remove_app_variant, engine, get_image
import docker
import pytest
from fastapi.testclient import TestClient
from deploy_server.main import app
from deploy_server.models.api.api_models import AppVariant, Image
import io
from random import choice
from string import ascii_letters

import docker
import pytest
from agenta_backend.main import app
from agenta_backend.models.api.api_models import AppVariant, Image
from agenta_backend.services.db_manager import (add_app_variant, engine,
get_image, get_session,
list_app_variants,
remove_app_variant)
from fastapi.testclient import TestClient
from sqlmodel import Session

client = TestClient(app)


Expand Down Expand Up @@ -63,15 +67,15 @@ def docker_test_image(docker_client):


def test_list_app_variant():
response = client.get("/app_variant/list/")
response = client.get("/app_variant/list_variants/")
assert response.status_code == 200
assert response.json() == []


def test_list_app_variant_after_manual_add(app_variant, image):
# This is the function from db_manager.py
add_app_variant(app_variant, image)
response = client.get("/app_variant/list/")
response = client.get("/app_variant/list_variants/")
assert response.status_code == 200
assert len(response.json()) == 1
result = AppVariant(**response.json()[0])
Expand All @@ -85,7 +89,7 @@ def test_add_variant(app_variant, docker_test_image):
response = client.post(
"app_variant/add/", json={"app_variant": app_variant.dict(), "image": image.dict()})
assert response.status_code == 200
response = client.get("/app_variant/list/")
response = client.get("/app_variant/list_variants/")
assert response.status_code == 200
assert len(response.json()) == 1
result = AppVariant(**response.json()[0])
Expand Down
2 changes: 1 addition & 1 deletion agenta-cli/agenta/docker/docker-assets/Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ RUN pip install fastapi uvicorn python-dotenv
EXPOSE 80

CMD ["python", "main.py"]
# uvicorn deploy_server.main:app --reload --host 0.0.0.0 --port 8881
# uvicorn agenta_backend.main:app --reload --host 0.0.0.0 --port 8881
# TODO: add root_path as env variable and give it to the docker to solve the docs issue
2 changes: 1 addition & 1 deletion agenta-cli/agenta/templates/simple_prompt/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


@post
def completion(product: str, temperature: FloatParam = 0.9, prompt_template: TextParam = default_prompt) -> str:
def generate(product: str, temperature: FloatParam = 0.9, prompt_template: TextParam = default_prompt) -> str:
llm = OpenAI(temperature=temperature)
prompt = PromptTemplate(
input_variables=["product"],
Expand Down
17 changes: 16 additions & 1 deletion agenta-cli/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions agenta-cli/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ fastapi = "^0.95.1"
toml = "^0.10.2"
questionary = "^1.10.0"
ipdb = "^0.13.13"
python-dotenv = "^1.0.0"

[tool.poetry.dev-dependencies]
pytest = "^6.2"
Expand Down
1 change: 0 additions & 1 deletion agenta-deploy-server/start_server.sh

This file was deleted.

12 changes: 0 additions & 12 deletions agenta-deploy-server/tests/manual_tests.py

This file was deleted.

27 changes: 27 additions & 0 deletions agenta-web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion agenta-web/src/components/AppSelector/AppSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const AppSelector = () => {
const { data, error, isLoading } = useSWR('http://localhost/api/app_variant/list_apps/', fetcher)
if (error) return <div>failed to load</div>
if (isLoading) return <div>loading...</div>
console.log(data)


return (
Expand Down
Loading

0 comments on commit 0db1868

Please sign in to comment.