Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move templates to backend #2125

Merged
merged 7 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions agenta-backend/agenta_backend/resources/templates/templates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
templates_info = {
"chat_openai": {
"name": "Single Prompt OpenAI",
"description": "Sample single prompt application using different OpenAI models",
},
"technical_startup_ideas": {
"name": "Chat Application OpenAI",
"description": "Sample Chat application using different OpenAI models",
},
}


def get_oss_templates():
aakrem marked this conversation as resolved.
Show resolved Hide resolved
"""
Returns a list of templates.

Returns:
List[dict]: A list of template dictionaries.
"""
return templates_info
36 changes: 7 additions & 29 deletions agenta-backend/agenta_backend/services/templates_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@
from agenta_backend.utils import redis_utils
from agenta_backend.services import db_manager
from agenta_backend.utils.common import isCloud, isOss
from agenta_backend.resources.templates.templates import get_oss_templates

from datetime import datetime, timezone

from agenta_backend.services.helpers import convert_to_utc_datetime

from agenta_backend.resources.templates.templates import (
get_oss_templates as get_templates,
)

if isCloud() or isOss():
from agenta_backend.services import container_manager


templates_base_url = os.getenv("TEMPLATES_BASE_URL")
agenta_template_repo = os.getenv("AGENTA_TEMPLATE_REPO")
docker_hub_url = os.getenv("DOCKER_HUB_URL")
Expand All @@ -36,7 +42,7 @@ async def update_and_sync_templates(cache: bool = True) -> None:
templates = await retrieve_templates_from_dockerhub_cached(cache)

templates_ids_not_to_remove = []
templates_info = await retrieve_templates_info_from_s3(cache)
templates_info = get_templates()
for temp in templates:
if temp["name"] in list(templates_info.keys()):
templates_ids_not_to_remove.append(int(temp["id"]))
Expand Down Expand Up @@ -96,34 +102,6 @@ async def retrieve_templates_from_dockerhub_cached(cache: bool) -> List[dict]:
return response_data


async def retrieve_templates_info_from_s3(
cache: bool,
) -> Dict[str, Dict[str, Any]]:
"""Retrieves templates information from s3 and caches the data in Redis for future use.

Args:
cache: A boolean value that indicates whether to use the cached data or not.

Returns:
Information about organization in s3 (cached or network-call)
"""

r = redis_utils.redis_connection()
if cache:
cached_data = r.get("temp_data")
if cached_data is not None:
print("Using cache...")
return json.loads(cached_data)

# If not cached, fetch data from Docker Hub and cache it in Redis
response = await get_templates_info_from_s3(f"{templates_base_url}/llm_info.json")

# Cache the data in Redis for 60 minutes
r.set("temp_data", json.dumps(response), ex=900)
print("Using network call...")
return response


@backoff.on_exception(backoff.expo, (ConnectError, CancelledError), max_tries=5)
async def retrieve_templates_from_dockerhub(
url: str, repo_name: str
Expand Down
Loading