From f76e0c11e7938fbcd1b2d8203f20fb6f68ee37f5 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 1 Dec 2024 07:46:12 +0000 Subject: [PATCH] feat: add necessary py extensions in manifest --- agents/.gitignore | 1 + agents/examples/demo/manifest.json | 45 ++++++ agents/examples/experimental/manifest.json | 135 ++++++++++++++++++ .../extension/http_server_python/__init__.py | 4 - .../http_server_python/http_server_addon.py | 14 -- .../http_server_extension.py | 89 ------------ .../extension/http_server_python/log.py | 13 -- .../http_server_python/manifest.json | 63 -------- .../http_server_python/property.json | 4 - 9 files changed, 181 insertions(+), 187 deletions(-) delete mode 100644 agents/ten_packages/extension/http_server_python/__init__.py delete mode 100644 agents/ten_packages/extension/http_server_python/http_server_addon.py delete mode 100644 agents/ten_packages/extension/http_server_python/http_server_extension.py delete mode 100644 agents/ten_packages/extension/http_server_python/log.py delete mode 100644 agents/ten_packages/extension/http_server_python/manifest.json delete mode 100644 agents/ten_packages/extension/http_server_python/property.json diff --git a/agents/.gitignore b/agents/.gitignore index faced1f0..d2e02e77 100644 --- a/agents/.gitignore +++ b/agents/.gitignore @@ -5,6 +5,7 @@ ten_packages/extension/azure_tts ten_packages/extension/agora_sess_ctrl ten_packages/extension/agora_rtm ten_packages/extension/py_init_extension_cpp +ten_packages/extension/http_server_python ten_packages/system/agora_rtc_sdk ten_packages/system/azure_speech_sdk ten_packages/system/nlohmann_json diff --git a/agents/examples/demo/manifest.json b/agents/examples/demo/manifest.json index ab4316ed..a4158c8f 100644 --- a/agents/examples/demo/manifest.json +++ b/agents/examples/demo/manifest.json @@ -37,6 +37,51 @@ "type": "extension", "name": "agora_rtm", "version": "=0.3.0" + }, + { + "type": "extension", + "name": "openai_chatgpt_python", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "openai_v2v_python", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "fish_audio_tts", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "message_collector", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "message_collector_rtm", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "vision_tool_python", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "vision_analyze_tool_python", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "weatherapi_tool_python", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "bingsearch_tool_python", + "version": "=0.1.0" } ] } \ No newline at end of file diff --git a/agents/examples/experimental/manifest.json b/agents/examples/experimental/manifest.json index 2a16c223..75532b50 100644 --- a/agents/examples/experimental/manifest.json +++ b/agents/examples/experimental/manifest.json @@ -37,6 +37,141 @@ "type": "extension", "name": "agora_rtm", "version": "=0.3.0" + }, + { + "type": "extension", + "name": "http_server_python", + "version": "0.7.0" + }, + { + "type": "extension", + "name": "aliyun_analyticdb_vector_storage", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "aliyun_text_embedding", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "file_chunker", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "llama_index_chat_engine", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "bedrock_llm_python", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "bingsearch_tool_python", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "cartesia_tts", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "cosy_tts_python", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "deepgram_asr_python", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "elevenlabs_tts_python", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "fashionai", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "fish_audio_tts", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "gemini_llm_python", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "gemini_llm_python", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "interrupt_detector_python", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "message_collector", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "minimax_tts_python", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "minimax_v2v_python", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "openai_chatgpt_python", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "openai_v2v_python", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "polly_tts", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "qwen_llm_python", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "transcribe_asr_python", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "tsdb_firestore", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "vision_tool_python", + "version": "=0.1.0" + }, + { + "type": "extension", + "name": "weatherapi_tool_python", + "version": "=0.1.0" } ] } \ No newline at end of file diff --git a/agents/ten_packages/extension/http_server_python/__init__.py b/agents/ten_packages/extension/http_server_python/__init__.py deleted file mode 100644 index 0bcc331c..00000000 --- a/agents/ten_packages/extension/http_server_python/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from . import http_server_addon -from .log import logger - -logger.info("http_server_python extension loaded") diff --git a/agents/ten_packages/extension/http_server_python/http_server_addon.py b/agents/ten_packages/extension/http_server_python/http_server_addon.py deleted file mode 100644 index 97f269aa..00000000 --- a/agents/ten_packages/extension/http_server_python/http_server_addon.py +++ /dev/null @@ -1,14 +0,0 @@ -from ten import ( - Addon, - register_addon_as_extension, - TenEnv, -) - - -@register_addon_as_extension("http_server_python") -class HTTPServerExtensionAddon(Addon): - def on_create_instance(self, ten: TenEnv, addon_name: str, context): - from .log import logger - from .http_server_extension import HTTPServerExtension - logger.info("on_create_instance") - ten.on_create_instance_done(HTTPServerExtension(addon_name), context) diff --git a/agents/ten_packages/extension/http_server_python/http_server_extension.py b/agents/ten_packages/extension/http_server_python/http_server_extension.py deleted file mode 100644 index 4148c7c9..00000000 --- a/agents/ten_packages/extension/http_server_python/http_server_extension.py +++ /dev/null @@ -1,89 +0,0 @@ -from ten import ( - Extension, - TenEnv, - Cmd, - StatusCode, - CmdResult, -) -from .log import logger -from http.server import HTTPServer, BaseHTTPRequestHandler -import threading -from functools import partial - - -class HTTPHandler(BaseHTTPRequestHandler): - def __init__(self, ten, *args, directory=None, **kwargs): - logger.info("new handler: %s %s %s", directory, args, kwargs) - self.ten = ten - super().__init__(*args, **kwargs) - - def do_POST(self): - logger.info("post request incoming %s", self.path) - if self.path == "/cmd": - try: - content_length = int(self.headers["Content-Length"]) - input = self.rfile.read(content_length).decode("utf-8") - logger.info("incoming request %s", input) - self.ten.send_cmd( - Cmd.create_from_json(input), - lambda ten, result: logger.info( - "finish send_cmd from http server %s %s", input, result - ), - ) - self.send_response_only(200) - self.end_headers() - except Exception as e: - logger.warning("failed to handle request, err {}".format(e)) - self.send_response_only(500) - self.end_headers() - else: - logger.warning("invalid path: %s", self.path) - self.send_response_only(404) - self.end_headers() - - -class HTTPServerExtension(Extension): - def __init__(self, name: str): - super().__init__(name) - self.listen_addr = "127.0.0.1" - self.listen_port = 8888 - self.cmd_white_list = None - self.server = None - self.thread = None - - def on_start(self, ten: TenEnv): - self.listen_addr = ten.get_property_string("listen_addr") - self.listen_port = ten.get_property_int("listen_port") - """ - white_list = ten.get_property_string("cmd_white_list") - if len(white_list) > 0: - self.cmd_white_list = white_list.split(",") - """ - - logger.info( - "HTTPServerExtension on_start %s:%d, %s", - self.listen_addr, - self.listen_port, - self.cmd_white_list, - ) - - self.server = HTTPServer( - (self.listen_addr, self.listen_port), partial(HTTPHandler, ten) - ) - self.thread = threading.Thread(target=self.server.serve_forever) - self.thread.start() - - ten.on_start_done() - - def on_stop(self, ten: TenEnv): - logger.info("on_stop") - self.server.shutdown() - self.thread.join() - ten.on_stop_done() - - def on_cmd(self, ten: TenEnv, cmd: Cmd): - cmd_json = cmd.to_json() - logger.info("on_cmd json: " + cmd_json) - cmd_result = CmdResult.create(StatusCode.OK) - cmd_result.set_property_string("detail", "ok") - ten.return_result(cmd_result, cmd) diff --git a/agents/ten_packages/extension/http_server_python/log.py b/agents/ten_packages/extension/http_server_python/log.py deleted file mode 100644 index a7b47d79..00000000 --- a/agents/ten_packages/extension/http_server_python/log.py +++ /dev/null @@ -1,13 +0,0 @@ -import logging - -logger = logging.getLogger("http_server_python") -logger.setLevel(logging.INFO) - -formatter = logging.Formatter( - "%(asctime)s - %(name)s - %(levelname)s - %(process)d - [%(filename)s:%(lineno)d] - %(message)s" -) - -console_handler = logging.StreamHandler() -console_handler.setFormatter(formatter) - -logger.addHandler(console_handler) diff --git a/agents/ten_packages/extension/http_server_python/manifest.json b/agents/ten_packages/extension/http_server_python/manifest.json deleted file mode 100644 index 913f3a1a..00000000 --- a/agents/ten_packages/extension/http_server_python/manifest.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "type": "extension", - "name": "http_server_python", - "version": "0.5.0", - "dependencies": [ - { - "type": "system", - "name": "ten_runtime_python", - "version": "0.4" - } - ], - "package": { - "include": [ - "manifest.json", - "property.json", - "**.py" - ] - }, - "api": { - "property": { - "listen_addr": { - "type": "string" - }, - "listen_port": { - "type": "int32" - } - }, - "cmd_out": [ - { - "name": "update_querying_collection", - "property": { - "filename": { - "type": "string" - }, - "collection": { - "type": "string" - } - }, - "required": [ - "filename", - "collection" - ] - }, - { - "name": "file_chunk", - "property": { - "filename": { - "type": "string" - }, - "path": { - "type": "string" - }, - "collection": { - "type": "string" - } - }, - "required": [ - "path" - ] - } - ] - } -} \ No newline at end of file diff --git a/agents/ten_packages/extension/http_server_python/property.json b/agents/ten_packages/extension/http_server_python/property.json deleted file mode 100644 index 27ae7c57..00000000 --- a/agents/ten_packages/extension/http_server_python/property.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "listen_addr": "0.0.0.0", - "listen_port": 8888 -} \ No newline at end of file