From d5918dca483f38e1dc0f76bcb2b2ac316a5a76cf Mon Sep 17 00:00:00 2001 From: mao3267 Date: Tue, 31 Dec 2024 11:00:51 +0800 Subject: [PATCH 1/9] feat: add template for custom agent build Signed-off-by: mao3267 --- basic-custom-agent/cookiecutter.json | 3 + .../{{cookiecutter.project_name}}/Dockerfile | 10 ++ .../{{cookiecutter.project_name}}/README.md | 39 ++++++++ .../docker_build.sh | 47 +++++++++ .../{{cookiecutter.project_name}}/__init__.py | 16 +++ .../{{cookiecutter.project_name}}/agent.py | 97 +++++++++++++++++++ .../{{cookiecutter.project_name}}/task.py | 85 ++++++++++++++++ .../{{cookiecutter.project_name}}/setup.py | 40 ++++++++ .../docker_build.sh | 2 +- 9 files changed, 338 insertions(+), 1 deletion(-) create mode 100644 basic-custom-agent/cookiecutter.json create mode 100644 basic-custom-agent/{{cookiecutter.project_name}}/Dockerfile create mode 100644 basic-custom-agent/{{cookiecutter.project_name}}/README.md create mode 100644 basic-custom-agent/{{cookiecutter.project_name}}/docker_build.sh create mode 100644 basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/__init__.py create mode 100644 basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/agent.py create mode 100644 basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/task.py create mode 100644 basic-custom-agent/{{cookiecutter.project_name}}/setup.py diff --git a/basic-custom-agent/cookiecutter.json b/basic-custom-agent/cookiecutter.json new file mode 100644 index 0000000..c99968b --- /dev/null +++ b/basic-custom-agent/cookiecutter.json @@ -0,0 +1,3 @@ +{ + "project_name": "Basic custom agent" +} \ No newline at end of file diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/Dockerfile b/basic-custom-agent/{{cookiecutter.project_name}}/Dockerfile new file mode 100644 index 0000000..7f6caab --- /dev/null +++ b/basic-custom-agent/{{cookiecutter.project_name}}/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.10-slim-bookworm + +MAINTAINER Flyte Team +LABEL org.opencontainers.image.source=https://github.com/flyteorg/flytekit + +# additional dependencies for running in k8s +RUN pip install prometheus-client grpcio-health-checking +# flytekit will autoload the agent if package is installed. +RUN pip install flytekitplugins-bigquery +CMD pyflyte serve agent --port 8000 \ No newline at end of file diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/README.md b/basic-custom-agent/{{cookiecutter.project_name}}/README.md new file mode 100644 index 0000000..7c2017e --- /dev/null +++ b/basic-custom-agent/{{cookiecutter.project_name}}/README.md @@ -0,0 +1,39 @@ +# flyte-custom-agent-template +How to write your custom agent and build it with a Dockerfile. + +## Concepts +1. flytekit will load plugin [here](https://github.com/flyteorg/flytekit/blob/ff2d0da686c82266db4dbf764a009896cf062349/flytekit/__init__.py#L322-L323), +so you must add your plugin to `entry_points` in [setup.py](https://github.com/Future-Outlier/flyte-custom-agent-template/blob/main/flytekit-bigquery/setup.py#L39). +2. Agent registration is triggered by loading the plugin. For example, +BigQuery's agent registration is triggered [here](https://github.com/Future-Outlier/flyte-custom-agent/blob/main/flytekit-bigquery/flytekitplugins/bigquery/agent.py#L97) + +## Build your custom agent +1. Following the folder structure in this repo, you can build your custom agent. +2. Build your own custom agent ([learn more](https://docs.flyte.org/en/latest/user_guide/flyte_agents/developing_agents.html)) + +> In the following command, `localhost:30000` is the Docker registry that ships with the Flyte demo cluster. Use it or replace it with a registry where you have push permissions. + +```bash +docker buildx build --platform linux/amd64 -t localhost:30000/flyteagent:custom-bigquery -f Dockerfile . +``` + +3. Test the image: +```bash +docker run -it localhost:30000/flyteagent:custom-bigquery +``` + +4. Check the logs (sensor is created by flytekit, bigquery is created by the custom agent) +``` +(dev) future@outlier ~ % docker run -it localhost:30000/flyteagent:custom-bigquery + +WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested +๐Ÿš€ Starting the agent service... +Starting up the server to expose the prometheus metrics... + Agent Metadata +โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”“ +โ”ƒ Agent Name โ”ƒ Support Task Types โ”ƒ Is Sync โ”ƒ +โ”กโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฉ +โ”‚ Sensor โ”‚ sensor (v0) โ”‚ False โ”‚ +โ”‚ Bigquery Agent โ”‚ bigquery_query_job_task (v0) โ”‚ False โ”‚ +โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ +``` \ No newline at end of file diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/docker_build.sh b/basic-custom-agent/{{cookiecutter.project_name}}/docker_build.sh new file mode 100644 index 0000000..df24f32 --- /dev/null +++ b/basic-custom-agent/{{cookiecutter.project_name}}/docker_build.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +set -e + +# SET the REGISTRY here, where the docker container should be pushed +REGISTRY="" + +# SET the appname here +PROJECT_NAME="{{ cookiecutter.project_name }}" + +while getopts a:r:v:h flag +do + case "${flag}" in + a) PROJECT_NAME=${OPTARG};; + r) REGISTRY=${OPTARG};; + v) VERSION=${OPTARG};; + h) echo "Usage: ${0} [-h|[-p ][-r ][-v ]]" + echo " h: help (this message)" + echo " p: PROJECT_NAME for your workflows. Defaults to '{{ cookiecutter.project_name }}'." + echo " r: REGISTRY name where the docker container should be pushed. Defaults to none - localhost" + echo " v: VERSION of the build. Defaults to using the current git head SHA" + exit 1;; + *) echo "Usage: ${0} [-h|[-a ][-r ][-v ]]" + exit 1;; + esac +done + +# If you are using git, then this will automatically use the git head as the +# version +if [ -z "${VERSION}" ]; then + echo "No version set, using git commit head sha as the version" + VERSION=$(git rev-parse HEAD) +fi + +TAG=${PROJECT_NAME}:${VERSION} +if [ -z "${REGISTRY}" ]; then + echo "No registry set, creating tag ${TAG}" +else + TAG="${REGISTRY}/${TAG}" + echo "Registry set: creating tag ${TAG}" +fi + +# Should be run in the folder that has Dockerfile +docker buildx build --platform linux/amd64 -t "${TAG}" -f Dockerfile . +docker push "${TAG}" + +echo "Docker image built with tag ${TAG}. You can use this image to run pyflyte package." diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/__init__.py b/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/__init__.py new file mode 100644 index 0000000..e2e190a --- /dev/null +++ b/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/__init__.py @@ -0,0 +1,16 @@ +""" +.. currentmodule:: flytekitplugins.bigquery + +This package contains things that are useful when extending Flytekit. + +.. autosummary:: + :template: custom.rst + :toctree: generated/ + + BigQueryConfig + BigQueryTask + BigQueryAgent +""" + +from .agent import BigQueryAgent +from .task import BigQueryConfig, BigQueryTask \ No newline at end of file diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/agent.py b/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/agent.py new file mode 100644 index 0000000..0fd6dec --- /dev/null +++ b/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/agent.py @@ -0,0 +1,97 @@ +import datetime +from dataclasses import dataclass +from typing import Dict, Optional + +from flyteidl.core.execution_pb2 import TaskExecution, TaskLog +from google.cloud import bigquery + +from flytekit import FlyteContextManager, StructuredDataset, logger +from flytekit.core.type_engine import TypeEngine +from flytekit.extend.backend.base_agent import AgentRegistry, AsyncAgentBase, Resource, ResourceMeta +from flytekit.extend.backend.utils import convert_to_flyte_phase +from flytekit.models.literals import LiteralMap +from flytekit.models.task import TaskTemplate + +pythonTypeToBigQueryType: Dict[type, str] = { + # https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#data_type_sizes + list: "ARRAY", + bool: "BOOL", + bytes: "BYTES", + datetime.datetime: "DATETIME", + float: "FLOAT64", + int: "INT64", + str: "STRING", +} + + +@dataclass +class BigQueryMetadata(ResourceMeta): + job_id: str + project: str + location: str + + +class BigQueryAgent(AsyncAgentBase): + name = "Bigquery Agent" + + def __init__(self): + super().__init__(task_type_name="bigquery_query_job_task", metadata_type=BigQueryMetadata) + + def create( + self, + task_template: TaskTemplate, + inputs: Optional[LiteralMap] = None, + **kwargs, + ) -> BigQueryMetadata: + job_config = None + if inputs: + ctx = FlyteContextManager.current_context() + python_interface_inputs = { + name: TypeEngine.guess_python_type(lt.type) for name, lt in task_template.interface.inputs.items() + } + native_inputs = TypeEngine.literal_map_to_kwargs(ctx, inputs, python_interface_inputs) + logger.info(f"Create BigQuery job config with inputs: {native_inputs}") + job_config = bigquery.QueryJobConfig( + query_parameters=[ + bigquery.ScalarQueryParameter(name, pythonTypeToBigQueryType[python_interface_inputs[name]], val) + for name, val in native_inputs.items() + ] + ) + + custom = task_template.custom + project = custom["ProjectID"] + location = custom["Location"] + client = bigquery.Client(project=project, location=location) + query_job = client.query(task_template.sql.statement, job_config=job_config) + + return BigQueryMetadata(job_id=str(query_job.job_id), location=location, project=project) + + def get(self, resource_meta: BigQueryMetadata, **kwargs) -> Resource: + client = bigquery.Client() + log_link = TaskLog( + uri=f"https://console.cloud.google.com/bigquery?project={resource_meta.project}&j=bq:{resource_meta.location}:{resource_meta.job_id}&page=queryresults", + name="BigQuery Console", + ) + + job = client.get_job(resource_meta.job_id, resource_meta.project, resource_meta.location) + if job.errors: + logger.error("failed to run BigQuery job with error:", job.errors.__str__()) + return Resource(phase=TaskExecution.FAILED, message=job.errors.__str__(), log_links=[log_link]) + + cur_phase = convert_to_flyte_phase(str(job.state)) + res = None + + if cur_phase == TaskExecution.SUCCEEDED: + dst = job.destination + if dst: + output_location = f"bq://{dst.project}:{dst.dataset_id}.{dst.table_id}" + res = {"results": StructuredDataset(uri=output_location)} + + return Resource(phase=cur_phase, message=str(job.state), log_links=[log_link], outputs=res) + + def delete(self, resource_meta: BigQueryMetadata, **kwargs): + client = bigquery.Client() + client.cancel_job(resource_meta.job_id, resource_meta.project, resource_meta.location) + + +AgentRegistry.register(BigQueryAgent()) \ No newline at end of file diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/task.py b/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/task.py new file mode 100644 index 0000000..8f63f8b --- /dev/null +++ b/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/task.py @@ -0,0 +1,85 @@ +from dataclasses import dataclass +from typing import Any, Dict, Optional, Type + +from google.protobuf import json_format +from google.protobuf.struct_pb2 import Struct + +from flytekit import lazy_module +from flytekit.configuration import SerializationSettings +from flytekit.extend import SQLTask +from flytekit.extend.backend.base_agent import AsyncAgentExecutorMixin +from flytekit.models import task as _task_model +from flytekit.types.structured import StructuredDataset + +bigquery = lazy_module("google.cloud.bigquery") + + +@dataclass +class BigQueryConfig(object): + """ + BigQueryConfig should be used to configure a BigQuery Task. + """ + + ProjectID: str + Location: Optional[str] = None + QueryJobConfig: Optional[bigquery.QueryJobConfig] = None + + +class BigQueryTask(AsyncAgentExecutorMixin, SQLTask[BigQueryConfig]): + """ + This is the simplest form of a BigQuery Task, that can be used even for tasks that do not produce any output. + """ + + # This task is executed using the BigQuery handler in the backend. + # https://github.com/flyteorg/flyteplugins/blob/43623826fb189fa64dc4cb53e7025b517d911f22/go/tasks/plugins/webapi/bigquery/plugin.go#L34 + _TASK_TYPE = "bigquery_query_job_task" + + def __init__( + self, + name: str, + query_template: str, + task_config: BigQueryConfig, + inputs: Optional[Dict[str, Type]] = None, + output_structured_dataset_type: Optional[Type[StructuredDataset]] = None, + **kwargs, + ): + """ + To be used to query BigQuery Tables. + + :param name: Name of this task, should be unique in the project + :param query_template: The actual query to run. We use Flyte's Golang templating format for Query templating. Refer to the templating documentation + :param task_config: BigQueryConfig object + :param inputs: Name and type of inputs specified as an ordered dictionary + :param output_structured_dataset_type: If some data is produced by this query, then you can specify the output StructuredDataset type + :param kwargs: All other args required by Parent type - SQLTask + """ + outputs = None + if output_structured_dataset_type is not None: + outputs = { + "results": output_structured_dataset_type, + } + super().__init__( + name=name, + task_config=task_config, + query_template=query_template, + inputs=inputs, + outputs=outputs, + task_type=self._TASK_TYPE, + **kwargs, + ) + self._output_structured_dataset_type = output_structured_dataset_type + + def get_custom(self, settings: SerializationSettings) -> Dict[str, Any]: + config = { + "Location": self.task_config.Location, + "ProjectID": self.task_config.ProjectID, + } + if self.task_config.QueryJobConfig is not None: + config.update(self.task_config.QueryJobConfig.to_api_repr()["query"]) + s = Struct() + s.update(config) + return json_format.MessageToDict(s) + + def get_sql(self, settings: SerializationSettings) -> Optional[_task_model.Sql]: + sql = _task_model.Sql(statement=self.query_template, dialect=_task_model.Sql.Dialect.ANSI) + return sql \ No newline at end of file diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/setup.py b/basic-custom-agent/{{cookiecutter.project_name}}/setup.py new file mode 100644 index 0000000..eae6095 --- /dev/null +++ b/basic-custom-agent/{{cookiecutter.project_name}}/setup.py @@ -0,0 +1,40 @@ +from setuptools import setup + +PLUGIN_NAME = "bigquery" + +microlib_name = f"flytekitplugins-{PLUGIN_NAME}" + +plugin_requires = [ + "flytekit>1.10.7", + "google-cloud-bigquery>=3.21.0", + "google-cloud-bigquery-storage>=2.25.0", + "flyteidl>1.10.7", +] + +__version__ = "0.0.0+develop" + +setup( + name=microlib_name, + version=__version__, + author="flyteorg", + author_email="admin@flyte.org", + description="This package holds the Bigquery plugins for flytekit", + namespace_packages=["flytekitplugins"], + packages=[f"flytekitplugins.{PLUGIN_NAME}"], + install_requires=plugin_requires, + license="apache2", + python_requires=">=3.9", + classifiers=[ + "Intended Audience :: Science/Research", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Topic :: Scientific/Engineering", + "Topic :: Scientific/Engineering :: Artificial Intelligence", + "Topic :: Software Development", + "Topic :: Software Development :: Libraries", + "Topic :: Software Development :: Libraries :: Python Modules", + ], + entry_points={"flytekit.plugins": [f"{PLUGIN_NAME}=flytekitplugins.{PLUGIN_NAME}"]}, +) \ No newline at end of file diff --git a/basic-template-dockerfile/{{cookiecutter.project_name}}/docker_build.sh b/basic-template-dockerfile/{{cookiecutter.project_name}}/docker_build.sh index 83f9069..ec968ce 100644 --- a/basic-template-dockerfile/{{cookiecutter.project_name}}/docker_build.sh +++ b/basic-template-dockerfile/{{cookiecutter.project_name}}/docker_build.sh @@ -11,7 +11,7 @@ PROJECT_NAME="{{ cookiecutter.project_name }}" while getopts a:r:v:h flag do case "${flag}" in - p) PROJECT_NAME=${OPTARG};; + a) PROJECT_NAME=${OPTARG};; r) REGISTRY=${OPTARG};; v) VERSION=${OPTARG};; h) echo "Usage: ${0} [-h|[-p ][-r ][-v ]]" From b2a8c22172cfb434376080d14f672a8d8555ca78 Mon Sep 17 00:00:00 2001 From: mao3267 Date: Tue, 31 Dec 2024 11:14:47 +0800 Subject: [PATCH 2/9] fix: directory tree Signed-off-by: mao3267 --- .../{{{cookiecutter.project_name}} => bigquery}/__init__.py | 0 .../{{{cookiecutter.project_name}} => bigquery}/agent.py | 0 .../{{{cookiecutter.project_name}} => bigquery}/task.py | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{{cookiecutter.project_name}} => bigquery}/__init__.py (100%) rename basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{{cookiecutter.project_name}} => bigquery}/agent.py (100%) rename basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{{cookiecutter.project_name}} => bigquery}/task.py (100%) diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/__init__.py b/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/bigquery/__init__.py similarity index 100% rename from basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/__init__.py rename to basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/bigquery/__init__.py diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/agent.py b/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/bigquery/agent.py similarity index 100% rename from basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/agent.py rename to basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/bigquery/agent.py diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/task.py b/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/bigquery/task.py similarity index 100% rename from basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/task.py rename to basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/bigquery/task.py From ffb844e501f4dc9d7c7067682142a57fd49ab0c2 Mon Sep 17 00:00:00 2001 From: mao3267 Date: Sat, 11 Jan 2025 10:50:38 +0800 Subject: [PATCH 3/9] fix: update sync agent openai Signed-off-by: mao3267 --- .../Dockerfile | 30 +++++++++++ .../README.md | 6 +-- .../docker_build.sh | 0 .../__init__.py | 0 .../{{cookiecutter.project_name}}}/agent.py | 0 .../{{cookiecutter.project_name}}}/task.py | 0 .../setup.py | 0 .../{{cookiecutter.project_name}}/Dockerfile | 10 ---- .../Dockerfile | 30 +++++++++++ .../README.md | 47 ++++++++++++++++ .../docker_build.sh | 47 ++++++++++++++++ .../flytekitplugins/openai/__init__.py | 16 ++++++ .../openai/chatgpt/__init__.py | 0 .../flytekitplugins/openai/chatgpt/agent.py | 53 +++++++++++++++++++ .../flytekitplugins/openai/chatgpt/task.py | 44 +++++++++++++++ .../setup.py | 40 ++++++++++++++ 16 files changed, 310 insertions(+), 13 deletions(-) create mode 100644 basic-custom-agent/flytekit-{{cookiecutter.project_name}}/Dockerfile rename basic-custom-agent/{{{cookiecutter.project_name}} => flytekit-{{cookiecutter.project_name}}}/README.md (95%) rename basic-custom-agent/{{{cookiecutter.project_name}} => flytekit-{{cookiecutter.project_name}}}/docker_build.sh (100%) rename basic-custom-agent/{{{cookiecutter.project_name}}/flytekitplugins/bigquery => flytekit-{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}}/__init__.py (100%) rename basic-custom-agent/{{{cookiecutter.project_name}}/flytekitplugins/bigquery => flytekit-{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}}/agent.py (100%) rename basic-custom-agent/{{{cookiecutter.project_name}}/flytekitplugins/bigquery => flytekit-{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}}/task.py (100%) rename basic-custom-agent/{{{cookiecutter.project_name}} => flytekit-{{cookiecutter.project_name}}}/setup.py (100%) delete mode 100644 basic-custom-agent/{{cookiecutter.project_name}}/Dockerfile create mode 100644 basic-sync-agent/flytekit-{{cookiecutter.project_name}}/Dockerfile create mode 100644 basic-sync-agent/flytekit-{{cookiecutter.project_name}}/README.md create mode 100644 basic-sync-agent/flytekit-{{cookiecutter.project_name}}/docker_build.sh create mode 100644 basic-sync-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/openai/__init__.py create mode 100644 basic-sync-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/__init__.py create mode 100644 basic-sync-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/agent.py create mode 100644 basic-sync-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/task.py create mode 100644 basic-sync-agent/flytekit-{{cookiecutter.project_name}}/setup.py diff --git a/basic-custom-agent/flytekit-{{cookiecutter.project_name}}/Dockerfile b/basic-custom-agent/flytekit-{{cookiecutter.project_name}}/Dockerfile new file mode 100644 index 0000000..24c7228 --- /dev/null +++ b/basic-custom-agent/flytekit-{{cookiecutter.project_name}}/Dockerfile @@ -0,0 +1,30 @@ +FROM python:3.10-slim-bookworm AS agent-slim + +ARG VERSION + +# Install required dependencies +RUN apt-get update && apt-get install -y \ + build-essential \ + git \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Install Python dependencies +RUN pip install --no-cache-dir \ + prometheus-client \ + grpcio-health-checking==1.67.1 + +# Install Flytekit from GitHub +RUN pip install --no-cache-dir git+https://github.com/flyteorg/flytekit.git@master + +# Copy and install the plugin +COPY flytekit-{{cookiecutter.project_name}} /flytekit-{{cookiecutter.project_name}} +RUN pip install --no-cache-dir /flytekit-{{cookiecutter.project_name}} + +# Cleanup +RUN apt-get purge -y build-essential git \ + && apt-get autoremove -y \ + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +# Set the default command +CMD ["pyflyte", "serve", "agent", "--port", "8000"] \ No newline at end of file diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/README.md b/basic-custom-agent/flytekit-{{cookiecutter.project_name}}/README.md similarity index 95% rename from basic-custom-agent/{{cookiecutter.project_name}}/README.md rename to basic-custom-agent/flytekit-{{cookiecutter.project_name}}/README.md index 7c2017e..4f35aaf 100644 --- a/basic-custom-agent/{{cookiecutter.project_name}}/README.md +++ b/basic-custom-agent/flytekit-{{cookiecutter.project_name}}/README.md @@ -14,17 +14,17 @@ BigQuery's agent registration is triggered [here](https://github.com/Future-Outl > In the following command, `localhost:30000` is the Docker registry that ships with the Flyte demo cluster. Use it or replace it with a registry where you have push permissions. ```bash -docker buildx build --platform linux/amd64 -t localhost:30000/flyteagent:custom-bigquery -f Dockerfile . +docker buildx build --platform linux/amd64 -t localhost:30000/flyteagent:custom-agent -f Dockerfile . ``` 3. Test the image: ```bash -docker run -it localhost:30000/flyteagent:custom-bigquery +docker run -it localhost:30000/flyteagent:custom-agent ``` 4. Check the logs (sensor is created by flytekit, bigquery is created by the custom agent) ``` -(dev) future@outlier ~ % docker run -it localhost:30000/flyteagent:custom-bigquery +(dev) future@outlier ~ % docker run -it localhost:30000/flyteagent:custom-agent WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested ๐Ÿš€ Starting the agent service... diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/docker_build.sh b/basic-custom-agent/flytekit-{{cookiecutter.project_name}}/docker_build.sh similarity index 100% rename from basic-custom-agent/{{cookiecutter.project_name}}/docker_build.sh rename to basic-custom-agent/flytekit-{{cookiecutter.project_name}}/docker_build.sh diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/bigquery/__init__.py b/basic-custom-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/__init__.py similarity index 100% rename from basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/bigquery/__init__.py rename to basic-custom-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/__init__.py diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/bigquery/agent.py b/basic-custom-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/agent.py similarity index 100% rename from basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/bigquery/agent.py rename to basic-custom-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/agent.py diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/bigquery/task.py b/basic-custom-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/task.py similarity index 100% rename from basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/bigquery/task.py rename to basic-custom-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/task.py diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/setup.py b/basic-custom-agent/flytekit-{{cookiecutter.project_name}}/setup.py similarity index 100% rename from basic-custom-agent/{{cookiecutter.project_name}}/setup.py rename to basic-custom-agent/flytekit-{{cookiecutter.project_name}}/setup.py diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/Dockerfile b/basic-custom-agent/{{cookiecutter.project_name}}/Dockerfile deleted file mode 100644 index 7f6caab..0000000 --- a/basic-custom-agent/{{cookiecutter.project_name}}/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM python:3.10-slim-bookworm - -MAINTAINER Flyte Team -LABEL org.opencontainers.image.source=https://github.com/flyteorg/flytekit - -# additional dependencies for running in k8s -RUN pip install prometheus-client grpcio-health-checking -# flytekit will autoload the agent if package is installed. -RUN pip install flytekitplugins-bigquery -CMD pyflyte serve agent --port 8000 \ No newline at end of file diff --git a/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/Dockerfile b/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/Dockerfile new file mode 100644 index 0000000..24c7228 --- /dev/null +++ b/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/Dockerfile @@ -0,0 +1,30 @@ +FROM python:3.10-slim-bookworm AS agent-slim + +ARG VERSION + +# Install required dependencies +RUN apt-get update && apt-get install -y \ + build-essential \ + git \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Install Python dependencies +RUN pip install --no-cache-dir \ + prometheus-client \ + grpcio-health-checking==1.67.1 + +# Install Flytekit from GitHub +RUN pip install --no-cache-dir git+https://github.com/flyteorg/flytekit.git@master + +# Copy and install the plugin +COPY flytekit-{{cookiecutter.project_name}} /flytekit-{{cookiecutter.project_name}} +RUN pip install --no-cache-dir /flytekit-{{cookiecutter.project_name}} + +# Cleanup +RUN apt-get purge -y build-essential git \ + && apt-get autoremove -y \ + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +# Set the default command +CMD ["pyflyte", "serve", "agent", "--port", "8000"] \ No newline at end of file diff --git a/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/README.md b/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/README.md new file mode 100644 index 0000000..de69169 --- /dev/null +++ b/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/README.md @@ -0,0 +1,47 @@ +# OpenAI Plugins + +The plugin currently features ChatGPT and Batch API agents. + +To install the plugin, run the following command: + +```bash +pip install flytekitplugins-openai +``` + +## ChatGPT + +The ChatGPT plugin allows you to run ChatGPT tasks within the Flyte workflow without requiring any code changes. + +```python +from flytekit import task, workflow +from flytekitplugins.openai import ChatGPTTask, ChatGPTConfig + +chatgpt_small_job = ChatGPTTask( + name="chatgpt gpt-3.5-turbo", + openai_organization="org-NayNG68kGnVXMJ8Ak4PMgQv7", + chatgpt_config={ + "model": "gpt-3.5-turbo", + "temperature": 0.7, + }, +) + +chatgpt_big_job = ChatGPTTask( + name="chatgpt gpt-4", + openai_organization="org-NayNG68kGnVXMJ8Ak4PMgQv7", + chatgpt_config={ + "model": "gpt-4", + "temperature": 0.7, + }, +) + + +@workflow +def wf(message: str) -> str: + message = chatgpt_small_job(message=message) + message = chatgpt_big_job(message=message) + return message + + +if __name__ == "__main__": + print(wf(message="hi")) +``` diff --git a/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/docker_build.sh b/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/docker_build.sh new file mode 100644 index 0000000..05ba9ef --- /dev/null +++ b/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/docker_build.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +set -e + +# SET the REGISTRY here, where the docker container should be pushed +REGISTRY="localhost:30000" + +# SET the appname here +PROJECT_NAME="{{ cookiecutter.project_name }}" + +while getopts a:r:v:h flag +do + case "${flag}" in + a) PROJECT_NAME=${OPTARG};; + r) REGISTRY=${OPTARG};; + v) VERSION=${OPTARG};; + h) echo "Usage: ${0} [-h|[-p ][-r ][-v ]]" + echo " h: help (this message)" + echo " p: PROJECT_NAME for your workflows. Defaults to '{{ cookiecutter.project_name }}'." + echo " r: REGISTRY name where the docker container should be pushed. Defaults to none - localhost" + echo " v: VERSION of the build. Defaults to using the current git head SHA" + exit 1;; + *) echo "Usage: ${0} [-h|[-a ][-r ][-v ]]" + exit 1;; + esac +done + +# If you are using git, then this will automatically use the git head as the +# version +if [ -z "${VERSION}" ]; then + echo "No version set, using git commit head sha as the version" + VERSION=$(git rev-parse HEAD) +fi + +TAG=${PROJECT_NAME}:${VERSION} +if [ -z "${REGISTRY}" ]; then + echo "No registry set, creating tag ${TAG}" +else + TAG="${REGISTRY}/${TAG}" + echo "Registry set: creating tag ${TAG}" +fi + +# Should be run in the folder that has Dockerfile +docker buildx build --platform linux/amd64 -t "${TAG}" -f Dockerfile . +docker push "${TAG}" + +echo "Docker image built with tag ${TAG}. You can use this image to run pyflyte package." diff --git a/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/openai/__init__.py b/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/openai/__init__.py new file mode 100644 index 0000000..cb85efa --- /dev/null +++ b/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/openai/__init__.py @@ -0,0 +1,16 @@ +""" +.. currentmodule:: flytekitplugins.openai + +.. autosummary:: + :template: custom.rst + :toctree: generated/ + + DownloadJSONFilesTask + UploadJSONLFileTask + OpenAIFileConfig + ChatGPTAgent + ChatGPTTask +""" + +from .chatgpt.agent import ChatGPTAgent +from .chatgpt.task import ChatGPTTask diff --git a/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/__init__.py b/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/agent.py b/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/agent.py new file mode 100644 index 0000000..e4f24ba --- /dev/null +++ b/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/agent.py @@ -0,0 +1,53 @@ +import asyncio +import logging +from typing import Optional + +from flyteidl.core.execution_pb2 import TaskExecution + +from flytekit import FlyteContextManager, lazy_module +from flytekit.core.type_engine import TypeEngine +from flytekit.extend.backend.base_agent import AgentRegistry, Resource, SyncAgentBase +from flytekit.extend.backend.utils import get_agent_secret +from flytekit.models.literals import LiteralMap +from flytekit.models.task import TaskTemplate + +openai = lazy_module("openai") + +TIMEOUT_SECONDS = 10 +OPENAI_API_KEY = "FLYTE_OPENAI_API_KEY" + + +class ChatGPTAgent(SyncAgentBase): + name = "ChatGPT Agent" + + def __init__(self): + super().__init__(task_type_name="chatgpt") + + async def do( + self, + task_template: TaskTemplate, + inputs: Optional[LiteralMap] = None, + **kwargs, + ) -> Resource: + ctx = FlyteContextManager.current_context() + input_python_value = TypeEngine.literal_map_to_kwargs(ctx, inputs, {"message": str}) + message = input_python_value["message"] + + custom = task_template.custom + custom["chatgpt_config"]["messages"] = [{"role": "user", "content": message}] + client = openai.AsyncOpenAI( + organization=custom["openai_organization"], + api_key=get_agent_secret(secret_key=OPENAI_API_KEY), + ) + + logger = logging.getLogger("httpx") + logger.setLevel(logging.WARNING) + + completion = await asyncio.wait_for(client.chat.completions.create(**custom["chatgpt_config"]), TIMEOUT_SECONDS) + message = completion.choices[0].message.content + outputs = {"o0": message} + + return Resource(phase=TaskExecution.SUCCEEDED, outputs=outputs) + + +AgentRegistry.register(ChatGPTAgent()) diff --git a/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/task.py b/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/task.py new file mode 100644 index 0000000..8a207e7 --- /dev/null +++ b/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/task.py @@ -0,0 +1,44 @@ +from typing import Any, Dict, Optional + +from flytekit.configuration import SerializationSettings +from flytekit.core.base_task import PythonTask +from flytekit.core.interface import Interface +from flytekit.extend.backend.base_agent import SyncAgentExecutorMixin + + +class ChatGPTTask(SyncAgentExecutorMixin, PythonTask): + """ + This is the simplest form of a ChatGPT Task, you can define the model and the input you want. + """ + + _TASK_TYPE = "chatgpt" + + def __init__(self, name: str, chatgpt_config: Dict[str, Any], openai_organization: Optional[str] = None, **kwargs): + """ + Args: + name: Name of this task, should be unique in the project + openai_organization: OpenAI Organization. String can be found here. https://platform.openai.com/docs/api-reference/organization-optional + chatgpt_config: ChatGPT job configuration. Config structure can be found here. https://platform.openai.com/docs/api-reference/completions/create + """ + + if "model" not in chatgpt_config: + raise ValueError("The 'model' configuration variable is required in chatgpt_config") + + task_config = {"openai_organization": openai_organization, "chatgpt_config": chatgpt_config} + + inputs = {"message": str} + outputs = {"o0": str} + + super().__init__( + task_type=self._TASK_TYPE, + name=name, + task_config=task_config, + interface=Interface(inputs=inputs, outputs=outputs), + **kwargs, + ) + + def get_custom(self, settings: SerializationSettings) -> Dict[str, Any]: + return { + "openai_organization": self.task_config["openai_organization"], + "chatgpt_config": self.task_config["chatgpt_config"], + } diff --git a/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/setup.py b/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/setup.py new file mode 100644 index 0000000..93b9b32 --- /dev/null +++ b/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/setup.py @@ -0,0 +1,40 @@ +from setuptools import setup + +PLUGIN_NAME = "openai" + +microlib_name = f"flytekitplugins-{PLUGIN_NAME}" + +plugin_requires = ["flytekit>1.10.7", "openai>=1.12.0", "flyteidl>=1.11.0"] + +__version__ = "0.0.0+develop" + +setup( + name=microlib_name, + version=__version__, + author="flyteorg", + author_email="admin@flyte.org", + description="This package holds the openai plugins for flytekit", + namespace_packages=["flytekitplugins"], + packages=[ + f"flytekitplugins.{PLUGIN_NAME}", + f"flytekitplugins.{PLUGIN_NAME}.chatgpt", + ], + install_requires=plugin_requires, + license="apache2", + python_requires=">=3.9", + classifiers=[ + "Intended Audience :: Science/Research", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Topic :: Scientific/Engineering", + "Topic :: Scientific/Engineering :: Artificial Intelligence", + "Topic :: Software Development", + "Topic :: Software Development :: Libraries", + "Topic :: Software Development :: Libraries :: Python Modules", + ], + entry_points={"flytekit.plugins": [f"{PLUGIN_NAME}=flytekitplugins.{PLUGIN_NAME}"]}, +) From 9c843ef3c7c42ddd8c0209ea85d072507b79ed52 Mon Sep 17 00:00:00 2001 From: mao3267 Date: Sat, 11 Jan 2025 10:54:21 +0800 Subject: [PATCH 4/9] fix: rename directory Signed-off-by: mao3267 --- .../Dockerfile | 0 .../README.md | 0 .../docker_build.sh | 0 .../flytekitplugins/{{cookiecutter.project_name}}/__init__.py | 0 .../flytekitplugins/{{cookiecutter.project_name}}/agent.py | 0 .../flytekitplugins/{{cookiecutter.project_name}}/task.py | 0 .../setup.py | 0 .../Dockerfile | 0 .../README.md | 0 .../docker_build.sh | 0 .../flytekitplugins/openai/__init__.py | 0 .../flytekitplugins/openai/chatgpt/__init__.py | 0 .../flytekitplugins/openai/chatgpt/agent.py | 0 .../flytekitplugins/openai/chatgpt/task.py | 0 .../setup.py | 0 15 files changed, 0 insertions(+), 0 deletions(-) rename basic-custom-agent/{flytekit-{{cookiecutter.project_name}} => {{cookiecutter.project_name}}}/Dockerfile (100%) rename basic-custom-agent/{flytekit-{{cookiecutter.project_name}} => {{cookiecutter.project_name}}}/README.md (100%) rename basic-custom-agent/{flytekit-{{cookiecutter.project_name}} => {{cookiecutter.project_name}}}/docker_build.sh (100%) rename basic-custom-agent/{flytekit-{{cookiecutter.project_name}} => {{cookiecutter.project_name}}}/flytekitplugins/{{cookiecutter.project_name}}/__init__.py (100%) rename basic-custom-agent/{flytekit-{{cookiecutter.project_name}} => {{cookiecutter.project_name}}}/flytekitplugins/{{cookiecutter.project_name}}/agent.py (100%) rename basic-custom-agent/{flytekit-{{cookiecutter.project_name}} => {{cookiecutter.project_name}}}/flytekitplugins/{{cookiecutter.project_name}}/task.py (100%) rename basic-custom-agent/{flytekit-{{cookiecutter.project_name}} => {{cookiecutter.project_name}}}/setup.py (100%) rename basic-sync-agent/{flytekit-{{cookiecutter.project_name}} => {{cookiecutter.project_name}}}/Dockerfile (100%) rename basic-sync-agent/{flytekit-{{cookiecutter.project_name}} => {{cookiecutter.project_name}}}/README.md (100%) rename basic-sync-agent/{flytekit-{{cookiecutter.project_name}} => {{cookiecutter.project_name}}}/docker_build.sh (100%) rename basic-sync-agent/{flytekit-{{cookiecutter.project_name}} => {{cookiecutter.project_name}}}/flytekitplugins/openai/__init__.py (100%) rename basic-sync-agent/{flytekit-{{cookiecutter.project_name}} => {{cookiecutter.project_name}}}/flytekitplugins/openai/chatgpt/__init__.py (100%) rename basic-sync-agent/{flytekit-{{cookiecutter.project_name}} => {{cookiecutter.project_name}}}/flytekitplugins/openai/chatgpt/agent.py (100%) rename basic-sync-agent/{flytekit-{{cookiecutter.project_name}} => {{cookiecutter.project_name}}}/flytekitplugins/openai/chatgpt/task.py (100%) rename basic-sync-agent/{flytekit-{{cookiecutter.project_name}} => {{cookiecutter.project_name}}}/setup.py (100%) diff --git a/basic-custom-agent/flytekit-{{cookiecutter.project_name}}/Dockerfile b/basic-custom-agent/{{cookiecutter.project_name}}/Dockerfile similarity index 100% rename from basic-custom-agent/flytekit-{{cookiecutter.project_name}}/Dockerfile rename to basic-custom-agent/{{cookiecutter.project_name}}/Dockerfile diff --git a/basic-custom-agent/flytekit-{{cookiecutter.project_name}}/README.md b/basic-custom-agent/{{cookiecutter.project_name}}/README.md similarity index 100% rename from basic-custom-agent/flytekit-{{cookiecutter.project_name}}/README.md rename to basic-custom-agent/{{cookiecutter.project_name}}/README.md diff --git a/basic-custom-agent/flytekit-{{cookiecutter.project_name}}/docker_build.sh b/basic-custom-agent/{{cookiecutter.project_name}}/docker_build.sh similarity index 100% rename from basic-custom-agent/flytekit-{{cookiecutter.project_name}}/docker_build.sh rename to basic-custom-agent/{{cookiecutter.project_name}}/docker_build.sh diff --git a/basic-custom-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/__init__.py b/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/__init__.py similarity index 100% rename from basic-custom-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/__init__.py rename to basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/__init__.py diff --git a/basic-custom-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/agent.py b/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/agent.py similarity index 100% rename from basic-custom-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/agent.py rename to basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/agent.py diff --git a/basic-custom-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/task.py b/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/task.py similarity index 100% rename from basic-custom-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/task.py rename to basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/task.py diff --git a/basic-custom-agent/flytekit-{{cookiecutter.project_name}}/setup.py b/basic-custom-agent/{{cookiecutter.project_name}}/setup.py similarity index 100% rename from basic-custom-agent/flytekit-{{cookiecutter.project_name}}/setup.py rename to basic-custom-agent/{{cookiecutter.project_name}}/setup.py diff --git a/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/Dockerfile b/basic-sync-agent/{{cookiecutter.project_name}}/Dockerfile similarity index 100% rename from basic-sync-agent/flytekit-{{cookiecutter.project_name}}/Dockerfile rename to basic-sync-agent/{{cookiecutter.project_name}}/Dockerfile diff --git a/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/README.md b/basic-sync-agent/{{cookiecutter.project_name}}/README.md similarity index 100% rename from basic-sync-agent/flytekit-{{cookiecutter.project_name}}/README.md rename to basic-sync-agent/{{cookiecutter.project_name}}/README.md diff --git a/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/docker_build.sh b/basic-sync-agent/{{cookiecutter.project_name}}/docker_build.sh similarity index 100% rename from basic-sync-agent/flytekit-{{cookiecutter.project_name}}/docker_build.sh rename to basic-sync-agent/{{cookiecutter.project_name}}/docker_build.sh diff --git a/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/openai/__init__.py b/basic-sync-agent/{{cookiecutter.project_name}}/flytekitplugins/openai/__init__.py similarity index 100% rename from basic-sync-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/openai/__init__.py rename to basic-sync-agent/{{cookiecutter.project_name}}/flytekitplugins/openai/__init__.py diff --git a/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/__init__.py b/basic-sync-agent/{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/__init__.py similarity index 100% rename from basic-sync-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/__init__.py rename to basic-sync-agent/{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/__init__.py diff --git a/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/agent.py b/basic-sync-agent/{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/agent.py similarity index 100% rename from basic-sync-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/agent.py rename to basic-sync-agent/{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/agent.py diff --git a/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/task.py b/basic-sync-agent/{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/task.py similarity index 100% rename from basic-sync-agent/flytekit-{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/task.py rename to basic-sync-agent/{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/task.py diff --git a/basic-sync-agent/flytekit-{{cookiecutter.project_name}}/setup.py b/basic-sync-agent/{{cookiecutter.project_name}}/setup.py similarity index 100% rename from basic-sync-agent/flytekit-{{cookiecutter.project_name}}/setup.py rename to basic-sync-agent/{{cookiecutter.project_name}}/setup.py From 6c3528b4af49757bb7b6fde944063e99b4f87d35 Mon Sep 17 00:00:00 2001 From: mao3267 Date: Sat, 11 Jan 2025 10:56:29 +0800 Subject: [PATCH 5/9] fix: update plugin install source Signed-off-by: mao3267 --- basic-custom-agent/{{cookiecutter.project_name}}/Dockerfile | 2 +- basic-sync-agent/{{cookiecutter.project_name}}/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/Dockerfile b/basic-custom-agent/{{cookiecutter.project_name}}/Dockerfile index 24c7228..6ca243f 100644 --- a/basic-custom-agent/{{cookiecutter.project_name}}/Dockerfile +++ b/basic-custom-agent/{{cookiecutter.project_name}}/Dockerfile @@ -18,7 +18,7 @@ RUN pip install --no-cache-dir \ RUN pip install --no-cache-dir git+https://github.com/flyteorg/flytekit.git@master # Copy and install the plugin -COPY flytekit-{{cookiecutter.project_name}} /flytekit-{{cookiecutter.project_name}} +COPY flytekit-{{cookiecutter.project_name}} /{{cookiecutter.project_name}} RUN pip install --no-cache-dir /flytekit-{{cookiecutter.project_name}} # Cleanup diff --git a/basic-sync-agent/{{cookiecutter.project_name}}/Dockerfile b/basic-sync-agent/{{cookiecutter.project_name}}/Dockerfile index 24c7228..6ca243f 100644 --- a/basic-sync-agent/{{cookiecutter.project_name}}/Dockerfile +++ b/basic-sync-agent/{{cookiecutter.project_name}}/Dockerfile @@ -18,7 +18,7 @@ RUN pip install --no-cache-dir \ RUN pip install --no-cache-dir git+https://github.com/flyteorg/flytekit.git@master # Copy and install the plugin -COPY flytekit-{{cookiecutter.project_name}} /flytekit-{{cookiecutter.project_name}} +COPY flytekit-{{cookiecutter.project_name}} /{{cookiecutter.project_name}} RUN pip install --no-cache-dir /flytekit-{{cookiecutter.project_name}} # Cleanup From 434c7af40942eda6d50fc6590b5858c4742b280f Mon Sep 17 00:00:00 2001 From: mao3267 Date: Sat, 11 Jan 2025 11:00:17 +0800 Subject: [PATCH 6/9] fix: copy cmd error Signed-off-by: mao3267 --- basic-custom-agent/{{cookiecutter.project_name}}/Dockerfile | 2 +- basic-sync-agent/{{cookiecutter.project_name}}/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/Dockerfile b/basic-custom-agent/{{cookiecutter.project_name}}/Dockerfile index 6ca243f..603857c 100644 --- a/basic-custom-agent/{{cookiecutter.project_name}}/Dockerfile +++ b/basic-custom-agent/{{cookiecutter.project_name}}/Dockerfile @@ -18,7 +18,7 @@ RUN pip install --no-cache-dir \ RUN pip install --no-cache-dir git+https://github.com/flyteorg/flytekit.git@master # Copy and install the plugin -COPY flytekit-{{cookiecutter.project_name}} /{{cookiecutter.project_name}} +COPY {{cookiecutter.project_name}} /flytekit-{{cookiecutter.project_name}} RUN pip install --no-cache-dir /flytekit-{{cookiecutter.project_name}} # Cleanup diff --git a/basic-sync-agent/{{cookiecutter.project_name}}/Dockerfile b/basic-sync-agent/{{cookiecutter.project_name}}/Dockerfile index 6ca243f..603857c 100644 --- a/basic-sync-agent/{{cookiecutter.project_name}}/Dockerfile +++ b/basic-sync-agent/{{cookiecutter.project_name}}/Dockerfile @@ -18,7 +18,7 @@ RUN pip install --no-cache-dir \ RUN pip install --no-cache-dir git+https://github.com/flyteorg/flytekit.git@master # Copy and install the plugin -COPY flytekit-{{cookiecutter.project_name}} /{{cookiecutter.project_name}} +COPY {{cookiecutter.project_name}} /flytekit-{{cookiecutter.project_name}} RUN pip install --no-cache-dir /flytekit-{{cookiecutter.project_name}} # Cleanup From 2d1fa5843fcb9d9e21d867c242ee897d9cf403f0 Mon Sep 17 00:00:00 2001 From: mao3267 Date: Sat, 11 Jan 2025 11:33:49 +0800 Subject: [PATCH 7/9] fix: use template from Future-Outlier/flyte-custom-agent-template Signed-off-by: mao3267 --- .../{{cookiecutter.project_name}}/Dockerfile | 11 +++-- .../{{cookiecutter.project_name}}/README.md | 5 +- .../docker_build.sh | 47 ------------------- .../flytekit-bigquery/README.md | 11 +++++ .../flytekitplugins/bigquery}/__init__.py | 2 +- .../flytekitplugins/bigquery}/agent.py | 2 +- .../flytekitplugins/bigquery}/task.py | 2 +- .../{ => flytekit-bigquery}/setup.py | 2 +- .../flytekit-openai}/README.md | 0 .../flytekitplugins/openai/__init__.py | 0 .../openai/chatgpt/__init__.py | 0 .../flytekitplugins/openai/chatgpt/agent.py | 0 .../flytekitplugins/openai/chatgpt/task.py | 0 .../flytekit-openai}/setup.py | 0 .../{{cookiecutter.project_name}}/Dockerfile | 30 ------------ .../docker_build.sh | 47 ------------------- 16 files changed, 25 insertions(+), 134 deletions(-) delete mode 100644 basic-custom-agent/{{cookiecutter.project_name}}/docker_build.sh create mode 100644 basic-custom-agent/{{cookiecutter.project_name}}/flytekit-bigquery/README.md rename basic-custom-agent/{{cookiecutter.project_name}}/{flytekitplugins/{{cookiecutter.project_name}} => flytekit-bigquery/flytekitplugins/bigquery}/__init__.py (85%) rename basic-custom-agent/{{cookiecutter.project_name}}/{flytekitplugins/{{cookiecutter.project_name}} => flytekit-bigquery/flytekitplugins/bigquery}/agent.py (98%) rename basic-custom-agent/{{cookiecutter.project_name}}/{flytekitplugins/{{cookiecutter.project_name}} => flytekit-bigquery/flytekitplugins/bigquery}/task.py (99%) rename basic-custom-agent/{{cookiecutter.project_name}}/{ => flytekit-bigquery}/setup.py (99%) rename {basic-sync-agent/{{cookiecutter.project_name}} => basic-custom-agent/{{cookiecutter.project_name}}/flytekit-openai}/README.md (100%) rename {basic-sync-agent/{{cookiecutter.project_name}} => basic-custom-agent/{{cookiecutter.project_name}}/flytekit-openai}/flytekitplugins/openai/__init__.py (100%) rename {basic-sync-agent/{{cookiecutter.project_name}} => basic-custom-agent/{{cookiecutter.project_name}}/flytekit-openai}/flytekitplugins/openai/chatgpt/__init__.py (100%) rename {basic-sync-agent/{{cookiecutter.project_name}} => basic-custom-agent/{{cookiecutter.project_name}}/flytekit-openai}/flytekitplugins/openai/chatgpt/agent.py (100%) rename {basic-sync-agent/{{cookiecutter.project_name}} => basic-custom-agent/{{cookiecutter.project_name}}/flytekit-openai}/flytekitplugins/openai/chatgpt/task.py (100%) rename {basic-sync-agent/{{cookiecutter.project_name}} => basic-custom-agent/{{cookiecutter.project_name}}/flytekit-openai}/setup.py (100%) delete mode 100644 basic-sync-agent/{{cookiecutter.project_name}}/Dockerfile delete mode 100644 basic-sync-agent/{{cookiecutter.project_name}}/docker_build.sh diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/Dockerfile b/basic-custom-agent/{{cookiecutter.project_name}}/Dockerfile index 603857c..67711af 100644 --- a/basic-custom-agent/{{cookiecutter.project_name}}/Dockerfile +++ b/basic-custom-agent/{{cookiecutter.project_name}}/Dockerfile @@ -17,9 +17,12 @@ RUN pip install --no-cache-dir \ # Install Flytekit from GitHub RUN pip install --no-cache-dir git+https://github.com/flyteorg/flytekit.git@master -# Copy and install the plugin -COPY {{cookiecutter.project_name}} /flytekit-{{cookiecutter.project_name}} -RUN pip install --no-cache-dir /flytekit-{{cookiecutter.project_name}} +# Copy and install the bigquery plugin +COPY flytekit-bigquery /flytekit-bigquery +RUN pip install --no-cache-dir /flytekit-bigquery + +COPY flytekit-openai /flytekit-openai +RUN pip install --no-cache-dir /flytekit-openai # Cleanup RUN apt-get purge -y build-essential git \ @@ -27,4 +30,4 @@ RUN apt-get purge -y build-essential git \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* # Set the default command -CMD ["pyflyte", "serve", "agent", "--port", "8000"] \ No newline at end of file +CMD ["pyflyte", "serve", "agent", "--port", "8000"] diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/README.md b/basic-custom-agent/{{cookiecutter.project_name}}/README.md index 4f35aaf..f5e906e 100644 --- a/basic-custom-agent/{{cookiecutter.project_name}}/README.md +++ b/basic-custom-agent/{{cookiecutter.project_name}}/README.md @@ -22,7 +22,7 @@ docker buildx build --platform linux/amd64 -t localhost:30000/flyteagent:custom- docker run -it localhost:30000/flyteagent:custom-agent ``` -4. Check the logs (sensor is created by flytekit, bigquery is created by the custom agent) +4. Check the logs (sensor is created by flytekit, bigquery and openai is created by the custom agent) ``` (dev) future@outlier ~ % docker run -it localhost:30000/flyteagent:custom-agent @@ -34,6 +34,7 @@ Starting up the server to expose the prometheus metrics... โ”ƒ Agent Name โ”ƒ Support Task Types โ”ƒ Is Sync โ”ƒ โ”กโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฉ โ”‚ Sensor โ”‚ sensor (v0) โ”‚ False โ”‚ +โ”‚ ChatGPT Agent โ”‚ chatgpt (v0) โ”‚ True โ”‚ โ”‚ Bigquery Agent โ”‚ bigquery_query_job_task (v0) โ”‚ False โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` \ No newline at end of file +``` diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/docker_build.sh b/basic-custom-agent/{{cookiecutter.project_name}}/docker_build.sh deleted file mode 100644 index df24f32..0000000 --- a/basic-custom-agent/{{cookiecutter.project_name}}/docker_build.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -set -e - -# SET the REGISTRY here, where the docker container should be pushed -REGISTRY="" - -# SET the appname here -PROJECT_NAME="{{ cookiecutter.project_name }}" - -while getopts a:r:v:h flag -do - case "${flag}" in - a) PROJECT_NAME=${OPTARG};; - r) REGISTRY=${OPTARG};; - v) VERSION=${OPTARG};; - h) echo "Usage: ${0} [-h|[-p ][-r ][-v ]]" - echo " h: help (this message)" - echo " p: PROJECT_NAME for your workflows. Defaults to '{{ cookiecutter.project_name }}'." - echo " r: REGISTRY name where the docker container should be pushed. Defaults to none - localhost" - echo " v: VERSION of the build. Defaults to using the current git head SHA" - exit 1;; - *) echo "Usage: ${0} [-h|[-a ][-r ][-v ]]" - exit 1;; - esac -done - -# If you are using git, then this will automatically use the git head as the -# version -if [ -z "${VERSION}" ]; then - echo "No version set, using git commit head sha as the version" - VERSION=$(git rev-parse HEAD) -fi - -TAG=${PROJECT_NAME}:${VERSION} -if [ -z "${REGISTRY}" ]; then - echo "No registry set, creating tag ${TAG}" -else - TAG="${REGISTRY}/${TAG}" - echo "Registry set: creating tag ${TAG}" -fi - -# Should be run in the folder that has Dockerfile -docker buildx build --platform linux/amd64 -t "${TAG}" -f Dockerfile . -docker push "${TAG}" - -echo "Docker image built with tag ${TAG}. You can use this image to run pyflyte package." diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/flytekit-bigquery/README.md b/basic-custom-agent/{{cookiecutter.project_name}}/flytekit-bigquery/README.md new file mode 100644 index 0000000..7b8468f --- /dev/null +++ b/basic-custom-agent/{{cookiecutter.project_name}}/flytekit-bigquery/README.md @@ -0,0 +1,11 @@ +# Flytekit BigQuery Plugin + +BigQuery enables us to build data-intensive applications without operational burden. Flyte backend can be connected with the BigQuery service. Once enabled, it can allow you to query a BigQuery table. + +To install the plugin, run the following command: + +```bash +pip install flytekitplugins-bigquery +``` + +To configure BigQuery in the Flyte deployment's backend, follow the [configuration guide](https://docs.flyte.org/en/latest/deployment/plugin_setup/gcp/bigquery.html#deployment-plugin-setup-gcp-bigquery). diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/__init__.py b/basic-custom-agent/{{cookiecutter.project_name}}/flytekit-bigquery/flytekitplugins/bigquery/__init__.py similarity index 85% rename from basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/__init__.py rename to basic-custom-agent/{{cookiecutter.project_name}}/flytekit-bigquery/flytekitplugins/bigquery/__init__.py index e2e190a..0e0fe80 100644 --- a/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/__init__.py +++ b/basic-custom-agent/{{cookiecutter.project_name}}/flytekit-bigquery/flytekitplugins/bigquery/__init__.py @@ -13,4 +13,4 @@ """ from .agent import BigQueryAgent -from .task import BigQueryConfig, BigQueryTask \ No newline at end of file +from .task import BigQueryConfig, BigQueryTask diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/agent.py b/basic-custom-agent/{{cookiecutter.project_name}}/flytekit-bigquery/flytekitplugins/bigquery/agent.py similarity index 98% rename from basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/agent.py rename to basic-custom-agent/{{cookiecutter.project_name}}/flytekit-bigquery/flytekitplugins/bigquery/agent.py index 0fd6dec..ff34f7a 100644 --- a/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/agent.py +++ b/basic-custom-agent/{{cookiecutter.project_name}}/flytekit-bigquery/flytekitplugins/bigquery/agent.py @@ -94,4 +94,4 @@ def delete(self, resource_meta: BigQueryMetadata, **kwargs): client.cancel_job(resource_meta.job_id, resource_meta.project, resource_meta.location) -AgentRegistry.register(BigQueryAgent()) \ No newline at end of file +AgentRegistry.register(BigQueryAgent()) diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/task.py b/basic-custom-agent/{{cookiecutter.project_name}}/flytekit-bigquery/flytekitplugins/bigquery/task.py similarity index 99% rename from basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/task.py rename to basic-custom-agent/{{cookiecutter.project_name}}/flytekit-bigquery/flytekitplugins/bigquery/task.py index 8f63f8b..c1707f0 100644 --- a/basic-custom-agent/{{cookiecutter.project_name}}/flytekitplugins/{{cookiecutter.project_name}}/task.py +++ b/basic-custom-agent/{{cookiecutter.project_name}}/flytekit-bigquery/flytekitplugins/bigquery/task.py @@ -82,4 +82,4 @@ def get_custom(self, settings: SerializationSettings) -> Dict[str, Any]: def get_sql(self, settings: SerializationSettings) -> Optional[_task_model.Sql]: sql = _task_model.Sql(statement=self.query_template, dialect=_task_model.Sql.Dialect.ANSI) - return sql \ No newline at end of file + return sql diff --git a/basic-custom-agent/{{cookiecutter.project_name}}/setup.py b/basic-custom-agent/{{cookiecutter.project_name}}/flytekit-bigquery/setup.py similarity index 99% rename from basic-custom-agent/{{cookiecutter.project_name}}/setup.py rename to basic-custom-agent/{{cookiecutter.project_name}}/flytekit-bigquery/setup.py index eae6095..b0aab31 100644 --- a/basic-custom-agent/{{cookiecutter.project_name}}/setup.py +++ b/basic-custom-agent/{{cookiecutter.project_name}}/flytekit-bigquery/setup.py @@ -37,4 +37,4 @@ "Topic :: Software Development :: Libraries :: Python Modules", ], entry_points={"flytekit.plugins": [f"{PLUGIN_NAME}=flytekitplugins.{PLUGIN_NAME}"]}, -) \ No newline at end of file +) diff --git a/basic-sync-agent/{{cookiecutter.project_name}}/README.md b/basic-custom-agent/{{cookiecutter.project_name}}/flytekit-openai/README.md similarity index 100% rename from basic-sync-agent/{{cookiecutter.project_name}}/README.md rename to basic-custom-agent/{{cookiecutter.project_name}}/flytekit-openai/README.md diff --git a/basic-sync-agent/{{cookiecutter.project_name}}/flytekitplugins/openai/__init__.py b/basic-custom-agent/{{cookiecutter.project_name}}/flytekit-openai/flytekitplugins/openai/__init__.py similarity index 100% rename from basic-sync-agent/{{cookiecutter.project_name}}/flytekitplugins/openai/__init__.py rename to basic-custom-agent/{{cookiecutter.project_name}}/flytekit-openai/flytekitplugins/openai/__init__.py diff --git a/basic-sync-agent/{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/__init__.py b/basic-custom-agent/{{cookiecutter.project_name}}/flytekit-openai/flytekitplugins/openai/chatgpt/__init__.py similarity index 100% rename from basic-sync-agent/{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/__init__.py rename to basic-custom-agent/{{cookiecutter.project_name}}/flytekit-openai/flytekitplugins/openai/chatgpt/__init__.py diff --git a/basic-sync-agent/{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/agent.py b/basic-custom-agent/{{cookiecutter.project_name}}/flytekit-openai/flytekitplugins/openai/chatgpt/agent.py similarity index 100% rename from basic-sync-agent/{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/agent.py rename to basic-custom-agent/{{cookiecutter.project_name}}/flytekit-openai/flytekitplugins/openai/chatgpt/agent.py diff --git a/basic-sync-agent/{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/task.py b/basic-custom-agent/{{cookiecutter.project_name}}/flytekit-openai/flytekitplugins/openai/chatgpt/task.py similarity index 100% rename from basic-sync-agent/{{cookiecutter.project_name}}/flytekitplugins/openai/chatgpt/task.py rename to basic-custom-agent/{{cookiecutter.project_name}}/flytekit-openai/flytekitplugins/openai/chatgpt/task.py diff --git a/basic-sync-agent/{{cookiecutter.project_name}}/setup.py b/basic-custom-agent/{{cookiecutter.project_name}}/flytekit-openai/setup.py similarity index 100% rename from basic-sync-agent/{{cookiecutter.project_name}}/setup.py rename to basic-custom-agent/{{cookiecutter.project_name}}/flytekit-openai/setup.py diff --git a/basic-sync-agent/{{cookiecutter.project_name}}/Dockerfile b/basic-sync-agent/{{cookiecutter.project_name}}/Dockerfile deleted file mode 100644 index 603857c..0000000 --- a/basic-sync-agent/{{cookiecutter.project_name}}/Dockerfile +++ /dev/null @@ -1,30 +0,0 @@ -FROM python:3.10-slim-bookworm AS agent-slim - -ARG VERSION - -# Install required dependencies -RUN apt-get update && apt-get install -y \ - build-essential \ - git \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* - -# Install Python dependencies -RUN pip install --no-cache-dir \ - prometheus-client \ - grpcio-health-checking==1.67.1 - -# Install Flytekit from GitHub -RUN pip install --no-cache-dir git+https://github.com/flyteorg/flytekit.git@master - -# Copy and install the plugin -COPY {{cookiecutter.project_name}} /flytekit-{{cookiecutter.project_name}} -RUN pip install --no-cache-dir /flytekit-{{cookiecutter.project_name}} - -# Cleanup -RUN apt-get purge -y build-essential git \ - && apt-get autoremove -y \ - && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* - -# Set the default command -CMD ["pyflyte", "serve", "agent", "--port", "8000"] \ No newline at end of file diff --git a/basic-sync-agent/{{cookiecutter.project_name}}/docker_build.sh b/basic-sync-agent/{{cookiecutter.project_name}}/docker_build.sh deleted file mode 100644 index 05ba9ef..0000000 --- a/basic-sync-agent/{{cookiecutter.project_name}}/docker_build.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -set -e - -# SET the REGISTRY here, where the docker container should be pushed -REGISTRY="localhost:30000" - -# SET the appname here -PROJECT_NAME="{{ cookiecutter.project_name }}" - -while getopts a:r:v:h flag -do - case "${flag}" in - a) PROJECT_NAME=${OPTARG};; - r) REGISTRY=${OPTARG};; - v) VERSION=${OPTARG};; - h) echo "Usage: ${0} [-h|[-p ][-r ][-v ]]" - echo " h: help (this message)" - echo " p: PROJECT_NAME for your workflows. Defaults to '{{ cookiecutter.project_name }}'." - echo " r: REGISTRY name where the docker container should be pushed. Defaults to none - localhost" - echo " v: VERSION of the build. Defaults to using the current git head SHA" - exit 1;; - *) echo "Usage: ${0} [-h|[-a ][-r ][-v ]]" - exit 1;; - esac -done - -# If you are using git, then this will automatically use the git head as the -# version -if [ -z "${VERSION}" ]; then - echo "No version set, using git commit head sha as the version" - VERSION=$(git rev-parse HEAD) -fi - -TAG=${PROJECT_NAME}:${VERSION} -if [ -z "${REGISTRY}" ]; then - echo "No registry set, creating tag ${TAG}" -else - TAG="${REGISTRY}/${TAG}" - echo "Registry set: creating tag ${TAG}" -fi - -# Should be run in the folder that has Dockerfile -docker buildx build --platform linux/amd64 -t "${TAG}" -f Dockerfile . -docker push "${TAG}" - -echo "Docker image built with tag ${TAG}. You can use this image to run pyflyte package." From 77253db3a09d3da9a61a5ceca3c42033a120f1f9 Mon Sep 17 00:00:00 2001 From: mao3267 Date: Sat, 11 Jan 2025 11:35:21 +0800 Subject: [PATCH 8/9] fix: standardize getopts parameters Signed-off-by: mao3267 --- .../{{cookiecutter.project_name}}/docker_build.sh | 4 ++-- .../{{cookiecutter.project_name}}/docker_build.sh | 2 +- mnist-training/{{cookiecutter.project_name}}/docker_build.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/basic-template-dockerfile/{{cookiecutter.project_name}}/docker_build.sh b/basic-template-dockerfile/{{cookiecutter.project_name}}/docker_build.sh index ec968ce..74a76b7 100644 --- a/basic-template-dockerfile/{{cookiecutter.project_name}}/docker_build.sh +++ b/basic-template-dockerfile/{{cookiecutter.project_name}}/docker_build.sh @@ -8,10 +8,10 @@ REGISTRY="" # SET the appname here PROJECT_NAME="{{ cookiecutter.project_name }}" -while getopts a:r:v:h flag +while getopts p:r:v:h flag do case "${flag}" in - a) PROJECT_NAME=${OPTARG};; + p) PROJECT_NAME=${OPTARG};; r) REGISTRY=${OPTARG};; v) VERSION=${OPTARG};; h) echo "Usage: ${0} [-h|[-p ][-r ][-v ]]" diff --git a/bayesian-optimization/{{cookiecutter.project_name}}/docker_build.sh b/bayesian-optimization/{{cookiecutter.project_name}}/docker_build.sh index 83f9069..74a76b7 100755 --- a/bayesian-optimization/{{cookiecutter.project_name}}/docker_build.sh +++ b/bayesian-optimization/{{cookiecutter.project_name}}/docker_build.sh @@ -8,7 +8,7 @@ REGISTRY="" # SET the appname here PROJECT_NAME="{{ cookiecutter.project_name }}" -while getopts a:r:v:h flag +while getopts p:r:v:h flag do case "${flag}" in p) PROJECT_NAME=${OPTARG};; diff --git a/mnist-training/{{cookiecutter.project_name}}/docker_build.sh b/mnist-training/{{cookiecutter.project_name}}/docker_build.sh index 83f9069..74a76b7 100644 --- a/mnist-training/{{cookiecutter.project_name}}/docker_build.sh +++ b/mnist-training/{{cookiecutter.project_name}}/docker_build.sh @@ -8,7 +8,7 @@ REGISTRY="" # SET the appname here PROJECT_NAME="{{ cookiecutter.project_name }}" -while getopts a:r:v:h flag +while getopts p:r:v:h flag do case "${flag}" in p) PROJECT_NAME=${OPTARG};; From fdb16b22a26f9c786fa7d6edb5562ef2db420adb Mon Sep 17 00:00:00 2001 From: mao3267 Date: Fri, 17 Jan 2025 22:42:40 +0800 Subject: [PATCH 9/9] fix: add newline Signed-off-by: mao3267 --- basic-custom-agent/cookiecutter.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basic-custom-agent/cookiecutter.json b/basic-custom-agent/cookiecutter.json index c99968b..e130182 100644 --- a/basic-custom-agent/cookiecutter.json +++ b/basic-custom-agent/cookiecutter.json @@ -1,3 +1,3 @@ { "project_name": "Basic custom agent" -} \ No newline at end of file +}