From 830a780ab7cd48334c1b458be7df9b3bc1e7827b Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 09:26:00 +0000 Subject: [PATCH 01/25] fix: ext path and manifest for upgrading ten --- agents/manifest-lock.json | 152 ++ agents/manifest.json | 16 +- agents/scripts/build/go.mod | 3 - agents/scripts/build/main.go | 1418 ----------------- .../bak/litellm_python/__init__.py | 0 .../bak/litellm_python/extension.py | 0 .../bak/litellm_python/litellm.py | 0 .../bak/litellm_python/litellm_addon.py | 0 .../bak/litellm_python/litellm_extension.py | 0 .../bak/litellm_python/log.py | 0 .../bak/litellm_python/manifest.json | 0 .../bak/litellm_python/requirements.txt | 0 .../bak/litellm_python/utils.py | 0 .../__init__.py | 0 .../client.py | 0 .../aliyun_analyticdb_vector_storage/log.py | 0 .../manifest.json | 5 +- .../aliyun_analyticdb_vector_storage/model.py | 0 .../property.json | 0 .../requirements.txt | 0 .../vector_storage_addon.py | 0 .../vector_storage_extension.py | 0 .../aliyun_text_embedding/__init__.py | 0 .../aliyun_text_embedding/embedding_addon.py | 0 .../embedding_extension.py | 0 .../extension/aliyun_text_embedding/log.py | 0 .../aliyun_text_embedding/manifest.json | 5 +- .../aliyun_text_embedding/property.json | 0 .../aliyun_text_embedding/requirements.txt | 0 .../extension/azure_tts/BUILD.gn | 0 .../extension/azure_tts/README.md | 0 .../extension/azure_tts/manifest.json | 7 +- .../extension/azure_tts/property.json | 0 .../extension/azure_tts/src/log.h | 0 .../extension/azure_tts/src/main.cc | 0 .../extension/azure_tts/src/tts.cc | 0 .../extension/azure_tts/src/tts.h | 0 .../extension/bedrock_llm_python/README.md | 0 .../extension/bedrock_llm_python/__init__.py | 0 .../bedrock_llm_python/bedrock_llm.py | 0 .../bedrock_llm_extension.py | 0 .../extension/bedrock_llm_python/log.py | 0 .../bedrock_llm_python/manifest.json | 7 +- .../bedrock_llm_python/property.json | 0 .../bedrock_llm_python/requirements.txt | 0 .../extension/chat_transcriber/extension.go | 0 .../extension/chat_transcriber/go.mod | 0 .../extension/chat_transcriber/go.sum | 0 .../extension/chat_transcriber/manifest.json | 7 +- .../chat_transcriber/pb/chat_text.pb.go | 0 .../chat_transcriber/pb/chat_text.proto | 0 .../extension/chat_transcriber/property.json | 0 .../chat_transcriber_python/__init__.py | 0 .../chat_transcriber_addon.py | 0 .../chat_transcriber_extension.py | 0 .../extension/chat_transcriber_python/log.py | 0 .../chat_transcriber_python/manifest.json | 7 +- .../pb/chat_text.proto | 0 .../pb/chat_text_pb2.py | 0 .../chat_transcriber_python/property.json | 0 .../chat_transcriber_python/requirements.txt | 0 .../extension/cosy_tts/__init__.py | 0 .../extension/cosy_tts/cosy_tts_addon.py | 0 .../extension/cosy_tts/cosy_tts_extension.py | 0 .../extension/cosy_tts/log.py | 0 .../extension/cosy_tts/manifest.json | 9 +- .../extension/cosy_tts/property.json | 0 .../extension/cosy_tts/requirements.txt | 0 .../elevenlabs_tts/elevenlabs_tts.go | 0 .../elevenlabs_tts_extension.go | 0 .../extension/elevenlabs_tts/go.mod | 0 .../extension/elevenlabs_tts/go.sum | 0 .../extension/elevenlabs_tts/manifest.json | 9 +- .../extension/elevenlabs_tts/pcm.go | 0 .../extension/elevenlabs_tts/property.json | 0 .../elevenlabs_tts_python/__init__.py | 0 .../elevenlabs_tts_python/elevenlabs_tts.py | 0 .../elevenlabs_tts_addon.py | 0 .../elevenlabs_tts_extension.py | 0 .../elevenlabs_tts_python/extension.py | 0 .../extension/elevenlabs_tts_python/log.py | 0 .../elevenlabs_tts_python/manifest.json | 9 +- .../extension/elevenlabs_tts_python/pcm.py | 0 .../elevenlabs_tts_python/property.json | 0 .../elevenlabs_tts_python/requirements.txt | 0 .../extension/file_chunker/__init__.py | 0 .../file_chunker/file_chunker_addon.py | 0 .../file_chunker/file_chunker_extension.py | 0 .../extension/file_chunker/log.py | 0 .../extension/file_chunker/manifest.json | 5 +- .../extension/file_chunker/property.json | 0 .../extension/file_chunker/requirements.txt | 0 .../extension/gemini_llm_python/__init__.py | 0 .../extension/gemini_llm_python/extension.py | 0 .../extension/gemini_llm_python/gemini_llm.py | 0 .../gemini_llm_python/gemini_llm_addon.py | 0 .../gemini_llm_python/gemini_llm_extension.py | 0 .../extension/gemini_llm_python/log.py | 0 .../extension/gemini_llm_python/manifest.json | 9 +- .../gemini_llm_python/requirements.txt | 0 .../extension/gemini_llm_python/utils.py | 0 .../extension/http_server_python/__init__.py | 0 .../http_server_python/http_server_addon.py | 0 .../http_server_extension.py | 0 .../extension/http_server_python/log.py | 0 .../http_server_python/manifest.json | 7 +- .../http_server_python/property.json | 0 .../extension/interrupt_detector/extension.go | 0 .../extension/interrupt_detector/go.mod | 0 .../interrupt_detector/manifest.json | 7 +- .../interrupt_detector/property.json | 0 .../interrupt_detector_python/__init__.py | 0 .../interrupt_detector_addon.py | 0 .../interrupt_detector_extension.py | 0 .../interrupt_detector_python/log.py | 0 .../interrupt_detector_python/manifest.json | 7 +- .../interrupt_detector_python/property.json | 0 .../llama_index_chat_engine/__init__.py | 0 .../llama_index_chat_engine/addon.py | 0 .../astra_embedding.py | 0 .../llama_index_chat_engine/astra_llm.py | 0 .../astra_retriever.py | 0 .../llama_index_chat_engine/extension.py | 0 .../extension/llama_index_chat_engine/log.py | 0 .../llama_index_chat_engine/manifest.json | 5 +- .../llama_index_chat_engine/property.json | 0 .../llama_index_chat_engine/requirements.txt | 0 .../extension/openai_chatgpt/README.md | 0 .../extension/openai_chatgpt/go.mod | 0 .../extension/openai_chatgpt/go.sum | 0 .../extension/openai_chatgpt/manifest.json | 8 +- .../openai_chatgpt/openai_chatgpt.go | 0 .../openai_chatgpt_extension.go | 0 .../extension/openai_chatgpt/property.json | 0 .../extension/openai_chatgpt/sentence.go | 0 .../extension/openai_chatgpt/sentence_test.go | 0 .../openai_chatgpt_python/__init__.py | 0 .../extension/openai_chatgpt_python/log.py | 0 .../openai_chatgpt_python/manifest.json | 13 +- .../openai_chatgpt_python/openai_chatgpt.py | 0 .../openai_chatgpt_addon.py | 0 .../openai_chatgpt_extension.py | 0 .../openai_chatgpt_python/property.json | 0 .../openai_chatgpt_python/requirements.txt | 0 .../extension/polly_tts/README.md | 0 .../extension/polly_tts/__init__.py | 0 .../extension/polly_tts/extension.py | 0 .../extension/polly_tts/log.py | 0 .../extension/polly_tts/manifest.json | 9 +- .../extension/polly_tts/polly_tts_addon.py | 0 .../polly_tts/polly_tts_extension.py | 0 .../extension/polly_tts/polly_wrapper.py | 0 .../extension/polly_tts/requirements.txt | 0 .../extension/qwen_llm_python/__init__.py | 0 .../extension/qwen_llm_python/log.py | 0 .../extension/qwen_llm_python/manifest.json | 5 +- .../extension/qwen_llm_python/property.json | 0 .../qwen_llm_python/qwen_llm_addon.py | 0 .../qwen_llm_python/qwen_llm_extension.py | 0 .../qwen_llm_python/requirements.txt | 0 .../extension/transcribe_asr_python/README.md | 0 .../transcribe_asr_python/__init__.py | 0 .../transcribe_asr_python/extension.py | 0 .../extension/transcribe_asr_python/log.py | 0 .../transcribe_asr_python/manifest.json | 9 +- .../transcribe_asr_python/property.json | 0 .../transcribe_asr_python/requirements.txt | 0 .../transcribe_asr_addon.py | 0 .../transcribe_asr_extension.py | 0 .../transcribe_config.py | 0 .../transcribe_wrapper.py | 0 171 files changed, 221 insertions(+), 1517 deletions(-) create mode 100644 agents/manifest-lock.json delete mode 100644 agents/scripts/build/go.mod delete mode 100644 agents/scripts/build/main.go rename agents/{addon => ten_packages}/bak/litellm_python/__init__.py (100%) rename agents/{addon => ten_packages}/bak/litellm_python/extension.py (100%) rename agents/{addon => ten_packages}/bak/litellm_python/litellm.py (100%) rename agents/{addon => ten_packages}/bak/litellm_python/litellm_addon.py (100%) rename agents/{addon => ten_packages}/bak/litellm_python/litellm_extension.py (100%) rename agents/{addon => ten_packages}/bak/litellm_python/log.py (100%) rename agents/{addon => ten_packages}/bak/litellm_python/manifest.json (100%) rename agents/{addon => ten_packages}/bak/litellm_python/requirements.txt (100%) rename agents/{addon => ten_packages}/bak/litellm_python/utils.py (100%) rename agents/{addon => ten_packages}/extension/aliyun_analyticdb_vector_storage/__init__.py (100%) rename agents/{addon => ten_packages}/extension/aliyun_analyticdb_vector_storage/client.py (100%) rename agents/{addon => ten_packages}/extension/aliyun_analyticdb_vector_storage/log.py (100%) rename agents/{addon => ten_packages}/extension/aliyun_analyticdb_vector_storage/manifest.json (96%) rename agents/{addon => ten_packages}/extension/aliyun_analyticdb_vector_storage/model.py (100%) rename agents/{addon => ten_packages}/extension/aliyun_analyticdb_vector_storage/property.json (100%) rename agents/{addon => ten_packages}/extension/aliyun_analyticdb_vector_storage/requirements.txt (100%) rename agents/{addon => ten_packages}/extension/aliyun_analyticdb_vector_storage/vector_storage_addon.py (100%) rename agents/{addon => ten_packages}/extension/aliyun_analyticdb_vector_storage/vector_storage_extension.py (100%) rename agents/{addon => ten_packages}/extension/aliyun_text_embedding/__init__.py (100%) rename agents/{addon => ten_packages}/extension/aliyun_text_embedding/embedding_addon.py (100%) rename agents/{addon => ten_packages}/extension/aliyun_text_embedding/embedding_extension.py (100%) rename agents/{addon => ten_packages}/extension/aliyun_text_embedding/log.py (100%) rename agents/{addon => ten_packages}/extension/aliyun_text_embedding/manifest.json (95%) rename agents/{addon => ten_packages}/extension/aliyun_text_embedding/property.json (100%) rename agents/{addon => ten_packages}/extension/aliyun_text_embedding/requirements.txt (100%) rename agents/{addon => ten_packages}/extension/azure_tts/BUILD.gn (100%) rename agents/{addon => ten_packages}/extension/azure_tts/README.md (100%) rename agents/{addon => ten_packages}/extension/azure_tts/manifest.json (90%) rename agents/{addon => ten_packages}/extension/azure_tts/property.json (100%) rename agents/{addon => ten_packages}/extension/azure_tts/src/log.h (100%) rename agents/{addon => ten_packages}/extension/azure_tts/src/main.cc (100%) rename agents/{addon => ten_packages}/extension/azure_tts/src/tts.cc (100%) rename agents/{addon => ten_packages}/extension/azure_tts/src/tts.h (100%) rename agents/{addon => ten_packages}/extension/bedrock_llm_python/README.md (100%) rename agents/{addon => ten_packages}/extension/bedrock_llm_python/__init__.py (100%) rename agents/{addon => ten_packages}/extension/bedrock_llm_python/bedrock_llm.py (100%) rename agents/{addon => ten_packages}/extension/bedrock_llm_python/bedrock_llm_extension.py (100%) rename agents/{addon => ten_packages}/extension/bedrock_llm_python/log.py (100%) rename agents/{addon => ten_packages}/extension/bedrock_llm_python/manifest.json (90%) rename agents/{addon => ten_packages}/extension/bedrock_llm_python/property.json (100%) rename agents/{addon => ten_packages}/extension/bedrock_llm_python/requirements.txt (100%) rename agents/{addon => ten_packages}/extension/chat_transcriber/extension.go (100%) rename agents/{addon => ten_packages}/extension/chat_transcriber/go.mod (100%) rename agents/{addon => ten_packages}/extension/chat_transcriber/go.sum (100%) rename agents/{addon => ten_packages}/extension/chat_transcriber/manifest.json (85%) rename agents/{addon => ten_packages}/extension/chat_transcriber/pb/chat_text.pb.go (100%) rename agents/{addon => ten_packages}/extension/chat_transcriber/pb/chat_text.proto (100%) rename agents/{addon => ten_packages}/extension/chat_transcriber/property.json (100%) rename agents/{addon => ten_packages}/extension/chat_transcriber_python/__init__.py (100%) rename agents/{addon => ten_packages}/extension/chat_transcriber_python/chat_transcriber_addon.py (100%) rename agents/{addon => ten_packages}/extension/chat_transcriber_python/chat_transcriber_extension.py (100%) rename agents/{addon => ten_packages}/extension/chat_transcriber_python/log.py (100%) rename agents/{addon => ten_packages}/extension/chat_transcriber_python/manifest.json (84%) rename agents/{addon => ten_packages}/extension/chat_transcriber_python/pb/chat_text.proto (100%) rename agents/{addon => ten_packages}/extension/chat_transcriber_python/pb/chat_text_pb2.py (100%) rename agents/{addon => ten_packages}/extension/chat_transcriber_python/property.json (100%) rename agents/{addon => ten_packages}/extension/chat_transcriber_python/requirements.txt (100%) rename agents/{addon => ten_packages}/extension/cosy_tts/__init__.py (100%) rename agents/{addon => ten_packages}/extension/cosy_tts/cosy_tts_addon.py (100%) rename agents/{addon => ten_packages}/extension/cosy_tts/cosy_tts_extension.py (100%) rename agents/{addon => ten_packages}/extension/cosy_tts/log.py (100%) rename agents/{addon => ten_packages}/extension/cosy_tts/manifest.json (86%) rename agents/{addon => ten_packages}/extension/cosy_tts/property.json (100%) rename agents/{addon => ten_packages}/extension/cosy_tts/requirements.txt (100%) rename agents/{addon => ten_packages}/extension/elevenlabs_tts/elevenlabs_tts.go (100%) rename agents/{addon => ten_packages}/extension/elevenlabs_tts/elevenlabs_tts_extension.go (100%) rename agents/{addon => ten_packages}/extension/elevenlabs_tts/go.mod (100%) rename agents/{addon => ten_packages}/extension/elevenlabs_tts/go.sum (100%) rename agents/{addon => ten_packages}/extension/elevenlabs_tts/manifest.json (90%) rename agents/{addon => ten_packages}/extension/elevenlabs_tts/pcm.go (100%) rename agents/{addon => ten_packages}/extension/elevenlabs_tts/property.json (100%) rename agents/{addon => ten_packages}/extension/elevenlabs_tts_python/__init__.py (100%) rename agents/{addon => ten_packages}/extension/elevenlabs_tts_python/elevenlabs_tts.py (100%) rename agents/{addon => ten_packages}/extension/elevenlabs_tts_python/elevenlabs_tts_addon.py (100%) rename agents/{addon => ten_packages}/extension/elevenlabs_tts_python/elevenlabs_tts_extension.py (100%) rename agents/{addon => ten_packages}/extension/elevenlabs_tts_python/extension.py (100%) rename agents/{addon => ten_packages}/extension/elevenlabs_tts_python/log.py (100%) rename agents/{addon => ten_packages}/extension/elevenlabs_tts_python/manifest.json (90%) rename agents/{addon => ten_packages}/extension/elevenlabs_tts_python/pcm.py (100%) rename agents/{addon => ten_packages}/extension/elevenlabs_tts_python/property.json (100%) rename agents/{addon => ten_packages}/extension/elevenlabs_tts_python/requirements.txt (100%) rename agents/{addon => ten_packages}/extension/file_chunker/__init__.py (100%) rename agents/{addon => ten_packages}/extension/file_chunker/file_chunker_addon.py (100%) rename agents/{addon => ten_packages}/extension/file_chunker/file_chunker_extension.py (100%) rename agents/{addon => ten_packages}/extension/file_chunker/log.py (100%) rename agents/{addon => ten_packages}/extension/file_chunker/manifest.json (95%) rename agents/{addon => ten_packages}/extension/file_chunker/property.json (100%) rename agents/{addon => ten_packages}/extension/file_chunker/requirements.txt (100%) rename agents/{addon => ten_packages}/extension/gemini_llm_python/__init__.py (100%) rename agents/{addon => ten_packages}/extension/gemini_llm_python/extension.py (100%) rename agents/{addon => ten_packages}/extension/gemini_llm_python/gemini_llm.py (100%) rename agents/{addon => ten_packages}/extension/gemini_llm_python/gemini_llm_addon.py (100%) rename agents/{addon => ten_packages}/extension/gemini_llm_python/gemini_llm_extension.py (100%) rename agents/{addon => ten_packages}/extension/gemini_llm_python/log.py (100%) rename agents/{addon => ten_packages}/extension/gemini_llm_python/manifest.json (92%) rename agents/{addon => ten_packages}/extension/gemini_llm_python/requirements.txt (100%) rename agents/{addon => ten_packages}/extension/gemini_llm_python/utils.py (100%) rename agents/{addon => ten_packages}/extension/http_server_python/__init__.py (100%) rename agents/{addon => ten_packages}/extension/http_server_python/http_server_addon.py (100%) rename agents/{addon => ten_packages}/extension/http_server_python/http_server_extension.py (100%) rename agents/{addon => ten_packages}/extension/http_server_python/log.py (100%) rename agents/{addon => ten_packages}/extension/http_server_python/manifest.json (91%) rename agents/{addon => ten_packages}/extension/http_server_python/property.json (100%) rename agents/{addon => ten_packages}/extension/interrupt_detector/extension.go (100%) rename agents/{addon => ten_packages}/extension/interrupt_detector/go.mod (100%) rename agents/{addon => ten_packages}/extension/interrupt_detector/manifest.json (81%) rename agents/{addon => ten_packages}/extension/interrupt_detector/property.json (100%) rename agents/{addon => ten_packages}/extension/interrupt_detector_python/__init__.py (100%) rename agents/{addon => ten_packages}/extension/interrupt_detector_python/interrupt_detector_addon.py (100%) rename agents/{addon => ten_packages}/extension/interrupt_detector_python/interrupt_detector_extension.py (100%) rename agents/{addon => ten_packages}/extension/interrupt_detector_python/log.py (100%) rename agents/{addon => ten_packages}/extension/interrupt_detector_python/manifest.json (85%) rename agents/{addon => ten_packages}/extension/interrupt_detector_python/property.json (100%) rename agents/{addon => ten_packages}/extension/llama_index_chat_engine/__init__.py (100%) rename agents/{addon => ten_packages}/extension/llama_index_chat_engine/addon.py (100%) rename agents/{addon => ten_packages}/extension/llama_index_chat_engine/astra_embedding.py (100%) rename agents/{addon => ten_packages}/extension/llama_index_chat_engine/astra_llm.py (100%) rename agents/{addon => ten_packages}/extension/llama_index_chat_engine/astra_retriever.py (100%) rename agents/{addon => ten_packages}/extension/llama_index_chat_engine/extension.py (100%) rename agents/{addon => ten_packages}/extension/llama_index_chat_engine/log.py (100%) rename agents/{addon => ten_packages}/extension/llama_index_chat_engine/manifest.json (97%) rename agents/{addon => ten_packages}/extension/llama_index_chat_engine/property.json (100%) rename agents/{addon => ten_packages}/extension/llama_index_chat_engine/requirements.txt (100%) rename agents/{addon => ten_packages}/extension/openai_chatgpt/README.md (100%) rename agents/{addon => ten_packages}/extension/openai_chatgpt/go.mod (100%) rename agents/{addon => ten_packages}/extension/openai_chatgpt/go.sum (100%) rename agents/{addon => ten_packages}/extension/openai_chatgpt/manifest.json (92%) rename agents/{addon => ten_packages}/extension/openai_chatgpt/openai_chatgpt.go (100%) rename agents/{addon => ten_packages}/extension/openai_chatgpt/openai_chatgpt_extension.go (100%) rename agents/{addon => ten_packages}/extension/openai_chatgpt/property.json (100%) rename agents/{addon => ten_packages}/extension/openai_chatgpt/sentence.go (100%) rename agents/{addon => ten_packages}/extension/openai_chatgpt/sentence_test.go (100%) rename agents/{addon => ten_packages}/extension/openai_chatgpt_python/__init__.py (100%) rename agents/{addon => ten_packages}/extension/openai_chatgpt_python/log.py (100%) rename agents/{addon => ten_packages}/extension/openai_chatgpt_python/manifest.json (89%) rename agents/{addon => ten_packages}/extension/openai_chatgpt_python/openai_chatgpt.py (100%) rename agents/{addon => ten_packages}/extension/openai_chatgpt_python/openai_chatgpt_addon.py (100%) rename agents/{addon => ten_packages}/extension/openai_chatgpt_python/openai_chatgpt_extension.py (100%) rename agents/{addon => ten_packages}/extension/openai_chatgpt_python/property.json (100%) rename agents/{addon => ten_packages}/extension/openai_chatgpt_python/requirements.txt (100%) rename agents/{addon => ten_packages}/extension/polly_tts/README.md (100%) rename agents/{addon => ten_packages}/extension/polly_tts/__init__.py (100%) rename agents/{addon => ten_packages}/extension/polly_tts/extension.py (100%) rename agents/{addon => ten_packages}/extension/polly_tts/log.py (100%) rename agents/{addon => ten_packages}/extension/polly_tts/manifest.json (88%) rename agents/{addon => ten_packages}/extension/polly_tts/polly_tts_addon.py (100%) rename agents/{addon => ten_packages}/extension/polly_tts/polly_tts_extension.py (100%) rename agents/{addon => ten_packages}/extension/polly_tts/polly_wrapper.py (100%) rename agents/{addon => ten_packages}/extension/polly_tts/requirements.txt (100%) rename agents/{addon => ten_packages}/extension/qwen_llm_python/__init__.py (100%) rename agents/{addon => ten_packages}/extension/qwen_llm_python/log.py (100%) rename agents/{addon => ten_packages}/extension/qwen_llm_python/manifest.json (94%) rename agents/{addon => ten_packages}/extension/qwen_llm_python/property.json (100%) rename agents/{addon => ten_packages}/extension/qwen_llm_python/qwen_llm_addon.py (100%) rename agents/{addon => ten_packages}/extension/qwen_llm_python/qwen_llm_extension.py (100%) rename agents/{addon => ten_packages}/extension/qwen_llm_python/requirements.txt (100%) rename agents/{addon => ten_packages}/extension/transcribe_asr_python/README.md (100%) rename agents/{addon => ten_packages}/extension/transcribe_asr_python/__init__.py (100%) rename agents/{addon => ten_packages}/extension/transcribe_asr_python/extension.py (100%) rename agents/{addon => ten_packages}/extension/transcribe_asr_python/log.py (100%) rename agents/{addon => ten_packages}/extension/transcribe_asr_python/manifest.json (92%) rename agents/{addon => ten_packages}/extension/transcribe_asr_python/property.json (100%) rename agents/{addon => ten_packages}/extension/transcribe_asr_python/requirements.txt (100%) rename agents/{addon => ten_packages}/extension/transcribe_asr_python/transcribe_asr_addon.py (100%) rename agents/{addon => ten_packages}/extension/transcribe_asr_python/transcribe_asr_extension.py (100%) rename agents/{addon => ten_packages}/extension/transcribe_asr_python/transcribe_config.py (100%) rename agents/{addon => ten_packages}/extension/transcribe_asr_python/transcribe_wrapper.py (100%) diff --git a/agents/manifest-lock.json b/agents/manifest-lock.json new file mode 100644 index 00000000..18edd850 --- /dev/null +++ b/agents/manifest-lock.json @@ -0,0 +1,152 @@ +{ + "packages": [ + { + "type": "system", + "name": "ten_runtime_go", + "version": "0.1.0", + "hash": "ab66a8ed40c744a52cce36f26a233e669d989d9f620876156e3cc7187f214977", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime" + } + ], + "supports": [ + { + "os": "linux", + "arch": "x64" + } + ] + }, + { + "type": "extension", + "name": "py_init_extension_cpp", + "version": "0.1.0", + "hash": "b39c4dddbec58e1a756b7e71f41ab0ec419ab0043525ba94e6ed98b7ef634697", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime" + }, + { + "type": "system", + "name": "ten_runtime_python" + } + ], + "supports": [ + { + "os": "linux", + "arch": "x64" + } + ] + }, + { + "type": "extension_group", + "name": "default_extension_group", + "version": "0.1.0", + "hash": "cfadaf8f951de42965e92becc67a597501196bc3bd6f17f39a64260836393c64", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime" + } + ], + "supports": [ + { + "os": "linux", + "arch": "x64" + } + ] + }, + { + "type": "extension", + "name": "agora_rtc", + "version": "0.5.0-rc1", + "hash": "36ddf94cd5b2db11ec399ccb5522061fce8a1323570aac9bb9ec0ef3eb7a9368", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime" + }, + { + "type": "system", + "name": "agora_rtc_sdk" + }, + { + "type": "system", + "name": "azure_speech_sdk" + }, + { + "type": "system", + "name": "nlohmann_json" + } + ], + "supports": [ + { + "os": "linux", + "arch": "x64" + } + ] + }, + { + "type": "system", + "name": "ten_runtime", + "version": "0.1.0", + "hash": "b630f52ef9787132dc854fb4e90f962336be3f836baba137ca3b6dc132df0b86", + "supports": [ + { + "os": "linux", + "arch": "x64" + } + ] + }, + { + "type": "system", + "name": "agora_rtc_sdk", + "version": "4.1.35+build328115", + "hash": "fd33989f9913d77e05970eb2b265fa5e08322141b7e0f8f9fd3e521f87929b3b", + "supports": [ + { + "os": "linux", + "arch": "x64" + } + ] + }, + { + "type": "system", + "name": "azure_speech_sdk", + "version": "1.38.0", + "hash": "66a50ef361f8190fa0595d8298c135e13b73796d57174a0802631263a8f15806", + "supports": [ + { + "os": "linux", + "arch": "x64" + } + ] + }, + { + "type": "system", + "name": "nlohmann_json", + "version": "3.11.2", + "hash": "72b15822c7ea9deef5e7ad96216ac55e93f11b00466dd1943afd5ee276e99d19" + }, + { + "type": "system", + "name": "ten_runtime_python", + "version": "0.1.0", + "hash": "a8980c39ba0cf1f21b38490c3167950f750403b1b29d756cfbacc5c5147becd7", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime" + } + ], + "supports": [ + { + "os": "linux", + "arch": "x64" + } + ] + } + ] +} \ No newline at end of file diff --git a/agents/manifest.json b/agents/manifest.json index e9fe1e4a..49c6df8f 100644 --- a/agents/manifest.json +++ b/agents/manifest.json @@ -2,32 +2,26 @@ "type": "app", "name": "astra_agents", "version": "0.4.0", - "language": "go", "dependencies": [ { "type": "system", - "name": "rte_runtime_python", - "version": "0.4" - }, - { - "type": "system", - "name": "rte_runtime_go", - "version": "0.4" + "name": "ten_runtime_go", + "version": "0.1" }, { "type": "extension", "name": "py_init_extension_cpp", - "version": "0.4" + "version": "0.1" }, { "type": "extension_group", "name": "default_extension_group", - "version": "0.4" + "version": "0.1" }, { "type": "extension", "name": "agora_rtc", - "version": "0.4.1-rc3" + "version": "=0.5.0-rc1" } ] } \ No newline at end of file diff --git a/agents/scripts/build/go.mod b/agents/scripts/build/go.mod deleted file mode 100644 index 313512d1..00000000 --- a/agents/scripts/build/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module build - -go 1.20 diff --git a/agents/scripts/build/main.go b/agents/scripts/build/main.go deleted file mode 100644 index 38c7cce5..00000000 --- a/agents/scripts/build/main.go +++ /dev/null @@ -1,1418 +0,0 @@ -/** - * - * Agora Real Time Engagement - * Created by Liu Loulou in 2024-04. - * Copyright (c) 2024 Agora IO. All rights reserved. - * - */ - -package main - -import ( - "bufio" - "bytes" - "encoding/json" - "errors" - "flag" - "fmt" - "go/build" - "io" - "log" - "os" - "os/exec" - "path" - "reflect" - "regexp" - "runtime" - "strconv" - "strings" -) - -const ( - AcquiredGoVersion string = "1.20" - BackupGoMod string = "_go.mod" - BackupGoSum string = "_go.sum" -) - -func getAppDir() string { - // Golang provides the following three ways to get the location of this - // module: - // - // - filepath.Dir(os.Args[0]) - // - // - os.Executable() - // - // - os.Getwd() - // - // However, this module might be executed using `go run scripts/build/*.go`, - // a temporary executable will be built by Golang (ex: - // /tmp/go-build2621984543/b001/exe/builder) in this case. And the first and - // second methods will return the exactly path of the executable, in other - // words, the temporary directory will be returned if this module is - // executed using `go run` command. - - cwd, err := os.Getwd() - if err != nil { - log.Fatalf("Failed to get location of GO app, %v", err) - } - - return cwd -} - -func getAppPkgName(appDir string) string { - pkg, err := build.ImportDir(appDir, build.AllowBinary) - if err != nil { - log.Fatalf("Failed to read GO package of app, %v", err) - } - - return pkg.Name -} - -func main() { - // Setup logging. - log.SetFlags(log.Ltime) - - options := &BuildOption{} - flag.StringVar( - &options.AppDir, - "app_dir", - getAppDir(), - "The base directory of the GO app, used for debug.", - ) - flag.StringVar( - &options.AutoGenImportFile, - "auto_gen_import_file", - DefaultAutoImportFile, - "The name of auto generated file used to import all addons.", - ) - flag.BoolVar( - &options.KeepAutoGen, - "keep_auto_gen", - false, - "Whether to keep the auto-gen files.", - ) - flag.BoolVar( - &options.CleanAutoGen, - "clean_auto_gen", - false, - "Clean the auto-gen files only, without building the app.", - ) - flag.StringVar( - &options.Mod, - "mod", - "", - "Module download mode to use: readonly, vendor, or mod. Same as the -mod flag in go build.", - ) - flag.StringVar( - &options.GCFlags, - "gcflags", - "", - "Flags to pass to the Go compiler. Same as the -gcflags flag in go build.", - ) - flag.StringVar( - &options.LdFlags, - "ldflags", - "", - "Flags to pass to the Go linker. Same as the -ldflags flag in go build.", - ) - flag.BoolVar( - &options.EnableAsan, - "asan", - false, - "Enable address sanitizer. Same as the -asan flag in go build.", - ) - flag.BoolVar( - &options.Verbose, - "verbose", - false, - "Displays the verbose output.", - ) - flag.Parse() - - if err := options.Valid(); err != nil { - log.Fatalf("Invalid options: %v", err) - } - - appPkgName := getAppPkgName(options.AppDir) - ab := NewAppBuilder(appPkgName, AcquiredGoVersion, options) - - if options.CleanAutoGen { - ab.Cleanup() - log.Println("Clean auto-gen files successfully.") - return - } - - err := ab.Build() - - // No matter the build is successful or not, we need to cleanup the - // temporary files. - if !options.KeepAutoGen { - ab.Cleanup() - } - - if err != nil { - log.Fatalf("Error: %v", err) - } else { - log.Println("Build GO app successfully.") - } -} - -// -------------- version ---------------- - -// Copy from https://github.com/hashicorp/go-version/blob/main/version.go. - -// The compiled regular expression used to test the validity of a version. -var ( - versionRegexp *regexp.Regexp -) - -// The raw regular expression string used for testing the validity -// of a version. -const ( - VersionRegexpRaw string = `v?([0-9]+(\.[0-9]+)*?)` + - `(-([0-9]+[0-9A-Za-z\-~]*(\.[0-9A-Za-z\-~]+)*)|(-?([A-Za-z\-~]+[0-9A-Za-z\-~]*(\.[0-9A-Za-z\-~]+)*)))?` + - `(\+([0-9A-Za-z\-~]+(\.[0-9A-Za-z\-~]+)*))?` + - `?` -) - -// Version represents a single version. -type Version struct { - metadata string - pre string - segments []int64 - si int - original string -} - -func init() { - versionRegexp = regexp.MustCompile("^" + VersionRegexpRaw + "$") -} - -// NewVersion parses the given version and returns a new -// Version. -func NewVersion(v string) (*Version, error) { - return newVersion(v, versionRegexp) -} - -func newVersion(v string, pattern *regexp.Regexp) (*Version, error) { - matches := pattern.FindStringSubmatch(v) - if matches == nil { - return nil, fmt.Errorf("malformed version: %s", v) - } - segmentsStr := strings.Split(matches[1], ".") - segments := make([]int64, len(segmentsStr)) - for i, str := range segmentsStr { - val, err := strconv.ParseInt(str, 10, 64) - if err != nil { - return nil, fmt.Errorf( - "error parsing version: %s", err) - } - - segments[i] = val - } - - // Even though we could support more than three segments, if we - // got less than three, pad it with 0s. This is to cover the basic - // default usecase of semver, which is MAJOR.MINOR.PATCH at the minimum - for i := len(segments); i < 3; i++ { - segments = append(segments, 0) - } - - pre := matches[7] - if pre == "" { - pre = matches[4] - } - - return &Version{ - metadata: matches[10], - pre: pre, - segments: segments, - si: len(segmentsStr), - original: v, - }, nil -} - -// Compare compares this version to another version. This -// returns -1, 0, or 1 if this version is smaller, equal, -// or larger than the other version, respectively. -// -// If you want boolean results, use the LessThan, Equal, -// GreaterThan, GreaterThanOrEqual or LessThanOrEqual methods. -func (v *Version) Compare(other *Version) int { - // A quick, efficient equality check - if v.String() == other.String() { - return 0 - } - - segmentsSelf := v.Segments64() - segmentsOther := other.Segments64() - - // If the segments are the same, we must compare on prerelease info - if reflect.DeepEqual(segmentsSelf, segmentsOther) { - preSelf := v.Prerelease() - preOther := other.Prerelease() - if preSelf == "" && preOther == "" { - return 0 - } - if preSelf == "" { - return 1 - } - if preOther == "" { - return -1 - } - - return comparePrereleases(preSelf, preOther) - } - - // Get the highest specificity (hS), or if they're equal, just use - // segmentSelf length - lenSelf := len(segmentsSelf) - lenOther := len(segmentsOther) - hS := lenSelf - if lenSelf < lenOther { - hS = lenOther - } - // Compare the segments - // Because a constraint could have more/less specificity than the version - // it's - // checking, we need to account for a lopsided or jagged comparison - for i := 0; i < hS; i++ { - if i > lenSelf-1 { - // This means Self had the lower specificity - // Check to see if the remaining segments in Other are all zeros - if !allZero(segmentsOther[i:]) { - // if not, it means that Other has to be greater than Self - return -1 - } - break - } else if i > lenOther-1 { - // this means Other had the lower specificity - // Check to see if the remaining segments in Self are all zeros - - if !allZero(segmentsSelf[i:]) { - //if not, it means that Self has to be greater than Other - return 1 - } - break - } - lhs := segmentsSelf[i] - rhs := segmentsOther[i] - if lhs == rhs { - continue - } else if lhs < rhs { - return -1 - } - // Otherwis, rhs was > lhs, they're not equal - return 1 - } - - // if we got this far, they're equal - return 0 -} - -func allZero(segs []int64) bool { - for _, s := range segs { - if s != 0 { - return false - } - } - return true -} - -func comparePart(preSelf string, preOther string) int { - if preSelf == preOther { - return 0 - } - - var selfInt int64 - selfNumeric := true - selfInt, err := strconv.ParseInt(preSelf, 10, 64) - if err != nil { - selfNumeric = false - } - - var otherInt int64 - otherNumeric := true - otherInt, err = strconv.ParseInt(preOther, 10, 64) - if err != nil { - otherNumeric = false - } - - // if a part is empty, we use the other to decide - if preSelf == "" { - if otherNumeric { - return -1 - } - return 1 - } - - if preOther == "" { - if selfNumeric { - return 1 - } - return -1 - } - - if selfNumeric && !otherNumeric { - return -1 - } else if !selfNumeric && otherNumeric { - return 1 - } else if !selfNumeric && !otherNumeric && preSelf > preOther { - return 1 - } else if selfInt > otherInt { - return 1 - } - - return -1 -} - -func comparePrereleases(v string, other string) int { - // the same pre release! - if v == other { - return 0 - } - - // split both pre releases for analyse their parts - selfPreReleaseMeta := strings.Split(v, ".") - otherPreReleaseMeta := strings.Split(other, ".") - - selfPreReleaseLen := len(selfPreReleaseMeta) - otherPreReleaseLen := len(otherPreReleaseMeta) - - biggestLen := otherPreReleaseLen - if selfPreReleaseLen > otherPreReleaseLen { - biggestLen = selfPreReleaseLen - } - - // loop for parts to find the first difference - for i := 0; i < biggestLen; i = i + 1 { - partSelfPre := "" - if i < selfPreReleaseLen { - partSelfPre = selfPreReleaseMeta[i] - } - - partOtherPre := "" - if i < otherPreReleaseLen { - partOtherPre = otherPreReleaseMeta[i] - } - - compare := comparePart(partSelfPre, partOtherPre) - // if parts are equals, continue the loop - if compare != 0 { - return compare - } - } - - return 0 -} - -// GreaterThan tests if this version is greater than another version. -func (v *Version) GreaterThan(o *Version) bool { - return v.Compare(o) > 0 -} - -// Prerelease returns any prerelease data that is part of the version, -// or blank if there is no prerelease data. -// -// Prerelease information is anything that comes after the "-" in the -// version (but before any metadata). For example, with "1.2.3-beta", -// the prerelease information is "beta". -func (v *Version) Prerelease() string { - return v.pre -} - -// Segments64 returns the numeric segments of the version as a slice of int64s. -// -// This excludes any metadata or pre-release information. For example, -// for a version "1.2.3-beta", segments will return a slice of -// 1, 2, 3. -func (v *Version) Segments64() []int64 { - result := make([]int64, len(v.segments)) - copy(result, v.segments) - return result -} - -// String returns the full version string included pre-release -// and metadata information. -// -// This value is rebuilt according to the parsed segments and other -// information. Therefore, ambiguities in the version string such as -// prefixed zeroes (1.04.0 => 1.4.0), `v` prefix (v1.0.0 => 1.0.0), and -// missing parts (1.0 => 1.0.0) will be made into a canonicalized form -// as shown in the parenthesized examples. -func (v *Version) String() string { - var buf bytes.Buffer - fmtParts := make([]string, len(v.segments)) - for i, s := range v.segments { - // We can ignore err here since we've pre-parsed the values in segments - str := strconv.FormatInt(s, 10) - fmtParts[i] = str - } - fmt.Fprint(&buf, strings.Join(fmtParts, ".")) - if v.pre != "" { - fmt.Fprintf(&buf, "-%s", v.pre) - } - if v.metadata != "" { - fmt.Fprintf(&buf, "+%s", v.metadata) - } - - return buf.String() -} - -// -------------- version ---------------- - -// -------------- mod -------------------- - -// Copy from golang.org/x/mod@v0.15.0/modfile/read.go. - -var ( - slashSlash = []byte("//") - moduleStr = []byte("module") -) - -// ModulePath returns the module path from the gomod file text. -// If it cannot find a module path, it returns an empty string. -// It is tolerant of unrelated problems in the go.mod file. -func ModulePath(mod []byte) string { - for len(mod) > 0 { - line := mod - mod = nil - if i := bytes.IndexByte(line, '\n'); i >= 0 { - line, mod = line[:i], line[i+1:] - } - if i := bytes.Index(line, slashSlash); i >= 0 { - line = line[:i] - } - line = bytes.TrimSpace(line) - if !bytes.HasPrefix(line, moduleStr) { - continue - } - line = line[len(moduleStr):] - n := len(line) - line = bytes.TrimSpace(line) - if len(line) == n || len(line) == 0 { - continue - } - - if line[0] == '"' || line[0] == '`' { - p, err := strconv.Unquote(string(line)) - if err != nil { - return "" // malformed quoted string or multiline module path - } - return p - } - - return string(line) - } - return "" // missing module path -} - -func ModTidy(location string, envs []string, verbose bool) error { - mod_file := path.Join(location, "go.mod") - if !IsFilePresent(mod_file) { - return fmt.Errorf("%s/go.mod does not exist", location) - } - - if verbose { - log.Printf("Run 'go mod tidy' on [%s].\n", location) - } - - if err := ExecCmd([]string{"go", "mod", "tidy"}, location, envs, verbose); err != nil { - return fmt.Errorf( - "failed to execute 'go mod tidy' on [%s]. \n\t%w", - location, - err, - ) - } - - return nil -} - -func Generate(location string, envs []string, verbose bool) error { - if verbose { - log.Printf("Run 'go generate' on [%s].\n", location) - } - - err := ExecCmd([]string{"go", "generate"}, location, envs, verbose) - if err != nil { - return fmt.Errorf( - "failed to execute 'go generate' on [%s]. \n\t%w", - location, - err, - ) - } - - return nil -} - -func ModAddLocalModule(module *ExtensionModule, target string) error { - // go mod edit -replace = - // - // Note that the module must be replaced with the full path, as the module - // should be recognized when running 'go mod tidy' in directory. - err := ExecCmd( - []string{ - "go", - "mod", - "edit", - "-replace", - fmt.Sprintf( - "%s=./addon/extension/%s", - module.module, - path.Base(module.location), - ), - }, - target, - nil, - false, - ) - if err != nil { - return err - } - - // go mod edit -require @ - // - // The version is a Go-generated pseudo-version number, which contains the - // following three parts. - // - // - baseVersionPrefix (vX.0.0 or vX.Y.Z-0) is a value derived either from a - // semantic version tag that precedes the revision or from vX.0.0 if there - // is no such tag. - // - // - timestamp (yymmddhhmmss) is the UTC time the revision was created. In - // Git, this is the commit time, not the author time. - // - // - revisionIdentifier (abcdefabcdef) is a 12-character prefix of the - // commit hash, or in Subversion, a zero-padded revision number. - // - // TODO(Liu): auto generated the version based on the above rule. - err = ExecCmd( - []string{ - "go", - "mod", - "edit", - "-require", - fmt.Sprintf("%s@v0.0.0-00010101000000-000000000000", - module.module, - ), - }, - target, - nil, - false, - ) - - return err -} - -// -------------- mod -------------------- - -// -------------- options ---------------- - -const ( - DefaultAutoImportFile string = "generated_auto_import_addons.go" -) - -type BuildOption struct { - AppDir string - Verbose bool - AutoGenImportFile string - KeepAutoGen bool - CleanAutoGen bool - - // Same as the flags in 'go build'. - Mod string - GCFlags string - LdFlags string - EnableAsan bool -} - -func (b *BuildOption) Valid() error { - return nil -} - -// -------------- options ---------------- - -// -------------- builder ---------------- - -type AppBuilder struct { - pkgName string - acquiredGoVersion string - options *BuildOption - cachedEnv map[string]string - extensions []*ExtensionModule -} - -func NewAppBuilder( - pkgName string, - goVersion string, - options *BuildOption, -) *AppBuilder { - return &AppBuilder{ - pkgName: pkgName, - acquiredGoVersion: goVersion, - options: options, - cachedEnv: make(map[string]string), - extensions: make([]*ExtensionModule, 0), - } -} - -// runTidyAndGenerate executes 'go mod tidy' and 'go generate' on GO app and all -// GO extensions. -func (ab *AppBuilder) runTidyAndGenerate(envs []string) error { - for _, ext := range ab.extensions { - if err := ModTidy(ext.location, envs, ab.options.Verbose); err != nil { - return err - } - - if err := Generate(ext.location, envs, ab.options.Verbose); err != nil { - return err - } - } - - if err := ModTidy(ab.options.AppDir, envs, ab.options.Verbose); err != nil { - return err - } - - if err := Generate(ab.options.AppDir, envs, ab.options.Verbose); err != nil { - return err - } - - return nil -} - -func (ab *AppBuilder) buildGoApp(envs []string) error { - // go build -o bin/ -v . - cmdline := []string{ - "go", - "build", - "-o", - fmt.Sprintf("bin/%s", ab.pkgName), - } - - if ab.options.EnableAsan { - cmdline = append(cmdline, "-asan") - } - - if ab.options.Verbose { - cmdline = append(cmdline, "-v") - } - - // There are more than one source file in the app, as the auto-import file - // has been generated. - cmdline = append(cmdline, ".") - - log.Printf("Build GO app with command: %s\n", strings.Join(cmdline, " ")) - - return ExecCmd(cmdline, ab.options.AppDir, envs, ab.options.Verbose) -} - -func (ab *AppBuilder) Build() error { - if err := ab.precheck(); err != nil { - return fmt.Errorf("precheck failed. Root cause: \n\t%w", err) - } - - if err := ab.autoDetectExtensions(); err != nil { - return fmt.Errorf( - "auto detect extensions failed. Root cause: \n\t%w", - err, - ) - } - - // Prepare the execution environments. - ab.addPrivateRepo() - ab.addRuntimeLdflags() - // ab.autoDetectCompiler() - - // All commands will be executed with the environments. - envs := ab.buildExecEnvs() - - if err := ab.runTidyAndGenerate(envs); err != nil { - return err - } - - if err := ab.generateAutoImportFile(); err != nil { - return err - } - - if err := ab.requireExtensionModules(); err != nil { - return err - } - - // Run 'go mod tidy' to sync the dependencies of the extensions. - if err := ModTidy(ab.options.AppDir, envs, ab.options.Verbose); err != nil { - return err - } - - // Everything is ready, we can build the app. - return ab.buildGoApp(envs) -} - -func (ab *AppBuilder) Cleanup() { - if err := ab.restoreGoModAndGoSum(); err != nil { - log.Fatalf("%v\n", err) - } - - autoGenImport := path.Join(ab.options.AppDir, ab.options.AutoGenImportFile) - if IsFilePresent(autoGenImport) { - err := os.Remove(autoGenImport) - if err != nil { - log.Fatalf("Failed to remove auto-gen file, %v\n", err) - } - } -} - -// -------------- builder ---------------- - -// -------------- check ------------------ - -const ( - KeyCGOEnabled string = "CGO_ENABLED" -) - -func (ab *AppBuilder) checkGoVersion() error { - go_version := runtime.Version() - if strings.HasPrefix(go_version, "go") { - go_version = go_version[2:] - v, _ := NewVersion(go_version) - acquired, _ := NewVersion(ab.acquiredGoVersion) - if acquired.GreaterThan(v) { - return fmt.Errorf( - "go version higher than %s is acquired, current is %s", - ab.acquiredGoVersion, - go_version, - ) - } - } else { - return fmt.Errorf("not recognizable go version, %s", go_version) - } - - if ab.options.Verbose { - log.Printf("Go version [%s] is found.\n", go_version) - } - - return nil -} - -func (ab *AppBuilder) checkAppIntegrity() error { - if len(ab.options.AppDir) == 0 { - return errors.New("failed to detect GO app directory") - } - - manifest, err := LoadManifest(ab.options.AppDir) - if err != nil { - return fmt.Errorf("%s is not a GO app, %w", ab.options.AppDir, err) - } - - if err := manifest.IsGoApp(); err != nil { - return fmt.Errorf("%s is not a GO app, %w", ab.options.AppDir, err) - } - - if !IsDirPresent(path.Join(ab.options.AppDir, "scripts/build")) { - return errors.New("invalid GO app, scripts/build is absent") - } - - if ab.options.Verbose { - log.Printf("Go app [%s] is found.\n", ab.options.AppDir) - } - - return nil -} - -func (ab *AppBuilder) checkCGOEnabled() error { - if err := ab.getGoEnv(); err != nil { - return fmt.Errorf("failed to execute 'go env' command. \n\t%w", err) - } - - if enabled, ok := ab.cachedEnv[KeyCGOEnabled]; ok { - if enabled != "1" { - return errors.New("CGO is not enabled") - } - } else { - // CGO is enabled by default at most platform. Refer to `cgoEnabled` map - // in `cmd/dist/build.go`. - if ab.options.Verbose { - log.Printf("%s is not found, which is treated as enabled.\n", KeyCGOEnabled) - } - } - - return nil -} - -func (ab *AppBuilder) precheck() error { - if err := ab.checkGoVersion(); err != nil { - return err - } - - if err := ab.checkAppIntegrity(); err != nil { - return err - } - - if err := ab.checkCGOEnabled(); err != nil { - return err - } - - return nil -} - -// -------------- check ------------------ - -// -------------- env -------------------- - -const ( - KeyGoPrivate string = "GOPRIVATE" - KeyGoNoProxy string = "GONOPROXY" - KeyGoNoSumdb string = "GONOSUMDB" - KeyCGOLdflags string = "CGO_LDFLAGS" - KeyCGOCflags string = "CGO_CFLAGS" - AgoraPrivateRepo string = "*.agoralab.co" -) - -func (ab *AppBuilder) getGoEnv() error { - if len(ab.cachedEnv) > 0 { - return nil - } - - cmd := exec.Command("go", "env", "-json") - - var stdout bytes.Buffer - cmd.Stdout = &stdout - - if err := cmd.Run(); err != nil { - return err - } - - if err := json.Unmarshal(stdout.Bytes(), &ab.cachedEnv); err != nil { - return err - } - - return nil -} - -// addPrivateRepo adds repositories owned in agoralab.co to private go modules. -// -// Note that when you execute command 'go env -w GOPRIVATE="*.agoralab.co"', the -// GONOPROXY and GONOSUMDB will be set to "*.agoralab.co" automatically. And you -// can not change GONOPROXY or GONOSUMDB without changing GOPRIVATE. -func (ab *AppBuilder) addPrivateRepo() { - privates := ab.cachedEnv[KeyGoPrivate] - if len(privates) == 0 { - privates = AgoraPrivateRepo - } else { - if !strings.Contains(privates, AgoraPrivateRepo) { - privates = privates + "," + AgoraPrivateRepo - } - } - - ab.cachedEnv[KeyGoPrivate] = privates - - // GONOPROXY and GONOSUMDB must be same as GOPRIVATE. - ab.cachedEnv[KeyGoNoProxy] = privates - ab.cachedEnv[KeyGoNoSumdb] = privates -} - -// autoDetectCompiler chooses the C compiler (gcc or clang) to compile the cgo -// codes (auto generated by the cgo compiler, not the C codes in go binding). -// -// The final application executable will link rte_runtime_go.so, if asan is -// enabled in compiling rte_runtime_go.so, the C compiler must be same as the -// compiler used to compile rte_runtime_go.so. -// -// If there is any C/C++ extension in this GO app, and the compiler and flags -// (whether enables asan) must be same as the extension if the extension is -// compiled with asan. However, this is the job of the arpm when installing -// extensions, not this app builder. -func (ab *AppBuilder) autoDetectCompiler() { - // TODO(Liu): auto detect the C compiler. - ab.cachedEnv["CC"] = "clang" - - var cflags, ldflags string - switch runtime.GOOS { - case "linux": - cflags = "-fsanitize=address -fsanitize=leak" - ldflags = "-fsanitize=address -fsanitize=leak" - case "darwin": - cflags = "-fsanitize=address" - ldflags = "-fsanitize=address" - default: - log.Fatalf("Unsupported platform %s.\n", runtime.GOOS) - } - - cflags += " " + ab.cachedEnv[KeyCGOCflags] - ab.cachedEnv[KeyCGOCflags] = cflags - - ldflags += " " + ab.cachedEnv[KeyCGOLdflags] - ab.cachedEnv[KeyCGOLdflags] = ldflags -} - -func (ab *AppBuilder) addRuntimeLdflags() { - var flags string - - switch runtime.GOOS { - case "linux": - flags = "-Llib -lrte_runtime_go -Wl,-rpath=$ORIGIN/../lib" - case "darwin": - flags = "-Llib -lrte_runtime_go -Wl,-rpath,@loader_path/../lib" - default: - log.Fatalf("Unsupported platform %s.\n", runtime.GOOS) - } - - _flags := ab.cachedEnv[KeyCGOLdflags] - if len(_flags) > 0 { - flags += " " + _flags - } - - ab.cachedEnv[KeyCGOLdflags] = flags -} - -// buildExecEnvs combines the OS environments and GO environments (i.e., go -// env) as the final execution environments. -func (ab *AppBuilder) buildExecEnvs() []string { - envs := os.Environ() - - if ab.options.Verbose { - log.Println("Go env:") - } - - for k, v := range ab.cachedEnv { - if ab.options.Verbose { - log.Printf("\t%s='%s'\n", k, v) - } - - envs = append(envs, k+"="+v) - } - - return envs -} - -// -------------- env -------------------- - -// -------------- extension -------------- - -type ExtensionModule struct { - // The module name in go.mod - module string - - location string -} - -func (em *ExtensionModule) String() string { - return fmt.Sprintf("%s @ %s", em.module, em.location) -} - -func LoadExtensionModule( - location string, - verbose bool, -) (*ExtensionModule, error) { - if !IsFilePresent(path.Join(location, "manifest.json")) { - if verbose { - log.Printf("%s is not an extension, no manifest.json.\n", location) - } - - return nil, nil - } - - if mf, err := LoadManifest(location); err != nil { - return nil, err - } else { - if err := mf.IsGoExtension(); err != nil { - if verbose { - log.Printf("%s is not an extension, %v.\n", location, err) - } - - return nil, nil - } - } - - modFile := path.Join(location, "go.mod") - if !IsFilePresent(modFile) { - return nil, fmt.Errorf("%s extension is invalid, no go.mod", location) - } - - bytes, err := os.ReadFile(modFile) - if err != nil { - return nil, fmt.Errorf("%s extension is invalid. \n\t%w", location, err) - } - - module := ModulePath(bytes) - if len(module) == 0 { - return nil, fmt.Errorf("no mod is detected in %s/go.mod", location) - } - - return &ExtensionModule{ - module: module, - location: location, - }, nil -} - -func (ab *AppBuilder) autoDetectExtensions() error { - extBaseDir := path.Join(ab.options.AppDir, "addon/extension") - if !IsDirPresent(extBaseDir) { - if ab.options.Verbose { - log.Println( - "The base directory [addon/extension] is absent, no extensions.", - ) - } - - return nil - } - - entries, err := os.ReadDir(extBaseDir) - if err != nil { - return err - } - - // Ensure that all extension modules are unique, otherwise the modules with - // same name will be overwritten. - uniqueModules := make(map[string]string) - - for _, entry := range entries { - if !entry.IsDir() { - continue - } - - extDir := path.Join(extBaseDir, entry.Name()) - ext, err := LoadExtensionModule(extDir, ab.options.Verbose) - if err != nil { - return err - } - - if ext == nil { - // Not an GO extension. - continue - } - - if location, ok := uniqueModules[ext.module]; ok { - return fmt.Errorf( - "the extensions [%s] and [%s] have duplicated module name [%s]", - path.Base(location), - path.Base(ext.location), - ext.module, - ) - } - - uniqueModules[ext.module] = ext.location - ab.extensions = append(ab.extensions, ext) - } - - if ab.options.Verbose && len(ab.extensions) > 0 { - log.Println("Go Extensions are detected:") - for _, ext := range ab.extensions { - log.Printf("\t%s\n", ext) - } - } - - return nil -} - -// -------------- extension -------------- - -// -------------- manifest --------------- - -type RtePackageManifest struct { - Type string `json:"type"` - Language string `json:"language"` -} - -func LoadManifest(pkgDir string) (*RtePackageManifest, error) { - manifest := path.Join(pkgDir, "manifest.json") - if !IsFilePresent(manifest) { - return nil, fmt.Errorf("%s/manifest.json is absent", pkgDir) - } - - if mf, err := os.ReadFile(manifest); err != nil { - return nil, err - } else { - var manifest *RtePackageManifest - if err := json.Unmarshal(mf, &manifest); err != nil { - return nil, fmt.Errorf("%s/manifest.json is invalid. \n\t%w", pkgDir, err) - } else { - return manifest, nil - } - } -} - -func (pm *RtePackageManifest) IsGoApp() error { - if pm.Language != "go" { - return fmt.Errorf( - "the language in manifest.json is [%s]", pm.Language, - ) - } - - if pm.Type != "app" { - return fmt.Errorf( - "the type in manifest.json is [%s]", pm.Type, - ) - } - - return nil -} - -func (pm *RtePackageManifest) IsGoExtension() error { - if pm.Language != "go" { - return fmt.Errorf( - "the language in manifest.json is [%s]", pm.Language, - ) - } - - if pm.Type != "extension" { - return fmt.Errorf( - "the type in manifest.json is [%s]", pm.Type, - ) - } - - return nil -} - -// -------------- manifest --------------- - -// -------------- import ----------------- - -func (ab *AppBuilder) generateAutoImportFile() error { - // The auto generated import file must be located in the app directory. - importFile := path.Join(ab.options.AppDir, ab.options.AutoGenImportFile) - if IsFilePresent(importFile) { - if err := os.Remove(importFile); err != nil { - return fmt.Errorf( - "failed to remove auto-gen import file. \n\t%w", - err, - ) - } - } - - if len(ab.extensions) == 0 { - log.Println( - "No extension is detected, no need to generate import file.", - ) - - return nil - } - - f, err := os.Create(importFile) - if err != nil { - return fmt.Errorf("failed to create auto-gen import file. \n\t%w", err) - } - - defer f.Close() - - _, _ = f.WriteString("// Code generated by app builder. DO NOT EDIT.\n\n") - _, _ = f.WriteString(fmt.Sprintf("package %s\n\n", ab.pkgName)) - - for _, ext := range ab.extensions { - _, _ = f.WriteString(fmt.Sprintf("import _ \"%s\"\n", ext.module)) - } - - if ab.options.Verbose { - log.Printf("Auto-import file is generated at [%s].", importFile) - } - - return nil -} - -func (ab *AppBuilder) requireExtensionModules() error { - if len(ab.extensions) == 0 { - log.Println( - "No extension is detected, no need to require extension modules.", - ) - - return nil - } - - // The go.mod will be modified to add the extension as go modules. - // Therefore, we need to copy the original go.mod and go.sum as the backup, - // and restore them after the build. - - err := CopyFile( - path.Join(ab.options.AppDir, "go.mod"), - path.Join(ab.options.AppDir, BackupGoMod), - ) - if err != nil { - return fmt.Errorf("failed to backup go.mod. \n\t%w", err) - } - - originSum := path.Join(ab.options.AppDir, "go.sum") - if IsFilePresent(originSum) { - err = CopyFile(originSum, path.Join(ab.options.AppDir, BackupGoSum)) - if err != nil { - return fmt.Errorf("failed to backup go.sum. \n\t%w", err) - } - } - - // Add GO extensions as the module of the app. - for _, ext := range ab.extensions { - if err := ModAddLocalModule(ext, ab.options.AppDir); err != nil { - return fmt.Errorf( - "failed to add %s as go module of the app. \n\t%w", - ext.location, - err, - ) - } - } - - if ab.options.Verbose { - log.Println("Add extension modules to app successfully.") - } - - return nil -} - -func (ab *AppBuilder) restoreGoModAndGoSum() error { - backupMod := path.Join(ab.options.AppDir, BackupGoMod) - originMod := path.Join(ab.options.AppDir, "go.mod") - if IsFilePresent(backupMod) { - if err := os.Remove(originMod); err != nil { - return fmt.Errorf("failed to restore go.mod. \n\t%w", err) - } - - if err := MoveFile(backupMod, originMod); err != nil { - return fmt.Errorf("failed to restore go.mod. \n\t%w", err) - } - } - - backupSum := path.Join(ab.options.AppDir, BackupGoSum) - originSum := path.Join(ab.options.AppDir, "go.sum") - if IsFilePresent(backupSum) { - if err := os.Remove(originSum); err != nil { - return fmt.Errorf("failed to restore go.sum. \n\t%w", err) - } - - if err := MoveFile(backupSum, originSum); err != nil { - return fmt.Errorf("failed to restore go.sum. \n\t%w", err) - } - - } - - return nil -} - -// -------------- import ----------------- - -// -------------- io --------------------- - -func MkdirIfAbsent(path string) error { - if stat, err := os.Stat(path); err == nil { - // Present. - if stat.IsDir() { - return nil - } else { - return fmt.Errorf("%s is present, but not a directory", path) - } - } - - return os.MkdirAll(path, os.FileMode(0775).Perm()) -} - -func CopyFile(src string, dest string) error { - in, err := os.Open(src) - if err != nil { - return err - } - - defer in.Close() - - if _, err := os.Stat(dest); err == nil { - return fmt.Errorf("%s is already present", dest) - } - - out, err := os.Create(dest) - if err != nil { - return err - } - - defer out.Close() - - _, err = io.Copy(out, in) - return err -} - -func MoveFile(src string, dest string) error { - if err := CopyFile(src, dest); err != nil { - return err - } - - return os.Remove(src) -} - -func IsFilePresent(path string) bool { - if stat, err := os.Stat(path); err == nil { - return !stat.IsDir() - } - - return false -} - -func IsDirPresent(path string) bool { - if stat, err := os.Stat(path); err == nil { - return stat.IsDir() - } - - return false -} - -// -------------- io --------------------- - -// -------------- cmdline ---------------- - -func ExecCmd(cmdline []string, cwd string, envs []string, verbose bool) error { - name := cmdline[0] - var args []string - if len(cmdline) > 1 { - args = cmdline[1:] - } - - cmd := exec.Command(name, args...) - - if len(cwd) > 0 { - cmd.Dir = cwd - } - - if len(envs) > 0 { - cmd.Env = envs - } - - var stdoutScanner, stderrScanner *bufio.Scanner - - if stdout, err := cmd.StdoutPipe(); err != nil { - return err - } else { - stdoutScanner = bufio.NewScanner(stdout) - } - - if stderr, err := cmd.StderrPipe(); err != nil { - return err - } else { - stderrScanner = bufio.NewScanner(stderr) - } - - if err := cmd.Start(); err != nil { - return err - } - - for stderrScanner.Scan() { - log.Printf("\t%s\n", stderrScanner.Text()) - } - - if verbose { - done := make(chan struct{}, 1) - go func() { - for stdoutScanner.Scan() { - log.Printf("\t%s\n", stdoutScanner.Text()) - } - done <- struct{}{} - }() - <-done - } - - err := stdoutScanner.Err() - if err == nil { - err = stderrScanner.Err() - } - - if err != nil { - _ = cmd.Process.Kill() - _ = cmd.Wait() - return err - } - - return cmd.Wait() -} - -// -------------- cmdline ---------------- diff --git a/agents/addon/bak/litellm_python/__init__.py b/agents/ten_packages/bak/litellm_python/__init__.py similarity index 100% rename from agents/addon/bak/litellm_python/__init__.py rename to agents/ten_packages/bak/litellm_python/__init__.py diff --git a/agents/addon/bak/litellm_python/extension.py b/agents/ten_packages/bak/litellm_python/extension.py similarity index 100% rename from agents/addon/bak/litellm_python/extension.py rename to agents/ten_packages/bak/litellm_python/extension.py diff --git a/agents/addon/bak/litellm_python/litellm.py b/agents/ten_packages/bak/litellm_python/litellm.py similarity index 100% rename from agents/addon/bak/litellm_python/litellm.py rename to agents/ten_packages/bak/litellm_python/litellm.py diff --git a/agents/addon/bak/litellm_python/litellm_addon.py b/agents/ten_packages/bak/litellm_python/litellm_addon.py similarity index 100% rename from agents/addon/bak/litellm_python/litellm_addon.py rename to agents/ten_packages/bak/litellm_python/litellm_addon.py diff --git a/agents/addon/bak/litellm_python/litellm_extension.py b/agents/ten_packages/bak/litellm_python/litellm_extension.py similarity index 100% rename from agents/addon/bak/litellm_python/litellm_extension.py rename to agents/ten_packages/bak/litellm_python/litellm_extension.py diff --git a/agents/addon/bak/litellm_python/log.py b/agents/ten_packages/bak/litellm_python/log.py similarity index 100% rename from agents/addon/bak/litellm_python/log.py rename to agents/ten_packages/bak/litellm_python/log.py diff --git a/agents/addon/bak/litellm_python/manifest.json b/agents/ten_packages/bak/litellm_python/manifest.json similarity index 100% rename from agents/addon/bak/litellm_python/manifest.json rename to agents/ten_packages/bak/litellm_python/manifest.json diff --git a/agents/addon/bak/litellm_python/requirements.txt b/agents/ten_packages/bak/litellm_python/requirements.txt similarity index 100% rename from agents/addon/bak/litellm_python/requirements.txt rename to agents/ten_packages/bak/litellm_python/requirements.txt diff --git a/agents/addon/bak/litellm_python/utils.py b/agents/ten_packages/bak/litellm_python/utils.py similarity index 100% rename from agents/addon/bak/litellm_python/utils.py rename to agents/ten_packages/bak/litellm_python/utils.py diff --git a/agents/addon/extension/aliyun_analyticdb_vector_storage/__init__.py b/agents/ten_packages/extension/aliyun_analyticdb_vector_storage/__init__.py similarity index 100% rename from agents/addon/extension/aliyun_analyticdb_vector_storage/__init__.py rename to agents/ten_packages/extension/aliyun_analyticdb_vector_storage/__init__.py diff --git a/agents/addon/extension/aliyun_analyticdb_vector_storage/client.py b/agents/ten_packages/extension/aliyun_analyticdb_vector_storage/client.py similarity index 100% rename from agents/addon/extension/aliyun_analyticdb_vector_storage/client.py rename to agents/ten_packages/extension/aliyun_analyticdb_vector_storage/client.py diff --git a/agents/addon/extension/aliyun_analyticdb_vector_storage/log.py b/agents/ten_packages/extension/aliyun_analyticdb_vector_storage/log.py similarity index 100% rename from agents/addon/extension/aliyun_analyticdb_vector_storage/log.py rename to agents/ten_packages/extension/aliyun_analyticdb_vector_storage/log.py diff --git a/agents/addon/extension/aliyun_analyticdb_vector_storage/manifest.json b/agents/ten_packages/extension/aliyun_analyticdb_vector_storage/manifest.json similarity index 96% rename from agents/addon/extension/aliyun_analyticdb_vector_storage/manifest.json rename to agents/ten_packages/extension/aliyun_analyticdb_vector_storage/manifest.json index 028a2154..4137a8f2 100644 --- a/agents/addon/extension/aliyun_analyticdb_vector_storage/manifest.json +++ b/agents/ten_packages/extension/aliyun_analyticdb_vector_storage/manifest.json @@ -2,12 +2,11 @@ "type": "extension", "name": "aliyun_analyticdb_vector_storage", "version": "0.4.0", - "language": "python", "dependencies": [ { "type": "system", - "name": "rte_runtime_python", - "version": "0.4" + "name": "ten_runtime_python", + "version": "0.1" } ], "api": { diff --git a/agents/addon/extension/aliyun_analyticdb_vector_storage/model.py b/agents/ten_packages/extension/aliyun_analyticdb_vector_storage/model.py similarity index 100% rename from agents/addon/extension/aliyun_analyticdb_vector_storage/model.py rename to agents/ten_packages/extension/aliyun_analyticdb_vector_storage/model.py diff --git a/agents/addon/extension/aliyun_analyticdb_vector_storage/property.json b/agents/ten_packages/extension/aliyun_analyticdb_vector_storage/property.json similarity index 100% rename from agents/addon/extension/aliyun_analyticdb_vector_storage/property.json rename to agents/ten_packages/extension/aliyun_analyticdb_vector_storage/property.json diff --git a/agents/addon/extension/aliyun_analyticdb_vector_storage/requirements.txt b/agents/ten_packages/extension/aliyun_analyticdb_vector_storage/requirements.txt similarity index 100% rename from agents/addon/extension/aliyun_analyticdb_vector_storage/requirements.txt rename to agents/ten_packages/extension/aliyun_analyticdb_vector_storage/requirements.txt diff --git a/agents/addon/extension/aliyun_analyticdb_vector_storage/vector_storage_addon.py b/agents/ten_packages/extension/aliyun_analyticdb_vector_storage/vector_storage_addon.py similarity index 100% rename from agents/addon/extension/aliyun_analyticdb_vector_storage/vector_storage_addon.py rename to agents/ten_packages/extension/aliyun_analyticdb_vector_storage/vector_storage_addon.py diff --git a/agents/addon/extension/aliyun_analyticdb_vector_storage/vector_storage_extension.py b/agents/ten_packages/extension/aliyun_analyticdb_vector_storage/vector_storage_extension.py similarity index 100% rename from agents/addon/extension/aliyun_analyticdb_vector_storage/vector_storage_extension.py rename to agents/ten_packages/extension/aliyun_analyticdb_vector_storage/vector_storage_extension.py diff --git a/agents/addon/extension/aliyun_text_embedding/__init__.py b/agents/ten_packages/extension/aliyun_text_embedding/__init__.py similarity index 100% rename from agents/addon/extension/aliyun_text_embedding/__init__.py rename to agents/ten_packages/extension/aliyun_text_embedding/__init__.py diff --git a/agents/addon/extension/aliyun_text_embedding/embedding_addon.py b/agents/ten_packages/extension/aliyun_text_embedding/embedding_addon.py similarity index 100% rename from agents/addon/extension/aliyun_text_embedding/embedding_addon.py rename to agents/ten_packages/extension/aliyun_text_embedding/embedding_addon.py diff --git a/agents/addon/extension/aliyun_text_embedding/embedding_extension.py b/agents/ten_packages/extension/aliyun_text_embedding/embedding_extension.py similarity index 100% rename from agents/addon/extension/aliyun_text_embedding/embedding_extension.py rename to agents/ten_packages/extension/aliyun_text_embedding/embedding_extension.py diff --git a/agents/addon/extension/aliyun_text_embedding/log.py b/agents/ten_packages/extension/aliyun_text_embedding/log.py similarity index 100% rename from agents/addon/extension/aliyun_text_embedding/log.py rename to agents/ten_packages/extension/aliyun_text_embedding/log.py diff --git a/agents/addon/extension/aliyun_text_embedding/manifest.json b/agents/ten_packages/extension/aliyun_text_embedding/manifest.json similarity index 95% rename from agents/addon/extension/aliyun_text_embedding/manifest.json rename to agents/ten_packages/extension/aliyun_text_embedding/manifest.json index 2fd19099..627c044f 100644 --- a/agents/addon/extension/aliyun_text_embedding/manifest.json +++ b/agents/ten_packages/extension/aliyun_text_embedding/manifest.json @@ -2,12 +2,11 @@ "type": "extension", "name": "aliyun_text_embedding", "version": "0.4.0", - "language": "python", "dependencies": [ { "type": "system", - "name": "rte_runtime_python", - "version": "0.4" + "name": "ten_runtime_python", + "version": "0.1" } ], "api": { diff --git a/agents/addon/extension/aliyun_text_embedding/property.json b/agents/ten_packages/extension/aliyun_text_embedding/property.json similarity index 100% rename from agents/addon/extension/aliyun_text_embedding/property.json rename to agents/ten_packages/extension/aliyun_text_embedding/property.json diff --git a/agents/addon/extension/aliyun_text_embedding/requirements.txt b/agents/ten_packages/extension/aliyun_text_embedding/requirements.txt similarity index 100% rename from agents/addon/extension/aliyun_text_embedding/requirements.txt rename to agents/ten_packages/extension/aliyun_text_embedding/requirements.txt diff --git a/agents/addon/extension/azure_tts/BUILD.gn b/agents/ten_packages/extension/azure_tts/BUILD.gn similarity index 100% rename from agents/addon/extension/azure_tts/BUILD.gn rename to agents/ten_packages/extension/azure_tts/BUILD.gn diff --git a/agents/addon/extension/azure_tts/README.md b/agents/ten_packages/extension/azure_tts/README.md similarity index 100% rename from agents/addon/extension/azure_tts/README.md rename to agents/ten_packages/extension/azure_tts/README.md diff --git a/agents/addon/extension/azure_tts/manifest.json b/agents/ten_packages/extension/azure_tts/manifest.json similarity index 90% rename from agents/addon/extension/azure_tts/manifest.json rename to agents/ten_packages/extension/azure_tts/manifest.json index 979a8743..4f9fdfe1 100644 --- a/agents/addon/extension/azure_tts/manifest.json +++ b/agents/ten_packages/extension/azure_tts/manifest.json @@ -2,12 +2,11 @@ "type": "extension", "name": "azure_tts", "version": "0.4.0", - "language": "cpp", "dependencies": [ { "type": "system", - "name": "rte_runtime", - "version": "0.4.0" + "name": "ten_runtime", + "version": "0.1" }, { "type": "system", @@ -47,7 +46,7 @@ "name": "flush" } ], - "pcm_frame_out": [ + "audio_frame_out": [ { "name": "pcm_frame" } diff --git a/agents/addon/extension/azure_tts/property.json b/agents/ten_packages/extension/azure_tts/property.json similarity index 100% rename from agents/addon/extension/azure_tts/property.json rename to agents/ten_packages/extension/azure_tts/property.json diff --git a/agents/addon/extension/azure_tts/src/log.h b/agents/ten_packages/extension/azure_tts/src/log.h similarity index 100% rename from agents/addon/extension/azure_tts/src/log.h rename to agents/ten_packages/extension/azure_tts/src/log.h diff --git a/agents/addon/extension/azure_tts/src/main.cc b/agents/ten_packages/extension/azure_tts/src/main.cc similarity index 100% rename from agents/addon/extension/azure_tts/src/main.cc rename to agents/ten_packages/extension/azure_tts/src/main.cc diff --git a/agents/addon/extension/azure_tts/src/tts.cc b/agents/ten_packages/extension/azure_tts/src/tts.cc similarity index 100% rename from agents/addon/extension/azure_tts/src/tts.cc rename to agents/ten_packages/extension/azure_tts/src/tts.cc diff --git a/agents/addon/extension/azure_tts/src/tts.h b/agents/ten_packages/extension/azure_tts/src/tts.h similarity index 100% rename from agents/addon/extension/azure_tts/src/tts.h rename to agents/ten_packages/extension/azure_tts/src/tts.h diff --git a/agents/addon/extension/bedrock_llm_python/README.md b/agents/ten_packages/extension/bedrock_llm_python/README.md similarity index 100% rename from agents/addon/extension/bedrock_llm_python/README.md rename to agents/ten_packages/extension/bedrock_llm_python/README.md diff --git a/agents/addon/extension/bedrock_llm_python/__init__.py b/agents/ten_packages/extension/bedrock_llm_python/__init__.py similarity index 100% rename from agents/addon/extension/bedrock_llm_python/__init__.py rename to agents/ten_packages/extension/bedrock_llm_python/__init__.py diff --git a/agents/addon/extension/bedrock_llm_python/bedrock_llm.py b/agents/ten_packages/extension/bedrock_llm_python/bedrock_llm.py similarity index 100% rename from agents/addon/extension/bedrock_llm_python/bedrock_llm.py rename to agents/ten_packages/extension/bedrock_llm_python/bedrock_llm.py diff --git a/agents/addon/extension/bedrock_llm_python/bedrock_llm_extension.py b/agents/ten_packages/extension/bedrock_llm_python/bedrock_llm_extension.py similarity index 100% rename from agents/addon/extension/bedrock_llm_python/bedrock_llm_extension.py rename to agents/ten_packages/extension/bedrock_llm_python/bedrock_llm_extension.py diff --git a/agents/addon/extension/bedrock_llm_python/log.py b/agents/ten_packages/extension/bedrock_llm_python/log.py similarity index 100% rename from agents/addon/extension/bedrock_llm_python/log.py rename to agents/ten_packages/extension/bedrock_llm_python/log.py diff --git a/agents/addon/extension/bedrock_llm_python/manifest.json b/agents/ten_packages/extension/bedrock_llm_python/manifest.json similarity index 90% rename from agents/addon/extension/bedrock_llm_python/manifest.json rename to agents/ten_packages/extension/bedrock_llm_python/manifest.json index 3613083f..602e5a84 100644 --- a/agents/addon/extension/bedrock_llm_python/manifest.json +++ b/agents/ten_packages/extension/bedrock_llm_python/manifest.json @@ -1,13 +1,12 @@ { "type": "extension", "name": "bedrock_llm_python", - "version": "0.1.0", - "language": "python", + "version": "0.4.0", "dependencies": [ { "type": "system", - "name": "rte_runtime_python", - "version": "0.4.0" + "name": "ten_runtime_python", + "version": "0.1" } ], "api": { diff --git a/agents/addon/extension/bedrock_llm_python/property.json b/agents/ten_packages/extension/bedrock_llm_python/property.json similarity index 100% rename from agents/addon/extension/bedrock_llm_python/property.json rename to agents/ten_packages/extension/bedrock_llm_python/property.json diff --git a/agents/addon/extension/bedrock_llm_python/requirements.txt b/agents/ten_packages/extension/bedrock_llm_python/requirements.txt similarity index 100% rename from agents/addon/extension/bedrock_llm_python/requirements.txt rename to agents/ten_packages/extension/bedrock_llm_python/requirements.txt diff --git a/agents/addon/extension/chat_transcriber/extension.go b/agents/ten_packages/extension/chat_transcriber/extension.go similarity index 100% rename from agents/addon/extension/chat_transcriber/extension.go rename to agents/ten_packages/extension/chat_transcriber/extension.go diff --git a/agents/addon/extension/chat_transcriber/go.mod b/agents/ten_packages/extension/chat_transcriber/go.mod similarity index 100% rename from agents/addon/extension/chat_transcriber/go.mod rename to agents/ten_packages/extension/chat_transcriber/go.mod diff --git a/agents/addon/extension/chat_transcriber/go.sum b/agents/ten_packages/extension/chat_transcriber/go.sum similarity index 100% rename from agents/addon/extension/chat_transcriber/go.sum rename to agents/ten_packages/extension/chat_transcriber/go.sum diff --git a/agents/addon/extension/chat_transcriber/manifest.json b/agents/ten_packages/extension/chat_transcriber/manifest.json similarity index 85% rename from agents/addon/extension/chat_transcriber/manifest.json rename to agents/ten_packages/extension/chat_transcriber/manifest.json index aaf7ad82..0d03a858 100644 --- a/agents/addon/extension/chat_transcriber/manifest.json +++ b/agents/ten_packages/extension/chat_transcriber/manifest.json @@ -1,13 +1,12 @@ { "type": "extension", "name": "chat_transcriber", - "version": "0.1.0", - "language": "go", + "version": "0.4.0", "dependencies": [ { "type": "system", - "name": "rte_runtime_go", - "version": "0.4.0" + "name": "ten_runtime_go", + "version": "0.1" } ], "api": { diff --git a/agents/addon/extension/chat_transcriber/pb/chat_text.pb.go b/agents/ten_packages/extension/chat_transcriber/pb/chat_text.pb.go similarity index 100% rename from agents/addon/extension/chat_transcriber/pb/chat_text.pb.go rename to agents/ten_packages/extension/chat_transcriber/pb/chat_text.pb.go diff --git a/agents/addon/extension/chat_transcriber/pb/chat_text.proto b/agents/ten_packages/extension/chat_transcriber/pb/chat_text.proto similarity index 100% rename from agents/addon/extension/chat_transcriber/pb/chat_text.proto rename to agents/ten_packages/extension/chat_transcriber/pb/chat_text.proto diff --git a/agents/addon/extension/chat_transcriber/property.json b/agents/ten_packages/extension/chat_transcriber/property.json similarity index 100% rename from agents/addon/extension/chat_transcriber/property.json rename to agents/ten_packages/extension/chat_transcriber/property.json diff --git a/agents/addon/extension/chat_transcriber_python/__init__.py b/agents/ten_packages/extension/chat_transcriber_python/__init__.py similarity index 100% rename from agents/addon/extension/chat_transcriber_python/__init__.py rename to agents/ten_packages/extension/chat_transcriber_python/__init__.py diff --git a/agents/addon/extension/chat_transcriber_python/chat_transcriber_addon.py b/agents/ten_packages/extension/chat_transcriber_python/chat_transcriber_addon.py similarity index 100% rename from agents/addon/extension/chat_transcriber_python/chat_transcriber_addon.py rename to agents/ten_packages/extension/chat_transcriber_python/chat_transcriber_addon.py diff --git a/agents/addon/extension/chat_transcriber_python/chat_transcriber_extension.py b/agents/ten_packages/extension/chat_transcriber_python/chat_transcriber_extension.py similarity index 100% rename from agents/addon/extension/chat_transcriber_python/chat_transcriber_extension.py rename to agents/ten_packages/extension/chat_transcriber_python/chat_transcriber_extension.py diff --git a/agents/addon/extension/chat_transcriber_python/log.py b/agents/ten_packages/extension/chat_transcriber_python/log.py similarity index 100% rename from agents/addon/extension/chat_transcriber_python/log.py rename to agents/ten_packages/extension/chat_transcriber_python/log.py diff --git a/agents/addon/extension/chat_transcriber_python/manifest.json b/agents/ten_packages/extension/chat_transcriber_python/manifest.json similarity index 84% rename from agents/addon/extension/chat_transcriber_python/manifest.json rename to agents/ten_packages/extension/chat_transcriber_python/manifest.json index d380f117..ad8c8bde 100644 --- a/agents/addon/extension/chat_transcriber_python/manifest.json +++ b/agents/ten_packages/extension/chat_transcriber_python/manifest.json @@ -1,13 +1,12 @@ { "type": "extension", "name": "chat_transcriber_python", - "version": "0.1.0", - "language": "python", + "version": "0.4.0", "dependencies": [ { "type": "system", - "name": "rte_runtime_python", - "version": "0.4.0" + "name": "ten_runtime_python", + "version": "0.1" } ], "api": { diff --git a/agents/addon/extension/chat_transcriber_python/pb/chat_text.proto b/agents/ten_packages/extension/chat_transcriber_python/pb/chat_text.proto similarity index 100% rename from agents/addon/extension/chat_transcriber_python/pb/chat_text.proto rename to agents/ten_packages/extension/chat_transcriber_python/pb/chat_text.proto diff --git a/agents/addon/extension/chat_transcriber_python/pb/chat_text_pb2.py b/agents/ten_packages/extension/chat_transcriber_python/pb/chat_text_pb2.py similarity index 100% rename from agents/addon/extension/chat_transcriber_python/pb/chat_text_pb2.py rename to agents/ten_packages/extension/chat_transcriber_python/pb/chat_text_pb2.py diff --git a/agents/addon/extension/chat_transcriber_python/property.json b/agents/ten_packages/extension/chat_transcriber_python/property.json similarity index 100% rename from agents/addon/extension/chat_transcriber_python/property.json rename to agents/ten_packages/extension/chat_transcriber_python/property.json diff --git a/agents/addon/extension/chat_transcriber_python/requirements.txt b/agents/ten_packages/extension/chat_transcriber_python/requirements.txt similarity index 100% rename from agents/addon/extension/chat_transcriber_python/requirements.txt rename to agents/ten_packages/extension/chat_transcriber_python/requirements.txt diff --git a/agents/addon/extension/cosy_tts/__init__.py b/agents/ten_packages/extension/cosy_tts/__init__.py similarity index 100% rename from agents/addon/extension/cosy_tts/__init__.py rename to agents/ten_packages/extension/cosy_tts/__init__.py diff --git a/agents/addon/extension/cosy_tts/cosy_tts_addon.py b/agents/ten_packages/extension/cosy_tts/cosy_tts_addon.py similarity index 100% rename from agents/addon/extension/cosy_tts/cosy_tts_addon.py rename to agents/ten_packages/extension/cosy_tts/cosy_tts_addon.py diff --git a/agents/addon/extension/cosy_tts/cosy_tts_extension.py b/agents/ten_packages/extension/cosy_tts/cosy_tts_extension.py similarity index 100% rename from agents/addon/extension/cosy_tts/cosy_tts_extension.py rename to agents/ten_packages/extension/cosy_tts/cosy_tts_extension.py diff --git a/agents/addon/extension/cosy_tts/log.py b/agents/ten_packages/extension/cosy_tts/log.py similarity index 100% rename from agents/addon/extension/cosy_tts/log.py rename to agents/ten_packages/extension/cosy_tts/log.py diff --git a/agents/addon/extension/cosy_tts/manifest.json b/agents/ten_packages/extension/cosy_tts/manifest.json similarity index 86% rename from agents/addon/extension/cosy_tts/manifest.json rename to agents/ten_packages/extension/cosy_tts/manifest.json index 82a29cc0..4b1c55bc 100644 --- a/agents/addon/extension/cosy_tts/manifest.json +++ b/agents/ten_packages/extension/cosy_tts/manifest.json @@ -1,13 +1,12 @@ { "type": "extension", "name": "cosy_tts", - "version": "0.2.0", - "language": "python", + "version": "0.4.0", "dependencies": [ { "type": "system", - "name": "rte_runtime_python", - "version": "0.4.0" + "name": "ten_runtime_python", + "version": "0.1" } ], "api": { @@ -45,7 +44,7 @@ "name": "flush" } ], - "pcm_frame_out": [ + "audio_frame_out": [ { "name": "pcm_frame" } diff --git a/agents/addon/extension/cosy_tts/property.json b/agents/ten_packages/extension/cosy_tts/property.json similarity index 100% rename from agents/addon/extension/cosy_tts/property.json rename to agents/ten_packages/extension/cosy_tts/property.json diff --git a/agents/addon/extension/cosy_tts/requirements.txt b/agents/ten_packages/extension/cosy_tts/requirements.txt similarity index 100% rename from agents/addon/extension/cosy_tts/requirements.txt rename to agents/ten_packages/extension/cosy_tts/requirements.txt diff --git a/agents/addon/extension/elevenlabs_tts/elevenlabs_tts.go b/agents/ten_packages/extension/elevenlabs_tts/elevenlabs_tts.go similarity index 100% rename from agents/addon/extension/elevenlabs_tts/elevenlabs_tts.go rename to agents/ten_packages/extension/elevenlabs_tts/elevenlabs_tts.go diff --git a/agents/addon/extension/elevenlabs_tts/elevenlabs_tts_extension.go b/agents/ten_packages/extension/elevenlabs_tts/elevenlabs_tts_extension.go similarity index 100% rename from agents/addon/extension/elevenlabs_tts/elevenlabs_tts_extension.go rename to agents/ten_packages/extension/elevenlabs_tts/elevenlabs_tts_extension.go diff --git a/agents/addon/extension/elevenlabs_tts/go.mod b/agents/ten_packages/extension/elevenlabs_tts/go.mod similarity index 100% rename from agents/addon/extension/elevenlabs_tts/go.mod rename to agents/ten_packages/extension/elevenlabs_tts/go.mod diff --git a/agents/addon/extension/elevenlabs_tts/go.sum b/agents/ten_packages/extension/elevenlabs_tts/go.sum similarity index 100% rename from agents/addon/extension/elevenlabs_tts/go.sum rename to agents/ten_packages/extension/elevenlabs_tts/go.sum diff --git a/agents/addon/extension/elevenlabs_tts/manifest.json b/agents/ten_packages/extension/elevenlabs_tts/manifest.json similarity index 90% rename from agents/addon/extension/elevenlabs_tts/manifest.json rename to agents/ten_packages/extension/elevenlabs_tts/manifest.json index 40c256ea..25fa61e3 100644 --- a/agents/addon/extension/elevenlabs_tts/manifest.json +++ b/agents/ten_packages/extension/elevenlabs_tts/manifest.json @@ -1,13 +1,12 @@ { "type": "extension", "name": "elevenlabs_tts", - "version": "0.1.0", - "language": "go", + "version": "0.4.0", "dependencies": [ { "type": "system", - "name": "rte_runtime_go", - "version": "0.4.0" + "name": "ten_runtime_go", + "version": "0.1" } ], "api": { @@ -60,7 +59,7 @@ "name": "flush" } ], - "pcm_frame_out": [ + "audio_frame_out": [ { "name": "pcm_frame" } diff --git a/agents/addon/extension/elevenlabs_tts/pcm.go b/agents/ten_packages/extension/elevenlabs_tts/pcm.go similarity index 100% rename from agents/addon/extension/elevenlabs_tts/pcm.go rename to agents/ten_packages/extension/elevenlabs_tts/pcm.go diff --git a/agents/addon/extension/elevenlabs_tts/property.json b/agents/ten_packages/extension/elevenlabs_tts/property.json similarity index 100% rename from agents/addon/extension/elevenlabs_tts/property.json rename to agents/ten_packages/extension/elevenlabs_tts/property.json diff --git a/agents/addon/extension/elevenlabs_tts_python/__init__.py b/agents/ten_packages/extension/elevenlabs_tts_python/__init__.py similarity index 100% rename from agents/addon/extension/elevenlabs_tts_python/__init__.py rename to agents/ten_packages/extension/elevenlabs_tts_python/__init__.py diff --git a/agents/addon/extension/elevenlabs_tts_python/elevenlabs_tts.py b/agents/ten_packages/extension/elevenlabs_tts_python/elevenlabs_tts.py similarity index 100% rename from agents/addon/extension/elevenlabs_tts_python/elevenlabs_tts.py rename to agents/ten_packages/extension/elevenlabs_tts_python/elevenlabs_tts.py diff --git a/agents/addon/extension/elevenlabs_tts_python/elevenlabs_tts_addon.py b/agents/ten_packages/extension/elevenlabs_tts_python/elevenlabs_tts_addon.py similarity index 100% rename from agents/addon/extension/elevenlabs_tts_python/elevenlabs_tts_addon.py rename to agents/ten_packages/extension/elevenlabs_tts_python/elevenlabs_tts_addon.py diff --git a/agents/addon/extension/elevenlabs_tts_python/elevenlabs_tts_extension.py b/agents/ten_packages/extension/elevenlabs_tts_python/elevenlabs_tts_extension.py similarity index 100% rename from agents/addon/extension/elevenlabs_tts_python/elevenlabs_tts_extension.py rename to agents/ten_packages/extension/elevenlabs_tts_python/elevenlabs_tts_extension.py diff --git a/agents/addon/extension/elevenlabs_tts_python/extension.py b/agents/ten_packages/extension/elevenlabs_tts_python/extension.py similarity index 100% rename from agents/addon/extension/elevenlabs_tts_python/extension.py rename to agents/ten_packages/extension/elevenlabs_tts_python/extension.py diff --git a/agents/addon/extension/elevenlabs_tts_python/log.py b/agents/ten_packages/extension/elevenlabs_tts_python/log.py similarity index 100% rename from agents/addon/extension/elevenlabs_tts_python/log.py rename to agents/ten_packages/extension/elevenlabs_tts_python/log.py diff --git a/agents/addon/extension/elevenlabs_tts_python/manifest.json b/agents/ten_packages/extension/elevenlabs_tts_python/manifest.json similarity index 90% rename from agents/addon/extension/elevenlabs_tts_python/manifest.json rename to agents/ten_packages/extension/elevenlabs_tts_python/manifest.json index 0c9fe25c..48a956b1 100644 --- a/agents/addon/extension/elevenlabs_tts_python/manifest.json +++ b/agents/ten_packages/extension/elevenlabs_tts_python/manifest.json @@ -1,13 +1,12 @@ { "type": "extension", "name": "elevenlabs_tts_python", - "version": "0.1.0", - "language": "python", + "version": "0.4.0", "dependencies": [ { "type": "system", - "name": "rte_runtime_python", - "version": "0.4.0" + "name": "ten_runtime_python", + "version": "0.1" } ], "api": { @@ -60,7 +59,7 @@ "name": "flush" } ], - "pcm_frame_out": [ + "audio_frame_out": [ { "name": "pcm_frame" } diff --git a/agents/addon/extension/elevenlabs_tts_python/pcm.py b/agents/ten_packages/extension/elevenlabs_tts_python/pcm.py similarity index 100% rename from agents/addon/extension/elevenlabs_tts_python/pcm.py rename to agents/ten_packages/extension/elevenlabs_tts_python/pcm.py diff --git a/agents/addon/extension/elevenlabs_tts_python/property.json b/agents/ten_packages/extension/elevenlabs_tts_python/property.json similarity index 100% rename from agents/addon/extension/elevenlabs_tts_python/property.json rename to agents/ten_packages/extension/elevenlabs_tts_python/property.json diff --git a/agents/addon/extension/elevenlabs_tts_python/requirements.txt b/agents/ten_packages/extension/elevenlabs_tts_python/requirements.txt similarity index 100% rename from agents/addon/extension/elevenlabs_tts_python/requirements.txt rename to agents/ten_packages/extension/elevenlabs_tts_python/requirements.txt diff --git a/agents/addon/extension/file_chunker/__init__.py b/agents/ten_packages/extension/file_chunker/__init__.py similarity index 100% rename from agents/addon/extension/file_chunker/__init__.py rename to agents/ten_packages/extension/file_chunker/__init__.py diff --git a/agents/addon/extension/file_chunker/file_chunker_addon.py b/agents/ten_packages/extension/file_chunker/file_chunker_addon.py similarity index 100% rename from agents/addon/extension/file_chunker/file_chunker_addon.py rename to agents/ten_packages/extension/file_chunker/file_chunker_addon.py diff --git a/agents/addon/extension/file_chunker/file_chunker_extension.py b/agents/ten_packages/extension/file_chunker/file_chunker_extension.py similarity index 100% rename from agents/addon/extension/file_chunker/file_chunker_extension.py rename to agents/ten_packages/extension/file_chunker/file_chunker_extension.py diff --git a/agents/addon/extension/file_chunker/log.py b/agents/ten_packages/extension/file_chunker/log.py similarity index 100% rename from agents/addon/extension/file_chunker/log.py rename to agents/ten_packages/extension/file_chunker/log.py diff --git a/agents/addon/extension/file_chunker/manifest.json b/agents/ten_packages/extension/file_chunker/manifest.json similarity index 95% rename from agents/addon/extension/file_chunker/manifest.json rename to agents/ten_packages/extension/file_chunker/manifest.json index b491e55a..02e91d2f 100644 --- a/agents/addon/extension/file_chunker/manifest.json +++ b/agents/ten_packages/extension/file_chunker/manifest.json @@ -2,12 +2,11 @@ "type": "extension", "name": "file_chunker", "version": "0.4.0", - "language": "python", "dependencies": [ { "type": "system", - "name": "rte_runtime_python", - "version": "0.4" + "name": "ten_runtime_python", + "version": "0.1" } ], "api": { diff --git a/agents/addon/extension/file_chunker/property.json b/agents/ten_packages/extension/file_chunker/property.json similarity index 100% rename from agents/addon/extension/file_chunker/property.json rename to agents/ten_packages/extension/file_chunker/property.json diff --git a/agents/addon/extension/file_chunker/requirements.txt b/agents/ten_packages/extension/file_chunker/requirements.txt similarity index 100% rename from agents/addon/extension/file_chunker/requirements.txt rename to agents/ten_packages/extension/file_chunker/requirements.txt diff --git a/agents/addon/extension/gemini_llm_python/__init__.py b/agents/ten_packages/extension/gemini_llm_python/__init__.py similarity index 100% rename from agents/addon/extension/gemini_llm_python/__init__.py rename to agents/ten_packages/extension/gemini_llm_python/__init__.py diff --git a/agents/addon/extension/gemini_llm_python/extension.py b/agents/ten_packages/extension/gemini_llm_python/extension.py similarity index 100% rename from agents/addon/extension/gemini_llm_python/extension.py rename to agents/ten_packages/extension/gemini_llm_python/extension.py diff --git a/agents/addon/extension/gemini_llm_python/gemini_llm.py b/agents/ten_packages/extension/gemini_llm_python/gemini_llm.py similarity index 100% rename from agents/addon/extension/gemini_llm_python/gemini_llm.py rename to agents/ten_packages/extension/gemini_llm_python/gemini_llm.py diff --git a/agents/addon/extension/gemini_llm_python/gemini_llm_addon.py b/agents/ten_packages/extension/gemini_llm_python/gemini_llm_addon.py similarity index 100% rename from agents/addon/extension/gemini_llm_python/gemini_llm_addon.py rename to agents/ten_packages/extension/gemini_llm_python/gemini_llm_addon.py diff --git a/agents/addon/extension/gemini_llm_python/gemini_llm_extension.py b/agents/ten_packages/extension/gemini_llm_python/gemini_llm_extension.py similarity index 100% rename from agents/addon/extension/gemini_llm_python/gemini_llm_extension.py rename to agents/ten_packages/extension/gemini_llm_python/gemini_llm_extension.py diff --git a/agents/addon/extension/gemini_llm_python/log.py b/agents/ten_packages/extension/gemini_llm_python/log.py similarity index 100% rename from agents/addon/extension/gemini_llm_python/log.py rename to agents/ten_packages/extension/gemini_llm_python/log.py diff --git a/agents/addon/extension/gemini_llm_python/manifest.json b/agents/ten_packages/extension/gemini_llm_python/manifest.json similarity index 92% rename from agents/addon/extension/gemini_llm_python/manifest.json rename to agents/ten_packages/extension/gemini_llm_python/manifest.json index 218ac8ae..d652b105 100644 --- a/agents/addon/extension/gemini_llm_python/manifest.json +++ b/agents/ten_packages/extension/gemini_llm_python/manifest.json @@ -1,13 +1,12 @@ { "type": "extension", "name": "gemini_llm_python", - "version": "0.1.0", - "language": "python", + "version": "0.4.0", "dependencies": [ { "type": "system", - "name": "rte_runtime_python", - "version": "0.4.0" + "name": "ten_runtime_python", + "version": "0.1" } ], "api": { @@ -71,4 +70,4 @@ } ] } -} +} \ No newline at end of file diff --git a/agents/addon/extension/gemini_llm_python/requirements.txt b/agents/ten_packages/extension/gemini_llm_python/requirements.txt similarity index 100% rename from agents/addon/extension/gemini_llm_python/requirements.txt rename to agents/ten_packages/extension/gemini_llm_python/requirements.txt diff --git a/agents/addon/extension/gemini_llm_python/utils.py b/agents/ten_packages/extension/gemini_llm_python/utils.py similarity index 100% rename from agents/addon/extension/gemini_llm_python/utils.py rename to agents/ten_packages/extension/gemini_llm_python/utils.py diff --git a/agents/addon/extension/http_server_python/__init__.py b/agents/ten_packages/extension/http_server_python/__init__.py similarity index 100% rename from agents/addon/extension/http_server_python/__init__.py rename to agents/ten_packages/extension/http_server_python/__init__.py diff --git a/agents/addon/extension/http_server_python/http_server_addon.py b/agents/ten_packages/extension/http_server_python/http_server_addon.py similarity index 100% rename from agents/addon/extension/http_server_python/http_server_addon.py rename to agents/ten_packages/extension/http_server_python/http_server_addon.py diff --git a/agents/addon/extension/http_server_python/http_server_extension.py b/agents/ten_packages/extension/http_server_python/http_server_extension.py similarity index 100% rename from agents/addon/extension/http_server_python/http_server_extension.py rename to agents/ten_packages/extension/http_server_python/http_server_extension.py diff --git a/agents/addon/extension/http_server_python/log.py b/agents/ten_packages/extension/http_server_python/log.py similarity index 100% rename from agents/addon/extension/http_server_python/log.py rename to agents/ten_packages/extension/http_server_python/log.py diff --git a/agents/addon/extension/http_server_python/manifest.json b/agents/ten_packages/extension/http_server_python/manifest.json similarity index 91% rename from agents/addon/extension/http_server_python/manifest.json rename to agents/ten_packages/extension/http_server_python/manifest.json index 358d6e39..05f62097 100644 --- a/agents/addon/extension/http_server_python/manifest.json +++ b/agents/ten_packages/extension/http_server_python/manifest.json @@ -2,15 +2,14 @@ "type": "extension", "name": "http_server_python", "version": "0.4.0", - "language": "python", "dependencies": [ { "type": "system", - "name": "rte_runtime_python", - "version": "0.4" + "name": "ten_runtime_python", + "version": "0.1" } ], - "publish": { + "package": { "include": [ "manifest.json", "property.json", diff --git a/agents/addon/extension/http_server_python/property.json b/agents/ten_packages/extension/http_server_python/property.json similarity index 100% rename from agents/addon/extension/http_server_python/property.json rename to agents/ten_packages/extension/http_server_python/property.json diff --git a/agents/addon/extension/interrupt_detector/extension.go b/agents/ten_packages/extension/interrupt_detector/extension.go similarity index 100% rename from agents/addon/extension/interrupt_detector/extension.go rename to agents/ten_packages/extension/interrupt_detector/extension.go diff --git a/agents/addon/extension/interrupt_detector/go.mod b/agents/ten_packages/extension/interrupt_detector/go.mod similarity index 100% rename from agents/addon/extension/interrupt_detector/go.mod rename to agents/ten_packages/extension/interrupt_detector/go.mod diff --git a/agents/addon/extension/interrupt_detector/manifest.json b/agents/ten_packages/extension/interrupt_detector/manifest.json similarity index 81% rename from agents/addon/extension/interrupt_detector/manifest.json rename to agents/ten_packages/extension/interrupt_detector/manifest.json index f4c88008..7e4beda6 100644 --- a/agents/addon/extension/interrupt_detector/manifest.json +++ b/agents/ten_packages/extension/interrupt_detector/manifest.json @@ -1,13 +1,12 @@ { "type": "extension", "name": "interrupt_detector", - "version": "0.1.0", - "language": "go", + "version": "0.4.0", "dependencies": [ { "type": "system", - "name": "rte_runtime_go", - "version": "0.4.0" + "name": "ten_runtime_go", + "version": "0.1" } ], "api": { diff --git a/agents/addon/extension/interrupt_detector/property.json b/agents/ten_packages/extension/interrupt_detector/property.json similarity index 100% rename from agents/addon/extension/interrupt_detector/property.json rename to agents/ten_packages/extension/interrupt_detector/property.json diff --git a/agents/addon/extension/interrupt_detector_python/__init__.py b/agents/ten_packages/extension/interrupt_detector_python/__init__.py similarity index 100% rename from agents/addon/extension/interrupt_detector_python/__init__.py rename to agents/ten_packages/extension/interrupt_detector_python/__init__.py diff --git a/agents/addon/extension/interrupt_detector_python/interrupt_detector_addon.py b/agents/ten_packages/extension/interrupt_detector_python/interrupt_detector_addon.py similarity index 100% rename from agents/addon/extension/interrupt_detector_python/interrupt_detector_addon.py rename to agents/ten_packages/extension/interrupt_detector_python/interrupt_detector_addon.py diff --git a/agents/addon/extension/interrupt_detector_python/interrupt_detector_extension.py b/agents/ten_packages/extension/interrupt_detector_python/interrupt_detector_extension.py similarity index 100% rename from agents/addon/extension/interrupt_detector_python/interrupt_detector_extension.py rename to agents/ten_packages/extension/interrupt_detector_python/interrupt_detector_extension.py diff --git a/agents/addon/extension/interrupt_detector_python/log.py b/agents/ten_packages/extension/interrupt_detector_python/log.py similarity index 100% rename from agents/addon/extension/interrupt_detector_python/log.py rename to agents/ten_packages/extension/interrupt_detector_python/log.py diff --git a/agents/addon/extension/interrupt_detector_python/manifest.json b/agents/ten_packages/extension/interrupt_detector_python/manifest.json similarity index 85% rename from agents/addon/extension/interrupt_detector_python/manifest.json rename to agents/ten_packages/extension/interrupt_detector_python/manifest.json index c092d77e..bf872358 100644 --- a/agents/addon/extension/interrupt_detector_python/manifest.json +++ b/agents/ten_packages/extension/interrupt_detector_python/manifest.json @@ -1,13 +1,12 @@ { "type": "extension", "name": "interrupt_detector_python", - "version": "0.1.0", - "language": "python", + "version": "0.4.0", "dependencies": [ { "type": "system", - "name": "rte_runtime_python", - "version": "0.4.0" + "name": "ten_runtime_python", + "version": "0.1" } ], "api": { diff --git a/agents/addon/extension/interrupt_detector_python/property.json b/agents/ten_packages/extension/interrupt_detector_python/property.json similarity index 100% rename from agents/addon/extension/interrupt_detector_python/property.json rename to agents/ten_packages/extension/interrupt_detector_python/property.json diff --git a/agents/addon/extension/llama_index_chat_engine/__init__.py b/agents/ten_packages/extension/llama_index_chat_engine/__init__.py similarity index 100% rename from agents/addon/extension/llama_index_chat_engine/__init__.py rename to agents/ten_packages/extension/llama_index_chat_engine/__init__.py diff --git a/agents/addon/extension/llama_index_chat_engine/addon.py b/agents/ten_packages/extension/llama_index_chat_engine/addon.py similarity index 100% rename from agents/addon/extension/llama_index_chat_engine/addon.py rename to agents/ten_packages/extension/llama_index_chat_engine/addon.py diff --git a/agents/addon/extension/llama_index_chat_engine/astra_embedding.py b/agents/ten_packages/extension/llama_index_chat_engine/astra_embedding.py similarity index 100% rename from agents/addon/extension/llama_index_chat_engine/astra_embedding.py rename to agents/ten_packages/extension/llama_index_chat_engine/astra_embedding.py diff --git a/agents/addon/extension/llama_index_chat_engine/astra_llm.py b/agents/ten_packages/extension/llama_index_chat_engine/astra_llm.py similarity index 100% rename from agents/addon/extension/llama_index_chat_engine/astra_llm.py rename to agents/ten_packages/extension/llama_index_chat_engine/astra_llm.py diff --git a/agents/addon/extension/llama_index_chat_engine/astra_retriever.py b/agents/ten_packages/extension/llama_index_chat_engine/astra_retriever.py similarity index 100% rename from agents/addon/extension/llama_index_chat_engine/astra_retriever.py rename to agents/ten_packages/extension/llama_index_chat_engine/astra_retriever.py diff --git a/agents/addon/extension/llama_index_chat_engine/extension.py b/agents/ten_packages/extension/llama_index_chat_engine/extension.py similarity index 100% rename from agents/addon/extension/llama_index_chat_engine/extension.py rename to agents/ten_packages/extension/llama_index_chat_engine/extension.py diff --git a/agents/addon/extension/llama_index_chat_engine/log.py b/agents/ten_packages/extension/llama_index_chat_engine/log.py similarity index 100% rename from agents/addon/extension/llama_index_chat_engine/log.py rename to agents/ten_packages/extension/llama_index_chat_engine/log.py diff --git a/agents/addon/extension/llama_index_chat_engine/manifest.json b/agents/ten_packages/extension/llama_index_chat_engine/manifest.json similarity index 97% rename from agents/addon/extension/llama_index_chat_engine/manifest.json rename to agents/ten_packages/extension/llama_index_chat_engine/manifest.json index a7c9d62f..0feacf83 100644 --- a/agents/addon/extension/llama_index_chat_engine/manifest.json +++ b/agents/ten_packages/extension/llama_index_chat_engine/manifest.json @@ -2,12 +2,11 @@ "type": "extension", "name": "llama_index_chat_engine", "version": "0.4.0", - "language": "python", "dependencies": [ { "type": "system", - "name": "rte_runtime_python", - "version": "0.4" + "name": "ten_runtime_python", + "version": "0.1" } ], "api": { diff --git a/agents/addon/extension/llama_index_chat_engine/property.json b/agents/ten_packages/extension/llama_index_chat_engine/property.json similarity index 100% rename from agents/addon/extension/llama_index_chat_engine/property.json rename to agents/ten_packages/extension/llama_index_chat_engine/property.json diff --git a/agents/addon/extension/llama_index_chat_engine/requirements.txt b/agents/ten_packages/extension/llama_index_chat_engine/requirements.txt similarity index 100% rename from agents/addon/extension/llama_index_chat_engine/requirements.txt rename to agents/ten_packages/extension/llama_index_chat_engine/requirements.txt diff --git a/agents/addon/extension/openai_chatgpt/README.md b/agents/ten_packages/extension/openai_chatgpt/README.md similarity index 100% rename from agents/addon/extension/openai_chatgpt/README.md rename to agents/ten_packages/extension/openai_chatgpt/README.md diff --git a/agents/addon/extension/openai_chatgpt/go.mod b/agents/ten_packages/extension/openai_chatgpt/go.mod similarity index 100% rename from agents/addon/extension/openai_chatgpt/go.mod rename to agents/ten_packages/extension/openai_chatgpt/go.mod diff --git a/agents/addon/extension/openai_chatgpt/go.sum b/agents/ten_packages/extension/openai_chatgpt/go.sum similarity index 100% rename from agents/addon/extension/openai_chatgpt/go.sum rename to agents/ten_packages/extension/openai_chatgpt/go.sum diff --git a/agents/addon/extension/openai_chatgpt/manifest.json b/agents/ten_packages/extension/openai_chatgpt/manifest.json similarity index 92% rename from agents/addon/extension/openai_chatgpt/manifest.json rename to agents/ten_packages/extension/openai_chatgpt/manifest.json index 8b1720d0..4bc6783e 100644 --- a/agents/addon/extension/openai_chatgpt/manifest.json +++ b/agents/ten_packages/extension/openai_chatgpt/manifest.json @@ -1,14 +1,12 @@ { "type": "extension", "name": "openai_chatgpt", - "version": "0.1.0", - "language": "go", - "support": [], + "version": "0.4.0", "dependencies": [ { "type": "system", - "name": "rte_runtime_go", - "version": "0.4.0" + "name": "ten_runtime_go", + "version": "0.1" } ], "api": { diff --git a/agents/addon/extension/openai_chatgpt/openai_chatgpt.go b/agents/ten_packages/extension/openai_chatgpt/openai_chatgpt.go similarity index 100% rename from agents/addon/extension/openai_chatgpt/openai_chatgpt.go rename to agents/ten_packages/extension/openai_chatgpt/openai_chatgpt.go diff --git a/agents/addon/extension/openai_chatgpt/openai_chatgpt_extension.go b/agents/ten_packages/extension/openai_chatgpt/openai_chatgpt_extension.go similarity index 100% rename from agents/addon/extension/openai_chatgpt/openai_chatgpt_extension.go rename to agents/ten_packages/extension/openai_chatgpt/openai_chatgpt_extension.go diff --git a/agents/addon/extension/openai_chatgpt/property.json b/agents/ten_packages/extension/openai_chatgpt/property.json similarity index 100% rename from agents/addon/extension/openai_chatgpt/property.json rename to agents/ten_packages/extension/openai_chatgpt/property.json diff --git a/agents/addon/extension/openai_chatgpt/sentence.go b/agents/ten_packages/extension/openai_chatgpt/sentence.go similarity index 100% rename from agents/addon/extension/openai_chatgpt/sentence.go rename to agents/ten_packages/extension/openai_chatgpt/sentence.go diff --git a/agents/addon/extension/openai_chatgpt/sentence_test.go b/agents/ten_packages/extension/openai_chatgpt/sentence_test.go similarity index 100% rename from agents/addon/extension/openai_chatgpt/sentence_test.go rename to agents/ten_packages/extension/openai_chatgpt/sentence_test.go diff --git a/agents/addon/extension/openai_chatgpt_python/__init__.py b/agents/ten_packages/extension/openai_chatgpt_python/__init__.py similarity index 100% rename from agents/addon/extension/openai_chatgpt_python/__init__.py rename to agents/ten_packages/extension/openai_chatgpt_python/__init__.py diff --git a/agents/addon/extension/openai_chatgpt_python/log.py b/agents/ten_packages/extension/openai_chatgpt_python/log.py similarity index 100% rename from agents/addon/extension/openai_chatgpt_python/log.py rename to agents/ten_packages/extension/openai_chatgpt_python/log.py diff --git a/agents/addon/extension/openai_chatgpt_python/manifest.json b/agents/ten_packages/extension/openai_chatgpt_python/manifest.json similarity index 89% rename from agents/addon/extension/openai_chatgpt_python/manifest.json rename to agents/ten_packages/extension/openai_chatgpt_python/manifest.json index 8193a637..95d461ad 100644 --- a/agents/addon/extension/openai_chatgpt_python/manifest.json +++ b/agents/ten_packages/extension/openai_chatgpt_python/manifest.json @@ -1,13 +1,12 @@ { "type": "extension", "name": "openai_chatgpt_python", - "version": "0.1.0", - "language": "python", + "version": "0.4.0", "dependencies": [ { "type": "system", - "name": "rte_runtime_python", - "version": "0.4.0" + "name": "ten_runtime_python", + "version": "0.1" } ], "api": { @@ -82,10 +81,10 @@ "name": "flush" } ], - "image_frame_in": [ + "video_frame_in": [ { - "name": "image_frame" + "name": "video_frame" } ] } -} +} \ No newline at end of file diff --git a/agents/addon/extension/openai_chatgpt_python/openai_chatgpt.py b/agents/ten_packages/extension/openai_chatgpt_python/openai_chatgpt.py similarity index 100% rename from agents/addon/extension/openai_chatgpt_python/openai_chatgpt.py rename to agents/ten_packages/extension/openai_chatgpt_python/openai_chatgpt.py diff --git a/agents/addon/extension/openai_chatgpt_python/openai_chatgpt_addon.py b/agents/ten_packages/extension/openai_chatgpt_python/openai_chatgpt_addon.py similarity index 100% rename from agents/addon/extension/openai_chatgpt_python/openai_chatgpt_addon.py rename to agents/ten_packages/extension/openai_chatgpt_python/openai_chatgpt_addon.py diff --git a/agents/addon/extension/openai_chatgpt_python/openai_chatgpt_extension.py b/agents/ten_packages/extension/openai_chatgpt_python/openai_chatgpt_extension.py similarity index 100% rename from agents/addon/extension/openai_chatgpt_python/openai_chatgpt_extension.py rename to agents/ten_packages/extension/openai_chatgpt_python/openai_chatgpt_extension.py diff --git a/agents/addon/extension/openai_chatgpt_python/property.json b/agents/ten_packages/extension/openai_chatgpt_python/property.json similarity index 100% rename from agents/addon/extension/openai_chatgpt_python/property.json rename to agents/ten_packages/extension/openai_chatgpt_python/property.json diff --git a/agents/addon/extension/openai_chatgpt_python/requirements.txt b/agents/ten_packages/extension/openai_chatgpt_python/requirements.txt similarity index 100% rename from agents/addon/extension/openai_chatgpt_python/requirements.txt rename to agents/ten_packages/extension/openai_chatgpt_python/requirements.txt diff --git a/agents/addon/extension/polly_tts/README.md b/agents/ten_packages/extension/polly_tts/README.md similarity index 100% rename from agents/addon/extension/polly_tts/README.md rename to agents/ten_packages/extension/polly_tts/README.md diff --git a/agents/addon/extension/polly_tts/__init__.py b/agents/ten_packages/extension/polly_tts/__init__.py similarity index 100% rename from agents/addon/extension/polly_tts/__init__.py rename to agents/ten_packages/extension/polly_tts/__init__.py diff --git a/agents/addon/extension/polly_tts/extension.py b/agents/ten_packages/extension/polly_tts/extension.py similarity index 100% rename from agents/addon/extension/polly_tts/extension.py rename to agents/ten_packages/extension/polly_tts/extension.py diff --git a/agents/addon/extension/polly_tts/log.py b/agents/ten_packages/extension/polly_tts/log.py similarity index 100% rename from agents/addon/extension/polly_tts/log.py rename to agents/ten_packages/extension/polly_tts/log.py diff --git a/agents/addon/extension/polly_tts/manifest.json b/agents/ten_packages/extension/polly_tts/manifest.json similarity index 88% rename from agents/addon/extension/polly_tts/manifest.json rename to agents/ten_packages/extension/polly_tts/manifest.json index 2cc19a02..dfbc94ea 100644 --- a/agents/addon/extension/polly_tts/manifest.json +++ b/agents/ten_packages/extension/polly_tts/manifest.json @@ -1,13 +1,12 @@ { "type": "extension", "name": "polly_tts", - "version": "0.1.0", - "language": "python", + "version": "0.4.0", "dependencies": [ { "type": "system", - "name": "rte_runtime_python", - "version": "0.4.0" + "name": "ten_runtime_python", + "version": "0.1" } ], "api": { @@ -54,7 +53,7 @@ "name": "flush" } ], - "pcm_frame_out": [ + "audio_frame_out": [ { "name": "pcm_frame" } diff --git a/agents/addon/extension/polly_tts/polly_tts_addon.py b/agents/ten_packages/extension/polly_tts/polly_tts_addon.py similarity index 100% rename from agents/addon/extension/polly_tts/polly_tts_addon.py rename to agents/ten_packages/extension/polly_tts/polly_tts_addon.py diff --git a/agents/addon/extension/polly_tts/polly_tts_extension.py b/agents/ten_packages/extension/polly_tts/polly_tts_extension.py similarity index 100% rename from agents/addon/extension/polly_tts/polly_tts_extension.py rename to agents/ten_packages/extension/polly_tts/polly_tts_extension.py diff --git a/agents/addon/extension/polly_tts/polly_wrapper.py b/agents/ten_packages/extension/polly_tts/polly_wrapper.py similarity index 100% rename from agents/addon/extension/polly_tts/polly_wrapper.py rename to agents/ten_packages/extension/polly_tts/polly_wrapper.py diff --git a/agents/addon/extension/polly_tts/requirements.txt b/agents/ten_packages/extension/polly_tts/requirements.txt similarity index 100% rename from agents/addon/extension/polly_tts/requirements.txt rename to agents/ten_packages/extension/polly_tts/requirements.txt diff --git a/agents/addon/extension/qwen_llm_python/__init__.py b/agents/ten_packages/extension/qwen_llm_python/__init__.py similarity index 100% rename from agents/addon/extension/qwen_llm_python/__init__.py rename to agents/ten_packages/extension/qwen_llm_python/__init__.py diff --git a/agents/addon/extension/qwen_llm_python/log.py b/agents/ten_packages/extension/qwen_llm_python/log.py similarity index 100% rename from agents/addon/extension/qwen_llm_python/log.py rename to agents/ten_packages/extension/qwen_llm_python/log.py diff --git a/agents/addon/extension/qwen_llm_python/manifest.json b/agents/ten_packages/extension/qwen_llm_python/manifest.json similarity index 94% rename from agents/addon/extension/qwen_llm_python/manifest.json rename to agents/ten_packages/extension/qwen_llm_python/manifest.json index 153369c1..a05290af 100644 --- a/agents/addon/extension/qwen_llm_python/manifest.json +++ b/agents/ten_packages/extension/qwen_llm_python/manifest.json @@ -2,12 +2,11 @@ "type": "extension", "name": "qwen_llm_python", "version": "0.4.0", - "language": "python", "dependencies": [ { "type": "system", - "name": "rte_runtime_python", - "version": "0.4" + "name": "ten_runtime_python", + "version": "0.1" } ], "api": { diff --git a/agents/addon/extension/qwen_llm_python/property.json b/agents/ten_packages/extension/qwen_llm_python/property.json similarity index 100% rename from agents/addon/extension/qwen_llm_python/property.json rename to agents/ten_packages/extension/qwen_llm_python/property.json diff --git a/agents/addon/extension/qwen_llm_python/qwen_llm_addon.py b/agents/ten_packages/extension/qwen_llm_python/qwen_llm_addon.py similarity index 100% rename from agents/addon/extension/qwen_llm_python/qwen_llm_addon.py rename to agents/ten_packages/extension/qwen_llm_python/qwen_llm_addon.py diff --git a/agents/addon/extension/qwen_llm_python/qwen_llm_extension.py b/agents/ten_packages/extension/qwen_llm_python/qwen_llm_extension.py similarity index 100% rename from agents/addon/extension/qwen_llm_python/qwen_llm_extension.py rename to agents/ten_packages/extension/qwen_llm_python/qwen_llm_extension.py diff --git a/agents/addon/extension/qwen_llm_python/requirements.txt b/agents/ten_packages/extension/qwen_llm_python/requirements.txt similarity index 100% rename from agents/addon/extension/qwen_llm_python/requirements.txt rename to agents/ten_packages/extension/qwen_llm_python/requirements.txt diff --git a/agents/addon/extension/transcribe_asr_python/README.md b/agents/ten_packages/extension/transcribe_asr_python/README.md similarity index 100% rename from agents/addon/extension/transcribe_asr_python/README.md rename to agents/ten_packages/extension/transcribe_asr_python/README.md diff --git a/agents/addon/extension/transcribe_asr_python/__init__.py b/agents/ten_packages/extension/transcribe_asr_python/__init__.py similarity index 100% rename from agents/addon/extension/transcribe_asr_python/__init__.py rename to agents/ten_packages/extension/transcribe_asr_python/__init__.py diff --git a/agents/addon/extension/transcribe_asr_python/extension.py b/agents/ten_packages/extension/transcribe_asr_python/extension.py similarity index 100% rename from agents/addon/extension/transcribe_asr_python/extension.py rename to agents/ten_packages/extension/transcribe_asr_python/extension.py diff --git a/agents/addon/extension/transcribe_asr_python/log.py b/agents/ten_packages/extension/transcribe_asr_python/log.py similarity index 100% rename from agents/addon/extension/transcribe_asr_python/log.py rename to agents/ten_packages/extension/transcribe_asr_python/log.py diff --git a/agents/addon/extension/transcribe_asr_python/manifest.json b/agents/ten_packages/extension/transcribe_asr_python/manifest.json similarity index 92% rename from agents/addon/extension/transcribe_asr_python/manifest.json rename to agents/ten_packages/extension/transcribe_asr_python/manifest.json index d780d2c4..69386329 100644 --- a/agents/addon/extension/transcribe_asr_python/manifest.json +++ b/agents/ten_packages/extension/transcribe_asr_python/manifest.json @@ -1,13 +1,12 @@ { "type": "extension", "name": "transcribe_asr_python", - "version": "0.1.0", - "language": "python", + "version": "0.4.0", "dependencies": [ { "type": "system", - "name": "rte_runtime_python", - "version": "0.4.0" + "name": "ten_runtime_python", + "version": "0.1" } ], "api": { @@ -28,7 +27,7 @@ "type": "string" } }, - "pcm_frame_in": [ + "audio_frame_in": [ { "name": "pcm_frame" } diff --git a/agents/addon/extension/transcribe_asr_python/property.json b/agents/ten_packages/extension/transcribe_asr_python/property.json similarity index 100% rename from agents/addon/extension/transcribe_asr_python/property.json rename to agents/ten_packages/extension/transcribe_asr_python/property.json diff --git a/agents/addon/extension/transcribe_asr_python/requirements.txt b/agents/ten_packages/extension/transcribe_asr_python/requirements.txt similarity index 100% rename from agents/addon/extension/transcribe_asr_python/requirements.txt rename to agents/ten_packages/extension/transcribe_asr_python/requirements.txt diff --git a/agents/addon/extension/transcribe_asr_python/transcribe_asr_addon.py b/agents/ten_packages/extension/transcribe_asr_python/transcribe_asr_addon.py similarity index 100% rename from agents/addon/extension/transcribe_asr_python/transcribe_asr_addon.py rename to agents/ten_packages/extension/transcribe_asr_python/transcribe_asr_addon.py diff --git a/agents/addon/extension/transcribe_asr_python/transcribe_asr_extension.py b/agents/ten_packages/extension/transcribe_asr_python/transcribe_asr_extension.py similarity index 100% rename from agents/addon/extension/transcribe_asr_python/transcribe_asr_extension.py rename to agents/ten_packages/extension/transcribe_asr_python/transcribe_asr_extension.py diff --git a/agents/addon/extension/transcribe_asr_python/transcribe_config.py b/agents/ten_packages/extension/transcribe_asr_python/transcribe_config.py similarity index 100% rename from agents/addon/extension/transcribe_asr_python/transcribe_config.py rename to agents/ten_packages/extension/transcribe_asr_python/transcribe_config.py diff --git a/agents/addon/extension/transcribe_asr_python/transcribe_wrapper.py b/agents/ten_packages/extension/transcribe_asr_python/transcribe_wrapper.py similarity index 100% rename from agents/addon/extension/transcribe_asr_python/transcribe_wrapper.py rename to agents/ten_packages/extension/transcribe_asr_python/transcribe_wrapper.py From d8761abde2c7a9e466dcdc8e687c4921a7cdc1bc Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 09:26:54 +0000 Subject: [PATCH 02/25] feat: use ten build image --- .devcontainer/devcontainer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 6aec5d28..8dd86986 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,7 +2,7 @@ // README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile { "name": "astra", - "image": "ghcr.io/rte-design/astra_agents_build:0.3.6", + "image": "ghcr.io/rte-design/astra_agents_build:0.4.0", "customizations": { "vscode": { "extensions": [ From e92d65c0f055a971f8bc03e5d0d1f6fe113dde1f Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 09:43:00 +0000 Subject: [PATCH 03/25] fix: cxx build --- agents/manifest-lock.json | 31 ++++-- agents/manifest.json | 5 + agents/scripts/BUILD.gn | 55 ++------- agents/scripts/install_deps_and_build.sh | 35 +++--- .../ten_packages/extension/azure_tts/BUILD.gn | 104 +++++++----------- .../extension/azure_tts/src/log.h | 10 +- .../extension/azure_tts/src/main.cc | 69 ++++++------ 7 files changed, 130 insertions(+), 179 deletions(-) diff --git a/agents/manifest-lock.json b/agents/manifest-lock.json index 18edd850..778ec8c4 100644 --- a/agents/manifest-lock.json +++ b/agents/manifest-lock.json @@ -88,6 +88,22 @@ } ] }, + { + "type": "extension", + "name": "azure_tts", + "version": "0.4.0", + "hash": "4f25e8c2a9c82f2a699a4e8378d11d2fbb31c90ec5df1718271ebfe6377a5389", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime" + }, + { + "type": "system", + "name": "azure_speech_sdk" + } + ] + }, { "type": "system", "name": "ten_runtime", @@ -102,9 +118,9 @@ }, { "type": "system", - "name": "agora_rtc_sdk", - "version": "4.1.35+build328115", - "hash": "fd33989f9913d77e05970eb2b265fa5e08322141b7e0f8f9fd3e521f87929b3b", + "name": "azure_speech_sdk", + "version": "1.38.0", + "hash": "66a50ef361f8190fa0595d8298c135e13b73796d57174a0802631263a8f15806", "supports": [ { "os": "linux", @@ -114,9 +130,9 @@ }, { "type": "system", - "name": "azure_speech_sdk", - "version": "1.38.0", - "hash": "66a50ef361f8190fa0595d8298c135e13b73796d57174a0802631263a8f15806", + "name": "agora_rtc_sdk", + "version": "4.1.35+build328115", + "hash": "fd33989f9913d77e05970eb2b265fa5e08322141b7e0f8f9fd3e521f87929b3b", "supports": [ { "os": "linux", @@ -128,7 +144,8 @@ "type": "system", "name": "nlohmann_json", "version": "3.11.2", - "hash": "72b15822c7ea9deef5e7ad96216ac55e93f11b00466dd1943afd5ee276e99d19" + "hash": "72b15822c7ea9deef5e7ad96216ac55e93f11b00466dd1943afd5ee276e99d19", + "supports": [] }, { "type": "system", diff --git a/agents/manifest.json b/agents/manifest.json index 49c6df8f..e0a72e56 100644 --- a/agents/manifest.json +++ b/agents/manifest.json @@ -22,6 +22,11 @@ "type": "extension", "name": "agora_rtc", "version": "=0.5.0-rc1" + }, + { + "type": "extension", + "name": "azure_tts", + "version": "=0.4.0" } ] } \ No newline at end of file diff --git a/agents/scripts/BUILD.gn b/agents/scripts/BUILD.gn index c9fa5f1f..7164e486 100644 --- a/agents/scripts/BUILD.gn +++ b/agents/scripts/BUILD.gn @@ -5,55 +5,14 @@ # Copyright (c) 2024 Agora IO. All rights reserved. # # -import("//exts/rte/base_options.gni") -import("//exts/rte/rte_package.gni") +import("//build/feature/ten_package.gni") -config("common_config") { - defines = common_defines - include_dirs = common_includes - cflags = common_cflags - cflags_c = common_cflags_c - cflags_cc = common_cflags_cc - cflags_objc = common_cflags_objc - cflags_objcc = common_cflags_objcc - libs = common_libs - lib_dirs = common_lib_dirs - ldflags = common_ldflags -} - -# NOTE: -# -# This file is only used to build all C++ extensions automatically, the -# `build_type` can not be `executable`. - -rte_package("default_app_cpp") { - package_type = "develop" # develop | release +ten_package("default_app_go") { package_kind = "app" + enable_build = false - manifest = "manifest.json" - - if (package_type == "develop") { - # It's 'develop' package, therefore, need to build the result. - build_type = "shared_library" - - sources = [] - - include_dirs = [ - "//include", - "//include/utils", - "//include/nlohmann_json", - ] - - lib_dirs = [ "//lib" ] - - if (is_win) { - libs = [ - "rte_runtime.dll.lib", - ] - } else { - libs = [ - "rte_runtime", - ] - } - } + resources = [ + "manifest.json", + "property.json", + ] } diff --git a/agents/scripts/install_deps_and_build.sh b/agents/scripts/install_deps_and_build.sh index 45a3ead4..a4b510ea 100755 --- a/agents/scripts/install_deps_and_build.sh +++ b/agents/scripts/install_deps_and_build.sh @@ -6,40 +6,39 @@ OS="linux" # x64, arm64 CPU="x64" -build_cxx_addon() { +build_cxx_extensions() { local app_dir=$1 if [[ ! -f $app_dir/scripts/BUILD.gn ]]; then - echo "FATAL: the scripts/BUILD.gn is required to build cxx addons." + echo "FATAL: the scripts/BUILD.gn is required to build cxx extensions." exit 1 fi cp $app_dir/scripts/BUILD.gn $app_dir - ag gen $OS $CPU release -- is_clang=false - ag build $OS $CPU release + tgn gen $OS $CPU release -- is_clang=false + tgn build $OS $CPU release local ret=$? cd $app_dir if [[ $ret -ne 0 ]]; then - echo "FATAL: failed to build cxx addons, see logs for detail." + echo "FATAL: failed to build cxx extensions, see logs for detail." exit 1 fi - # Copy the output of addons to the addon/extension/xx/lib. - + # Copy the output of ten_packages to the ten_packages/extension/xx/lib. local out="out/$OS/$CPU" - for extension in $out/addon/extension/*; do + for extension in $out/ten_packages/extension/*; do local extension_name=$(basename $extension) if [[ ! -d $extension/lib ]]; then echo "No output for extension $extension_name." exit 1 fi - mkdir -p $app_dir/addon/extension/$extension_name/lib - cp -r $extension/lib/* $app_dir/addon/extension/$extension_name/lib + mkdir -p $app_dir/ten_packages/extension/$extension_name/lib + cp -r $extension/lib/* $app_dir/ten_packages/extension/$extension_name/lib done } @@ -50,9 +49,9 @@ install_python_requirements() { pip install -r requirements.txt fi - # traverse the addon/extension directory to find the requirements.txt - if [[ -d "addon/extension" ]]; then - for extension in addon/extension/*; do + # traverse the ten_packages/extension directory to find the requirements.txt + if [[ -d "ten_packages/extension" ]]; then + for extension in ten_packages/extension/*; do if [[ -f "$extension/requirements.txt" ]]; then pip install -r $extension/requirements.txt fi @@ -64,7 +63,7 @@ build_go_app() { local app_dir=$1 cd $app_dir - go run scripts/build/main.go --verbose + go run ten_packages/system/ten_runtime_go/tools/build/main.go --verbose if [[ $? -ne 0 ]]; then echo "FATAL: failed to build go app, see logs for detail." exit 1 @@ -110,11 +109,11 @@ main() { # Install all dependencies specified in manifest.json. echo "install dependencies..." - arpm install + tman install - # build addons and app - echo "build_cxx_addon..." - build_cxx_addon $APP_HOME + # build extensions and app + echo "build_cxx_extensions..." + build_cxx_extensions $APP_HOME echo "build_go_app..." build_go_app $APP_HOME echo "install_python_requirements..." diff --git a/agents/ten_packages/extension/azure_tts/BUILD.gn b/agents/ten_packages/extension/azure_tts/BUILD.gn index ef2211c2..0537c92a 100644 --- a/agents/ten_packages/extension/azure_tts/BUILD.gn +++ b/agents/ten_packages/extension/azure_tts/BUILD.gn @@ -5,71 +5,45 @@ # Copyright (c) 2024 Agora IO. All rights reserved. # # -import("//exts/rte/base_options.gni") -import("//exts/rte/rte_package.gni") +import("//.gnfiles/build/feature/base_options.gni") +import("//.gnfiles/build/feature/ten_package.gni") -config("common_config") { - defines = common_defines - include_dirs = common_includes - cflags = common_cflags - cflags_c = common_cflags_c - cflags_cc = common_cflags_cc - cflags_objc = common_cflags_objc - cflags_objcc = common_cflags_objcc - libs = common_libs - lib_dirs = common_lib_dirs - ldflags = common_ldflags -} - -rte_package("azure_tts") { - package_type = "develop" # develop | release +ten_package("azure_tts") { package_kind = "extension" - - manifest = "manifest.json" - property = "property.json" - - if (package_type == "develop") { - # It's 'develop' package, therefore, need to build the result. - build_type = "shared_library" - - sources = [ - "src/main.cc", - "src/tts.cc" - ] - - include_dirs = [ - "//include/microsoft/c_api", - "//include/microsoft/cxx_api", - "//include", - "//include/utils", - "//include/nlohmann_json", - "//include/msgpackc", - ] - - lib_dirs = [ "//lib", "lib" ] - - if (is_win) { - libs = [ - "rte_runtime.dll.lib", - "utils.dll.lib", - ] - } else { - libs = [ - "rte_runtime", - "utils", - ] - - if (is_linux) { - libs += [ - "Microsoft.CognitiveServices.Speech.core", - "Microsoft.CognitiveServices.Speech.extension.audio.sys", - "Microsoft.CognitiveServices.Speech.extension.codec", - "Microsoft.CognitiveServices.Speech.extension.kws.ort", - "Microsoft.CognitiveServices.Speech.extension.kws", - "Microsoft.CognitiveServices.Speech.extension.lu", - "Microsoft.CognitiveServices.Speech.extension.mas" - ] - } - } - } + enable_build = true + + resources = [ + "manifest.json", + "property.json", + ] + + sources = [ + "src/main.cc", + "src/tts.cc" + ] + + include_dirs = [ + "include", + "//ten_packages/system/ten_runtime/include", + "//ten_packages/system/azure_speech_sdk/include/microsoft/c_api", + "//ten_packages/system/azure_speech_sdk/include/microsoft/cxx_api", + ] + + lib_dirs = [ + "lib", + "//ten_packages/system/ten_runtime/lib", + "//ten_packages/system/azure_speech_sdk/lib" + ] + + libs = [ + "ten_runtime", + "ten_utils", + "Microsoft.CognitiveServices.Speech.core", + "Microsoft.CognitiveServices.Speech.extension.audio.sys", + "Microsoft.CognitiveServices.Speech.extension.codec", + "Microsoft.CognitiveServices.Speech.extension.kws.ort", + "Microsoft.CognitiveServices.Speech.extension.kws", + "Microsoft.CognitiveServices.Speech.extension.lu", + "Microsoft.CognitiveServices.Speech.extension.mas" + ] } diff --git a/agents/ten_packages/extension/azure_tts/src/log.h b/agents/ten_packages/extension/azure_tts/src/log.h index c3e98a66..bca83eac 100644 --- a/agents/ten_packages/extension/azure_tts/src/log.h +++ b/agents/ten_packages/extension/azure_tts/src/log.h @@ -9,9 +9,9 @@ #define AZURE_TTS_LOG_TAG "AZURE_TTS_EXTENSION" -#include "utils/log/log.h" +#include "ten_utils/log/log.h" -#define AZURE_TTS_LOGI(...) RTE_LOG_WRITE(RTE_LOG_INFO, AZURE_TTS_LOG_TAG, __VA_ARGS__) -#define AZURE_TTS_LOGE(...) RTE_LOG_WRITE(RTE_LOG_ERROR, AZURE_TTS_LOG_TAG, __VA_ARGS__) -#define AZURE_TTS_LOGW(...) RTE_LOG_WRITE(RTE_LOG_WARN, AZURE_TTS_LOG_TAG, __VA_ARGS__) -#define AZURE_TTS_LOGD(...) RTE_LOG_WRITE(RTE_LOG_DEBUG, AZURE_TTS_LOG_TAG, __VA_ARGS__) +#define AZURE_TTS_LOGI(...) TEN_LOG_WRITE(TEN_LOG_INFO, AZURE_TTS_LOG_TAG, __VA_ARGS__) +#define AZURE_TTS_LOGE(...) TEN_LOG_WRITE(TEN_LOG_ERROR, AZURE_TTS_LOG_TAG, __VA_ARGS__) +#define AZURE_TTS_LOGW(...) TEN_LOG_WRITE(TEN_LOG_WARN, AZURE_TTS_LOG_TAG, __VA_ARGS__) +#define AZURE_TTS_LOGD(...) TEN_LOG_WRITE(TEN_LOG_DEBUG, AZURE_TTS_LOG_TAG, __VA_ARGS__) diff --git a/agents/ten_packages/extension/azure_tts/src/main.cc b/agents/ten_packages/extension/azure_tts/src/main.cc index 272fc47d..aaec9fd2 100644 --- a/agents/ten_packages/extension/azure_tts/src/main.cc +++ b/agents/ten_packages/extension/azure_tts/src/main.cc @@ -12,29 +12,29 @@ #include #include "log.h" -#include "macro/check.h" -#include "rte_runtime/binding/cpp/rte.h" +#include "ten_runtime/binding/cpp/ten.h" +#include "ten_utils/macro/check.h" #include "tts.h" namespace azure_tts_extension { -class azure_tts_extension_t : public rte::extension_t { +class azure_tts_extension_t : public ten::extension_t { public: explicit azure_tts_extension_t(const std::string &name) : extension_t(name) {} - // on_start will be called when the extension is starting, + // on_start will be called when the extension is starting, // properies can be read here to initialize and start the extension. - // current supported properties: + // current supported properties: // - azure_subscription_key // - azure_subscription_region // - azure_synthesis_voice_name - void on_start(rte::rte_env_t &rte) override { + void on_start(ten::ten_env_t &ten) override { AZURE_TTS_LOGI("start"); // read properties - auto key = rte.get_property_string("azure_subscription_key"); - auto region = rte.get_property_string("azure_subscription_region"); - auto voice_name = rte.get_property_string("azure_synthesis_voice_name"); + auto key = ten.get_property_string("azure_subscription_key"); + auto region = ten.get_property_string("azure_subscription_region"); + auto voice_name = ten.get_property_string("azure_synthesis_voice_name"); if (key.empty() || region.empty() || voice_name.empty()) { AZURE_TTS_LOGE( "azure_subscription_key, azure_subscription_region, azure_synthesis_voice_name should not be empty, start " @@ -42,8 +42,8 @@ class azure_tts_extension_t : public rte::extension_t { return; } - rte_proxy_ = std::unique_ptr(rte::rte_env_proxy_t::create(rte)); - RTE_ASSERT(rte_proxy_ != nullptr, "rte_proxy should not be nullptr"); + ten_proxy_ = std::unique_ptr(ten::ten_env_proxy_t::create(ten)); + TEN_ASSERT(ten_proxy_ != nullptr, "ten_proxy should not be nullptr"); // pcm parameters auto sample_rate = 16000; @@ -54,19 +54,19 @@ class azure_tts_extension_t : public rte::extension_t { // initialize the callback to send pcm to RTC extension auto pcm_callback = - [rte_proxy = rte_proxy_.get(), sample_rate, bytes_per_sample, samples_per_10ms, channel, pcm_frame_size]( + [ten_proxy = ten_proxy_.get(), sample_rate, bytes_per_sample, samples_per_10ms, channel, pcm_frame_size]( const uint8_t *data, size_t size) { - auto pcm_frame = rte::pcm_frame_t::create("pcm_frame"); + auto pcm_frame = ten::audio_frame_t::create("pcm_frame"); pcm_frame->set_bytes_per_sample(bytes_per_sample); pcm_frame->set_sample_rate(sample_rate); pcm_frame->set_channel_layout(1); pcm_frame->set_number_of_channels(channel); pcm_frame->set_timestamp(0); - pcm_frame->set_data_fmt(RTE_PCM_FRAME_DATA_FMT_INTERLEAVE); + pcm_frame->set_data_fmt(TEN_AUDIO_FRAME_DATA_FMT_INTERLEAVE); pcm_frame->set_samples_per_channel(samples_per_10ms); pcm_frame->alloc_buf(pcm_frame_size); - rte::buf_t borrowed_buf = pcm_frame->lock_buf(0); + ten::buf_t borrowed_buf = pcm_frame->lock_buf(0); auto *buf = borrowed_buf.data(); if (buf != nullptr) { memset(buf, 0, pcm_frame_size); // fill empty if size is not enough for 10ms @@ -74,12 +74,11 @@ class azure_tts_extension_t : public rte::extension_t { } pcm_frame->unlock_buf(borrowed_buf); - auto pcm_frame_shared = std::make_shared>(std::move(pcm_frame)); - rte_proxy->notify( - [frame = std::move(pcm_frame_shared)](rte::rte_env_t &rte) { rte.send_pcm_frame(std::move(*frame)); }); + auto pcm_frame_shared = std::make_shared>(std::move(pcm_frame)); + ten_proxy->notify( + [frame = std::move(pcm_frame_shared)](ten::ten_env_t &ten) { ten.send_audio_frame(std::move(*frame)); }); }; - // initialize Azure TTS azure_tts_ = std::make_unique( key, @@ -88,21 +87,20 @@ class azure_tts_extension_t : public rte::extension_t { Microsoft::CognitiveServices::Speech::SpeechSynthesisOutputFormat::Raw16Khz16BitMonoPcm, pcm_frame_size, std::move(pcm_callback)); - RTE_ASSERT(azure_tts_ != nullptr, "azure_tts should not be nullptr"); + TEN_ASSERT(azure_tts_ != nullptr, "azure_tts should not be nullptr"); azure_tts_->Start(); - rte.on_start_done(); + ten.on_start_done(); AZURE_TTS_LOGI("start done"); } - // on_cmd receives cmd from rte graph. + // on_cmd receives cmd from ten graph. // current supported cmd: // - name: flush // example: // {"name": "flush"} - void on_cmd(rte::rte_env_t &rte, std::unique_ptr cmd) override { - + void on_cmd(ten::ten_env_t &ten, std::unique_ptr cmd) override { std::string command = cmd->get_name(); AZURE_TTS_LOGI("%s", command.c_str()); @@ -111,25 +109,24 @@ class azure_tts_extension_t : public rte::extension_t { azure_tts_->Flush(); // passthrough cmd - auto ret = rte.send_cmd(rte::cmd_t::create(kCmdNameFlush.c_str())); + auto ret = ten.send_cmd(ten::cmd_t::create(kCmdNameFlush.c_str())); if (!ret) { AZURE_TTS_LOGE("Failed to send cmd %s", kCmdNameFlush.c_str()); - rte.return_result(rte::cmd_result_t::create(RTE_STATUS_CODE_ERROR), std::move(cmd)); + ten.return_result(ten::cmd_result_t::create(TEN_STATUS_CODE_ERROR), std::move(cmd)); } else { - rte.return_result(rte::cmd_result_t::create(RTE_STATUS_CODE_OK), std::move(cmd)); + ten.return_result(ten::cmd_result_t::create(TEN_STATUS_CODE_OK), std::move(cmd)); } } else { - rte.return_result(rte::cmd_result_t::create(RTE_STATUS_CODE_OK), std::move(cmd)); + ten.return_result(ten::cmd_result_t::create(TEN_STATUS_CODE_OK), std::move(cmd)); } } - // on_data receives data from rte graph. + // on_data receives data from ten graph. // current supported data: // - name: text_data // example: // {"name": "text_data", "properties": {"text": "hello"} - void on_data(rte::rte_env_t &rte, std::unique_ptr data) override { - + void on_data(ten::ten_env_t &ten, std::unique_ptr data) override { auto text = data->get_property_string(kDataFieldText.c_str()); if (text.empty()) { AZURE_TTS_LOGD("input text is empty, ignored"); @@ -142,21 +139,21 @@ class azure_tts_extension_t : public rte::extension_t { } // on_stop will be called when the extension is stopping. - void on_stop(rte::rte_env_t &rte) override { + void on_stop(ten::ten_env_t &ten) override { AZURE_TTS_LOGI("stop"); if (azure_tts_) { azure_tts_->Stop(); azure_tts_ = nullptr; } - rte_proxy_.reset(); + ten_proxy_.reset(); // Extension stop. - rte.on_stop_done(); + ten.on_stop_done(); AZURE_TTS_LOGI("stop done"); } private: - std::unique_ptr rte_proxy_; + std::unique_ptr ten_proxy_; std::unique_ptr azure_tts_; @@ -164,6 +161,6 @@ class azure_tts_extension_t : public rte::extension_t { const std::string kDataFieldText{"text"}; }; -RTE_CPP_REGISTER_ADDON_AS_EXTENSION(azure_tts, azure_tts_extension_t); +TEN_CPP_REGISTER_ADDON_AS_EXTENSION(azure_tts, azure_tts_extension_t); } // namespace azure_tts_extension From 1a3a2f6f7d41fbbd16b889ebc96476da1d84d2c2 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 10:10:15 +0000 Subject: [PATCH 04/25] fix: --- agents/go.mod | 4 +- agents/main.go | 18 ++-- agents/manifest-lock.json | 3 +- .../extension/chat_transcriber/extension.go | 25 +++--- .../extension/chat_transcriber/go.mod | 6 +- .../elevenlabs_tts_extension.go | 68 +++++++-------- .../extension/elevenlabs_tts/go.mod | 6 +- .../extension/elevenlabs_tts/pcm.go | 12 +-- .../extension/interrupt_detector/extension.go | 20 ++--- .../extension/interrupt_detector/go.mod | 8 +- .../extension/openai_chatgpt/go.mod | 6 +- .../openai_chatgpt_extension.go | 83 ++++++++++--------- 12 files changed, 130 insertions(+), 129 deletions(-) diff --git a/agents/go.mod b/agents/go.mod index 4abb8d95..b5fa6db0 100644 --- a/agents/go.mod +++ b/agents/go.mod @@ -2,6 +2,6 @@ module app go 1.20 -replace agora.io/rte => ./interface +replace ten_framework => ./ten_packages/system/ten_runtime_go/interface -require agora.io/rte v0.0.0-00010101000000-000000000000 +require ten_framework v0.0.0-00010101000000-000000000000 diff --git a/agents/main.go b/agents/main.go index 97b9ef1d..360ec2b4 100644 --- a/agents/main.go +++ b/agents/main.go @@ -11,7 +11,7 @@ import ( "flag" "log" - "agora.io/rte/rte" + "ten_framework/ten" ) type appConfig struct { @@ -19,25 +19,25 @@ type appConfig struct { } type defaultApp struct { - rte.DefaultApp + ten.DefaultApp cfg *appConfig } func (p *defaultApp) OnInit( - rteEnv rte.RteEnv, - property rte.MetadataInfo, + tenEnv ten.TenEnv, ) { // Using the default property.json if not specified. if len(p.cfg.PropertyFilePath) > 0 { - property.Set(rte.MetadataTypeJSONFileName, p.cfg.PropertyFilePath) + // TODO: fix init property + // property.Set(ten.MetadataTypeJSONFileName, p.cfg.PropertyFilePath) } - rteEnv.OnInitDone(property) + tenEnv.OnInitDone() } func startAppBlocking(cfg *appConfig) { - appInstance, err := rte.NewApp(&defaultApp{ + appInstance, err := ten.NewApp(&defaultApp{ cfg: cfg, }) if err != nil { @@ -46,9 +46,9 @@ func startAppBlocking(cfg *appConfig) { appInstance.Run(true) appInstance.Wait() - rte.UnloadAllAddons() + ten.UnloadAllAddons() - rte.EnsureCleanupWhenProcessExit() + ten.EnsureCleanupWhenProcessExit() } func setDefaultLog() { diff --git a/agents/manifest-lock.json b/agents/manifest-lock.json index 778ec8c4..ad0bdce3 100644 --- a/agents/manifest-lock.json +++ b/agents/manifest-lock.json @@ -144,8 +144,7 @@ "type": "system", "name": "nlohmann_json", "version": "3.11.2", - "hash": "72b15822c7ea9deef5e7ad96216ac55e93f11b00466dd1943afd5ee276e99d19", - "supports": [] + "hash": "72b15822c7ea9deef5e7ad96216ac55e93f11b00466dd1943afd5ee276e99d19" }, { "type": "system", diff --git a/agents/ten_packages/extension/chat_transcriber/extension.go b/agents/ten_packages/extension/chat_transcriber/extension.go index d684e7c6..db37a314 100644 --- a/agents/ten_packages/extension/chat_transcriber/extension.go +++ b/agents/ten_packages/extension/chat_transcriber/extension.go @@ -13,7 +13,8 @@ import ( "log/slog" "time" - "agora.io/rte/rte" + "ten_framework/ten" + "google.golang.org/protobuf/proto" ) @@ -29,25 +30,25 @@ var ( ) type chatTranscriberExtension struct { - rte.DefaultExtension + ten.DefaultExtension cachedTextMap map[uint32]string // record the cached text data for each stream id } -func newExtension(name string) rte.Extension { +func newExtension(name string) ten.Extension { return &chatTranscriberExtension{ cachedTextMap: make(map[uint32]string), } } -// OnData receives data from rte graph. -// current supported data: +// OnData receives data from ten graph. +// current suppotend data: // - name: text_data // example: // {"name": "text_data", "properties": {"text": "hello", "is_final": true, "stream_id": 123, "end_of_segment": true}} func (p *chatTranscriberExtension) OnData( - rteEnv rte.RteEnv, - data rte.Data, + tenEnv ten.TenEnv, + data ten.Data, ) { // Get the text data from data. text, err := data.GetPropertyString(textDataTextField) @@ -126,22 +127,22 @@ func (p *chatTranscriberExtension) OnData( } // convert the origin text data to the protobuf data and send it to the graph. - rteData, err := rte.NewData("data") - rteData.SetPropertyBytes("data", pbData) + tenData, err := ten.NewData("data") + tenData.SetPropertyBytes("data", pbData) if err != nil { slog.Warn(fmt.Sprintf("OnData NewData error: %v", err), logTag) return } - rteEnv.SendData(rteData) + tenEnv.SendData(tenData) } func init() { slog.Info("chat_transcriber extension init", logTag) // Register addon - rte.RegisterAddonAsExtension( + ten.RegisterAddonAsExtension( "chat_transcriber", - rte.NewDefaultExtensionAddon(newExtension), + ten.NewDefaultExtensionAddon(newExtension), ) } diff --git a/agents/ten_packages/extension/chat_transcriber/go.mod b/agents/ten_packages/extension/chat_transcriber/go.mod index 311ff8aa..6643f21e 100644 --- a/agents/ten_packages/extension/chat_transcriber/go.mod +++ b/agents/ten_packages/extension/chat_transcriber/go.mod @@ -1,10 +1,10 @@ module chat_transcriber -go 1.18 +go 1.20 -replace agora.io/rte => ../../../interface +replace ten_framework => ../../system/ten_runtime_go/interface require ( - agora.io/rte v0.0.0-00010101000000-000000000000 google.golang.org/protobuf v1.34.2 + ten_framework v0.0.0-00010101000000-000000000000 ) diff --git a/agents/ten_packages/extension/elevenlabs_tts/elevenlabs_tts_extension.go b/agents/ten_packages/extension/elevenlabs_tts/elevenlabs_tts_extension.go index 16e64321..d4d4d305 100644 --- a/agents/ten_packages/extension/elevenlabs_tts/elevenlabs_tts_extension.go +++ b/agents/ten_packages/extension/elevenlabs_tts/elevenlabs_tts_extension.go @@ -18,7 +18,7 @@ import ( "sync/atomic" "time" - "agora.io/rte/rte" + "ten_framework/ten" ) const ( @@ -50,7 +50,7 @@ var ( ) type elevenlabsTTSExtension struct { - rte.DefaultExtension + ten.DefaultExtension elevenlabsTTS *elevenlabsTTS } @@ -59,7 +59,7 @@ type message struct { receivedTs int64 } -func newElevenlabsTTSExtension(name string) rte.Extension { +func newElevenlabsTTSExtension(name string) ten.Extension { return &elevenlabsTTSExtension{} } @@ -75,20 +75,20 @@ func newElevenlabsTTSExtension(name string) rte.Extension { // - stability // - style // - voice_id -func (e *elevenlabsTTSExtension) OnStart(rte rte.RteEnv) { +func (e *elevenlabsTTSExtension) OnStart(ten ten.TenEnv) { slog.Info("OnStart", logTag) // prepare configuration elevenlabsTTSConfig := defaultElevenlabsTTSConfig() - if apiKey, err := rte.GetPropertyString(propertyApiKey); err != nil { + if apiKey, err := ten.GetPropertyString(propertyApiKey); err != nil { slog.Error(fmt.Sprintf("GetProperty required %s failed, err: %v", propertyApiKey, err), logTag) return } else { elevenlabsTTSConfig.ApiKey = apiKey } - if modelId, err := rte.GetPropertyString(propertyModelId); err != nil { + if modelId, err := ten.GetPropertyString(propertyModelId); err != nil { slog.Warn(fmt.Sprintf("GetProperty optional %s failed, err: %v", propertyModelId, err), logTag) } else { if len(modelId) > 0 { @@ -96,7 +96,7 @@ func (e *elevenlabsTTSExtension) OnStart(rte rte.RteEnv) { } } - if optimizeStreamingLatency, err := rte.GetPropertyInt64(propertyOptimizeStreamingLatency); err != nil { + if optimizeStreamingLatency, err := ten.GetPropertyInt64(propertyOptimizeStreamingLatency); err != nil { slog.Warn(fmt.Sprintf("GetProperty optional %s failed, err: %v", propertyOptimizeStreamingLatency, err), logTag) } else { if optimizeStreamingLatency > 0 { @@ -104,7 +104,7 @@ func (e *elevenlabsTTSExtension) OnStart(rte rte.RteEnv) { } } - if requestTimeoutSeconds, err := rte.GetPropertyInt64(propertyRequestTimeoutSeconds); err != nil { + if requestTimeoutSeconds, err := ten.GetPropertyInt64(propertyRequestTimeoutSeconds); err != nil { slog.Warn(fmt.Sprintf("GetProperty optional %s failed, err: %v", propertyRequestTimeoutSeconds, err), logTag) } else { if requestTimeoutSeconds > 0 { @@ -112,31 +112,31 @@ func (e *elevenlabsTTSExtension) OnStart(rte rte.RteEnv) { } } - if similarityBoost, err := rte.GetPropertyFloat64(propertySimilarityBoost); err != nil { + if similarityBoost, err := ten.GetPropertyFloat64(propertySimilarityBoost); err != nil { slog.Warn(fmt.Sprintf("GetProperty optional %s failed, err: %v", propertySimilarityBoost, err), logTag) } else { elevenlabsTTSConfig.SimilarityBoost = float32(similarityBoost) } - if speakerBoost, err := rte.GetPropertyBool(propertySpeakerBoost); err != nil { + if speakerBoost, err := ten.GetPropertyBool(propertySpeakerBoost); err != nil { slog.Warn(fmt.Sprintf("GetProperty optional %s failed, err: %v", propertySpeakerBoost, err), logTag) } else { elevenlabsTTSConfig.SpeakerBoost = speakerBoost } - if stability, err := rte.GetPropertyFloat64(propertyStability); err != nil { + if stability, err := ten.GetPropertyFloat64(propertyStability); err != nil { slog.Warn(fmt.Sprintf("GetProperty optional %s failed, err: %v", propertyStability, err), logTag) } else { elevenlabsTTSConfig.Stability = float32(stability) } - if style, err := rte.GetPropertyFloat64(propertyStyle); err != nil { + if style, err := ten.GetPropertyFloat64(propertyStyle); err != nil { slog.Warn(fmt.Sprintf("GetProperty optional %s failed, err: %v", propertyStyle, err), logTag) } else { elevenlabsTTSConfig.Style = float32(style) } - if voiceId, err := rte.GetPropertyString(propertyVoiceId); err != nil { + if voiceId, err := ten.GetPropertyString(propertyVoiceId); err != nil { slog.Warn(fmt.Sprintf("GetProperty optional %s failed, err: %v", propertyVoiceId, err), logTag) } else { if len(voiceId) > 0 { @@ -231,7 +231,7 @@ func (e *elevenlabsTTSExtension) OnStart(rte rte.RteEnv) { continue } - pcm.send(rte, buf) + pcm.send(ten, buf) // clear buf buf = pcm.newBuf() pcmFrameRead = 0 @@ -246,7 +246,7 @@ func (e *elevenlabsTTSExtension) OnStart(rte rte.RteEnv) { } if pcmFrameRead > 0 { - pcm.send(rte, buf) + pcm.send(ten, buf) sentFrames++ slog.Info(fmt.Sprintf("sending pcm remain data, text: [%s], pcmFrameRead: %d", msg.text, pcmFrameRead), logTag) } @@ -257,23 +257,23 @@ func (e *elevenlabsTTSExtension) OnStart(rte rte.RteEnv) { } }() - rte.OnStartDone() + ten.OnStartDone() } -// OnCmd receives cmd from rte graph. +// OnCmd receives cmd from ten graph. // current supported cmd: // - name: flush // example: // {"name": "flush"} func (e *elevenlabsTTSExtension) OnCmd( - rteEnv rte.RteEnv, - cmd rte.Cmd, + tenEnv ten.TenEnv, + cmd ten.Cmd, ) { cmdName, err := cmd.GetName() if err != nil { slog.Error(fmt.Sprintf("OnCmd get name failed, err: %v", err), logTag) - cmdResult, _ := rte.NewCmdResult(rte.StatusCodeError) - rteEnv.ReturnResult(cmdResult, cmd) + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) + tenEnv.ReturnResult(cmdResult, cmd) return } @@ -284,36 +284,36 @@ func (e *elevenlabsTTSExtension) OnCmd( outdateTs.Store(time.Now().UnixMicro()) // send out - outCmd, err := rte.NewCmd(cmdOutFlush) + outCmd, err := ten.NewCmd(cmdOutFlush) if err != nil { slog.Error(fmt.Sprintf("new cmd %s failed, err: %v", cmdOutFlush, err), logTag) - cmdResult, _ := rte.NewCmdResult(rte.StatusCodeError) - rteEnv.ReturnResult(cmdResult, cmd) + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) + tenEnv.ReturnResult(cmdResult, cmd) return } - if err := rteEnv.SendCmd(outCmd, nil); err != nil { + if err := tenEnv.SendCmd(outCmd, nil); err != nil { slog.Error(fmt.Sprintf("send cmd %s failed, err: %v", cmdOutFlush, err), logTag) - cmdResult, _ := rte.NewCmdResult(rte.StatusCodeError) - rteEnv.ReturnResult(cmdResult, cmd) + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) + tenEnv.ReturnResult(cmdResult, cmd) return } else { slog.Info(fmt.Sprintf("cmd %s sent", cmdOutFlush), logTag) } } - cmdResult, _ := rte.NewCmdResult(rte.StatusCodeOk) - rteEnv.ReturnResult(cmdResult, cmd) + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) + tenEnv.ReturnResult(cmdResult, cmd) } -// OnData receives data from rte graph. +// OnData receives data from ten graph. // current supported data: // - name: text_data // example: // {name: text_data, properties: {text: "hello"} func (e *elevenlabsTTSExtension) OnData( - rteEnv rte.RteEnv, - data rte.Data, + tenEnv ten.TenEnv, + data ten.Data, ) { text, err := data.GetPropertyString(dataInTextDataPropertyText) if err != nil { @@ -337,8 +337,8 @@ func init() { slog.Info("elevenlabs_tts extension init", logTag) // Register addon - rte.RegisterAddonAsExtension( + ten.RegisterAddonAsExtension( "elevenlabs_tts", - rte.NewDefaultExtensionAddon(newElevenlabsTTSExtension), + ten.NewDefaultExtensionAddon(newElevenlabsTTSExtension), ) } diff --git a/agents/ten_packages/extension/elevenlabs_tts/go.mod b/agents/ten_packages/extension/elevenlabs_tts/go.mod index bb90f1c6..04de2ed5 100644 --- a/agents/ten_packages/extension/elevenlabs_tts/go.mod +++ b/agents/ten_packages/extension/elevenlabs_tts/go.mod @@ -1,10 +1,10 @@ module elevenlabs_tts -go 1.21 +go 1.20 -replace agora.io/rte => ../../../interface +replace ten_framework => ../../system/ten_runtime_go/interface require ( - agora.io/rte v0.0.0-00010101000000-000000000000 github.com/haguro/elevenlabs-go v0.2.4 + ten_framework v0.0.0-00010101000000-000000000000 ) diff --git a/agents/ten_packages/extension/elevenlabs_tts/pcm.go b/agents/ten_packages/extension/elevenlabs_tts/pcm.go index c135d9d4..f5e248a3 100644 --- a/agents/ten_packages/extension/elevenlabs_tts/pcm.go +++ b/agents/ten_packages/extension/elevenlabs_tts/pcm.go @@ -14,7 +14,7 @@ import ( "fmt" "log/slog" - "agora.io/rte/rte" + "ten_framework/ten" ) type pcm struct { @@ -49,8 +49,8 @@ func newPcm(config *pcmConfig) *pcm { } } -func (p *pcm) getPcmFrame(buf []byte) (pcmFrame rte.PcmFrame, err error) { - pcmFrame, err = rte.NewPcmFrame(p.config.Name) +func (p *pcm) getPcmFrame(buf []byte) (pcmFrame ten.AudioFrame, err error) { + pcmFrame, err = ten.NewAudioFrame(p.config.Name) if err != nil { slog.Error(fmt.Sprintf("NewPcmFrame failed, err: %v", err), logTag) return @@ -62,7 +62,7 @@ func (p *pcm) getPcmFrame(buf []byte) (pcmFrame rte.PcmFrame, err error) { pcmFrame.SetChannelLayout(p.config.ChannelLayout) pcmFrame.SetNumberOfChannels(p.config.Channel) pcmFrame.SetTimestamp(p.config.Timestamp) - pcmFrame.SetDataFmt(rte.PcmFrameDataFmtInterleave) + pcmFrame.SetDataFmt(ten.AudioFrameDataFmtInterleave) pcmFrame.SetSamplesPerChannel(p.config.SamplesPerChannel) pcmFrame.AllocBuf(p.getPcmFrameSize()) @@ -87,7 +87,7 @@ func (p *pcm) newBuf() []byte { return make([]byte, p.getPcmFrameSize()) } -func (p *pcm) send(rteEnv rte.RteEnv, buf []byte) (err error) { +func (p *pcm) send(tenEnv ten.TenEnv, buf []byte) (err error) { pcmFrame, err := p.getPcmFrame(buf) if err != nil { slog.Error(fmt.Sprintf("getPcmFrame failed, err: %v", err), logTag) @@ -95,7 +95,7 @@ func (p *pcm) send(rteEnv rte.RteEnv, buf []byte) (err error) { } // send pcm - if err = rteEnv.SendPcmFrame(pcmFrame); err != nil { + if err = tenEnv.SendAudioFrame(pcmFrame); err != nil { slog.Error(fmt.Sprintf("SendPcmFrame failed, err: %v", err), logTag) return } diff --git a/agents/ten_packages/extension/interrupt_detector/extension.go b/agents/ten_packages/extension/interrupt_detector/extension.go index 8fdc201b..4a3d4002 100644 --- a/agents/ten_packages/extension/interrupt_detector/extension.go +++ b/agents/ten_packages/extension/interrupt_detector/extension.go @@ -14,7 +14,7 @@ import ( "fmt" "log/slog" - "agora.io/rte/rte" + "ten_framework/ten" ) const ( @@ -29,21 +29,21 @@ var ( ) type interruptDetectorExtension struct { - rte.DefaultExtension + ten.DefaultExtension } -func newExtension(name string) rte.Extension { +func newExtension(name string) ten.Extension { return &interruptDetectorExtension{} } -// OnData receives data from rte graph. +// OnData receives data from ten graph. // current supported data: // - name: text_data // example: // {name: text_data, properties: {text: "hello", is_final: false} func (p *interruptDetectorExtension) OnData( - rteEnv rte.RteEnv, - data rte.Data, + tenEnv ten.TenEnv, + data ten.Data, ) { text, err := data.GetPropertyString(textDataTextField) if err != nil { @@ -60,8 +60,8 @@ func (p *interruptDetectorExtension) OnData( slog.Debug(fmt.Sprintf("OnData %s: %s %s: %t", textDataTextField, text, textDataFinalField, final), logTag) if final || len(text) >= 2 { - flushCmd, _ := rte.NewCmd(cmdNameFlush) - rteEnv.SendCmd(flushCmd, nil) + flushCmd, _ := ten.NewCmd(cmdNameFlush) + tenEnv.SendCmd(flushCmd, nil) slog.Info(fmt.Sprintf("sent cmd: %s", cmdNameFlush), logTag) } @@ -71,8 +71,8 @@ func init() { slog.Info("interrupt_detector extension init", logTag) // Register addon - rte.RegisterAddonAsExtension( + ten.RegisterAddonAsExtension( "interrupt_detector", - rte.NewDefaultExtensionAddon(newExtension), + ten.NewDefaultExtensionAddon(newExtension), ) } diff --git a/agents/ten_packages/extension/interrupt_detector/go.mod b/agents/ten_packages/extension/interrupt_detector/go.mod index bced26e0..4f384c29 100644 --- a/agents/ten_packages/extension/interrupt_detector/go.mod +++ b/agents/ten_packages/extension/interrupt_detector/go.mod @@ -1,7 +1,7 @@ -module extension +module interrupt_detector -go 1.18 +go 1.20 -replace agora.io/rte => ../../../interface +replace ten_framework => ../../system/ten_runtime_go/interface -require agora.io/rte v0.0.0-00010101000000-000000000000 +require ten_framework v0.0.0-00010101000000-000000000000 diff --git a/agents/ten_packages/extension/openai_chatgpt/go.mod b/agents/ten_packages/extension/openai_chatgpt/go.mod index 5bb6b52b..02a09856 100644 --- a/agents/ten_packages/extension/openai_chatgpt/go.mod +++ b/agents/ten_packages/extension/openai_chatgpt/go.mod @@ -1,13 +1,13 @@ module openai_chatgpt -go 1.21 +go 1.20 -replace agora.io/rte => ../../../interface +replace ten_framework => ../../system/ten_runtime_go/interface require ( - agora.io/rte v0.0.0-00010101000000-000000000000 github.com/sashabaranov/go-openai v1.24.1 github.com/stretchr/testify v1.9.0 + ten_framework v0.0.0-00010101000000-000000000000 ) require ( diff --git a/agents/ten_packages/extension/openai_chatgpt/openai_chatgpt_extension.go b/agents/ten_packages/extension/openai_chatgpt/openai_chatgpt_extension.go index 34534a91..2a1cd294 100644 --- a/agents/ten_packages/extension/openai_chatgpt/openai_chatgpt_extension.go +++ b/agents/ten_packages/extension/openai_chatgpt/openai_chatgpt_extension.go @@ -19,7 +19,8 @@ import ( "sync/atomic" "time" - "agora.io/rte/rte" + "ten_framework/ten" + openai "github.com/sashabaranov/go-openai" ) @@ -28,7 +29,7 @@ var ( ) type openaiChatGPTExtension struct { - rte.DefaultExtension + ten.DefaultExtension openaiChatGPT *openaiChatGPT } @@ -63,7 +64,7 @@ var ( wg sync.WaitGroup ) -func newChatGPTExtension(name string) rte.Extension { +func newChatGPTExtension(name string) ten.Extension { return &openaiChatGPTExtension{} } @@ -80,13 +81,13 @@ func newChatGPTExtension(name string) rte.Extension { // - max_tokens // - greeting // - proxy_url -func (p *openaiChatGPTExtension) OnStart(rteEnv rte.RteEnv) { +func (p *openaiChatGPTExtension) OnStart(tenEnv ten.TenEnv) { slog.Info("OnStart", logTag) // prepare configuration openaiChatGPTConfig := defaultOpenaiChatGPTConfig() - if baseUrl, err := rteEnv.GetPropertyString(propertyBaseUrl); err != nil { + if baseUrl, err := tenEnv.GetPropertyString(propertyBaseUrl); err != nil { slog.Error(fmt.Sprintf("GetProperty required %s failed, err: %v", propertyBaseUrl, err), logTag) } else { if len(baseUrl) > 0 { @@ -94,14 +95,14 @@ func (p *openaiChatGPTExtension) OnStart(rteEnv rte.RteEnv) { } } - if apiKey, err := rteEnv.GetPropertyString(propertyApiKey); err != nil { + if apiKey, err := tenEnv.GetPropertyString(propertyApiKey); err != nil { slog.Error(fmt.Sprintf("GetProperty required %s failed, err: %v", propertyApiKey, err), logTag) return } else { openaiChatGPTConfig.ApiKey = apiKey } - if model, err := rteEnv.GetPropertyString(propertyModel); err != nil { + if model, err := tenEnv.GetPropertyString(propertyModel); err != nil { slog.Warn(fmt.Sprintf("GetProperty optional %s error:%v", propertyModel, err), logTag) } else { if len(model) > 0 { @@ -109,7 +110,7 @@ func (p *openaiChatGPTExtension) OnStart(rteEnv rte.RteEnv) { } } - if prompt, err := rteEnv.GetPropertyString(propertyPrompt); err != nil { + if prompt, err := tenEnv.GetPropertyString(propertyPrompt); err != nil { slog.Warn(fmt.Sprintf("GetProperty optional %s error:%v", propertyPrompt, err), logTag) } else { if len(prompt) > 0 { @@ -117,31 +118,31 @@ func (p *openaiChatGPTExtension) OnStart(rteEnv rte.RteEnv) { } } - if frequencyPenalty, err := rteEnv.GetPropertyFloat64(propertyFrequencyPenalty); err != nil { + if frequencyPenalty, err := tenEnv.GetPropertyFloat64(propertyFrequencyPenalty); err != nil { slog.Warn(fmt.Sprintf("GetProperty optional %s failed, err: %v", propertyFrequencyPenalty, err), logTag) } else { openaiChatGPTConfig.FrequencyPenalty = float32(frequencyPenalty) } - if presencePenalty, err := rteEnv.GetPropertyFloat64(propertyPresencePenalty); err != nil { + if presencePenalty, err := tenEnv.GetPropertyFloat64(propertyPresencePenalty); err != nil { slog.Warn(fmt.Sprintf("GetProperty optional %s failed, err: %v", propertyPresencePenalty, err), logTag) } else { openaiChatGPTConfig.PresencePenalty = float32(presencePenalty) } - if temperature, err := rteEnv.GetPropertyFloat64(propertyTemperature); err != nil { + if temperature, err := tenEnv.GetPropertyFloat64(propertyTemperature); err != nil { slog.Warn(fmt.Sprintf("GetProperty optional %s failed, err: %v", propertyTemperature, err), logTag) } else { openaiChatGPTConfig.Temperature = float32(temperature) } - if topP, err := rteEnv.GetPropertyFloat64(propertyTopP); err != nil { + if topP, err := tenEnv.GetPropertyFloat64(propertyTopP); err != nil { slog.Warn(fmt.Sprintf("GetProperty optional %s failed, err: %v", propertyTopP, err), logTag) } else { openaiChatGPTConfig.TopP = float32(topP) } - if maxTokens, err := rteEnv.GetPropertyInt64(propertyMaxTokens); err != nil { + if maxTokens, err := tenEnv.GetPropertyInt64(propertyMaxTokens); err != nil { slog.Warn(fmt.Sprintf("GetProperty optional %s failed, err: %v", propertyMaxTokens, err), logTag) } else { if maxTokens > 0 { @@ -149,18 +150,18 @@ func (p *openaiChatGPTExtension) OnStart(rteEnv rte.RteEnv) { } } - if proxyUrl, err := rteEnv.GetPropertyString(propertyProxyUrl); err != nil { + if proxyUrl, err := tenEnv.GetPropertyString(propertyProxyUrl); err != nil { slog.Warn(fmt.Sprintf("GetProperty optional %s failed, err: %v", propertyProxyUrl, err), logTag) } else { openaiChatGPTConfig.ProxyUrl = proxyUrl } - greeting, err := rteEnv.GetPropertyString(propertyGreeting) + greeting, err := tenEnv.GetPropertyString(propertyGreeting) if err != nil { slog.Warn(fmt.Sprintf("GetProperty optional %s failed, err: %v", propertyGreeting, err), logTag) } - if propMaxMemoryLength, err := rteEnv.GetPropertyInt64(propertyMaxMemoryLength); err != nil { + if propMaxMemoryLength, err := tenEnv.GetPropertyInt64(propertyMaxMemoryLength); err != nil { slog.Warn(fmt.Sprintf("GetProperty optional %s failed, err: %v", propertyMaxMemoryLength, err), logTag) } else { if propMaxMemoryLength > 0 { @@ -183,33 +184,33 @@ func (p *openaiChatGPTExtension) OnStart(rteEnv rte.RteEnv) { // send greeting if available if len(greeting) > 0 { - outputData, _ := rte.NewData("text_data") + outputData, _ := ten.NewData("text_data") outputData.SetProperty(dataOutTextDataPropertyText, greeting) outputData.SetProperty(dataOutTextDataPropertyTextEndOfSegment, true) - if err := rteEnv.SendData(outputData); err != nil { + if err := tenEnv.SendData(outputData); err != nil { slog.Error(fmt.Sprintf("greeting [%s] send failed, err: %v", greeting, err), logTag) } else { slog.Info(fmt.Sprintf("greeting [%s] sent", greeting), logTag) } } - rteEnv.OnStartDone() + tenEnv.OnStartDone() } -// OnCmd receives cmd from rte graph. +// OnCmd receives cmd from ten graph. // current supported cmd: // - name: flush // example: // {"name": "flush"} func (p *openaiChatGPTExtension) OnCmd( - rteEnv rte.RteEnv, - cmd rte.Cmd, + tenEnv ten.TenEnv, + cmd ten.Cmd, ) { cmdName, err := cmd.GetName() if err != nil { slog.Error(fmt.Sprintf("OnCmd get name failed, err: %v", err), logTag) - cmdResult, _ := rte.NewCmdResult(rte.StatusCodeError) - rteEnv.ReturnResult(cmdResult, cmd) + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) + tenEnv.ReturnResult(cmdResult, cmd) return } slog.Info(fmt.Sprintf("OnCmd %s", cmdInFlush), logTag) @@ -221,34 +222,34 @@ func (p *openaiChatGPTExtension) OnCmd( wg.Wait() // wait for chat completion stream to finish // send out - outCmd, err := rte.NewCmd(cmdOutFlush) + outCmd, err := ten.NewCmd(cmdOutFlush) if err != nil { slog.Error(fmt.Sprintf("new cmd %s failed, err: %v", cmdOutFlush, err), logTag) - cmdResult, _ := rte.NewCmdResult(rte.StatusCodeError) - rteEnv.ReturnResult(cmdResult, cmd) + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) + tenEnv.ReturnResult(cmdResult, cmd) return } - if err := rteEnv.SendCmd(outCmd, nil); err != nil { + if err := tenEnv.SendCmd(outCmd, nil); err != nil { slog.Error(fmt.Sprintf("send cmd %s failed, err: %v", cmdOutFlush, err), logTag) - cmdResult, _ := rte.NewCmdResult(rte.StatusCodeError) - rteEnv.ReturnResult(cmdResult, cmd) + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) + tenEnv.ReturnResult(cmdResult, cmd) return } else { slog.Info(fmt.Sprintf("cmd %s sent", cmdOutFlush), logTag) } } - cmdResult, _ := rte.NewCmdResult(rte.StatusCodeOk) - rteEnv.ReturnResult(cmdResult, cmd) + cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) + tenEnv.ReturnResult(cmdResult, cmd) } -// OnData receives data from rte graph. +// OnData receives data from ten graph. // current supported data: // - name: text_data // example: // {"name": "text_data", "properties": {"text": "hello", "is_final": true} func (p *openaiChatGPTExtension) OnData( - rteEnv rte.RteEnv, - data rte.Data, + tenEnv ten.TenEnv, + data ten.Data, ) { // Get isFinal isFinal, err := data.GetPropertyBool(dataInTextDataPropertyIsFinal) @@ -343,14 +344,14 @@ func (p *openaiChatGPTExtension) OnData( slog.Debug(fmt.Sprintf("GetChatCompletionsStream recv for input text: [%s] got sentence: [%s]", inputText, sentence), logTag) // send sentence - outputData, err := rte.NewData("text_data") + outputData, err := ten.NewData("text_data") if err != nil { slog.Error(fmt.Sprintf("NewData failed, err: %v", err), logTag) break } outputData.SetProperty(dataOutTextDataPropertyText, sentence) outputData.SetProperty(dataOutTextDataPropertyTextEndOfSegment, false) - if err := rteEnv.SendData(outputData); err != nil { + if err := tenEnv.SendData(outputData); err != nil { slog.Error(fmt.Sprintf("GetChatCompletionsStream recv for input text: [%s] send sentence [%s] failed, err: %v", inputText, sentence, err), logTag) break } else { @@ -373,10 +374,10 @@ func (p *openaiChatGPTExtension) OnData( } // send end of segment - outputData, _ := rte.NewData("text_data") + outputData, _ := ten.NewData("text_data") outputData.SetProperty(dataOutTextDataPropertyText, sentence) outputData.SetProperty(dataOutTextDataPropertyTextEndOfSegment, true) - if err := rteEnv.SendData(outputData); err != nil { + if err := tenEnv.SendData(outputData); err != nil { slog.Error(fmt.Sprintf("GetChatCompletionsStream for input text: [%s] end of segment with sentence [%s] send failed, err: %v", inputText, sentence, err), logTag) } else { slog.Info(fmt.Sprintf("GetChatCompletionsStream for input text: [%s] end of segment with sentence [%s] sent", inputText, sentence), logTag) @@ -388,8 +389,8 @@ func init() { slog.Info("init") // Register addon - rte.RegisterAddonAsExtension( + ten.RegisterAddonAsExtension( "openai_chatgpt", - rte.NewDefaultExtensionAddon(newChatGPTExtension), + ten.NewDefaultExtensionAddon(newChatGPTExtension), ) } From a4c857043c0f10767b2baf26e13b872f9ed2b499 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 10:14:58 +0000 Subject: [PATCH 05/25] chore: ignore ten --- agents/.gitignore | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/agents/.gitignore b/agents/.gitignore index a1ee1d30..13d45539 100644 --- a/agents/.gitignore +++ b/agents/.gitignore @@ -1,9 +1,9 @@ *.log -addon/extension_group/ -addon/extension/agora_rtc -addon/extension/py_init_extension_cpp -addon/system -.rte +ten_packages/extension_group/ +ten_packages/extension/agora_rtc +ten_packages/extension/py_init_extension_cpp +ten_packages/system +.ten agoradns.dat agorareport.dat bin/ From 55e32809e710a99b5deaeb86e3587be1eb7f51c7 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 11:58:18 +0000 Subject: [PATCH 06/25] feat: upgrade python ext to ten --- agents/main.py | 68 ------ .../bak/litellm_python/litellm_addon.py | 8 +- .../bak/litellm_python/litellm_extension.py | 40 ++-- .../bak/litellm_python/manifest.json | 7 +- .../vector_storage_addon.py | 8 +- .../vector_storage_extension.py | 76 +++---- .../aliyun_text_embedding/embedding_addon.py | 8 +- .../embedding_extension.py | 34 +-- .../bedrock_llm_extension.py | 75 ++++--- .../chat_transcriber_addon.py | 8 +- .../chat_transcriber_extension.py | 28 +-- .../extension/cosy_tts/cosy_tts_addon.py | 8 +- .../extension/cosy_tts/cosy_tts_extension.py | 50 ++--- .../elevenlabs_tts_addon.py | 8 +- .../elevenlabs_tts_extension.py | 48 ++--- .../extension/elevenlabs_tts_python/pcm.py | 12 +- .../file_chunker/file_chunker_addon.py | 8 +- .../file_chunker/file_chunker_extension.py | 48 ++--- .../gemini_llm_python/gemini_llm_addon.py | 8 +- .../gemini_llm_python/gemini_llm_extension.py | 128 ++++++++---- .../http_server_python/http_server_addon.py | 8 +- .../http_server_extension.py | 32 +-- .../interrupt_detector_addon.py | 8 +- .../interrupt_detector_extension.py | 37 ++-- .../llama_index_chat_engine/addon.py | 6 +- .../astra_embedding.py | 10 +- .../llama_index_chat_engine/astra_llm.py | 12 +- .../astra_retriever.py | 14 +- .../llama_index_chat_engine/extension.py | 52 ++--- .../openai_chatgpt_addon.py | 8 +- .../openai_chatgpt_extension.py | 197 ++++++++++-------- .../extension/polly_tts/polly_tts_addon.py | 8 +- .../polly_tts/polly_tts_extension.py | 80 ++++--- .../qwen_llm_python/qwen_llm_addon.py | 8 +- .../qwen_llm_python/qwen_llm_extension.py | 46 ++-- .../transcribe_asr_addon.py | 8 +- .../transcribe_asr_extension.py | 53 +++-- .../transcribe_wrapper.py | 20 +- 38 files changed, 663 insertions(+), 622 deletions(-) delete mode 100644 agents/main.py diff --git a/agents/main.py b/agents/main.py deleted file mode 100644 index 4a4d297c..00000000 --- a/agents/main.py +++ /dev/null @@ -1,68 +0,0 @@ -# -# -# Agora Real Time Engagement -# Created by Wei Hu in 2024-05. -# Copyright (c) 2024 Agora IO. All rights reserved. -# -# -from glob import glob -import importlib.util -import os -import argparse -from os.path import dirname - -def log(msg): - print("[PYTHON] {}".format(msg)) - -def process_args(): - parser = argparse.ArgumentParser( - formatter_class=argparse.ArgumentDefaultsHelpFormatter - ) - parser.add_argument( - "--manifest", help="The absolute path of manifest.json" - ) - return parser.parse_args() - -if __name__ == "__main__": - args = process_args() - - basedir = dirname(__file__) - log("app init") - - for module in glob(os.path.join(basedir, "addon/extension/*")): - if os.path.isdir(module): - module_name = os.path.basename(module) - spec = importlib.util.find_spec( - "addon.extension.{}".format(module_name) - ) - if spec is not None: - mod = importlib.import_module( - "addon.extension.{}".format(module_name) - ) - print("imported module: {}".format(module_name)) - - from rte_runtime_python import App, MetadataType - class TestApp(App): - def on_init(self, rte, manifest, property): - log("app on_init") - - # Using the default manifest.json if not specified. - if self.manifest_path: - log("set manifest: {}".format(self.manifest_path)) - manifest.set(MetadataType.JSON_FILENAME, self.manifest_path) - - rte.on_init_done(manifest, property) - - def on_deinit(self, rte) -> None: - log("app on_deinit") - rte.on_deinit_done() - - def set_manifest_path(self, manifest_path): - self.manifest_path = manifest_path - - app = TestApp() - app.set_manifest_path(args.manifest) - log("app created") - - app.run(False) - log("app run done") diff --git a/agents/ten_packages/bak/litellm_python/litellm_addon.py b/agents/ten_packages/bak/litellm_python/litellm_addon.py index 460ae642..f6f2425f 100644 --- a/agents/ten_packages/bak/litellm_python/litellm_addon.py +++ b/agents/ten_packages/bak/litellm_python/litellm_addon.py @@ -5,10 +5,10 @@ # Copyright (c) 2024 Agora IO. All rights reserved. # # -from rte import ( +from ten import ( Addon, register_addon_as_extension, - RteEnv, + TenEnv, ) from .extension import EXTENSION_NAME from .log import logger @@ -17,7 +17,7 @@ @register_addon_as_extension(EXTENSION_NAME) class LiteLLMExtensionAddon(Addon): - def on_create_instance(self, rte: RteEnv, addon_name: str, context) -> None: + def on_create_instance(self, ten: TenEnv, addon_name: str, context) -> None: logger.info("on_create_instance") - rte.on_create_instance_done(LiteLLMExtension(addon_name), context) + ten.on_create_instance_done(LiteLLMExtension(addon_name), context) diff --git a/agents/ten_packages/bak/litellm_python/litellm_extension.py b/agents/ten_packages/bak/litellm_python/litellm_extension.py index fb007856..1b71389e 100644 --- a/agents/ten_packages/bak/litellm_python/litellm_extension.py +++ b/agents/ten_packages/bak/litellm_python/litellm_extension.py @@ -6,9 +6,9 @@ # # from threading import Thread -from rte import ( +from ten import ( Extension, - RteEnv, + TenEnv, Cmd, Data, StatusCode, @@ -46,14 +46,14 @@ class LiteLLMExtension(Extension): outdate_ts = 0 litellm = None - def on_start(self, rte: RteEnv) -> None: + def on_start(self, ten: TenEnv) -> None: logger.info("LiteLLMExtension on_start") # Prepare configuration litellm_config = LiteLLMConfig.default_config() for key in [PROPERTY_API_KEY, PROPERTY_GREETING, PROPERTY_MODEL, PROPERTY_PROMPT]: try: - val = rte.get_property_string(key) + val = ten.get_property_string(key) if val: litellm_config.key = val except Exception as e: @@ -61,13 +61,13 @@ def on_start(self, rte: RteEnv) -> None: for key in [PROPERTY_FREQUENCY_PENALTY, PROPERTY_PRESENCE_PENALTY, PROPERTY_TEMPERATURE, PROPERTY_TOP_P]: try: - litellm_config.key = float(rte.get_property_float(key)) + litellm_config.key = float(ten.get_property_float(key)) except Exception as e: logger.warning(f"get_property_float optional {key} failed, err: {e}") for key in [PROPERTY_MAX_MEMORY_LENGTH, PROPERTY_MAX_TOKENS]: try: - litellm_config.key = int(rte.get_property_int(key)) + litellm_config.key = int(ten.get_property_int(key)) except Exception as e: logger.warning(f"get_property_int optional {key} failed, err: {e}") @@ -76,24 +76,24 @@ def on_start(self, rte: RteEnv) -> None: logger.info(f"newLiteLLM succeed with max_tokens: {litellm_config.max_tokens}, model: {litellm_config.model}") # Send greeting if available - greeting = rte.get_property_string(PROPERTY_GREETING) + greeting = ten.get_property_string(PROPERTY_GREETING) if greeting: try: output_data = Data.create("text_data") output_data.set_property_string(DATA_OUT_TEXT_DATA_PROPERTY_TEXT, greeting) output_data.set_property_bool(DATA_OUT_TEXT_DATA_PROPERTY_TEXT_END_OF_SEGMENT, True) - rte.send_data(output_data) + ten.send_data(output_data) logger.info(f"greeting [{greeting}] sent") except Exception as e: logger.error(f"greeting [{greeting}] send failed, err: {e}") - rte.on_start_done() + ten.on_start_done() - def on_stop(self, rte: RteEnv) -> None: + def on_stop(self, ten: TenEnv) -> None: logger.info("LiteLLMExtension on_stop") - rte.on_stop_done() + ten.on_stop_done() - def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: + def on_cmd(self, ten: TenEnv, cmd: Cmd) -> None: logger.info("LiteLLMExtension on_cmd") cmd_json = cmd.to_json() logger.info(f"LiteLLMExtension on_cmd json: {cmd_json}") @@ -103,23 +103,23 @@ def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: if cmd_name == CMD_IN_FLUSH: self.outdate_ts = get_micro_ts() cmd_out = Cmd.create(CMD_OUT_FLUSH) - rte.send_cmd(cmd_out, None) + ten.send_cmd(cmd_out, None) logger.info(f"LiteLLMExtension on_cmd sent flush") else: logger.info(f"LiteLLMExtension on_cmd unknown cmd: {cmd_name}") cmd_result = CmdResult.create(StatusCode.ERROR) cmd_result.set_property_string("detail", "unknown cmd") - rte.return_result(cmd_result, cmd) + ten.return_result(cmd_result, cmd) return cmd_result = CmdResult.create(StatusCode.OK) cmd_result.set_property_string("detail", "success") - rte.return_result(cmd_result, cmd) + ten.return_result(cmd_result, cmd) - def on_data(self, rte: RteEnv, data: Data) -> None: + def on_data(self, ten: TenEnv, data: Data) -> None: """ - on_data receives data from rte graph. - current supported data: + on_data receives data from ten graph. + current suppotend data: - name: text_data example: {name: text_data, properties: {text: "hello"} @@ -192,7 +192,7 @@ def chat_completions_stream_worker(start_time, input_text, memory): output_data = Data.create("text_data") output_data.set_property_string(DATA_OUT_TEXT_DATA_PROPERTY_TEXT, sentence) output_data.set_property_bool(DATA_OUT_TEXT_DATA_PROPERTY_TEXT_END_OF_SEGMENT, False) - rte.send_data(output_data) + ten.send_data(output_data) logger.info(f"chat_completions_stream_worker recv for input text: [{input_text}] sent sentence [{sentence}]") except Exception as e: logger.error(f"chat_completions_stream_worker recv for input text: [{input_text}] send sentence [{sentence}] failed, err: {e}") @@ -211,7 +211,7 @@ def chat_completions_stream_worker(start_time, input_text, memory): output_data = Data.create("text_data") output_data.set_property_string(DATA_OUT_TEXT_DATA_PROPERTY_TEXT, sentence) output_data.set_property_bool(DATA_OUT_TEXT_DATA_PROPERTY_TEXT_END_OF_SEGMENT, True) - rte.send_data(output_data) + ten.send_data(output_data) logger.info(f"chat_completions_stream_worker for input text: [{input_text}] end of segment with sentence [{sentence}] sent") except Exception as e: logger.error(f"chat_completions_stream_worker for input text: [{input_text}] end of segment with sentence [{sentence}] send failed, err: {e}") diff --git a/agents/ten_packages/bak/litellm_python/manifest.json b/agents/ten_packages/bak/litellm_python/manifest.json index 16fb4429..cd76096a 100644 --- a/agents/ten_packages/bak/litellm_python/manifest.json +++ b/agents/ten_packages/bak/litellm_python/manifest.json @@ -1,13 +1,12 @@ { "type": "extension", "name": "litellm_python", - "version": "0.1.0", - "language": "python", + "version": "0.4.0", "dependencies": [ { "type": "system", - "name": "rte_runtime_python", - "version": "0.4.0" + "name": "ten_runtime_python", + "version": "0.4" } ], "api": { diff --git a/agents/ten_packages/extension/aliyun_analyticdb_vector_storage/vector_storage_addon.py b/agents/ten_packages/extension/aliyun_analyticdb_vector_storage/vector_storage_addon.py index 6bb26538..fd84df4d 100644 --- a/agents/ten_packages/extension/aliyun_analyticdb_vector_storage/vector_storage_addon.py +++ b/agents/ten_packages/extension/aliyun_analyticdb_vector_storage/vector_storage_addon.py @@ -1,7 +1,7 @@ -from rte import ( +from ten import ( Addon, register_addon_as_extension, - RteEnv, + TenEnv, ) from .log import logger from .vector_storage_extension import AliPGDBExtension @@ -9,6 +9,6 @@ @register_addon_as_extension("aliyun_analyticdb_vector_storage") class AliPGDBExtensionAddon(Addon): - def on_create_instance(self, rte: RteEnv, addon_name: str, context) -> None: + def on_create_instance(self, ten: TenEnv, addon_name: str, context) -> None: logger.info("on_create_instance") - rte.on_create_instance_done(AliPGDBExtension(addon_name), context) + ten.on_create_instance_done(AliPGDBExtension(addon_name), context) diff --git a/agents/ten_packages/extension/aliyun_analyticdb_vector_storage/vector_storage_extension.py b/agents/ten_packages/extension/aliyun_analyticdb_vector_storage/vector_storage_extension.py index c89174a5..65f6f72d 100644 --- a/agents/ten_packages/extension/aliyun_analyticdb_vector_storage/vector_storage_extension.py +++ b/agents/ten_packages/extension/aliyun_analyticdb_vector_storage/vector_storage_extension.py @@ -6,9 +6,9 @@ import json from .client import AliGPDBClient from .model import Model -from rte import ( +from ten import ( Extension, - RteEnv, + TenEnv, Cmd, Data, StatusCode, @@ -43,38 +43,38 @@ def __init__(self, name): self.namespace = os.environ.get("ADBPG_NAMESPACE") self.namespace_password = os.environ.get("ADBPG_NAMESPACE_PASSWORD") - async def __thread_routine(self, rte_env: RteEnv): + async def __thread_routine(self, ten_env: TenEnv): logger.info("__thread_routine start") self.loop = asyncio.get_running_loop() - rte_env.on_start_done() + ten_env.on_start_done() await self.stopEvent.wait() async def stop_thread(self): self.stopEvent.set() - def on_start(self, rte: RteEnv) -> None: + def on_start(self, ten: TenEnv) -> None: logger.info(f"on_start") self.access_key_id = self.get_property_string( - rte, "ALIBABA_CLOUD_ACCESS_KEY_ID", self.access_key_id + ten, "ALIBABA_CLOUD_ACCESS_KEY_ID", self.access_key_id ) self.access_key_secret = self.get_property_string( - rte, "ALIBABA_CLOUD_ACCESS_KEY_SECRET", self.access_key_secret + ten, "ALIBABA_CLOUD_ACCESS_KEY_SECRET", self.access_key_secret ) self.region_id = self.get_property_string( - rte, "ADBPG_INSTANCE_REGION", self.region_id + ten, "ADBPG_INSTANCE_REGION", self.region_id ) self.dbinstance_id = self.get_property_string( - rte, "ADBPG_INSTANCE_ID", self.dbinstance_id + ten, "ADBPG_INSTANCE_ID", self.dbinstance_id ) - self.account = self.get_property_string(rte, "ADBPG_ACCOUNT", self.account) + self.account = self.get_property_string(ten, "ADBPG_ACCOUNT", self.account) self.account_password = self.get_property_string( - rte, "ADBPG_ACCOUNT_PASSWORD", self.account_password + ten, "ADBPG_ACCOUNT_PASSWORD", self.account_password ) self.namespace = self.get_property_string( - rte, "ADBPG_NAMESPACE", self.namespace + ten, "ADBPG_NAMESPACE", self.namespace ) self.namespace_password = self.get_property_string( - rte, "ADBPG_NAMESPACE_PASSWORD", self.namespace_password + ten, "ADBPG_NAMESPACE_PASSWORD", self.namespace_password ) if self.region_id in ( @@ -96,51 +96,51 @@ def on_start(self, rte: RteEnv) -> None: self.access_key_id, self.access_key_secret, self.endpoint ) self.thread = threading.Thread( - target=asyncio.run, args=(self.__thread_routine(rte),) + target=asyncio.run, args=(self.__thread_routine(ten),) ) # Then 'on_start_done' will be called in the thread self.thread.start() return - def on_stop(self, rte: RteEnv) -> None: + def on_stop(self, ten: TenEnv) -> None: logger.info("on_stop") if self.thread is not None and self.thread.is_alive(): asyncio.run_coroutine_threadsafe(self.stop_thread(), self.loop) self.thread.join() self.thread = None - rte.on_stop_done() + ten.on_stop_done() return - def on_data(self, rte: RteEnv, data: Data) -> None: + def on_data(self, ten: TenEnv, data: Data) -> None: pass - def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: + def on_cmd(self, ten: TenEnv, cmd: Cmd) -> None: try: cmd_name = cmd.get_name() logger.info(f"on_cmd [{cmd_name}]") if cmd_name == "create_collection": asyncio.run_coroutine_threadsafe( - self.async_create_collection(rte, cmd), self.loop + self.async_create_collection(ten, cmd), self.loop ) elif cmd_name == "delete_collection": asyncio.run_coroutine_threadsafe( - self.async_delete_collection(rte, cmd), self.loop + self.async_delete_collection(ten, cmd), self.loop ) elif cmd_name == "upsert_vector": asyncio.run_coroutine_threadsafe( - self.async_upsert_vector(rte, cmd), self.loop + self.async_upsert_vector(ten, cmd), self.loop ) elif cmd_name == "query_vector": asyncio.run_coroutine_threadsafe( - self.async_query_vector(rte, cmd), self.loop + self.async_query_vector(ten, cmd), self.loop ) else: - rte.return_result(CmdResult.create(StatusCode.ERROR), cmd) + ten.return_result(CmdResult.create(StatusCode.ERROR), cmd) except Exception as e: - rte.return_result(CmdResult.create(StatusCode.ERROR), cmd) + ten.return_result(CmdResult.create(StatusCode.ERROR), cmd) - async def async_create_collection(self, rte: RteEnv, cmd: Cmd): + async def async_create_collection(self, ten: TenEnv, cmd: Cmd): m = Model(self.region_id, self.dbinstance_id, self.client) collection = cmd.get_property_string("collection_name") dimension = 1024 @@ -160,11 +160,11 @@ async def async_create_collection(self, rte: RteEnv, cmd: Cmd): collection, dimension, ) - rte.return_result(CmdResult.create(StatusCode.OK), cmd) + ten.return_result(CmdResult.create(StatusCode.OK), cmd) else: - rte.return_result(CmdResult.create(StatusCode.ERROR), cmd) + ten.return_result(CmdResult.create(StatusCode.ERROR), cmd) - async def async_upsert_vector(self, rte: RteEnv, cmd: Cmd): + async def async_upsert_vector(self, ten: TenEnv, cmd: Cmd): start_time = datetime.now() m = Model(self.region_id, self.dbinstance_id, self.client) collection = cmd.get_property_string("collection_name") @@ -186,11 +186,11 @@ async def async_upsert_vector(self, rte: RteEnv, cmd: Cmd): ) ) if err is None: - rte.return_result(CmdResult.create(StatusCode.OK), cmd) + ten.return_result(CmdResult.create(StatusCode.OK), cmd) else: - rte.return_result(CmdResult.create(StatusCode.ERROR), cmd) + ten.return_result(CmdResult.create(StatusCode.ERROR), cmd) - async def async_query_vector(self, rte: RteEnv, cmd: Cmd): + async def async_query_vector(self, ten: TenEnv, cmd: Cmd): start_time = datetime.now() m = Model(self.region_id, self.dbinstance_id, self.client) collection = cmd.get_property_string("collection_name") @@ -210,27 +210,27 @@ async def async_query_vector(self, rte: RteEnv, cmd: Cmd): ) if error: - return rte.return_result(CmdResult.create(StatusCode.ERROR), cmd) + return ten.return_result(CmdResult.create(StatusCode.ERROR), cmd) else: body = m.parse_collection_data(response.body) ret = CmdResult.create(StatusCode.OK) ret.set_property_from_json("response", body) - rte.return_result(ret, cmd) + ten.return_result(ret, cmd) - async def async_delete_collection(self, rte: RteEnv, cmd: Cmd): + async def async_delete_collection(self, ten: TenEnv, cmd: Cmd): m = Model(self.region_id, self.dbinstance_id, self.client) collection = cmd.get_property_string("collection_name") err = await m.delete_collection_async( self.account, self.account_password, self.namespace, collection ) if err is None: - return rte.return_result(CmdResult.create(StatusCode.OK), cmd) + return ten.return_result(CmdResult.create(StatusCode.OK), cmd) else: - return rte.return_result(CmdResult.create(StatusCode.ERROR), cmd) + return ten.return_result(CmdResult.create(StatusCode.ERROR), cmd) - def get_property_string(self, rte: RteEnv, key: str, default: str) -> str: + def get_property_string(self, ten: TenEnv, key: str, default: str) -> str: try: - return rte.get_property_string(key.lower()) + return ten.get_property_string(key.lower()) except Exception as e: logger.error(f"Error: {e}") return default diff --git a/agents/ten_packages/extension/aliyun_text_embedding/embedding_addon.py b/agents/ten_packages/extension/aliyun_text_embedding/embedding_addon.py index e149bbf6..69f68e10 100644 --- a/agents/ten_packages/extension/aliyun_text_embedding/embedding_addon.py +++ b/agents/ten_packages/extension/aliyun_text_embedding/embedding_addon.py @@ -1,7 +1,7 @@ -from rte import ( +from ten import ( Addon, register_addon_as_extension, - RteEnv, + TenEnv, ) from .log import logger from .embedding_extension import EmbeddingExtension @@ -9,6 +9,6 @@ @register_addon_as_extension("aliyun_text_embedding") class EmbeddingExtensionAddon(Addon): - def on_create_instance(self, rte: RteEnv, addon_name: str, context) -> None: + def on_create_instance(self, ten: TenEnv, addon_name: str, context) -> None: logger.info("on_create_instance") - rte.on_create_instance_done(EmbeddingExtension(addon_name), context) + ten.on_create_instance_done(EmbeddingExtension(addon_name), context) diff --git a/agents/ten_packages/extension/aliyun_text_embedding/embedding_extension.py b/agents/ten_packages/extension/aliyun_text_embedding/embedding_extension.py index 284a7918..df8e411c 100644 --- a/agents/ten_packages/extension/aliyun_text_embedding/embedding_extension.py +++ b/agents/ten_packages/extension/aliyun_text_embedding/embedding_extension.py @@ -1,6 +1,6 @@ -from rte import ( +from ten import ( Extension, - RteEnv, + TenEnv, Cmd, StatusCode, CmdResult, @@ -40,22 +40,22 @@ def __init__(self, name: str): # once v3 models supported self.parallel = 10 - def on_start(self, rte: RteEnv) -> None: + def on_start(self, ten: TenEnv) -> None: logger.info("on_start") - self.api_key = self.get_property_string(rte, "api_key", self.api_key) - self.model = self.get_property_string(rte, "model", self.api_key) + self.api_key = self.get_property_string(ten, "api_key", self.api_key) + self.model = self.get_property_string(ten, "model", self.api_key) dashscope.api_key = self.api_key for i in range(self.parallel): - thread = threading.Thread(target=self.async_handler, args=[i, rte]) + thread = threading.Thread(target=self.async_handler, args=[i, ten]) thread.start() self.threads.append(thread) - rte.on_start_done() + ten.on_start_done() - def async_handler(self, index: int, rte: RteEnv): - logger.info("async_handler {} started".format(index)) + def async_handler(self, index: int, ten: TenEnv): + logger.info("async_handler {} statend".format(index)) while not self.stop: cmd = self.queue.get() @@ -69,11 +69,11 @@ def async_handler(self, index: int, rte: RteEnv): if cmd_name == CMD_EMBED: cmd_result = self.call_with_str(cmd.get_property_string("input")) - rte.return_result(cmd_result, cmd) + ten.return_result(cmd_result, cmd) elif cmd_name == CMD_EMBED_BATCH: list = json.loads(cmd.get_property_to_json("inputs")) cmd_result = self.call_with_strs(list) - rte.return_result(cmd_result, cmd) + ten.return_result(cmd_result, cmd) else: logger.warning("unknown cmd {}".format(cmd_name)) @@ -135,7 +135,7 @@ def call_with_strs(self, messages: List[str]) -> CmdResult: logger.error("All batch failed") return cmd_result - def on_stop(self, rte: RteEnv) -> None: + def on_stop(self, ten: TenEnv) -> None: logger.info("on_stop") self.stop = True # clear queue @@ -148,9 +148,9 @@ def on_stop(self, rte: RteEnv) -> None: thread.join() self.threads = [] - rte.on_stop_done() + ten.on_stop_done() - def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: + def on_cmd(self, ten: TenEnv, cmd: Cmd) -> None: cmd_name = cmd.get_name() if cmd_name in [CMD_EMBED, CMD_EMBED_BATCH]: @@ -172,11 +172,11 @@ def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: else: logger.warning("unknown cmd {}".format(cmd_name)) cmd_result = CmdResult.create(StatusCode.ERROR) - rte.return_result(cmd_result, cmd) + ten.return_result(cmd_result, cmd) - def get_property_string(self, rte: RteEnv, key, default): + def get_property_string(self, ten: TenEnv, key, default): try: - return rte.get_property_string(key) + return ten.get_property_string(key) except Exception as e: logger.warning(f"err: {e}") return default diff --git a/agents/ten_packages/extension/bedrock_llm_python/bedrock_llm_extension.py b/agents/ten_packages/extension/bedrock_llm_python/bedrock_llm_extension.py index ccc4e2a5..5e7918a8 100644 --- a/agents/ten_packages/extension/bedrock_llm_python/bedrock_llm_extension.py +++ b/agents/ten_packages/extension/bedrock_llm_python/bedrock_llm_extension.py @@ -1,16 +1,15 @@ from .bedrock_llm import BedrockLLM, BedrockLLMConfig from datetime import datetime from threading import Thread -from rte import ( +from ten import ( Addon, Extension, register_addon_as_extension, - RteEnv, + TenEnv, Cmd, Data, StatusCode, CmdResult, - MetadataInfo, ) from .log import logger @@ -70,31 +69,39 @@ class BedrockLLMExtension(Extension): outdate_ts = 0 bedrock_llm = None - def on_start(self, rte: RteEnv) -> None: + def on_start(self, ten: TenEnv) -> None: logger.info("BedrockLLMExtension on_start") # Prepare configuration bedrock_llm_config = BedrockLLMConfig.default_config() for optional_str_param in [ - PROPERTY_REGION, PROPERTY_ACCESS_KEY, PROPERTY_SECRET_KEY, - PROPERTY_MODEL, PROPERTY_PROMPT]: + PROPERTY_REGION, + PROPERTY_ACCESS_KEY, + PROPERTY_SECRET_KEY, + PROPERTY_MODEL, + PROPERTY_PROMPT, + ]: try: - value = rte.get_property_string(optional_str_param).strip() + value = ten.get_property_string(optional_str_param).strip() if value: bedrock_llm_config.__setattr__(optional_str_param, value) except Exception as err: - logger.debug(f"GetProperty optional {optional_str_param} failed, err: {err}. Using default value: {bedrock_llm_config.__getattribute__(optional_str_param)}") + logger.debug( + f"GetProperty optional {optional_str_param} failed, err: {err}. Using default value: {bedrock_llm_config.__getattribute__(optional_str_param)}" + ) for optional_float_param in [PROPERTY_TEMPERATURE, PROPERTY_TOP_P]: try: - value = rte.get_property_float(optional_float_param) + value = ten.get_property_float(optional_float_param) if value: bedrock_llm_config.__setattr__(optional_float_param, value) except Exception as err: - logger.debug(f"GetProperty optional {optional_float_param} failed, err: {err}. Using default value: {bedrock_llm_config.__getattribute__(optional_float_param)}") + logger.debug( + f"GetProperty optional {optional_float_param} failed, err: {err}. Using default value: {bedrock_llm_config.__getattribute__(optional_float_param)}" + ) try: - max_tokens = rte.get_property_int(PROPERTY_MAX_TOKENS) + max_tokens = ten.get_property_int(PROPERTY_MAX_TOKENS) if max_tokens > 0: bedrock_llm_config.max_tokens = int(max_tokens) except Exception as err: @@ -103,14 +110,14 @@ def on_start(self, rte: RteEnv) -> None: ) try: - greeting = rte.get_property_string(PROPERTY_GREETING) + greeting = ten.get_property_string(PROPERTY_GREETING) except Exception as err: logger.debug( f"GetProperty optional {PROPERTY_GREETING} failed, err: {err}." ) try: - prop_max_memory_length = rte.get_property_int(PROPERTY_MAX_MEMORY_LENGTH) + prop_max_memory_length = ten.get_property_int(PROPERTY_MAX_MEMORY_LENGTH) if prop_max_memory_length > 0: self.max_memory_length = int(prop_max_memory_length) except Exception as err: @@ -137,17 +144,17 @@ def on_start(self, rte: RteEnv) -> None: output_data.set_property_bool( DATA_OUT_TEXT_DATA_PROPERTY_TEXT_END_OF_SEGMENT, True ) - rte.send_data(output_data) + ten.send_data(output_data) logger.info(f"greeting [{greeting}] sent") except Exception as err: logger.info(f"greeting [{greeting}] send failed, err: {err}") - rte.on_start_done() + ten.on_start_done() - def on_stop(self, rte: RteEnv) -> None: + def on_stop(self, ten: TenEnv) -> None: logger.info("BedrockLLMExtension on_stop") - rte.on_stop_done() + ten.on_stop_done() - def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: + def on_cmd(self, ten: TenEnv, cmd: Cmd) -> None: logger.info("BedrockLLMExtension on_cmd") cmd_json = cmd.to_json() logger.info("BedrockLLMExtension on_cmd json: " + cmd_json) @@ -157,23 +164,23 @@ def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: if cmd_name == CMD_IN_FLUSH: self.outdate_ts = get_current_time() cmd_out = Cmd.create(CMD_OUT_FLUSH) - rte.send_cmd(cmd_out, None) + ten.send_cmd(cmd_out, None) logger.info(f"BedrockLLMExtension on_cmd sent flush") else: logger.info(f"BedrockLLMExtension on_cmd unknown cmd: {cmd_name}") cmd_result = CmdResult.create(StatusCode.ERROR) cmd_result.set_property_string("detail", "unknown cmd") - rte.return_result(cmd_result, cmd) + ten.return_result(cmd_result, cmd) return cmd_result = CmdResult.create(StatusCode.OK) cmd_result.set_property_string("detail", "success") - rte.return_result(cmd_result, cmd) + ten.return_result(cmd_result, cmd) - def on_data(self, rte: RteEnv, data: Data) -> None: + def on_data(self, ten: TenEnv, data: Data) -> None: """ - on_data receives data from rte graph. - current supported data: + on_data receives data from ten graph. + current suppotend data: - name: text_data example: {name: text_data, properties: {text: "hello"} @@ -251,7 +258,9 @@ def converse_stream_worker(start_time, input_text, memory): for event in stream: # allow 100ms buffer time, in case interruptor's flush cmd comes just after on_data event if (start_time + 100_000) < self.outdate_ts: - logger.info(f"GetConverseStream recv interrupt and flushing for input text: [{input_text}], startTs: {start_time}, outdateTs: {self.outdate_ts}, delta > 100ms") + logger.info( + f"GetConverseStream recv interrupt and flushing for input text: [{input_text}], startTs: {start_time}, outdateTs: {self.outdate_ts}, delta > 100ms" + ) break if "contentBlockDelta" in event: @@ -293,7 +302,7 @@ def converse_stream_worker(start_time, input_text, memory): output_data.set_property_bool( DATA_OUT_TEXT_DATA_PROPERTY_TEXT_END_OF_SEGMENT, False ) - rte.send_data(output_data) + ten.send_data(output_data) logger.info( f"GetConverseStream recv for input text: [{input_text}] sent sentence [{sentence}]" ) @@ -312,12 +321,12 @@ def converse_stream_worker(start_time, input_text, memory): if len(full_content.strip()): # remember response as assistant content in memory - if memory and memory[-1]['role'] == 'assistant': - memory[-1]['content'].append({"text": full_content}) + if memory and memory[-1]["role"] == "assistant": + memory[-1]["content"].append({"text": full_content}) else: memory.append( - {"role": "assistant", "content": [{"text": full_content}]} - ) + {"role": "assistant", "content": [{"text": full_content}]} + ) else: # can not put empty model response into memory logger.error( @@ -334,7 +343,7 @@ def converse_stream_worker(start_time, input_text, memory): output_data.set_property_bool( DATA_OUT_TEXT_DATA_PROPERTY_TEXT_END_OF_SEGMENT, True ) - rte.send_data(output_data) + ten.send_data(output_data) logger.info( f"GetConverseStream for input text: [{input_text}] end of segment with sentence [{sentence}] sent" ) @@ -359,6 +368,6 @@ def converse_stream_worker(start_time, input_text, memory): @register_addon_as_extension("bedrock_llm_python") class BedrockLLMExtensionAddon(Addon): - def on_create_instance(self, rte: RteEnv, addon_name: str, context) -> None: + def on_create_instance(self, ten: TenEnv, addon_name: str, context) -> None: logger.info("on_create_instance") - rte.on_create_instance_done(BedrockLLMExtension(addon_name), context) + ten.on_create_instance_done(BedrockLLMExtension(addon_name), context) diff --git a/agents/ten_packages/extension/chat_transcriber_python/chat_transcriber_addon.py b/agents/ten_packages/extension/chat_transcriber_python/chat_transcriber_addon.py index 56c04e92..bddb3386 100644 --- a/agents/ten_packages/extension/chat_transcriber_python/chat_transcriber_addon.py +++ b/agents/ten_packages/extension/chat_transcriber_python/chat_transcriber_addon.py @@ -1,17 +1,17 @@ -from rte import ( +from ten import ( Addon, register_addon_as_extension, - RteEnv, + TenEnv, ) from .log import logger @register_addon_as_extension("chat_transcriber_python") class ChatTranscriberExtensionAddon(Addon): - def on_create_instance(self, rte: RteEnv, addon_name: str, context) -> None: + def on_create_instance(self, ten: TenEnv, addon_name: str, context) -> None: logger.info("on_create_instance") from .chat_transcriber_extension import ChatTranscriberExtension - rte.on_create_instance_done(ChatTranscriberExtension(addon_name), context) + ten.on_create_instance_done(ChatTranscriberExtension(addon_name), context) diff --git a/agents/ten_packages/extension/chat_transcriber_python/chat_transcriber_extension.py b/agents/ten_packages/extension/chat_transcriber_python/chat_transcriber_extension.py index 5aa3c02c..1d9dd79f 100644 --- a/agents/ten_packages/extension/chat_transcriber_python/chat_transcriber_extension.py +++ b/agents/ten_packages/extension/chat_transcriber_python/chat_transcriber_extension.py @@ -7,9 +7,9 @@ # import json -from rte import ( +from ten import ( Extension, - RteEnv, + TenEnv, Cmd, Data, StatusCode, @@ -32,27 +32,27 @@ class ChatTranscriberExtension(Extension): - def on_start(self, rte: RteEnv) -> None: + def on_start(self, ten: TenEnv) -> None: logger.info("on_start") - rte.on_start_done() + ten.on_start_done() - def on_stop(self, rte: RteEnv) -> None: + def on_stop(self, ten: TenEnv) -> None: logger.info("on_stop") - rte.on_stop_done() + ten.on_stop_done() - def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: + def on_cmd(self, ten: TenEnv, cmd: Cmd) -> None: logger.info("on_cmd") cmd_json = cmd.to_json() logger.info("on_cmd json: {}".format(cmd_json)) cmd_result = CmdResult.create(StatusCode.OK) cmd_result.set_property_string("detail", "success") - rte.return_result(cmd_result, cmd) + ten.return_result(cmd_result, cmd) - def on_data(self, rte: RteEnv, data: Data) -> None: + def on_data(self, ten: TenEnv, data: Data) -> None: """ - on_data receives data from rte graph. - current supported data: + on_data receives data from ten graph. + current suppotend data: - name: text_data example: {"name": "text_data", "properties": {"text": "hello", "is_final": true, "stream_id": 123, "end_of_segment": true}} @@ -128,9 +128,9 @@ def on_data(self, rte: RteEnv, data: Data) -> None: try: # convert the origin text data to the protobuf data and send it to the graph. - rte_data = Data.create("data") - rte_data.set_property_buf("data", pb_serialized_text) - rte.send_data(rte_data) + ten_data = Data.create("data") + ten_data.set_property_buf("data", pb_serialized_text) + ten.send_data(ten_data) logger.info("data sent") except Exception as e: logger.warning(f"on_data new_data error: {e}") diff --git a/agents/ten_packages/extension/cosy_tts/cosy_tts_addon.py b/agents/ten_packages/extension/cosy_tts/cosy_tts_addon.py index 4c4a05b5..04711700 100644 --- a/agents/ten_packages/extension/cosy_tts/cosy_tts_addon.py +++ b/agents/ten_packages/extension/cosy_tts/cosy_tts_addon.py @@ -1,16 +1,16 @@ -from rte import ( +from ten import ( Addon, register_addon_as_extension, - RteEnv, + TenEnv, ) from .log import logger @register_addon_as_extension("cosy_tts") class CosyTTSExtensionAddon(Addon): - def on_create_instance(self, rte: RteEnv, addon_name: str, context) -> None: + def on_create_instance(self, ten: TenEnv, addon_name: str, context) -> None: logger.info("on_create_instance") from .cosy_tts_extension import CosyTTSExtension - rte.on_create_instance_done(CosyTTSExtension(addon_name), context) + ten.on_create_instance_done(CosyTTSExtension(addon_name), context) diff --git a/agents/ten_packages/extension/cosy_tts/cosy_tts_extension.py b/agents/ten_packages/extension/cosy_tts/cosy_tts_extension.py index 6d6d294d..647341ad 100644 --- a/agents/ten_packages/extension/cosy_tts/cosy_tts_extension.py +++ b/agents/ten_packages/extension/cosy_tts/cosy_tts_extension.py @@ -6,12 +6,12 @@ # # import traceback -from rte import ( +from ten import ( Extension, - RteEnv, + TenEnv, Cmd, - PcmFrame, - PcmFrameDataFmt, + AudioFrame, + AudioFrameDataFmt, Data, StatusCode, CmdResult, @@ -26,9 +26,9 @@ class CosyTTSCallback(ResultCallback): - def __init__(self, rte: RteEnv, sample_rate: int, need_interrupt_callback): + def __init__(self, ten: TenEnv, sample_rate: int, need_interrupt_callback): super().__init__() - self.rte = rte + self.ten = ten self.sample_rate = sample_rate self.frame_size = int(self.sample_rate * 1 * 2 / 100) self.ts = datetime.now() # current task ts @@ -60,13 +60,13 @@ def on_event(self, message): pass # logger.info(f"recv speech synthsis message {message}") - def get_frame(self, data: bytes) -> PcmFrame: - f = PcmFrame.create("pcm_frame") + def get_frame(self, data: bytes) -> AudioFrame: + f = AudioFrame.create("pcm_frame") f.set_sample_rate(self.sample_rate) f.set_bytes_per_sample(2) f.set_number_of_channels(1) # f.set_timestamp = 0 - f.set_data_fmt(PcmFrameDataFmt.INTERLEAVE) + f.set_data_fmt(AudioFrameDataFmt.INTERLEAVE) f.set_samples_per_channel(len(data) // 2) f.alloc_buf(len(data)) buff = f.lock_buf() @@ -84,7 +84,7 @@ def on_data(self, data: bytes) -> None: # logger.info("audio result length: %d, %d", len(data), self.frame_size) try: f = self.get_frame(data) - self.rte.send_pcm_frame(f) + self.ten.send_audio_frame(f) except Exception as e: logger.exception(e) @@ -106,12 +106,12 @@ def __init__(self, name: str): self.thread = None self.queue = queue.Queue() - def on_start(self, rte: RteEnv) -> None: + def on_start(self, ten: TenEnv) -> None: logger.info("on_start") - self.api_key = rte.get_property_string("api_key") - self.voice = rte.get_property_string("voice") - self.model = rte.get_property_string("model") - self.sample_rate = rte.get_property_int("sample_rate") + self.api_key = ten.get_property_string("api_key") + self.voice = ten.get_property_string("voice") + self.model = ten.get_property_string("model") + self.sample_rate = ten.get_property_int("sample_rate") dashscope.api_key = self.api_key f = AudioFormat.PCM_16000HZ_MONO_16BIT @@ -133,11 +133,11 @@ def on_start(self, rte: RteEnv) -> None: self.format = f - self.thread = threading.Thread(target=self.async_handle, args=[rte]) + self.thread = threading.Thread(target=self.async_handle, args=[ten]) self.thread.start() - rte.on_start_done() + ten.on_start_done() - def on_stop(self, rte: RteEnv) -> None: + def on_stop(self, ten: TenEnv) -> None: logger.info("on_stop") self.stopped = True @@ -146,12 +146,12 @@ def on_stop(self, rte: RteEnv) -> None: if self.thread is not None: self.thread.join() self.thread = None - rte.on_stop_done() + ten.on_stop_done() def need_interrupt(self, ts: datetime.time) -> bool: return self.outdate_ts > ts - def async_handle(self, rte: RteEnv): + def async_handle(self, ten: TenEnv): try: tts = None callback = None @@ -185,7 +185,7 @@ def async_handle(self, rte: RteEnv): if tts is None or callback is None: logger.info("creating tts") callback = CosyTTSCallback( - rte, self.sample_rate, self.need_interrupt + ten, self.sample_rate, self.need_interrupt ) tts = SpeechSynthesizer( model=self.model, @@ -228,24 +228,24 @@ def flush(self): while not self.queue.empty(): self.queue.get() - def on_data(self, rte: RteEnv, data: Data) -> None: + def on_data(self, ten: TenEnv, data: Data) -> None: inputText = data.get_property_string("text") end_of_segment = data.get_property_bool("end_of_segment") logger.info("on data {} {}".format(inputText, end_of_segment)) self.queue.put((inputText, datetime.now(), end_of_segment)) - def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: + def on_cmd(self, ten: TenEnv, cmd: Cmd) -> None: cmd_name = cmd.get_name() logger.info("on_cmd {}".format(cmd_name)) if cmd_name == "flush": self.outdate_ts = datetime.now() self.flush() cmd_out = Cmd.create("flush") - rte.send_cmd(cmd_out, lambda rte, result: print("send_cmd flush done")) + ten.send_cmd(cmd_out, lambda ten, result: print("send_cmd flush done")) else: logger.info("unknown cmd {}".format(cmd_name)) cmd_result = CmdResult.create(StatusCode.OK) cmd_result.set_property_string("detail", "success") - rte.return_result(cmd_result, cmd) + ten.return_result(cmd_result, cmd) diff --git a/agents/ten_packages/extension/elevenlabs_tts_python/elevenlabs_tts_addon.py b/agents/ten_packages/extension/elevenlabs_tts_python/elevenlabs_tts_addon.py index 502fe867..99c448a8 100644 --- a/agents/ten_packages/extension/elevenlabs_tts_python/elevenlabs_tts_addon.py +++ b/agents/ten_packages/extension/elevenlabs_tts_python/elevenlabs_tts_addon.py @@ -6,10 +6,10 @@ # # -from rte import ( +from ten import ( Addon, register_addon_as_extension, - RteEnv, + TenEnv, ) from .extension import EXTENSION_NAME from .log import logger @@ -17,8 +17,8 @@ @register_addon_as_extension(EXTENSION_NAME) class ElevenlabsTTSExtensionAddon(Addon): - def on_create_instance(self, rte: RteEnv, addon_name: str, context) -> None: + def on_create_instance(self, ten: TenEnv, addon_name: str, context) -> None: logger.info("on_create_instance") from .elevenlabs_tts_extension import ElevenlabsTTSExtension - rte.on_create_instance_done(ElevenlabsTTSExtension(addon_name), context) + ten.on_create_instance_done(ElevenlabsTTSExtension(addon_name), context) diff --git a/agents/ten_packages/extension/elevenlabs_tts_python/elevenlabs_tts_extension.py b/agents/ten_packages/extension/elevenlabs_tts_python/elevenlabs_tts_extension.py index 52e8ca8a..1e47a359 100644 --- a/agents/ten_packages/extension/elevenlabs_tts_python/elevenlabs_tts_extension.py +++ b/agents/ten_packages/extension/elevenlabs_tts_python/elevenlabs_tts_extension.py @@ -10,9 +10,9 @@ import threading import time -from rte import ( +from ten import ( Extension, - RteEnv, + TenEnv, Cmd, CmdResult, StatusCode, @@ -44,7 +44,7 @@ def __init__(self, text: str, received_ts: int) -> None: class ElevenlabsTTSExtension(Extension): - def on_start(self, rte: RteEnv) -> None: + def on_start(self, ten: TenEnv) -> None: logger.info("on_start") self.elevenlabs_tts = None @@ -57,49 +57,49 @@ def on_start(self, rte: RteEnv) -> None: elevenlabs_tts_config = default_elevenlabs_tts_config() try: - elevenlabs_tts_config.api_key = rte.get_property_string(PROPERTY_API_KEY) + elevenlabs_tts_config.api_key = ten.get_property_string(PROPERTY_API_KEY) except Exception as e: logger.warning(f"on_start get_property_string {PROPERTY_API_KEY} error: {e}") return try: - model_id = rte.get_property_string(PROPERTY_MODEL_ID) + model_id = ten.get_property_string(PROPERTY_MODEL_ID) if len(model_id) > 0: elevenlabs_tts_config.model_id = model_id except Exception as e: logger.warning(f"on_start get_property_string {PROPERTY_MODEL_ID} error: {e}") try: - optimize_streaming_latency = rte.get_property_int(PROPERTY_OPTIMIZE_STREAMING_LATENCY) + optimize_streaming_latency = ten.get_property_int(PROPERTY_OPTIMIZE_STREAMING_LATENCY) if optimize_streaming_latency > 0: elevenlabs_tts_config.optimize_streaming_latency = optimize_streaming_latency except Exception as e: logger.warning(f"on_start get_property_int {PROPERTY_OPTIMIZE_STREAMING_LATENCY} error: {e}") try: - request_timeout_seconds = rte.get_property_int(PROPERTY_REQUEST_TIMEOUT_SECONDS) + request_timeout_seconds = ten.get_property_int(PROPERTY_REQUEST_TIMEOUT_SECONDS) if request_timeout_seconds > 0: elevenlabs_tts_config.request_timeout_seconds = request_timeout_seconds except Exception as e: logger.warning(f"on_start get_property_int {PROPERTY_REQUEST_TIMEOUT_SECONDS} error: {e}") try: - elevenlabs_tts_config.similarity_boost = rte.get_property_float(PROPERTY_SIMILARITY_BOOST) + elevenlabs_tts_config.similarity_boost = ten.get_property_float(PROPERTY_SIMILARITY_BOOST) except Exception as e: logger.warning(f"on_start get_property_float {PROPERTY_SIMILARITY_BOOST} error: {e}") try: - elevenlabs_tts_config.speaker_boost = rte.get_property_bool(PROPERTY_SPEAKER_BOOST) + elevenlabs_tts_config.speaker_boost = ten.get_property_bool(PROPERTY_SPEAKER_BOOST) except Exception as e: logger.warning(f"on_start get_property_bool {PROPERTY_SPEAKER_BOOST} error: {e}") try: - elevenlabs_tts_config.stability = rte.get_property_float(PROPERTY_STABILITY) + elevenlabs_tts_config.stability = ten.get_property_float(PROPERTY_STABILITY) except Exception as e: logger.warning(f"on_start get_property_float {PROPERTY_STABILITY} error: {e}") try: - elevenlabs_tts_config.style = rte.get_property_float(PROPERTY_STYLE) + elevenlabs_tts_config.style = ten.get_property_float(PROPERTY_STYLE) except Exception as e: logger.warning(f"on_start get_property_float {PROPERTY_STYLE} error: {e}") @@ -112,17 +112,17 @@ def on_start(self, rte: RteEnv) -> None: self.pcm = Pcm(PcmConfig()) self.pcm_frame_size = self.pcm.get_pcm_frame_size() - threading.Thread(target=self.process_text_queue, args=(rte,)).start() + threading.Thread(target=self.process_text_queue, args=(ten,)).start() - rte.on_start_done() + ten.on_start_done() - def on_stop(self, rte: RteEnv) -> None: + def on_stop(self, ten: TenEnv) -> None: logger.info("on_stop") - rte.on_stop_done() + ten.on_stop_done() - def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: + def on_cmd(self, ten: TenEnv, cmd: Cmd) -> None: """ - on_cmd receives cmd from rte graph. + on_cmd receives cmd from ten graph. current supported cmd: - name: flush example: @@ -138,15 +138,15 @@ def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: # send out out_cmd = Cmd.create(CMD_OUT_FLUSH) - rte.send_cmd(out_cmd) + ten.send_cmd(out_cmd) cmd_result = CmdResult.create(StatusCode.OK) cmd_result.set_property_string("detail", "success") - rte.return_result(cmd_result, cmd) + ten.return_result(cmd_result, cmd) - def on_data(self, rte: RteEnv, data: Data) -> None: + def on_data(self, ten: TenEnv, data: Data) -> None: """ - on_data receives data from rte graph. + on_data receives data from ten graph. current supported data: - name: text_data example: @@ -168,7 +168,7 @@ def on_data(self, rte: RteEnv, data: Data) -> None: self.text_queue.put(Message(text, int(time.time() * 1000000))) - def process_text_queue(self, rte: RteEnv): + def process_text_queue(self, ten: TenEnv): logger.info("process_text_queue") while True: @@ -206,7 +206,7 @@ def process_text_queue(self, rte: RteEnv): logger.debug(f"the number of bytes read is [{pcm_frame_read}] inconsistent with pcm frame size") continue - self.pcm.send(rte, buf) + self.pcm.send(ten, buf) buf = self.pcm.new_buf() pcm_frame_read = 0 sent_frames += 1 @@ -218,7 +218,7 @@ def process_text_queue(self, rte: RteEnv): logger.debug(f"sending pcm data, text: [{msg.text}]") if pcm_frame_read > 0: - self.pcm.send(rte, buf) + self.pcm.send(ten, buf) sent_frames += 1 logger.info(f"sending pcm remain data, text: [{msg.text}], pcm_frame_read: {pcm_frame_read}") diff --git a/agents/ten_packages/extension/elevenlabs_tts_python/pcm.py b/agents/ten_packages/extension/elevenlabs_tts_python/pcm.py index 713b74b1..6f0bf493 100644 --- a/agents/ten_packages/extension/elevenlabs_tts_python/pcm.py +++ b/agents/ten_packages/extension/elevenlabs_tts_python/pcm.py @@ -8,20 +8,20 @@ import logging from typing import Iterator -from rte import PcmFrame, RteEnv, PcmFrameDataFmt +from ten import AudioFrame, TenEnv, AudioFrameDataFmt class Pcm: def __init__(self, config) -> None: self.config = config - def get_pcm_frame(self, buf: memoryview) -> PcmFrame: - frame = PcmFrame.create(self.config.name) + def get_pcm_frame(self, buf: memoryview) -> AudioFrame: + frame = AudioFrame.create(self.config.name) frame.set_bytes_per_sample(self.config.bytes_per_sample) frame.set_sample_rate(self.config.sample_rate) frame.set_number_of_channels(self.config.num_channels) frame.set_timestamp(self.config.timestamp) - frame.set_data_fmt(PcmFrameDataFmt.INTERLEAVE) + frame.set_data_fmt(AudioFrameDataFmt.INTERLEAVE) frame.set_samples_per_channel(self.config.samples_per_channel // self.config.channel) frame.alloc_buf(self.get_pcm_frame_size()) @@ -49,10 +49,10 @@ def read_pcm_stream(self, stream: Iterator[bytes], chunk_size: int) -> Iterator[ if chunk: yield chunk - def send(self, rte: RteEnv, buf: memoryview) -> None: + def send(self, ten: TenEnv, buf: memoryview) -> None: try: frame = self.get_pcm_frame(buf) - rte.send_pcm_frame(frame) + ten.send_audio_frame(frame) except Exception as e: logging.error(f"send frame failed, {e}") diff --git a/agents/ten_packages/extension/file_chunker/file_chunker_addon.py b/agents/ten_packages/extension/file_chunker/file_chunker_addon.py index b5daf556..e12f5c64 100644 --- a/agents/ten_packages/extension/file_chunker/file_chunker_addon.py +++ b/agents/ten_packages/extension/file_chunker/file_chunker_addon.py @@ -1,7 +1,7 @@ -from rte import ( +from ten import ( Addon, register_addon_as_extension, - RteEnv, + TenEnv, ) from .log import logger from .file_chunker_extension import FileChunkerExtension @@ -9,6 +9,6 @@ @register_addon_as_extension("file_chunker") class FileChunkerExtensionAddon(Addon): - def on_create_instance(self, rte: RteEnv, addon_name: str, context) -> None: + def on_create_instance(self, ten: TenEnv, addon_name: str, context) -> None: logger.info("on_create_instance") - rte.on_create_instance_done(FileChunkerExtension(addon_name), context) + ten.on_create_instance_done(FileChunkerExtension(addon_name), context) diff --git a/agents/ten_packages/extension/file_chunker/file_chunker_extension.py b/agents/ten_packages/extension/file_chunker/file_chunker_extension.py index b9048988..4e2b4632 100644 --- a/agents/ten_packages/extension/file_chunker/file_chunker_extension.py +++ b/agents/ten_packages/extension/file_chunker/file_chunker_extension.py @@ -5,9 +5,9 @@ # Copyright (c) 2024 Agora IO. All rights reserved. # # -from rte import ( +from ten import ( Extension, - RteEnv, + TenEnv, Cmd, StatusCode, CmdResult, @@ -82,19 +82,19 @@ def split(self, path: str) -> List[Any]: ) return nodes - def create_collection(self, rte: RteEnv, collection_name: str, wait: bool): + def create_collection(self, ten: TenEnv, collection_name: str, wait: bool): cmd_out = Cmd.create("create_collection") cmd_out.set_property_string("collection_name", collection_name) wait_event = threading.Event() - rte.send_cmd( + ten.send_cmd( cmd_out, - lambda rte, result: wait_event.set(), + lambda ten, result: wait_event.set(), ) if wait: wait_event.wait() - def embedding(self, rte: RteEnv, path: str, texts: List[str]): + def embedding(self, ten: TenEnv, path: str, texts: List[str]): logger.info( "generate embeddings for the file: {}, with batch size: {}".format( path, len(texts) @@ -103,14 +103,14 @@ def embedding(self, rte: RteEnv, path: str, texts: List[str]): cmd_out = Cmd.create("embed_batch") cmd_out.set_property_from_json("inputs", json.dumps(texts)) - rte.send_cmd( + ten.send_cmd( cmd_out, - lambda rte, result: self.vector_store( - rte, path, texts, result + lambda ten, result: self.vector_store( + ten, path, texts, result ), # TODO: deal with error ) - def vector_store(self, rte: RteEnv, path: str, texts: List[str], result: CmdResult): + def vector_store(self, ten: TenEnv, path: str, texts: List[str], result: CmdResult): logger.info("vector store start for one splitting of the file {}".format(path)) file_name = path.split("/")[-1] embed_output_json = result.get_property_string("embeddings") @@ -124,9 +124,9 @@ def vector_store(self, rte: RteEnv, path: str, texts: List[str], result: CmdResu content.append({"text": text, "embedding": embedding}) cmd_out.set_property_string("content", json.dumps(content)) # logger.info(json.dumps(content)) - rte.send_cmd(cmd_out, lambda rte, result: self.file_chunked(rte, path)) + ten.send_cmd(cmd_out, lambda ten, result: self.file_chunked(ten, path)) - def file_chunked(self, rte: RteEnv, path: str): + def file_chunked(self, ten: TenEnv, path: str): if path in self.counters and path in self.expected: self.counters[path] += 1 logger.info( @@ -148,15 +148,15 @@ def file_chunked(self, rte: RteEnv, path: str): cmd_out = Cmd.create(FILE_CHUNKED_CMD) cmd_out.set_property_string("path", path) cmd_out.set_property_string("collection", self.new_collection_name) - rte.send_cmd( + ten.send_cmd( cmd_out, - lambda rte, result: logger.info("send_cmd done"), + lambda ten, result: logger.info("send_cmd done"), ) self.file_chunked_event.set() else: logger.error("missing counter for the file path: %s", path) - def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: + def on_cmd(self, ten: TenEnv, cmd: Cmd) -> None: cmd_name = cmd.get_name() if cmd_name == CMD_FILE_CHUNK: path = cmd.get_property_string("path") @@ -173,9 +173,9 @@ def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: cmd_result = CmdResult.create(StatusCode.OK) cmd_result.set_property_string("detail", "ok") - rte.return_result(cmd_result, cmd) + ten.return_result(cmd_result, cmd) - def async_handler(self, rte: RteEnv) -> None: + def async_handler(self, ten: TenEnv) -> None: while not self.stop: value = self.queue.get() if value is None: @@ -190,7 +190,7 @@ def async_handler(self, rte: RteEnv) -> None: logger.info("start processing {}, collection {}".format(path, collection)) # create collection - self.create_collection(rte, collection, True) + self.create_collection(ten, collection, True) logger.info("collection {} created".format(collection)) # split @@ -204,7 +204,7 @@ def async_handler(self, rte: RteEnv) -> None: # trigger embedding and vector storing in parallel for texts in list(batch(nodes, BATCH_SIZE)): - self.embedding(rte, path, texts) + self.embedding(ten, path, texts) # wait for all chunks to be processed self.file_chunked_event.wait() @@ -217,16 +217,16 @@ def async_handler(self, rte: RteEnv) -> None: ) ) - def on_start(self, rte: RteEnv) -> None: + def on_start(self, ten: TenEnv) -> None: logger.info("on_start") self.stop = False - self.thread = threading.Thread(target=self.async_handler, args=[rte]) + self.thread = threading.Thread(target=self.async_handler, args=[ten]) self.thread.start() - rte.on_start_done() + ten.on_start_done() - def on_stop(self, rte: RteEnv) -> None: + def on_stop(self, ten: TenEnv) -> None: logger.info("on_stop") self.stop = True @@ -237,4 +237,4 @@ def on_stop(self, rte: RteEnv) -> None: self.thread.join() self.thread = None - rte.on_stop_done() + ten.on_stop_done() diff --git a/agents/ten_packages/extension/gemini_llm_python/gemini_llm_addon.py b/agents/ten_packages/extension/gemini_llm_python/gemini_llm_addon.py index 961794b8..b68e150c 100644 --- a/agents/ten_packages/extension/gemini_llm_python/gemini_llm_addon.py +++ b/agents/ten_packages/extension/gemini_llm_python/gemini_llm_addon.py @@ -5,10 +5,10 @@ # Copyright (c) 2024 Agora IO. All rights reserved. # # -from rte import ( +from ten import ( Addon, register_addon_as_extension, - RteEnv, + TenEnv, ) from .extension import EXTENSION_NAME from .log import logger @@ -17,7 +17,7 @@ @register_addon_as_extension(EXTENSION_NAME) class GeminiLLMExtensionAddon(Addon): - def on_create_instance(self, rte: RteEnv, addon_name: str, context) -> None: + def on_create_instance(self, ten: TenEnv, addon_name: str, context) -> None: logger.info("on_create_instance") - rte.on_create_instance_done(GeminiLLMExtension(addon_name), context) + ten.on_create_instance_done(GeminiLLMExtension(addon_name), context) diff --git a/agents/ten_packages/extension/gemini_llm_python/gemini_llm_extension.py b/agents/ten_packages/extension/gemini_llm_python/gemini_llm_extension.py index 5ac51fa6..58295089 100644 --- a/agents/ten_packages/extension/gemini_llm_python/gemini_llm_extension.py +++ b/agents/ten_packages/extension/gemini_llm_python/gemini_llm_extension.py @@ -6,9 +6,9 @@ # # from threading import Thread -from rte import ( +from ten import ( Extension, - RteEnv, + TenEnv, Cmd, Data, StatusCode, @@ -43,13 +43,13 @@ class GeminiLLMExtension(Extension): outdate_ts = 0 gemini_llm = None - def on_start(self, rte: RteEnv) -> None: + def on_start(self, ten: TenEnv) -> None: logger.info("GeminiLLMExtension on_start") # Prepare configuration gemini_llm_config = GeminiLLMConfig.default_config() try: - api_key = rte.get_property_string(PROPERTY_API_KEY) + api_key = ten.get_property_string(PROPERTY_API_KEY) gemini_llm_config.api_key = api_key except Exception as err: logger.info(f"GetProperty required {PROPERTY_API_KEY} failed, err: {err}") @@ -57,7 +57,7 @@ def on_start(self, rte: RteEnv) -> None: for key in [PROPERTY_GREETING, PROPERTY_MODEL, PROPERTY_PROMPT]: try: - val = rte.get_property_string(key) + val = ten.get_property_string(key) if val: gemini_llm_config.key = val except Exception as e: @@ -65,46 +65,54 @@ def on_start(self, rte: RteEnv) -> None: for key in [PROPERTY_TEMPERATURE, PROPERTY_TOP_P]: try: - gemini_llm_config.key = float(rte.get_property_float(key)) + gemini_llm_config.key = float(ten.get_property_float(key)) except Exception as e: logger.warning(f"get_property_float optional {key} failed, err: {e}") for key in [PROPERTY_MAX_OUTPUT_TOKENS, PROPERTY_TOP_K]: try: - gemini_llm_config.key = int(rte.get_property_int(key)) + gemini_llm_config.key = int(ten.get_property_int(key)) except Exception as e: logger.warning(f"get_property_int optional {key} failed, err: {e}") try: - prop_max_memory_length = rte.get_property_int(PROPERTY_MAX_MEMORY_LENGTH) + prop_max_memory_length = ten.get_property_int(PROPERTY_MAX_MEMORY_LENGTH) if prop_max_memory_length > 0: self.max_memory_length = int(prop_max_memory_length) except Exception as err: - logger.warning(f"GetProperty optional {PROPERTY_MAX_MEMORY_LENGTH} failed, err: {err}") + logger.warning( + f"GetProperty optional {PROPERTY_MAX_MEMORY_LENGTH} failed, err: {err}" + ) # Create GeminiLLM instance self.gemini_llm = GeminiLLM(gemini_llm_config) - logger.info(f"newGeminiLLM succeed with max_output_tokens: {gemini_llm_config.max_output_tokens}, model: {gemini_llm_config.model}") + logger.info( + f"newGeminiLLM succeed with max_output_tokens: {gemini_llm_config.max_output_tokens}, model: {gemini_llm_config.model}" + ) # Send greeting if available - greeting = rte.get_property_string(PROPERTY_GREETING) + greeting = ten.get_property_string(PROPERTY_GREETING) if greeting: try: output_data = Data.create("text_data") - output_data.set_property_string(DATA_OUT_TEXT_DATA_PROPERTY_TEXT, greeting) - output_data.set_property_bool(DATA_OUT_TEXT_DATA_PROPERTY_TEXT_END_OF_SEGMENT, True) - rte.send_data(output_data) + output_data.set_property_string( + DATA_OUT_TEXT_DATA_PROPERTY_TEXT, greeting + ) + output_data.set_property_bool( + DATA_OUT_TEXT_DATA_PROPERTY_TEXT_END_OF_SEGMENT, True + ) + ten.send_data(output_data) logger.info(f"greeting [{greeting}] sent") except Exception as e: logger.error(f"greeting [{greeting}] send failed, err: {e}") - rte.on_start_done() + ten.on_start_done() - def on_stop(self, rte: RteEnv) -> None: + def on_stop(self, ten: TenEnv) -> None: logger.info("GeminiLLMExtension on_stop") - rte.on_stop_done() + ten.on_stop_done() - def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: + def on_cmd(self, ten: TenEnv, cmd: Cmd) -> None: logger.info("GeminiLLMExtension on_cmd") cmd_json = cmd.to_json() logger.info(f"GeminiLLMExtension on_cmd json: {cmd_json}") @@ -114,22 +122,22 @@ def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: if cmd_name == CMD_IN_FLUSH: self.outdate_ts = get_micro_ts() cmd_out = Cmd.create(CMD_OUT_FLUSH) - rte.send_cmd(cmd_out, None) + ten.send_cmd(cmd_out, None) logger.info(f"GeminiLLMExtension on_cmd sent flush") else: logger.info(f"GeminiLLMExtension on_cmd unknown cmd: {cmd_name}") cmd_result = CmdResult.create(StatusCode.ERROR) cmd_result.set_property_string("detail", "unknown cmd") - rte.return_result(cmd_result, cmd) + ten.return_result(cmd_result, cmd) return cmd_result = CmdResult.create(StatusCode.OK) cmd_result.set_property_string("detail", "success") - rte.return_result(cmd_result, cmd) + ten.return_result(cmd_result, cmd) - def on_data(self, rte: RteEnv, data: Data) -> None: + def on_data(self, ten: TenEnv, data: Data) -> None: """ - on_data receives data from rte graph. + on_data receives data from ten graph. current supported data: - name: text_data example: @@ -144,7 +152,9 @@ def on_data(self, rte: RteEnv, data: Data) -> None: logger.info("ignore non-final input") return except Exception as e: - logger.error(f"on_data get_property_bool {DATA_IN_TEXT_DATA_PROPERTY_IS_FINAL} failed, err: {e}") + logger.error( + f"on_data get_property_bool {DATA_IN_TEXT_DATA_PROPERTY_IS_FINAL} failed, err: {e}" + ) return # Get input text @@ -155,7 +165,9 @@ def on_data(self, rte: RteEnv, data: Data) -> None: return logger.info(f"on_data input text: [{input_text}]") except Exception as e: - logger.error(f"on_data get_property_string {DATA_IN_TEXT_DATA_PROPERTY_TEXT} failed, err: {e}") + logger.error( + f"on_data get_property_string {DATA_IN_TEXT_DATA_PROPERTY_TEXT} failed, err: {e}" + ) return # Prepare memory @@ -165,12 +177,16 @@ def on_data(self, rte: RteEnv, data: Data) -> None: def chat_completions_stream_worker(start_time, input_text, memory): try: - logger.info(f"chat_completions_stream_worker for input text: [{input_text}] memory: {memory}") + logger.info( + f"chat_completions_stream_worker for input text: [{input_text}] memory: {memory}" + ) # Get result from AI resp = self.gemini_llm.get_chat_completions_stream(memory) if resp is None: - logger.info(f"chat_completions_stream_worker for input text: [{input_text}] failed") + logger.info( + f"chat_completions_stream_worker for input text: [{input_text}] failed" + ) return sentence = "" @@ -179,10 +195,12 @@ def chat_completions_stream_worker(start_time, input_text, memory): for chat_completions in resp: if start_time < self.outdate_ts: - logger.info(f"chat_completions_stream_worker recv interrupt and flushing for input text: [{input_text}], startTs: {start_time}, outdateTs: {self.outdate_ts}") + logger.info( + f"chat_completions_stream_worker recv interrupt and flushing for input text: [{input_text}], startTs: {start_time}, outdateTs: {self.outdate_ts}" + ) break - if (chat_completions.text is not None): + if chat_completions.text is not None: content = chat_completions.text else: content = "" @@ -190,29 +208,43 @@ def chat_completions_stream_worker(start_time, input_text, memory): full_content += content while True: - sentence, content, sentence_is_final = parse_sentence(sentence, content) + sentence, content, sentence_is_final = parse_sentence( + sentence, content + ) if len(sentence) == 0 or not sentence_is_final: logger.info(f"sentence {sentence} is empty or not final") break - logger.info(f"chat_completions_stream_worker recv for input text: [{input_text}] got sentence: [{sentence}]") + logger.info( + f"chat_completions_stream_worker recv for input text: [{input_text}] got sentence: [{sentence}]" + ) # send sentence try: output_data = Data.create("text_data") - output_data.set_property_string(DATA_OUT_TEXT_DATA_PROPERTY_TEXT, sentence) - output_data.set_property_bool(DATA_OUT_TEXT_DATA_PROPERTY_TEXT_END_OF_SEGMENT, False) - rte.send_data(output_data) - logger.info(f"chat_completions_stream_worker recv for input text: [{input_text}] sent sentence [{sentence}]") + output_data.set_property_string( + DATA_OUT_TEXT_DATA_PROPERTY_TEXT, sentence + ) + output_data.set_property_bool( + DATA_OUT_TEXT_DATA_PROPERTY_TEXT_END_OF_SEGMENT, False + ) + ten.send_data(output_data) + logger.info( + f"chat_completions_stream_worker recv for input text: [{input_text}] sent sentence [{sentence}]" + ) except Exception as e: - logger.error(f"chat_completions_stream_worker recv for input text: [{input_text}] send sentence [{sentence}] failed, err: {e}") + logger.error( + f"chat_completions_stream_worker recv for input text: [{input_text}] send sentence [{sentence}] failed, err: {e}" + ) break sentence = "" if not first_sentence_sent: first_sentence_sent = True - logger.info(f"chat_completions_stream_worker recv for input text: [{input_text}] first sentence sent, first_sentence_latency {get_micro_ts() - start_time}ms") + logger.info( + f"chat_completions_stream_worker recv for input text: [{input_text}] first sentence sent, first_sentence_latency {get_micro_ts() - start_time}ms" + ) # remember response as assistant content in memory memory.append({"role": "model", "parts": full_content}) @@ -220,15 +252,25 @@ def chat_completions_stream_worker(start_time, input_text, memory): # send end of segment try: output_data = Data.create("text_data") - output_data.set_property_string(DATA_OUT_TEXT_DATA_PROPERTY_TEXT, sentence) - output_data.set_property_bool(DATA_OUT_TEXT_DATA_PROPERTY_TEXT_END_OF_SEGMENT, True) - rte.send_data(output_data) - logger.info(f"chat_completions_stream_worker for input text: [{input_text}] end of segment with sentence [{sentence}] sent") + output_data.set_property_string( + DATA_OUT_TEXT_DATA_PROPERTY_TEXT, sentence + ) + output_data.set_property_bool( + DATA_OUT_TEXT_DATA_PROPERTY_TEXT_END_OF_SEGMENT, True + ) + ten.send_data(output_data) + logger.info( + f"chat_completions_stream_worker for input text: [{input_text}] end of segment with sentence [{sentence}] sent" + ) except Exception as e: - logger.error(f"chat_completions_stream_worker for input text: [{input_text}] end of segment with sentence [{sentence}] send failed, err: {e}") + logger.error( + f"chat_completions_stream_worker for input text: [{input_text}] end of segment with sentence [{sentence}] send failed, err: {e}" + ) except Exception as e: - logger.error(f"chat_completions_stream_worker for input text: [{input_text}] failed, err: {e}") + logger.error( + f"chat_completions_stream_worker for input text: [{input_text}] failed, err: {e}" + ) # Start thread to request and read responses from GeminiLLM start_time = get_micro_ts() 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 index b1884e81..6786cd1a 100644 --- a/agents/ten_packages/extension/http_server_python/http_server_addon.py +++ b/agents/ten_packages/extension/http_server_python/http_server_addon.py @@ -1,7 +1,7 @@ -from rte import ( +from ten import ( Addon, register_addon_as_extension, - RteEnv, + TenEnv, ) from .log import logger from .http_server_extension import HTTPServerExtension @@ -9,6 +9,6 @@ @register_addon_as_extension("http_server_python") class HTTPServerExtensionAddon(Addon): - def on_create_instance(self, rte: RteEnv, addon_name: str, context): + def on_create_instance(self, ten: TenEnv, addon_name: str, context): logger.info("on_create_instance") - rte.on_create_instance_done(HTTPServerExtension(addon_name), context) + 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 index 1092231e..4148c7c9 100644 --- a/agents/ten_packages/extension/http_server_python/http_server_extension.py +++ b/agents/ten_packages/extension/http_server_python/http_server_extension.py @@ -1,6 +1,6 @@ -from rte import ( +from ten import ( Extension, - RteEnv, + TenEnv, Cmd, StatusCode, CmdResult, @@ -12,9 +12,9 @@ class HTTPHandler(BaseHTTPRequestHandler): - def __init__(self, rte, *args, directory=None, **kwargs): + def __init__(self, ten, *args, directory=None, **kwargs): logger.info("new handler: %s %s %s", directory, args, kwargs) - self.rte = rte + self.ten = ten super().__init__(*args, **kwargs) def do_POST(self): @@ -24,9 +24,9 @@ def do_POST(self): content_length = int(self.headers["Content-Length"]) input = self.rfile.read(content_length).decode("utf-8") logger.info("incoming request %s", input) - self.rte.send_cmd( + self.ten.send_cmd( Cmd.create_from_json(input), - lambda rte, result: logger.info( + lambda ten, result: logger.info( "finish send_cmd from http server %s %s", input, result ), ) @@ -51,11 +51,11 @@ def __init__(self, name: str): self.server = None self.thread = None - def on_start(self, rte: RteEnv): - self.listen_addr = rte.get_property_string("listen_addr") - self.listen_port = rte.get_property_int("listen_port") + 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 = rte.get_property_string("cmd_white_list") + white_list = ten.get_property_string("cmd_white_list") if len(white_list) > 0: self.cmd_white_list = white_list.split(",") """ @@ -68,22 +68,22 @@ def on_start(self, rte: RteEnv): ) self.server = HTTPServer( - (self.listen_addr, self.listen_port), partial(HTTPHandler, rte) + (self.listen_addr, self.listen_port), partial(HTTPHandler, ten) ) self.thread = threading.Thread(target=self.server.serve_forever) self.thread.start() - rte.on_start_done() + ten.on_start_done() - def on_stop(self, rte: RteEnv): + def on_stop(self, ten: TenEnv): logger.info("on_stop") self.server.shutdown() self.thread.join() - rte.on_stop_done() + ten.on_stop_done() - def on_cmd(self, rte: RteEnv, cmd: Cmd): + 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") - rte.return_result(cmd_result, cmd) + ten.return_result(cmd_result, cmd) diff --git a/agents/ten_packages/extension/interrupt_detector_python/interrupt_detector_addon.py b/agents/ten_packages/extension/interrupt_detector_python/interrupt_detector_addon.py index 8e69499c..48b57698 100644 --- a/agents/ten_packages/extension/interrupt_detector_python/interrupt_detector_addon.py +++ b/agents/ten_packages/extension/interrupt_detector_python/interrupt_detector_addon.py @@ -6,19 +6,19 @@ # # -from rte import ( +from ten import ( Addon, register_addon_as_extension, - RteEnv, + TenEnv, ) from .log import logger @register_addon_as_extension("interrupt_detector_python") class InterruptDetectorExtensionAddon(Addon): - def on_create_instance(self, rte: RteEnv, addon_name: str, context) -> None: + def on_create_instance(self, ten: TenEnv, addon_name: str, context) -> None: logger.info("on_create_instance") from .interrupt_detector_extension import InterruptDetectorExtension - rte.on_create_instance_done(InterruptDetectorExtension(addon_name), context) + ten.on_create_instance_done(InterruptDetectorExtension(addon_name), context) diff --git a/agents/ten_packages/extension/interrupt_detector_python/interrupt_detector_extension.py b/agents/ten_packages/extension/interrupt_detector_python/interrupt_detector_extension.py index f136891a..6710d8dc 100644 --- a/agents/ten_packages/extension/interrupt_detector_python/interrupt_detector_extension.py +++ b/agents/ten_packages/extension/interrupt_detector_python/interrupt_detector_extension.py @@ -6,14 +6,13 @@ # # -from rte import ( +from ten import ( Extension, - RteEnv, + TenEnv, Cmd, Data, StatusCode, CmdResult, - MetadataInfo, ) from .log import logger @@ -25,44 +24,44 @@ class InterruptDetectorExtension(Extension): - def on_start(self, rte: RteEnv) -> None: + def on_start(self, ten: TenEnv) -> None: logger.info("on_start") - rte.on_start_done() + ten.on_start_done() - def on_stop(self, rte: RteEnv) -> None: + def on_stop(self, ten: TenEnv) -> None: logger.info("on_stop") - rte.on_stop_done() + ten.on_stop_done() - def send_flush_cmd(self, rte: RteEnv) -> None: + def send_flush_cmd(self, ten: TenEnv) -> None: flush_cmd = Cmd.create(CMD_NAME_FLUSH) - rte.send_cmd( + ten.send_cmd( flush_cmd, - lambda rte, result: logger.info("send_cmd done"), + lambda ten, result: logger.info("send_cmd done"), ) logger.info(f"sent cmd: {CMD_NAME_FLUSH}") - def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: + def on_cmd(self, ten: TenEnv, cmd: Cmd) -> None: cmd_name = cmd.get_name() logger.info("on_cmd name {}".format(cmd_name)) # flush whatever cmd incoming at the moment - self.send_flush_cmd(rte) + self.send_flush_cmd(ten) # then forward the cmd to downstream cmd_json = cmd.to_json() new_cmd = Cmd.create_from_json(cmd_json) - rte.send_cmd( + ten.send_cmd( new_cmd, - lambda rte, result: logger.info("send_cmd done"), + lambda ten, result: logger.info("send_cmd done"), ) cmd_result = CmdResult.create(StatusCode.OK) - rte.return_result(cmd_result, cmd) + ten.return_result(cmd_result, cmd) - def on_data(self, rte: RteEnv, data: Data) -> None: + def on_data(self, ten: TenEnv, data: Data) -> None: """ - on_data receives data from rte graph. + on_data receives data from ten graph. current supported data: - name: text_data example: @@ -91,9 +90,9 @@ def on_data(self, rte: RteEnv, data: Data) -> None: ) if final or len(text) >= 2: - self.send_flush_cmd(rte) + self.send_flush_cmd(ten) d = Data.create("text_data") d.set_property_bool(TEXT_DATA_FINAL_FIELD, final) d.set_property_string(TEXT_DATA_TEXT_FIELD, text) - rte.send_data(d) + ten.send_data(d) diff --git a/agents/ten_packages/extension/llama_index_chat_engine/addon.py b/agents/ten_packages/extension/llama_index_chat_engine/addon.py index 03586528..bfdebc39 100644 --- a/agents/ten_packages/extension/llama_index_chat_engine/addon.py +++ b/agents/ten_packages/extension/llama_index_chat_engine/addon.py @@ -1,10 +1,10 @@ -from rte import Addon, register_addon_as_extension, RteEnv +from ten import Addon, register_addon_as_extension, TenEnv from .extension import LlamaIndexExtension from .log import logger @register_addon_as_extension("llama_index_chat_engine") class LlamaIndexExtensionAddon(Addon): - def on_create_instance(self, rte: RteEnv, addon_name: str, context) -> None: + def on_create_instance(self, ten: TenEnv, addon_name: str, context) -> None: logger.info("on_create_instance") - rte.on_create_instance_done(LlamaIndexExtension(addon_name), context) + ten.on_create_instance_done(LlamaIndexExtension(addon_name), context) diff --git a/agents/ten_packages/extension/llama_index_chat_engine/astra_embedding.py b/agents/ten_packages/extension/llama_index_chat_engine/astra_embedding.py index fb96da77..0a60c4fb 100644 --- a/agents/ten_packages/extension/llama_index_chat_engine/astra_embedding.py +++ b/agents/ten_packages/extension/llama_index_chat_engine/astra_embedding.py @@ -3,7 +3,7 @@ from llama_index.core.embeddings import BaseEmbedding from .log import logger import json -from rte import ( +from ten import ( Cmd, CmdResult, ) @@ -17,12 +17,12 @@ def embed_from_resp(cmd_result: CmdResult) -> List[float]: class ASTRAEmbedding(BaseEmbedding): - rte: Any + ten: Any - def __init__(self, rte): + def __init__(self, ten): """Creates a new ASTRA embedding interface.""" super().__init__() - self.rte = rte + self.ten = ten @classmethod def class_name(cls) -> str: @@ -52,7 +52,7 @@ def callback(_, result): cmd_out = Cmd.create(EMBED_CMD) cmd_out.set_property_string("input", query) - self.rte.send_cmd(cmd_out, callback) + self.ten.send_cmd(cmd_out, callback) wait_event.wait() return resp diff --git a/agents/ten_packages/extension/llama_index_chat_engine/astra_llm.py b/agents/ten_packages/extension/llama_index_chat_engine/astra_llm.py index a642603c..50f223da 100644 --- a/agents/ten_packages/extension/llama_index_chat_engine/astra_llm.py +++ b/agents/ten_packages/extension/llama_index_chat_engine/astra_llm.py @@ -16,7 +16,7 @@ from llama_index.core.llms.custom import CustomLLM from .log import logger -from rte import Cmd, StatusCode, CmdResult, RteEnv +from ten import Cmd, StatusCode, CmdResult def chat_from_astra_response(cmd_result: CmdResult) -> ChatResponse: @@ -37,12 +37,12 @@ def _messages_str_from_chat_messages(messages: Sequence[ChatMessage]) -> str: class ASTRALLM(CustomLLM): - rte: Any + ten: Any - def __init__(self, rte): + def __init__(self, ten): """Creates a new ASTRA model interface.""" super().__init__() - self.rte = rte + self.ten = ten @property def metadata(self) -> LLMMetadata: @@ -79,7 +79,7 @@ def callback(_, result): ) ) - self.rte.send_cmd(cmd, callback) + self.ten.send_cmd(cmd, callback) wait_event.wait() return resp @@ -135,7 +135,7 @@ def callback(_, result): cmd.get_name(), messages_str ) ) - self.rte.send_cmd(cmd, callback) + self.ten.send_cmd(cmd, callback) return gen() def stream_complete( diff --git a/agents/ten_packages/extension/llama_index_chat_engine/astra_retriever.py b/agents/ten_packages/extension/llama_index_chat_engine/astra_retriever.py index c74dfb99..95790cba 100644 --- a/agents/ten_packages/extension/llama_index_chat_engine/astra_retriever.py +++ b/agents/ten_packages/extension/llama_index_chat_engine/astra_retriever.py @@ -6,8 +6,8 @@ from .log import logger from .astra_embedding import ASTRAEmbedding -from rte import ( - RteEnv, +from ten import ( + TenEnv, Cmd, StatusCode, CmdResult, @@ -46,14 +46,14 @@ def format_node_result(cmd_result: CmdResult) -> List[NodeWithScore]: class ASTRARetriever(BaseRetriever): - rte: Any + ten: Any embed_model: ASTRAEmbedding - def __init__(self, rte: RteEnv, coll: str): + def __init__(self, ten: TenEnv, coll: str): super().__init__() try: - self.rte = rte - self.embed_model = ASTRAEmbedding(rte=rte) + self.ten = ten + self.embed_model = ASTRAEmbedding(ten=ten) self.collection_name = coll except Exception as e: logger.error(f"Failed to initialize ASTRARetriever: {e}") @@ -82,7 +82,7 @@ def cmd_callback(_, result): self.collection_name, len(embedding) ) ) - self.rte.send_cmd(query_cmd, cmd_callback) + self.ten.send_cmd(query_cmd, cmd_callback) wait_event.wait() return resp diff --git a/agents/ten_packages/extension/llama_index_chat_engine/extension.py b/agents/ten_packages/extension/llama_index_chat_engine/extension.py index 4b84221b..c4a62357 100644 --- a/agents/ten_packages/extension/llama_index_chat_engine/extension.py +++ b/agents/ten_packages/extension/llama_index_chat_engine/extension.py @@ -5,9 +5,9 @@ # Copyright (c) 2024 Agora IO. All rights reserved. # # -from rte import ( +from ten import ( Extension, - RteEnv, + TenEnv, Cmd, Data, StatusCode, @@ -43,12 +43,12 @@ def __init__(self, name: str): self.chat_memory_token_limit = 3000 self.chat_memory = None - def _send_text_data(self, rte: RteEnv, text: str, end_of_segment: bool): + def _send_text_data(self, ten: TenEnv, text: str, end_of_segment: bool): try: output_data = Data.create("text_data") output_data.set_property_string("text", text) output_data.set_property_bool("end_of_segment", end_of_segment) - rte.send_data(output_data) + ten.send_data(output_data) logger.info("text [{}] end_of_segment {} sent".format(text, end_of_segment)) except Exception as err: logger.info( @@ -57,17 +57,17 @@ def _send_text_data(self, rte: RteEnv, text: str, end_of_segment: bool): ) ) - def on_start(self, rte: RteEnv) -> None: + def on_start(self, ten: TenEnv) -> None: logger.info("on_start") greeting = None try: - greeting = rte.get_property_string(PROPERTY_GREETING) + greeting = ten.get_property_string(PROPERTY_GREETING) except Exception as err: logger.warning(f"get {PROPERTY_GREETING} property failed, err: {err}") try: - self.chat_memory_token_limit = rte.get_property_int( + self.chat_memory_token_limit = ten.get_property_int( PROPERTY_CHAT_MEMORY_TOKEN_LIMIT ) except Exception as err: @@ -75,7 +75,7 @@ def on_start(self, rte: RteEnv) -> None: f"get {PROPERTY_CHAT_MEMORY_TOKEN_LIMIT} property failed, err: {err}" ) - self.thread = threading.Thread(target=self.async_handle, args=[rte]) + self.thread = threading.Thread(target=self.async_handle, args=[ten]) self.thread.start() # enable chat memory @@ -86,11 +86,11 @@ def on_start(self, rte: RteEnv) -> None: # Send greeting if available if greeting is not None: - self._send_text_data(rte, greeting, True) + self._send_text_data(ten, greeting, True) - rte.on_start_done() + ten.on_start_done() - def on_stop(self, rte: RteEnv) -> None: + def on_stop(self, ten: TenEnv) -> None: logger.info("on_stop") self.stop = True @@ -101,9 +101,9 @@ def on_stop(self, rte: RteEnv) -> None: self.thread = None self.chat_memory = None - rte.on_stop_done() + ten.on_stop_done() - def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: + def on_cmd(self, ten: TenEnv, cmd: Cmd) -> None: cmd_name = cmd.get_name() logger.info("on_cmd {}".format(cmd_name)) @@ -127,14 +127,14 @@ def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: # notify user file_chunked_text = "Your document has been processed. You can now start asking questions about your document. " - # self._send_text_data(rte, file_chunked_text, True) + # self._send_text_data(ten, file_chunked_text, True) self.queue.put((file_chunked_text, datetime.now(), TASK_TYPE_GREETING)) elif cmd_name == "file_chunk": self.collection_name = "" # clear current collection # notify user file_chunk_text = "Your document has been received. Please wait a moment while we process it for you. " - # self._send_text_data(rte, file_chunk_text, True) + # self._send_text_data(ten, file_chunk_text, True) self.queue.put((file_chunk_text, datetime.now(), TASK_TYPE_GREETING)) elif cmd_name == "update_querying_collection": coll = cmd.get_property_string("collection") @@ -151,20 +151,20 @@ def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: update_querying_collection_text += ( "You can now start asking questions about your document. " ) - # self._send_text_data(rte, update_querying_collection_text, True) + # self._send_text_data(ten, update_querying_collection_text, True) self.queue.put( (update_querying_collection_text, datetime.now(), TASK_TYPE_GREETING) ) elif cmd_name == "flush": self.flush() - rte.send_cmd(Cmd.create("flush"), None) + ten.send_cmd(Cmd.create("flush"), None) cmd_result = CmdResult.create(StatusCode.OK) cmd_result.set_property_string("detail", "ok") - rte.return_result(cmd_result, cmd) + ten.return_result(cmd_result, cmd) - def on_data(self, rte: RteEnv, data: Data) -> None: + def on_data(self, ten: TenEnv, data: Data) -> None: is_final = data.get_property_bool("is_final") if not is_final: logger.info("on_data ignore non final") @@ -180,7 +180,7 @@ def on_data(self, rte: RteEnv, data: Data) -> None: logger.info("on_data text [%s], ts [%s]", inputText, ts) self.queue.put((inputText, ts, TASK_TYPE_CHAT_REQUEST)) - def async_handle(self, rte: RteEnv): + def async_handle(self, ten: TenEnv): logger.info("async_handle started") while not self.stop: try: @@ -199,7 +199,7 @@ def async_handle(self, rte: RteEnv): if task_type == TASK_TYPE_GREETING: # send greeting text directly - self._send_text_data(rte, input_text, True) + self._send_text_data(ten, input_text, True) continue logger.info("process input text [%s] ts [%s]", input_text, ts) @@ -208,8 +208,8 @@ def async_handle(self, rte: RteEnv): chat_engine = None if len(self.collection_name) > 0: chat_engine = ContextChatEngine.from_defaults( - llm=ASTRALLM(rte=rte), - retriever=ASTRARetriever(rte=rte, coll=self.collection_name), + llm=ASTRALLM(ten=ten), + retriever=ASTRARetriever(ten=ten, coll=self.collection_name), memory=self.chat_memory, system_prompt=( # "You are an expert Q&A system that is trusted around the world.\n" @@ -230,7 +230,7 @@ def async_handle(self, rte: RteEnv): ) else: chat_engine = SimpleChatEngine.from_defaults( - llm=ASTRALLM(rte=rte), + llm=ASTRALLM(ten=ten), system_prompt=( "You are a voice assistant who talks in a conversational way and can chat with me like my friends. \n" "I will speak to you in English or Chinese, and you will answer in the corrected and improved version of my text with the language I use. \n" @@ -256,10 +256,10 @@ def async_handle(self, rte: RteEnv): text = str(cur_token) # send out - self._send_text_data(rte, text, False) + self._send_text_data(ten, text, False) # send out end_of_segment - self._send_text_data(rte, "", True) + self._send_text_data(ten, "", True) except Exception as e: logger.exception(e) logger.info("async_handle stoped") diff --git a/agents/ten_packages/extension/openai_chatgpt_python/openai_chatgpt_addon.py b/agents/ten_packages/extension/openai_chatgpt_python/openai_chatgpt_addon.py index d9b3e0b9..861291c2 100644 --- a/agents/ten_packages/extension/openai_chatgpt_python/openai_chatgpt_addon.py +++ b/agents/ten_packages/extension/openai_chatgpt_python/openai_chatgpt_addon.py @@ -5,19 +5,19 @@ # Copyright (c) 2024 Agora IO. All rights reserved. # # -from rte import ( +from ten import ( Addon, register_addon_as_extension, - RteEnv, + TenEnv, ) from .log import logger @register_addon_as_extension("openai_chatgpt_python") class OpenAIChatGPTExtensionAddon(Addon): - def on_create_instance(self, rte: RteEnv, addon_name: str, context) -> None: + def on_create_instance(self, ten: TenEnv, addon_name: str, context) -> None: logger.info("on_create_instance") from .openai_chatgpt_extension import OpenAIChatGPTExtension - rte.on_create_instance_done(OpenAIChatGPTExtension(addon_name), context) + ten.on_create_instance_done(OpenAIChatGPTExtension(addon_name), context) diff --git a/agents/ten_packages/extension/openai_chatgpt_python/openai_chatgpt_extension.py b/agents/ten_packages/extension/openai_chatgpt_python/openai_chatgpt_extension.py index e8f670e9..84ee8f3a 100644 --- a/agents/ten_packages/extension/openai_chatgpt_python/openai_chatgpt_extension.py +++ b/agents/ten_packages/extension/openai_chatgpt_python/openai_chatgpt_extension.py @@ -6,20 +6,19 @@ # # import traceback -from rte.image_frame import ImageFrame +from ten.video_frame import VideoFrame from .openai_chatgpt import OpenAIChatGPT, OpenAIChatGPTConfig from datetime import datetime from threading import Thread -from rte import ( +from ten import ( Addon, Extension, register_addon_as_extension, - RteEnv, + TenEnv, Cmd, Data, StatusCode, CmdResult, - MetadataInfo, ) from .log import logger from base64 import b64encode @@ -79,10 +78,11 @@ def parse_sentence(sentence, content): return sentence, remain, found_punc + def rgb2base64jpeg(rgb_data, width, height): # Convert the RGB image to a PIL Image - pil_image = Image.frombytes('RGBA', (width, height), bytes(rgb_data)) - pil_image = pil_image.convert('RGB') + pil_image = Image.frombytes("RGBA", (width, height), bytes(rgb_data)) + pil_image = pil_image.convert("RGB") # Resize the image while maintaining its aspect ratio pil_image = resize_image_keep_aspect(pil_image, 320) @@ -96,18 +96,19 @@ def rgb2base64jpeg(rgb_data, width, height): jpeg_image_data = buffered.getvalue() # Convert the JPEG byte data to a Base64 encoded string - base64_encoded_image = b64encode(jpeg_image_data).decode('utf-8') + base64_encoded_image = b64encode(jpeg_image_data).decode("utf-8") # Create the data URL - mime_type = 'image/jpeg' + mime_type = "image/jpeg" base64_url = f"data:{mime_type};base64,{base64_encoded_image}" return base64_url + def resize_image_keep_aspect(image, max_size=512): """ Resize an image while maintaining its aspect ratio, ensuring the larger dimension is max_size. If both dimensions are smaller than max_size, the image is not resized. - + :param image: A PIL Image object :param max_size: The maximum size for the larger dimension (width or height) :return: A PIL Image object (resized or original) @@ -135,6 +136,7 @@ def resize_image_keep_aspect(image, max_size=512): return resized_image + class OpenAIChatGPTExtension(Extension): memory = [] max_memory_length = 10 @@ -145,51 +147,53 @@ class OpenAIChatGPTExtension(Extension): image_width = 0 image_height = 0 - available_tools = [{ - "type": "function", - "function": { - # ensure you use gpt-4o or later model if you need image recognition, gpt-4o-mini does not work quite well in this case - "name": "get_vision_image", - "description": "Get the image from camera. Call this whenever you need to understand the input camera image like you have vision capability, for example when user asks 'What can you see?' or 'Can you see me?'", - }, - "strict": True, - }] - - def on_start(self, rte: RteEnv) -> None: + available_tools = [ + { + "type": "function", + "function": { + # ensure you use gpt-4o or later model if you need image recognition, gpt-4o-mini does not work quite well in this case + "name": "get_vision_image", + "description": "Get the image from camera. Call this whenever you need to understand the input camera image like you have vision capability, for example when user asks 'What can you see?' or 'Can you see me?'", + }, + "strict": True, + } + ] + + def on_start(self, ten: TenEnv) -> None: logger.info("OpenAIChatGPTExtension on_start") # Prepare configuration openai_chatgpt_config = OpenAIChatGPTConfig.default_config() try: - base_url = rte.get_property_string(PROPERTY_BASE_URL) + base_url = ten.get_property_string(PROPERTY_BASE_URL) if base_url: openai_chatgpt_config.base_url = base_url except Exception as err: logger.info(f"GetProperty required {PROPERTY_BASE_URL} failed, err: {err}") try: - api_key = rte.get_property_string(PROPERTY_API_KEY) + api_key = ten.get_property_string(PROPERTY_API_KEY) openai_chatgpt_config.api_key = api_key except Exception as err: logger.info(f"GetProperty required {PROPERTY_API_KEY} failed, err: {err}") return try: - model = rte.get_property_string(PROPERTY_MODEL) + model = ten.get_property_string(PROPERTY_MODEL) if model: openai_chatgpt_config.model = model except Exception as err: logger.info(f"GetProperty optional {PROPERTY_MODEL} error: {err}") try: - prompt = rte.get_property_string(PROPERTY_PROMPT) + prompt = ten.get_property_string(PROPERTY_PROMPT) if prompt: openai_chatgpt_config.prompt = prompt except Exception as err: logger.info(f"GetProperty optional {PROPERTY_PROMPT} error: {err}") try: - frequency_penalty = rte.get_property_float(PROPERTY_FREQUENCY_PENALTY) + frequency_penalty = ten.get_property_float(PROPERTY_FREQUENCY_PENALTY) openai_chatgpt_config.frequency_penalty = float(frequency_penalty) except Exception as err: logger.info( @@ -197,7 +201,7 @@ def on_start(self, rte: RteEnv) -> None: ) try: - presence_penalty = rte.get_property_float(PROPERTY_PRESENCE_PENALTY) + presence_penalty = ten.get_property_float(PROPERTY_PRESENCE_PENALTY) openai_chatgpt_config.presence_penalty = float(presence_penalty) except Exception as err: logger.info( @@ -205,7 +209,7 @@ def on_start(self, rte: RteEnv) -> None: ) try: - temperature = rte.get_property_float(PROPERTY_TEMPERATURE) + temperature = ten.get_property_float(PROPERTY_TEMPERATURE) openai_chatgpt_config.temperature = float(temperature) except Exception as err: logger.info( @@ -213,13 +217,13 @@ def on_start(self, rte: RteEnv) -> None: ) try: - top_p = rte.get_property_float(PROPERTY_TOP_P) + top_p = ten.get_property_float(PROPERTY_TOP_P) openai_chatgpt_config.top_p = float(top_p) except Exception as err: logger.info(f"GetProperty optional {PROPERTY_TOP_P} failed, err: {err}") try: - max_tokens = rte.get_property_int(PROPERTY_MAX_TOKENS) + max_tokens = ten.get_property_int(PROPERTY_MAX_TOKENS) if max_tokens > 0: openai_chatgpt_config.max_tokens = int(max_tokens) except Exception as err: @@ -228,23 +232,25 @@ def on_start(self, rte: RteEnv) -> None: ) try: - proxy_url = rte.get_property_string(PROPERTY_PROXY_URL) + proxy_url = ten.get_property_string(PROPERTY_PROXY_URL) openai_chatgpt_config.proxy_url = proxy_url except Exception as err: logger.info(f"GetProperty optional {PROPERTY_PROXY_URL} failed, err: {err}") try: - greeting = rte.get_property_string(PROPERTY_GREETING) + greeting = ten.get_property_string(PROPERTY_GREETING) except Exception as err: logger.info(f"GetProperty optional {PROPERTY_GREETING} failed, err: {err}") try: - self.enable_tools = rte.get_property_bool(PROPERTY_ENABLE_TOOLS) + self.enable_tools = ten.get_property_bool(PROPERTY_ENABLE_TOOLS) except Exception as err: - logger.info(f"GetProperty optional {PROPERTY_ENABLE_TOOLS} failed, err: {err}") + logger.info( + f"GetProperty optional {PROPERTY_ENABLE_TOOLS} failed, err: {err}" + ) try: - prop_max_memory_length = rte.get_property_int(PROPERTY_MAX_MEMORY_LENGTH) + prop_max_memory_length = ten.get_property_int(PROPERTY_MAX_MEMORY_LENGTH) if prop_max_memory_length > 0: self.max_memory_length = int(prop_max_memory_length) except Exception as err: @@ -271,22 +277,22 @@ def on_start(self, rte: RteEnv) -> None: output_data.set_property_bool( DATA_OUT_TEXT_DATA_PROPERTY_TEXT_END_OF_SEGMENT, True ) - rte.send_data(output_data) + ten.send_data(output_data) logger.info(f"greeting [{greeting}] sent") except Exception as err: logger.info(f"greeting [{greeting}] send failed, err: {err}") - rte.on_start_done() + ten.on_start_done() - def on_stop(self, rte: RteEnv) -> None: + def on_stop(self, ten: TenEnv) -> None: logger.info("OpenAIChatGPTExtension on_stop") - rte.on_stop_done() + ten.on_stop_done() def append_memory(self, message): if len(self.memory) > self.max_memory_length: self.memory.pop(0) self.memory.append(message) - def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: + def on_cmd(self, ten: TenEnv, cmd: Cmd) -> None: logger.info("OpenAIChatGPTExtension on_cmd") cmd_json = cmd.to_json() logger.info("OpenAIChatGPTExtension on_cmd json: " + cmd_json) @@ -296,29 +302,29 @@ def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: if cmd_name == CMD_IN_FLUSH: self.outdate_ts = get_current_time() cmd_out = Cmd.create(CMD_OUT_FLUSH) - rte.send_cmd(cmd_out, None) + ten.send_cmd(cmd_out, None) logger.info(f"OpenAIChatGPTExtension on_cmd sent flush") else: logger.info(f"OpenAIChatGPTExtension on_cmd unknown cmd: {cmd_name}") cmd_result = CmdResult.create(StatusCode.ERROR) cmd_result.set_property_string("detail", "unknown cmd") - rte.return_result(cmd_result, cmd) + ten.return_result(cmd_result, cmd) return cmd_result = CmdResult.create(StatusCode.OK) cmd_result.set_property_string("detail", "success") - rte.return_result(cmd_result, cmd) + ten.return_result(cmd_result, cmd) - def on_image_frame(self, rte_env: RteEnv, image_frame: ImageFrame) -> None: - # logger.info(f"OpenAIChatGPTExtension on_image_frame {image_frame.get_width()} {image_frame.get_height()}") - self.image_data = image_frame.get_buf() - self.image_width = image_frame.get_width() - self.image_height = image_frame.get_height() + def on_video_frame(self, ten_env: TenEnv, frame: VideoFrame) -> None: + # logger.info(f"OpenAIChatGPTExtension on_video_frame {frame.get_width()} {frame.get_height()}") + self.image_data = frame.get_buf() + self.image_width = frame.get_width() + self.image_height = frame.get_height() return - def on_data(self, rte: RteEnv, data: Data) -> None: + def on_data(self, ten: TenEnv, data: Data) -> None: """ - on_data receives data from rte graph. + on_data receives data from ten graph. current supported data: - name: text_data example: @@ -352,7 +358,7 @@ def on_data(self, rte: RteEnv, data: Data) -> None: return def chat_completions_stream_worker(start_time, input_text, memory): - self.chat_completion(rte, start_time, input_text, memory) + self.chat_completion(ten, start_time, input_text, memory) # Start thread to request and read responses from OpenAI start_time = get_current_time() @@ -363,17 +369,25 @@ def chat_completions_stream_worker(start_time, input_text, memory): thread.start() logger.info(f"OpenAIChatGPTExtension on_data end") - def send_data(self, rte, sentence, end_of_segment, input_text): + def send_data(self, ten, sentence, end_of_segment, input_text): try: output_data = Data.create("text_data") output_data.set_property_string(DATA_OUT_TEXT_DATA_PROPERTY_TEXT, sentence) - output_data.set_property_bool(DATA_OUT_TEXT_DATA_PROPERTY_TEXT_END_OF_SEGMENT, end_of_segment) - rte.send_data(output_data) - logger.info(f"for input text: [{input_text}] {'end of segment ' if end_of_segment else ''}sent sentence [{sentence}]") + output_data.set_property_bool( + DATA_OUT_TEXT_DATA_PROPERTY_TEXT_END_OF_SEGMENT, end_of_segment + ) + ten.send_data(output_data) + logger.info( + f"for input text: [{input_text}] {'end of segment ' if end_of_segment else ''}sent sentence [{sentence}]" + ) except Exception as err: - logger.info(f"for input text: [{input_text}] send sentence [{sentence}] failed, err: {err}") + logger.info( + f"for input text: [{input_text}] send sentence [{sentence}] failed, err: {err}" + ) - def process_completions(self, chat_completions, rte, start_time, input_text, memory): + def process_completions( + self, chat_completions, ten, start_time, input_text, memory + ): sentence = "" full_content = "" first_sentence_sent = False @@ -381,22 +395,26 @@ def process_completions(self, chat_completions, rte, start_time, input_text, mem for chat_completion in chat_completions: content = "" if start_time < self.outdate_ts: - logger.info(f"recv interrupt and flushing for input text: [{input_text}], startTs: {start_time}, outdateTs: {self.outdate_ts}") + logger.info( + f"recv interrupt and flushing for input text: [{input_text}], startTs: {start_time}, outdateTs: {self.outdate_ts}" + ) break # content = chat_completion.choices[0].delta.content if len(chat_completion.choices) > 0 and chat_completion.choices[0].delta.content is not None else "" - if ( - len(chat_completion.choices) > 0 - ): + if len(chat_completion.choices) > 0: if chat_completion.choices[0].delta.tool_calls is not None: for tool_call in chat_completion.choices[0].delta.tool_calls: logger.info(f"tool_call: {tool_call}") if tool_call.function.name == "get_vision_image": if full_content is "": # if no text content, send a message to ask user to wait - self.send_data(rte, "Let me take a look...", True, input_text) + self.send_data( + ten, "Let me take a look...", True, input_text + ) # for get_vision_image, re-run the completion with vision, memory should not be affected - self.chat_completion_with_vision(rte, start_time, input_text, memory) + self.chat_completion_with_vision( + ten, start_time, input_text, memory + ) return elif chat_completion.choices[0].delta.content is not None: content = chat_completion.choices[0].delta.content @@ -410,62 +428,77 @@ def process_completions(self, chat_completions, rte, start_time, input_text, mem if len(sentence) == 0 or not sentence_is_final: logger.info(f"sentence {sentence} is empty or not final") break - logger.info(f"recv for input text: [{input_text}] got sentence: [{sentence}]") - self.send_data(rte, sentence, False, input_text) + logger.info( + f"recv for input text: [{input_text}] got sentence: [{sentence}]" + ) + self.send_data(ten, sentence, False, input_text) sentence = "" if not first_sentence_sent: first_sentence_sent = True - logger.info(f"recv for input text: [{input_text}] first sentence sent, first_sentence_latency {get_current_time() - start_time}ms") - + logger.info( + f"recv for input text: [{input_text}] first sentence sent, first_sentence_latency {get_current_time() - start_time}ms" + ) # memory is recorded only when completion is completely done, with single pair of user and assistant message self.append_memory({"role": "user", "content": input_text}) self.append_memory({"role": "assistant", "content": full_content}) - self.send_data(rte, sentence, True, input_text) + self.send_data(ten, sentence, True, input_text) - def chat_completion_with_vision(self, rte: RteEnv, start_time, input_text, memory): + def chat_completion_with_vision(self, ten: TenEnv, start_time, input_text, memory): try: logger.info(f"for input text: [{input_text}] memory: {memory}") message = {"role": "user", "content": input_text} if self.image_data is not None: - url = rgb2base64jpeg(self.image_data, self.image_width, self.image_height) - message = {"role": "user", "content": [ - {"type": "text", "text": input_text}, - {"type": "image_url", "image_url": {"url": url}} - ]} + url = rgb2base64jpeg( + self.image_data, self.image_width, self.image_height + ) + message = { + "role": "user", + "content": [ + {"type": "text", "text": input_text}, + {"type": "image_url", "image_url": {"url": url}}, + ], + } logger.info(f"msg: {message}") resp = self.openai_chatgpt.get_chat_completions_stream(memory + [message]) if resp is None: - logger.error(f"get_chat_completions_stream Response is None: {input_text}") + logger.error( + f"get_chat_completions_stream Response is None: {input_text}" + ) return - self.process_completions(resp, rte, start_time, input_text, memory) + self.process_completions(resp, ten, start_time, input_text, memory) except Exception as e: logger.error(f"err: {str(e)}: {input_text}") - def chat_completion(self, rte: RteEnv, start_time, input_text, memory): + def chat_completion(self, ten: TenEnv, start_time, input_text, memory): try: logger.info(f"for input text: [{input_text}] memory: {memory}") message = {"role": "user", "content": input_text} - + tools = self.available_tools if self.enable_tools else None logger.info(f"chat_completion tools: {tools}") - resp = self.openai_chatgpt.get_chat_completions_stream(memory + [message], tools) + resp = self.openai_chatgpt.get_chat_completions_stream( + memory + [message], tools + ) if resp is None: - logger.error(f"get_chat_completions_stream Response is None: {input_text}") + logger.error( + f"get_chat_completions_stream Response is None: {input_text}" + ) return - self.process_completions(resp, rte, start_time, input_text, memory) + self.process_completions(resp, ten, start_time, input_text, memory) except Exception as e: logger.error(f"err: {traceback.format_exc()}: {input_text}") + @register_addon_as_extension("openai_chatgpt_python") class OpenAIChatGPTExtensionAddon(Addon): - def on_create_instance(self, rte: RteEnv, addon_name: str, context) -> None: + def on_create_instance(self, ten: TenEnv, addon_name: str, context) -> None: logger.info("on_create_instance") - rte.on_create_instance_done(OpenAIChatGPTExtension(addon_name), context) + ten.on_create_instance_done(OpenAIChatGPTExtension(addon_name), context) diff --git a/agents/ten_packages/extension/polly_tts/polly_tts_addon.py b/agents/ten_packages/extension/polly_tts/polly_tts_addon.py index 92047df3..e8b9ab6a 100644 --- a/agents/ten_packages/extension/polly_tts/polly_tts_addon.py +++ b/agents/ten_packages/extension/polly_tts/polly_tts_addon.py @@ -1,7 +1,7 @@ -from rte import ( +from ten import ( Addon, register_addon_as_extension, - RteEnv, + TenEnv, ) from .extension import EXTENSION_NAME from .log import logger @@ -10,6 +10,6 @@ @register_addon_as_extension(EXTENSION_NAME) class PollyTTSExtensionAddon(Addon): - def on_create_instance(self, rte: RteEnv, addon_name: str, context) -> None: + def on_create_instance(self, ten: TenEnv, addon_name: str, context) -> None: logger.info("on_create_instance") - rte.on_create_instance_done(PollyTTSExtension(addon_name), context) + ten.on_create_instance_done(PollyTTSExtension(addon_name), context) diff --git a/agents/ten_packages/extension/polly_tts/polly_tts_extension.py b/agents/ten_packages/extension/polly_tts/polly_tts_extension.py index 78f95658..b41ad5fa 100644 --- a/agents/ten_packages/extension/polly_tts/polly_tts_extension.py +++ b/agents/ten_packages/extension/polly_tts/polly_tts_extension.py @@ -1,13 +1,12 @@ -from rte import ( +from ten import ( Extension, - RteEnv, + TenEnv, Cmd, - PcmFrame, - PcmFrameDataFmt, + AudioFrameDataFmt, + AudioFrame, Data, StatusCode, CmdResult, - MetadataInfo, ) import queue @@ -22,10 +21,10 @@ PROPERTY_REGION = "region" # Optional PROPERTY_ACCESS_KEY = "access_key" # Optional PROPERTY_SECRET_KEY = "secret_key" # Optional -PROPERTY_ENGINE = 'engine' # Optional -PROPERTY_VOICE = 'voice' # Optional -PROPERTY_SAMPLE_RATE = 'sample_rate' # Optional -PROPERTY_LANG_CODE = 'lang_code' # Optional +PROPERTY_ENGINE = "engine" # Optional +PROPERTY_VOICE = "voice" # Optional +PROPERTY_SAMPLE_RATE = "sample_rate" # Optional +PROPERTY_LANG_CODE = "lang_code" # Optional class PollyTTSExtension(Extension): @@ -41,59 +40,72 @@ def __init__(self, name: str): self.bytes_per_sample = 2 self.number_of_channels = 1 - def on_start(self, rte: RteEnv) -> None: + def on_start(self, ten: TenEnv) -> None: logger.info("PollyTTSExtension on_start") polly_config = PollyConfig.default_config() - for optional_param in [PROPERTY_REGION, PROPERTY_ENGINE, PROPERTY_VOICE, - PROPERTY_SAMPLE_RATE, PROPERTY_LANG_CODE, - PROPERTY_ACCESS_KEY, PROPERTY_SECRET_KEY]: + for optional_param in [ + PROPERTY_REGION, + PROPERTY_ENGINE, + PROPERTY_VOICE, + PROPERTY_SAMPLE_RATE, + PROPERTY_LANG_CODE, + PROPERTY_ACCESS_KEY, + PROPERTY_SECRET_KEY, + ]: try: - value = rte.get_property_string(optional_param).strip() + value = ten.get_property_string(optional_param).strip() if value: polly_config.__setattr__(optional_param, value) except Exception as err: - logger.debug(f"GetProperty optional {optional_param} failed, err: {err}. Using default value: {polly_config.__getattribute__(optional_param)}") + logger.debug( + f"GetProperty optional {optional_param} failed, err: {err}. Using default value: {polly_config.__getattribute__(optional_param)}" + ) self.polly = PollyWrapper(polly_config) - self.frame_size = int(int(polly_config.sample_rate) * self.number_of_channels * self.bytes_per_sample / 100) - - self.thread = threading.Thread(target=self.async_polly_handler, args=[rte]) + self.frame_size = int( + int(polly_config.sample_rate) + * self.number_of_channels + * self.bytes_per_sample + / 100 + ) + + self.thread = threading.Thread(target=self.async_polly_handler, args=[ten]) self.thread.start() - rte.on_start_done() + ten.on_start_done() - def on_stop(self, rte: RteEnv) -> None: + def on_stop(self, ten: TenEnv) -> None: logger.info("PollyTTSExtension on_stop") self.stopped = True self.queue.put(None) self.flush() self.thread.join() - rte.on_stop_done() + ten.on_stop_done() def need_interrupt(self, ts: datetime.time) -> bool: return (self.outdateTs - ts).total_seconds() > 1 - def __get_frame(self, data: bytes) -> PcmFrame: + def __get_frame(self, data: bytes) -> AudioFrame: sample_rate = int(self.polly.config.sample_rate) - f = PcmFrame.create("pcm_frame") + f = AudioFrame.create("pcm_frame") f.set_sample_rate(sample_rate) f.set_bytes_per_sample(2) f.set_number_of_channels(1) - f.set_data_fmt(PcmFrameDataFmt.INTERLEAVE) + f.set_data_fmt(AudioFrameDataFmt.INTERLEAVE) f.set_samples_per_channel(sample_rate // 100) f.alloc_buf(self.frame_size) buff = f.lock_buf() if len(data) < self.frame_size: buff[:] = bytes(self.frame_size) # fill with 0 - buff[:len(data)] = data + buff[: len(data)] = data f.unlock_buf(buff) return f - def async_polly_handler(self, rte: RteEnv): + def async_polly_handler(self, ten: TenEnv): while not self.stopped: value = self.queue.get() if value is None: @@ -108,11 +120,13 @@ def async_polly_handler(self, rte: RteEnv): with closing(audio_stream) as stream: for chunk in stream.iter_chunks(chunk_size=self.frame_size): if self.need_interrupt(ts): - logger.debug("async_polly_handler: got interrupt cmd, stop sending pcm frame.") + logger.debug( + "async_polly_handler: got interrupt cmd, stop sending pcm frame." + ) break f = self.__get_frame(chunk) - rte.send_pcm_frame(f) + ten.send_audio_frame(f) except Exception as e: logger.exception(e) logger.exception(traceback.format_exc()) @@ -123,7 +137,7 @@ def flush(self): self.queue.get() self.queue.put(("", datetime.now())) - def on_data(self, rte: RteEnv, data: Data) -> None: + def on_data(self, ten: TenEnv, data: Data) -> None: logger.info("PollyTTSExtension on_data") inputText = data.get_property_string("text") if len(inputText) == 0: @@ -135,7 +149,7 @@ def on_data(self, rte: RteEnv, data: Data) -> None: logger.info("on data %s %d", inputText, is_end) self.queue.put((inputText, datetime.now())) - def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: + def on_cmd(self, ten: TenEnv, cmd: Cmd) -> None: logger.info("PollyTTSExtension on_cmd") cmd_json = cmd.to_json() logger.info("PollyTTSExtension on_cmd json: %s" + cmd_json) @@ -145,10 +159,12 @@ def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: self.outdateTs = datetime.now() self.flush() cmd_out = Cmd.create("flush") - rte.send_cmd(cmd_out, lambda rte, result: print("PollyTTSExtension send_cmd done")) + ten.send_cmd( + cmd_out, lambda ten, result: print("PollyTTSExtension send_cmd done") + ) else: logger.info("unknown cmd %s", cmdName) cmd_result = CmdResult.create(StatusCode.OK) cmd_result.set_property_string("detail", "success") - rte.return_result(cmd_result, cmd) + ten.return_result(cmd_result, cmd) diff --git a/agents/ten_packages/extension/qwen_llm_python/qwen_llm_addon.py b/agents/ten_packages/extension/qwen_llm_python/qwen_llm_addon.py index c0a3fa94..3af6f95c 100644 --- a/agents/ten_packages/extension/qwen_llm_python/qwen_llm_addon.py +++ b/agents/ten_packages/extension/qwen_llm_python/qwen_llm_addon.py @@ -5,20 +5,20 @@ # Copyright (c) 2024 Agora IO. All rights reserved. # # -from rte import ( +from ten import ( Addon, register_addon_as_extension, - RteEnv, + TenEnv, ) from .log import logger @register_addon_as_extension("qwen_llm_python") class QWenLLMExtensionAddon(Addon): - def on_create_instance(self, rte: RteEnv, addon_name: str, context): + def on_create_instance(self, ten: TenEnv, addon_name: str, context): logger.info("on_create_instance") from .qwen_llm_extension import QWenLLMExtension - rte.on_create_instance_done(QWenLLMExtension(addon_name), context) + ten.on_create_instance_done(QWenLLMExtension(addon_name), context) diff --git a/agents/ten_packages/extension/qwen_llm_python/qwen_llm_extension.py b/agents/ten_packages/extension/qwen_llm_python/qwen_llm_extension.py index 6cd58f20..de6ba493 100644 --- a/agents/ten_packages/extension/qwen_llm_python/qwen_llm_extension.py +++ b/agents/ten_packages/extension/qwen_llm_python/qwen_llm_extension.py @@ -5,9 +5,9 @@ # Copyright (c) 2024 Agora IO. All rights reserved. # # -from rte import ( +from ten import ( Extension, - RteEnv, + TenEnv, Cmd, Data, StatusCode, @@ -71,7 +71,7 @@ def get_outdate_ts(self) -> datetime: with self.outdate_ts_lock: return self.outdate_ts - def complete_with_history(self, rte: RteEnv, ts: datetime.time, input_text: str): + def complete_with_history(self, ten: TenEnv, ts: datetime.time, input_text: str): """ Complete input_text querying with built-in chat history. """ @@ -80,7 +80,7 @@ def callback(text: str, end_of_segment: bool): d = Data.create("text_data") d.set_property_string("text", text) d.set_property_bool("end_of_segment", end_of_segment) - rte.send_data(d) + ten.send_data(d) messages = self.get_messages() messages.append({"role": "user", "content": input_text}) @@ -89,7 +89,7 @@ def callback(text: str, end_of_segment: bool): if len(total) > 0: self.on_msg("assistant", total) - def call_chat(self, rte: RteEnv, ts: datetime.time, cmd: Cmd): + def call_chat(self, ten: TenEnv, ts: datetime.time, cmd: Cmd): """ Respond to call_chat cmd and return results in streaming. The incoming 'messages' will contains all the system prompt, chat history and question. @@ -115,7 +115,7 @@ def callback(text: str, end_of_segment: bool): else: cmd_result.set_is_final(False) # keep streaming return logger.info("call_chat cmd return_result {}".format(cmd_result.to_json())) - rte.return_result(cmd_result, cmd) + ten.return_result(cmd_result, cmd) messages_str = cmd.get_property_string("messages") messages = json.loads(messages_str) @@ -184,19 +184,19 @@ def stream_chat(self, ts: datetime.time, messages: List[Any], callback): logger.info("stream_chat full_answer {}".format(total)) return total - def on_start(self, rte: RteEnv) -> None: + def on_start(self, ten: TenEnv) -> None: logger.info("on_start") - self.api_key = rte.get_property_string("api_key") - self.model = rte.get_property_string("model") - self.prompt = rte.get_property_string("prompt") - self.max_history = rte.get_property_int("max_memory_length") + self.api_key = ten.get_property_string("api_key") + self.model = ten.get_property_string("model") + self.prompt = ten.get_property_string("prompt") + self.max_history = ten.get_property_int("max_memory_length") dashscope.api_key = self.api_key - self.thread = threading.Thread(target=self.async_handle, args=[rte]) + self.thread = threading.Thread(target=self.async_handle, args=[ten]) self.thread.start() - rte.on_start_done() + ten.on_start_done() - def on_stop(self, rte: RteEnv) -> None: + def on_stop(self, ten: TenEnv) -> None: logger.info("on_stop") self.stopped = True self.flush() @@ -204,7 +204,7 @@ def on_stop(self, rte: RteEnv) -> None: if self.thread is not None: self.thread.join() self.thread = None - rte.on_stop_done() + ten.on_stop_done() def flush(self): with self.outdate_ts_lock: @@ -213,7 +213,7 @@ def flush(self): while not self.queue.empty(): self.queue.get() - def on_data(self, rte: RteEnv, data: Data) -> None: + def on_data(self, ten: TenEnv, data: Data) -> None: logger.info("on_data") is_final = data.get_property_bool("is_final") if not is_final: @@ -229,7 +229,7 @@ def on_data(self, rte: RteEnv, data: Data) -> None: logger.info("on data %s, %s", input_text, ts) self.queue.put((input_text, ts)) - def async_handle(self, rte: RteEnv): + def async_handle(self, ten: TenEnv): while not self.stopped: try: value = self.queue.get() @@ -241,14 +241,14 @@ def async_handle(self, rte: RteEnv): if isinstance(input, str): logger.info("fetched from queue {}".format(input)) - self.complete_with_history(rte, ts, input) + self.complete_with_history(ten, ts, input) else: logger.info("fetched from queue {}".format(input.get_name())) - self.call_chat(rte, ts, input) + self.call_chat(ten, ts, input) except Exception as e: logger.exception(e) - def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: + def on_cmd(self, ten: TenEnv, cmd: Cmd) -> None: ts = datetime.now() cmd_name = cmd.get_name() logger.info("on_cmd {}, {}".format(cmd_name, ts)) @@ -256,9 +256,9 @@ def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: if cmd_name == "flush": self.flush() cmd_out = Cmd.create("flush") - rte.send_cmd( + ten.send_cmd( cmd_out, - lambda rte, result: logger.info("send_cmd flush done"), + lambda ten, result: logger.info("send_cmd flush done"), ) elif cmd_name == "call_chat": self.queue.put((cmd, ts)) @@ -267,4 +267,4 @@ def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: logger.info("unknown cmd {}".format(cmd_name)) cmd_result = CmdResult.create(StatusCode.OK) - rte.return_result(cmd_result, cmd) + ten.return_result(cmd_result, cmd) diff --git a/agents/ten_packages/extension/transcribe_asr_python/transcribe_asr_addon.py b/agents/ten_packages/extension/transcribe_asr_python/transcribe_asr_addon.py index efdb31da..e9ebf7a9 100644 --- a/agents/ten_packages/extension/transcribe_asr_python/transcribe_asr_addon.py +++ b/agents/ten_packages/extension/transcribe_asr_python/transcribe_asr_addon.py @@ -1,7 +1,7 @@ -from rte import ( +from ten import ( Addon, register_addon_as_extension, - RteEnv, + TenEnv, ) from .extension import EXTENSION_NAME from .log import logger @@ -10,6 +10,6 @@ @register_addon_as_extension(EXTENSION_NAME) class TranscribeAsrExtensionAddon(Addon): - def on_create_instance(self, rte: RteEnv, addon_name: str, context) -> None: + def on_create_instance(self, ten: TenEnv, addon_name: str, context) -> None: logger.info("on_create_instance") - rte.on_create_instance_done(TranscribeAsrExtension(addon_name), context) + ten.on_create_instance_done(TranscribeAsrExtension(addon_name), context) diff --git a/agents/ten_packages/extension/transcribe_asr_python/transcribe_asr_extension.py b/agents/ten_packages/extension/transcribe_asr_python/transcribe_asr_extension.py index 0ce8a4b6..fb0307ee 100644 --- a/agents/ten_packages/extension/transcribe_asr_python/transcribe_asr_extension.py +++ b/agents/ten_packages/extension/transcribe_asr_python/transcribe_asr_extension.py @@ -1,8 +1,8 @@ -from rte import ( +from ten import ( Extension, - RteEnv, + TenEnv, Cmd, - PcmFrame, + AudioFrame, StatusCode, CmdResult, ) @@ -16,8 +16,8 @@ PROPERTY_REGION = "region" # Optional PROPERTY_ACCESS_KEY = "access_key" # Optional PROPERTY_SECRET_KEY = "secret_key" # Optional -PROPERTY_SAMPLE_RATE = 'sample_rate'# Optional -PROPERTY_LANG_CODE = 'lang_code' # Optional +PROPERTY_SAMPLE_RATE = "sample_rate" # Optional +PROPERTY_LANG_CODE = "lang_code" # Optional class TranscribeAsrExtension(Extension): @@ -25,47 +25,58 @@ def __init__(self, name: str): super().__init__(name) self.stopped = False - self.queue = asyncio.Queue(maxsize=3000) # about 3000 * 10ms = 30s input + self.queue = asyncio.Queue(maxsize=3000) # about 3000 * 10ms = 30s input self.transcribe = None self.thread = None self.loop = asyncio.new_event_loop() asyncio.set_event_loop(self.loop) - def on_start(self, rte: RteEnv) -> None: + def on_start(self, ten: TenEnv) -> None: logger.info("TranscribeAsrExtension on_start") transcribe_config = TranscribeConfig.default_config() - for optional_param in [PROPERTY_REGION, PROPERTY_SAMPLE_RATE, PROPERTY_LANG_CODE, - PROPERTY_ACCESS_KEY, PROPERTY_SECRET_KEY]: + for optional_param in [ + PROPERTY_REGION, + PROPERTY_SAMPLE_RATE, + PROPERTY_LANG_CODE, + PROPERTY_ACCESS_KEY, + PROPERTY_SECRET_KEY, + ]: try: - value = rte.get_property_string(optional_param).strip() + value = ten.get_property_string(optional_param).strip() if value: transcribe_config.__setattr__(optional_param, value) except Exception as err: - logger.debug(f"GetProperty optional {optional_param} failed, err: {err}. Using default value: {transcribe_config.__getattribute__(optional_param)}") + logger.debug( + f"GetProperty optional {optional_param} failed, err: {err}. Using default value: {transcribe_config.__getattribute__(optional_param)}" + ) - self.transcribe = AsyncTranscribeWrapper(transcribe_config, self.queue, rte, self.loop) + self.transcribe = AsyncTranscribeWrapper( + transcribe_config, self.queue, ten, self.loop + ) logger.info("Starting async_transcribe_wrapper thread") self.thread = threading.Thread(target=self.transcribe.run, args=[]) self.thread.start() - rte.on_start_done() + ten.on_start_done() - def put_pcm_frame(self, pcm_frame: PcmFrame) -> None: + def put_pcm_frame(self, pcm_frame: AudioFrame) -> None: try: - asyncio.run_coroutine_threadsafe(self.queue.put(pcm_frame), self.loop).result(timeout=0.1) + asyncio.run_coroutine_threadsafe( + self.queue.put(pcm_frame), self.loop + ).result(timeout=0.1) except asyncio.QueueFull: logger.exception("Queue is full, dropping frame") except Exception as e: logger.exception(f"Error putting frame in queue: {e}") - def on_pcm_frame(self, rte: RteEnv, pcm_frame: PcmFrame) -> None: - self.put_pcm_frame(pcm_frame=pcm_frame) + def on_audio_frame(self, ten: TenEnv, frame: AudioFrame) -> None: + self.put_pcm_frame(pcm_frame=frame) - def on_stop(self, rte: RteEnv) -> None: + def on_stop(self, ten: TenEnv) -> None: logger.info("TranscribeAsrExtension on_stop") # put an empty frame to stop transcribe_wrapper @@ -75,9 +86,9 @@ def on_stop(self, rte: RteEnv) -> None: self.loop.stop() self.loop.close() - rte.on_stop_done() + ten.on_stop_done() - def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: + def on_cmd(self, ten: TenEnv, cmd: Cmd) -> None: logger.info("TranscribeAsrExtension on_cmd") cmd_json = cmd.to_json() logger.info("TranscribeAsrExtension on_cmd json: " + cmd_json) @@ -87,4 +98,4 @@ def on_cmd(self, rte: RteEnv, cmd: Cmd) -> None: cmd_result = CmdResult.create(StatusCode.OK) cmd_result.set_property_string("detail", "success") - rte.return_result(cmd_result, cmd) + ten.return_result(cmd_result, cmd) diff --git a/agents/ten_packages/extension/transcribe_asr_python/transcribe_wrapper.py b/agents/ten_packages/extension/transcribe_asr_python/transcribe_wrapper.py index 16b9cd46..c6b500ba 100644 --- a/agents/ten_packages/extension/transcribe_asr_python/transcribe_wrapper.py +++ b/agents/ten_packages/extension/transcribe_asr_python/transcribe_wrapper.py @@ -1,8 +1,8 @@ from typing import Union import asyncio -from rte import ( - RteEnv, +from ten import ( + TenEnv, Data ) @@ -17,17 +17,17 @@ DATA_OUT_TEXT_DATA_PROPERTY_TEXT = "text" DATA_OUT_TEXT_DATA_PROPERTY_IS_FINAL = "is_final" -def create_and_send_data(rte: RteEnv, text_result: str, is_final: bool): +def create_and_send_data(ten: TenEnv, text_result: str, is_final: bool): stable_data = Data.create("text_data") stable_data.set_property_bool(DATA_OUT_TEXT_DATA_PROPERTY_IS_FINAL, is_final) stable_data.set_property_string(DATA_OUT_TEXT_DATA_PROPERTY_TEXT, text_result) - rte.send_data(stable_data) + ten.send_data(stable_data) class AsyncTranscribeWrapper(): - def __init__(self, config: TranscribeConfig, queue: asyncio.Queue, rte:RteEnv, loop: asyncio.BaseEventLoop): + def __init__(self, config: TranscribeConfig, queue: asyncio.Queue, ten:TenEnv, loop: asyncio.BaseEventLoop): self.queue = queue - self.rte = rte + self.ten = ten self.stopped = False self.config = config self.loop = loop @@ -70,7 +70,7 @@ async def cleanup(self): async def create_stream(self) -> bool: try: self.stream = await self.get_transcribe_stream() - self.handler = TranscribeEventHandler(self.stream.output_stream, self.rte) + self.handler = TranscribeEventHandler(self.stream.output_stream, self.ten) self.event_handler_task = asyncio.create_task(self.handler.handle_events()) except Exception as e: logger.exception(e) @@ -139,9 +139,9 @@ def stop(self) -> None: class TranscribeEventHandler(TranscriptResultStreamHandler): - def __init__(self, transcript_result_stream: TranscriptResultStream, rte: RteEnv): + def __init__(self, transcript_result_stream: TranscriptResultStream, ten: TenEnv): super().__init__(transcript_result_stream) - self.rte = rte + self.ten = ten async def handle_transcript_event(self, transcript_event: TranscriptEvent) -> None: results = transcript_event.transcript.results @@ -162,4 +162,4 @@ async def handle_transcript_event(self, transcript_event: TranscriptEvent) -> No logger.info(f"got transcript: [{text_result}], is_final: [{is_final}]") - create_and_send_data(rte=self.rte, text_result=text_result, is_final=is_final) + create_and_send_data(ten=self.ten, text_result=text_result, is_final=is_final) From 49809187812c070c29b42e4feec0cf9d047aedce Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 13:24:04 +0000 Subject: [PATCH 07/25] feat: upgrade agora_rtc --- agents/manifest-lock.json | 7 ++++--- agents/manifest.json | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/agents/manifest-lock.json b/agents/manifest-lock.json index ad0bdce3..d7ceba8d 100644 --- a/agents/manifest-lock.json +++ b/agents/manifest-lock.json @@ -61,8 +61,8 @@ { "type": "extension", "name": "agora_rtc", - "version": "0.5.0-rc1", - "hash": "36ddf94cd5b2db11ec399ccb5522061fce8a1323570aac9bb9ec0ef3eb7a9368", + "version": "0.5.0-rc2", + "hash": "02bd3a75f38a0d3f4a768c6b252fac66e348b8771f30e8f9108182286dcc28a7", "dependencies": [ { "type": "system", @@ -144,7 +144,8 @@ "type": "system", "name": "nlohmann_json", "version": "3.11.2", - "hash": "72b15822c7ea9deef5e7ad96216ac55e93f11b00466dd1943afd5ee276e99d19" + "hash": "72b15822c7ea9deef5e7ad96216ac55e93f11b00466dd1943afd5ee276e99d19", + "supports": [] }, { "type": "system", diff --git a/agents/manifest.json b/agents/manifest.json index e0a72e56..047c8d91 100644 --- a/agents/manifest.json +++ b/agents/manifest.json @@ -21,7 +21,7 @@ { "type": "extension", "name": "agora_rtc", - "version": "=0.5.0-rc1" + "version": "=0.5.0-rc2" }, { "type": "extension", From fc669d0dcecb1eccbc42ecbdf9f553d9155ec99a Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 13:25:19 +0000 Subject: [PATCH 08/25] feat: upgrade property --- agents/main.go | 8 ++++++-- agents/property.json.example | 28 +++++++++++++------------- server/internal/http_server.go | 6 +++--- server/internal/worker.go | 36 +++++++++++++++++----------------- server/main.go | 4 ++-- 5 files changed, 43 insertions(+), 39 deletions(-) diff --git a/agents/main.go b/agents/main.go index 360ec2b4..61107505 100644 --- a/agents/main.go +++ b/agents/main.go @@ -10,6 +10,7 @@ package main import ( "flag" "log" + "os" "ten_framework/ten" ) @@ -29,8 +30,11 @@ func (p *defaultApp) OnInit( ) { // Using the default property.json if not specified. if len(p.cfg.PropertyFilePath) > 0 { - // TODO: fix init property - // property.Set(ten.MetadataTypeJSONFileName, p.cfg.PropertyFilePath) + if b, err := os.ReadFile(p.cfg.PropertyFilePath); err != nil { + log.Fatalf("Failed to read property file %s, err %v\n", p.cfg.PropertyFilePath, err) + }else{ + tenEnv.InitPropertyFromJSONBytes(b) + } } tenEnv.OnInitDone() diff --git a/agents/property.json.example b/agents/property.json.example index 7cdf1629..cd1d860b 100644 --- a/agents/property.json.example +++ b/agents/property.json.example @@ -1,5 +1,5 @@ { - "rte": { + "_ten": { "predefined_graphs": [ { "name": "va.openai.azure", @@ -165,7 +165,7 @@ { "extension_group": "tts", "extension": "azure_tts", - "pcm_frame": [ + "audio_frame": [ { "name": "pcm_frame", "dest": [ @@ -390,7 +390,7 @@ { "extension_group": "tts", "extension": "elevenlabs_tts", - "pcm_frame": [ + "audio_frame": [ { "name": "pcm_frame", "dest": [ @@ -569,7 +569,7 @@ { "extension_group": "tts", "extension": "azure_tts", - "pcm_frame": [ + "audio_frame": [ { "name": "pcm_frame", "dest": [ @@ -774,7 +774,7 @@ { "extension_group": "tts", "extension": "cosy_tts", - "pcm_frame": [ + "audio_frame": [ { "name": "pcm_frame", "dest": [ @@ -1012,7 +1012,7 @@ { "extension_group": "tts", "extension": "cosy_tts", - "pcm_frame": [ + "audio_frame": [ { "name": "pcm_frame", "dest": [ @@ -1180,7 +1180,7 @@ { "extension_group": "tts", "extension": "polly_tts", - "pcm_frame": [ + "audio_frame": [ { "name": "pcm_frame", "dest": [ @@ -1321,7 +1321,7 @@ { "extension_group": "default", "extension": "agora_rtc", - "pcm_frame": [ + "audio_frame": [ { "name": "pcm_frame", "dest": [ @@ -1410,7 +1410,7 @@ { "extension_group": "tts", "extension": "polly_tts", - "pcm_frame": [ + "audio_frame": [ { "name": "pcm_frame", "dest": [ @@ -1563,9 +1563,9 @@ ] } ], - "image_frame": [ + "video_frame": [ { - "name": "image_frame", + "name": "video_frame", "dest": [ { "extension_group": "chatgpt", @@ -1628,7 +1628,7 @@ { "extension_group": "tts", "extension": "azure_tts", - "pcm_frame": [ + "audio_frame": [ { "name": "pcm_frame", "dest": [ @@ -1847,7 +1847,7 @@ { "extension_group": "tts", "extension": "azure_tts", - "pcm_frame": [ + "audio_frame": [ { "name": "pcm_frame", "dest": [ @@ -2191,7 +2191,7 @@ { "extension_group": "tts", "extension": "azure_tts", - "pcm_frame": [ + "audio_frame": [ { "name": "pcm_frame", "dest": [ diff --git a/server/internal/http_server.go b/server/internal/http_server.go index aa6e1c31..157b0c73 100644 --- a/server/internal/http_server.go +++ b/server/internal/http_server.go @@ -282,7 +282,7 @@ func (s *HttpServer) handlerVectorDocumentUpdate(c *gin.Context) { ChannelName: req.ChannelName, Collection: req.Collection, FileName: req.FileName, - Rte: &WorkerUpdateReqRte{ + Ten: &WorkerUpdateReqTen{ Name: "update_querying_collection", Type: "cmd", }, @@ -334,7 +334,7 @@ func (s *HttpServer) handlerVectorDocumentUpload(c *gin.Context) { Collection: collection, FileName: fileName, Path: uploadFile, - Rte: &WorkerUpdateReqRte{ + Ten: &WorkerUpdateReqTen{ Name: "file_chunk", Type: "cmd", }, @@ -382,7 +382,7 @@ func (s *HttpServer) processProperty(req *StartReq) (propertyJsonFile string, lo } } - graph := fmt.Sprintf(`rte.predefined_graphs.#(name=="%s")`, graphName) + graph := fmt.Sprintf(`_ten.predefined_graphs.#(name=="%s")`, graphName) // Automatically start on launch propertyJson, _ = sjson.Set(propertyJson, fmt.Sprintf(`%s.auto_start`, graph), true) diff --git a/server/internal/worker.go b/server/internal/worker.go index 93c746e4..5f948991 100644 --- a/server/internal/worker.go +++ b/server/internal/worker.go @@ -33,10 +33,10 @@ type WorkerUpdateReq struct { Collection string `form:"collection,omitempty" json:"collection"` FileName string `form:"filename,omitempty" json:"filename"` Path string `form:"path,omitempty" json:"path,omitempty"` - Rte *WorkerUpdateReqRte `form:"rte,omitempty" json:"rte,omitempty"` + Ten *WorkerUpdateReqTen `form:"_ten,omitempty" json:"_ten,omitempty"` } -type WorkerUpdateReqRte struct { +type WorkerUpdateReqTen struct { Name string `form:"name,omitempty" json:"name,omitempty"` Type string `form:"type,omitempty" json:"type,omitempty"` } @@ -86,22 +86,22 @@ func (w *Worker) start(req *StartReq) (err error) { slog.Info("Worker get pid", "requestId", req.RequestId, "shell", shell, logTag) var pid int - for i := 0; i < 3; i++ { // retry for 3 times - output, err := exec.Command("sh", "-c", shell).CombinedOutput() - if err == nil { - pid, err = strconv.Atoi(strings.TrimSpace(string(output))) - if err == nil && pid > 0 { - break // if pid is successfully obtained, exit loop - } - } - slog.Warn("Worker get pid failed, retrying...", "attempt", i+1, "requestId", req.RequestId, logTag) - time.Sleep(500 * time.Millisecond) // wait for 500ms - } - - if pid <= 0 { - slog.Error("Worker failed to obtain valid PID after 3 attempts", "requestId", req.RequestId, logTag) - return fmt.Errorf("failed to obtain valid PID") - } + for i := 0; i < 3; i++ { // retry for 3 times + output, err := exec.Command("sh", "-c", shell).CombinedOutput() + if err == nil { + pid, err = strconv.Atoi(strings.TrimSpace(string(output))) + if err == nil && pid > 0 { + break // if pid is successfully obtained, exit loop + } + } + slog.Warn("Worker get pid failed, retrying...", "attempt", i+1, "requestId", req.RequestId, logTag) + time.Sleep(500 * time.Millisecond) // wait for 500ms + } + + if pid <= 0 { + slog.Error("Worker failed to obtain valid PID after 3 attempts", "requestId", req.RequestId, logTag) + return fmt.Errorf("failed to obtain valid PID") + } w.Pid = pid return diff --git a/server/main.go b/server/main.go index 2bc4bd9c..dcd3880d 100644 --- a/server/main.go +++ b/server/main.go @@ -78,8 +78,8 @@ func processProperty(propertyJsonFile string) (err error) { } propertyJson := string(content) - for i := range gjson.Get(propertyJson, "rte.predefined_graphs").Array() { - graph := fmt.Sprintf("rte.predefined_graphs.%d", i) + for i := range gjson.Get(propertyJson, "_ten.predefined_graphs").Array() { + graph := fmt.Sprintf("_ten.predefined_graphs.%d", i) // Shut down all auto-starting Graphs propertyJson, _ = sjson.Set(propertyJson, fmt.Sprintf(`%s.auto_start`, graph), false) From 7c4472f664a99c36de423d679c5c22f5b991d018 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 13:26:21 +0000 Subject: [PATCH 09/25] chore: ignore --- agents/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/agents/.gitignore b/agents/.gitignore index 13d45539..2f785c62 100644 --- a/agents/.gitignore +++ b/agents/.gitignore @@ -26,4 +26,5 @@ session_control.conf.agora xdump_config .vscode *.pyc +*.pyc.* /property.json From 8e2767045a1267e8b75ff57464d2d61a4619ad8f Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 13:26:35 +0000 Subject: [PATCH 10/25] chore: clean --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1fe1dba3..31d80249 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ clean: clean-agents clean-agents: @echo ">> clean agents" - rm -rf agents/bin agents/out agents/interface agents/include agents/lib agents/lib64 agents/addon/system agents/addon/extension_group agents/.release + rm -rf agents/bin agents/out agents/interface agents/include agents/lib agents/lib64 agents/ten_packages/system agents/ten_packages/extension_group agents/.release @echo ">> done" docker-build-playground: From 9a1b2a7cce1f987e1d2b6c9421238c840ebb42be Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 13:26:54 +0000 Subject: [PATCH 11/25] chore: vscode --- .vscode/settings.json | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index b0181771..cb4779f7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,7 @@ { - "python.analysis.extraPaths": [ - "./agents/interface", - ], - "editor.formatOnSave": true, - } \ No newline at end of file + "python.analysis.extraPaths": [ + "./agents/ten_packages/system/ten_runtime_python/interface", + ], + "C_Cpp.intelliSenseEngine": "disabled", + "editor.formatOnSave": true, +} \ No newline at end of file From d740577c08ec1b6c0e7b5d99c5c7644ea73b54b6 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 14:22:48 +0000 Subject: [PATCH 12/25] fix: nltk version to avoid "Resource wordnet not found" error --- .../extension/llama_index_chat_engine/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/agents/ten_packages/extension/llama_index_chat_engine/requirements.txt b/agents/ten_packages/extension/llama_index_chat_engine/requirements.txt index f1987506..8d8165f2 100644 --- a/agents/ten_packages/extension/llama_index_chat_engine/requirements.txt +++ b/agents/ten_packages/extension/llama_index_chat_engine/requirements.txt @@ -1 +1,2 @@ +nltk==3.8.1 llama_index From fa6d8f9f8a3a5b33f09d187fc6684374b553042c Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 14:23:42 +0000 Subject: [PATCH 13/25] fix: remove wrong import --- .../chat_transcriber_python/chat_transcriber_extension.py | 1 - 1 file changed, 1 deletion(-) diff --git a/agents/ten_packages/extension/chat_transcriber_python/chat_transcriber_extension.py b/agents/ten_packages/extension/chat_transcriber_python/chat_transcriber_extension.py index 1d9dd79f..41a39bec 100644 --- a/agents/ten_packages/extension/chat_transcriber_python/chat_transcriber_extension.py +++ b/agents/ten_packages/extension/chat_transcriber_python/chat_transcriber_extension.py @@ -14,7 +14,6 @@ Data, StatusCode, CmdResult, - MetadataInfo, ) import time from .pb import chat_text_pb2 as pb From 15f75cab43cb0253d5ef69e6047102ff117e247a Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 14:26:32 +0000 Subject: [PATCH 14/25] fix: l --- agents/manifest-lock.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/agents/manifest-lock.json b/agents/manifest-lock.json index d7ceba8d..ff9542db 100644 --- a/agents/manifest-lock.json +++ b/agents/manifest-lock.json @@ -144,8 +144,7 @@ "type": "system", "name": "nlohmann_json", "version": "3.11.2", - "hash": "72b15822c7ea9deef5e7ad96216ac55e93f11b00466dd1943afd5ee276e99d19", - "supports": [] + "hash": "72b15822c7ea9deef5e7ad96216ac55e93f11b00466dd1943afd5ee276e99d19" }, { "type": "system", From d8ce07501ea1afd6cf7b83b44ea05e9e8011f803 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 14:28:45 +0000 Subject: [PATCH 15/25] fix: for ten --- agents/property.json.example | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/agents/property.json.example b/agents/property.json.example index 73a52cae..a982bca2 100644 --- a/agents/property.json.example +++ b/agents/property.json.example @@ -1564,9 +1564,9 @@ ] } ], - "image_frame": [ + "video_frame": [ { - "name": "image_frame", + "name": "video_frame", "dest": [ { "extension_group": "chatgpt", @@ -1629,7 +1629,7 @@ { "extension_group": "tts", "extension": "azure_tts", - "pcm_frame": [ + "audio_frame": [ { "name": "pcm_frame", "dest": [ From bca50e8e9d897f14ba5ba16fdaca8da15bd29ef1 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 14:31:38 +0000 Subject: [PATCH 16/25] fix: lock --- agents/manifest-lock.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/agents/manifest-lock.json b/agents/manifest-lock.json index ff9542db..d7ceba8d 100644 --- a/agents/manifest-lock.json +++ b/agents/manifest-lock.json @@ -144,7 +144,8 @@ "type": "system", "name": "nlohmann_json", "version": "3.11.2", - "hash": "72b15822c7ea9deef5e7ad96216ac55e93f11b00466dd1943afd5ee276e99d19" + "hash": "72b15822c7ea9deef5e7ad96216ac55e93f11b00466dd1943afd5ee276e99d19", + "supports": [] }, { "type": "system", From 0ffb5521f6a23b38dde0845bf1a9d1174e66cae2 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 15:26:41 +0000 Subject: [PATCH 17/25] fix: package --- Dockerfile | 2 +- agents/scripts/package.sh | 70 ++++++++++++++++++--------------------- 2 files changed, 33 insertions(+), 39 deletions(-) diff --git a/Dockerfile b/Dockerfile index dfac37fa..deb3faa6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ghcr.io/rte-design/astra_agents_build:0.3.6 AS builder +FROM ghcr.io/rte-design/astra_agents_build:0.4.0 AS builder ARG SESSION_CONTROL_CONF=session_control.conf diff --git a/agents/scripts/package.sh b/agents/scripts/package.sh index eedb734d..73f8e065 100755 --- a/agents/scripts/package.sh +++ b/agents/scripts/package.sh @@ -10,58 +10,52 @@ cd $APP_HOME rm -rf .release mkdir .release -copy_extension() { - local extension=$1 - mkdir -p .release/addon/extension/$extension +copy_package() { + local package_type=$1 + local package_name=$2 + mkdir -p .release/ten_packages/${package_type}/${package_name} - if [[ -d addon/extension/$extension/lib ]]; then - cp -r addon/extension/$extension/lib .release/addon/extension/$extension/ + if [[ -d ten_packages/${package_type}/${package_name}/lib ]]; then + cp -r ten_packages/${package_type}/${package_name}/lib .release/ten_packages/${package_type}/${package_name}/ fi - if [[ -f addon/extension/$extension/manifest.json ]]; then - cp addon/extension/$extension/manifest.json .release/addon/extension/$extension/ + if [[ -d ten_packages/${package_type}/${package_name}/interface ]]; then + cp -r ten_packages/${package_type}/${package_name}/interface .release/ten_packages/${package_type}/${package_name}/ + fi + + if [[ -f ten_packages/${package_type}/${package_name}/manifest.json ]]; then + cp ten_packages/${package_type}/${package_name}/manifest.json .release/ten_packages/${package_type}/${package_name}/ + fi + + if [[ -f ten_packages/${package_type}/${package_name}/property.json ]]; then + cp ten_packages/${package_type}/${package_name}/property.json .release/ten_packages/${package_type}/${package_name}/ + fi - # package .py for python extensions - EXTENSION_LANGUAGE=$(jq -r '.language' addon/extension/$extension/manifest.json) - if [[ $EXTENSION_LANGUAGE == "python" ]]; then - # TODO: package 'publish' contents only - cp addon/extension/$extension/*.py .release/addon/extension/$extension/ - if [[ -f addon/extension/$extension/requirements.txt ]]; then - cp addon/extension/$extension/requirements.txt .release/addon/extension/$extension/ - fi - # TODO: copy specific contents - if [[ -d addon/extension/$extension/pb ]]; then - cp -r addon/extension/$extension/pb .release/addon/extension/$extension/ - fi - fi + # package .py for python extensions + # TODO: package 'publish' contents only + cp ten_packages/${package_type}/${package_name}/*.py .release/ten_packages/${package_type}/${package_name}/ | true + if [[ -f ten_packages/${package_type}/${package_name}/requirements.txt ]]; then + cp ten_packages/${package_type}/${package_name}/requirements.txt .release/ten_packages/${package_type}/${package_name}/ fi - if [[ -f addon/extension/$extension/property.json ]]; then - cp addon/extension/$extension/property.json .release/addon/extension/$extension/ + # TODO: copy specific contents + if [[ -d ten_packages/${package_type}/${package_name}/pb ]]; then + cp -r ten_packages/${package_type}/${package_name}/pb .release/ten_packages/${package_type}/${package_name}/ fi } cp -r bin .release -cp -r lib .release cp manifest.json .release cp property.json .release -# python deps -if [[ -d interface/rte ]]; then - mkdir -p .release/interface - cp -r interface/rte .release/interface -fi - -# extension group -mkdir -p .release/addon -cp -r addon/extension_group .release/addon/ - -# extensions -mkdir -p .release/addon/extension -for extension in addon/extension/*; do - extension_name=$(basename $extension) - copy_extension $extension_name +# copy packages +mkdir -p .release/ten_packages +for package_type in system extension_group extension ; do + for package_path in ten_packages/${package_type}/*; do + package_name=$(basename ${package_path}) + copy_package ${package_type} ${package_name} + done done if [[ -f session_control.conf ]]; then From 1daa1224c9c2b3be93f62e965f2e31c858cba23a Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 15:58:33 +0000 Subject: [PATCH 18/25] feat: use start script --- agents/bin/start | 9 +++++++++ agents/manifest-lock.json | 3 +-- server/internal/worker.go | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100755 agents/bin/start diff --git a/agents/bin/start b/agents/bin/start new file mode 100755 index 00000000..475c7f94 --- /dev/null +++ b/agents/bin/start @@ -0,0 +1,9 @@ +#!/bin/bash + +set -e + +cd "$(dirname "${BASH_SOURCE[0]}")/.." + +export LD_LIBRARY_PATH=$(pwd)/ten_packages/system/agora_rtc_sdk/lib:$(pwd)/ten_packages/system/azure_speech_sdk/lib + +exec bin/worker "$@" diff --git a/agents/manifest-lock.json b/agents/manifest-lock.json index d7ceba8d..ff9542db 100644 --- a/agents/manifest-lock.json +++ b/agents/manifest-lock.json @@ -144,8 +144,7 @@ "type": "system", "name": "nlohmann_json", "version": "3.11.2", - "hash": "72b15822c7ea9deef5e7ad96216ac55e93f11b00466dd1943afd5ee276e99d19", - "supports": [] + "hash": "72b15822c7ea9deef5e7ad96216ac55e93f11b00466dd1943afd5ee276e99d19" }, { "type": "system", diff --git a/server/internal/worker.go b/server/internal/worker.go index 5f948991..bab2ffe4 100644 --- a/server/internal/worker.go +++ b/server/internal/worker.go @@ -43,7 +43,7 @@ type WorkerUpdateReqTen struct { const ( workerCleanSleepSeconds = 5 - workerExec = "/app/agents/bin/worker" + workerExec = "/app/agents/bin/start" workerHttpServerUrl = "http://127.0.0.1" ) From f1c7babcafa2b34fd50d58f39b10b3be848184c9 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 16:17:38 +0000 Subject: [PATCH 19/25] fix: build image for compose --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index a398da96..7d3057ec 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ services: astra_agents_dev: - image: ghcr.io/rte-design/astra_agents_build:0.3.6 + image: ghcr.io/rte-design/astra_agents_build:0.4.0 container_name: astra_agents_dev platform: linux/amd64 tty: true From d095b15c41b9ca78de78541ef2d7c4fdc74a3d09 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 16:18:46 +0000 Subject: [PATCH 20/25] fix: lock --- agents/manifest-lock.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/agents/manifest-lock.json b/agents/manifest-lock.json index ff9542db..d7ceba8d 100644 --- a/agents/manifest-lock.json +++ b/agents/manifest-lock.json @@ -144,7 +144,8 @@ "type": "system", "name": "nlohmann_json", "version": "3.11.2", - "hash": "72b15822c7ea9deef5e7ad96216ac55e93f11b00466dd1943afd5ee276e99d19" + "hash": "72b15822c7ea9deef5e7ad96216ac55e93f11b00466dd1943afd5ee276e99d19", + "supports": [] }, { "type": "system", From 381697a7aaafd42bc56d802f25f4ecdaf9af89e3 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 16:27:27 +0000 Subject: [PATCH 21/25] fix: start gd server --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 31d80249..b4145359 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,7 @@ docker-build-server: run-gd-server: @echo ">> run graph designer server" - cd agents && arpm dev-server + cd agents && tman dev-server @echo ">> done" run-server: From 18147c5738afeec56c98dc1e319b7f647b26329a Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 17:21:00 +0000 Subject: [PATCH 22/25] fix: better error log --- .../extension/aliyun_analyticdb_vector_storage/model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agents/ten_packages/extension/aliyun_analyticdb_vector_storage/model.py b/agents/ten_packages/extension/aliyun_analyticdb_vector_storage/model.py index 48365736..cee402d1 100644 --- a/agents/ten_packages/extension/aliyun_analyticdb_vector_storage/model.py +++ b/agents/ten_packages/extension/aliyun_analyticdb_vector_storage/model.py @@ -443,7 +443,7 @@ def parse_collection_data( json_str = json.dumps(results) return json_str except Exception as e: - logger.error(f"Error: {e}") + logger.error(f"parse collection data failed, error: {e}, data: {body.to_map()}") return "[]" def list_collections(self, namespace, namespace_password) -> Tuple[List[str], Any]: From ff23f52cdb7ddb82611f4b953102e63ddd75efd8 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 17:21:48 +0000 Subject: [PATCH 23/25] chore: also clean property.json and .env --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b4145359..a377b2e7 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ clean: clean-agents clean-agents: @echo ">> clean agents" - rm -rf agents/bin agents/out agents/interface agents/include agents/lib agents/lib64 agents/ten_packages/system agents/ten_packages/extension_group agents/.release + rm -rf agents/bin agents/out agents/interface agents/include agents/lib agents/lib64 agents/ten_packages/system agents/ten_packages/extension_group agents/.release agents/property.json .env @echo ">> done" docker-build-playground: From 10e4f832bbe58d1d28262b8f0fb586bcdf4f0f5c Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 17:27:02 +0000 Subject: [PATCH 24/25] fix: lock --- agents/manifest-lock.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/agents/manifest-lock.json b/agents/manifest-lock.json index d7ceba8d..ff9542db 100644 --- a/agents/manifest-lock.json +++ b/agents/manifest-lock.json @@ -144,8 +144,7 @@ "type": "system", "name": "nlohmann_json", "version": "3.11.2", - "hash": "72b15822c7ea9deef5e7ad96216ac55e93f11b00466dd1943afd5ee276e99d19", - "supports": [] + "hash": "72b15822c7ea9deef5e7ad96216ac55e93f11b00466dd1943afd5ee276e99d19" }, { "type": "system", From dc3430e93e0fd92354240fdc7894a1a12fc6ae4a Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Sun, 18 Aug 2024 17:28:48 +0000 Subject: [PATCH 25/25] Revert "chore: also clean property.json and .env" This reverts commit ff23f52cdb7ddb82611f4b953102e63ddd75efd8. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a377b2e7..b4145359 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ clean: clean-agents clean-agents: @echo ">> clean agents" - rm -rf agents/bin agents/out agents/interface agents/include agents/lib agents/lib64 agents/ten_packages/system agents/ten_packages/extension_group agents/.release agents/property.json .env + rm -rf agents/bin agents/out agents/interface agents/include agents/lib agents/lib64 agents/ten_packages/system agents/ten_packages/extension_group agents/.release @echo ">> done" docker-build-playground: