From 9a819f07b7050cfcb358a5d01df4f79cdd28ae14 Mon Sep 17 00:00:00 2001 From: zhang_lu Date: Sun, 20 Oct 2024 23:24:38 +0800 Subject: [PATCH] refactor the framework --- .gitignore | 2 +- README.md | 4 +- README_FR.md | 2 +- README_JP.md | 4 +- README_ZH.md | 4 +- engine/loop/inf_loop.py | 12 -- engine/video_process/__init__.py | 3 - .../general => examples/dnc_loop}/config.yml | 0 .../dnc_loop}/llms/gpt4o.json | 0 .../dnc_loop}/llms/json_res.json | 0 .../dnc_loop}/llms/text_res.json | 0 .../general => examples/dnc_loop}/main.json | 0 .../dnc_loop}/nodes/task_conqueror.json | 0 .../dnc_loop}/nodes/task_divider.json | 0 .../dnc_loop}/nodes/task_rescue.json | 0 .../dnc_loop}/tools/all_tools.json | 0 .../agent/conqueror}/__init__.py | 0 .../agent}/conqueror/conqueror.py | 16 +- .../agent}/conqueror/sys_prompt.prompt | 0 .../agent}/conqueror/user_prompt.prompt | 0 .../agent/divider}/__init__.py | 0 .../agent}/divider/divider.py | 18 +- .../agent}/divider/sys_prompt.prompt | 0 .../agent}/divider/user_prompt.prompt | 0 .../video_understanding/agent}/qa.py | 12 +- .../agent}/sys_prompt.prompt | 0 .../agent}/user_prompt.prompt | 0 .../video_understanding/config.yml | 0 .../video_understanding/llms/gpt4o.json | 0 .../video_understanding/llms/json_res.json | 0 .../video_understanding/llms/text_res.json | 0 .../video_understanding/loops/dnc_loop.json | 0 .../loops/inf_qa_loop.json | 0 .../video_understanding/ltm.json | 0 .../video_understanding/main.json | 0 .../nodes/video_conqueror.json | 0 .../nodes/video_divider.json | 0 .../video_understanding/nodes/video_qa.json | 0 .../tools/video_tools.json | 0 omagent-core/pyproject.toml | 4 +- .../advanced_components/__init__ copy.py | 0 .../advanced_components}/__init__.py | 0 .../node/Infinite_loop/inf_loop.py | 12 ++ .../advanced_components/node}/__init__.py | 0 .../node/conclude}/__init__.py | 0 .../node/conclude/conclude.py | 16 +- .../node/conclude/sys_prompt.prompt | 0 .../node/conclude/user_prompt.prompt | 0 .../node/conqueror}/__init__.py | 0 .../node}/conqueror/conqueror.py | 20 +- .../node}/conqueror/sys_prompt.prompt | 0 .../node}/conqueror/user_prompt.prompt | 0 .../node/divider}/__init__.py | 0 .../node}/divider/divider.py | 20 +- .../node}/divider/sys_prompt.prompt | 0 .../node}/divider/user_prompt.prompt | 0 .../node/dnc_loop}/dnc_loop.py | 10 +- .../node/video_preprocess}/__init__.py | 0 .../node/video_preprocess/preprocess.py | 24 +-- .../node/video_preprocess/sys_prompt.prompt | 0 .../node/video_preprocess/user_prompt.prompt | 0 .../src/omagent_core/{core => }/base.py | 2 +- .../base}/callback.py | 13 +- .../src/omagent_core/core/__init__.py | 18 -- omagent-core/src/omagent_core/core/llm/gpt.py | 186 ------------------ .../omagent_core/core/node/dnc/__init__.py | 6 - .../omagent_core/core/node/dnc/interface.py | 6 - .../src/omagent_core/core/node/misc/rescue.py | 119 ----------- .../core/node/misc/sys_prompt.prompt | 5 - .../core/node/misc/user_prompt.prompt | 6 - .../core/tool_system/tools/__init__.py | 0 .../{core/llm => engine}/__init__.py | 0 .../node/base => engine/node}/__init__.py | 0 .../{core/node/base => engine/node}/base.py | 16 +- .../node/base => engine/node}/decider.py | 20 +- .../{core/node/base => engine/node}/loop.py | 18 +- .../node/base => engine/node}/processor.py | 18 +- .../schemas.py => engine/task/agent_task.py} | 0 .../node => engine/workflow}/__init__.py | 0 .../omagent_core/engine/workflow/context.py | 16 ++ .../src/omagent_core/handlers/__init__.py | 6 - .../handlers/callback_handler/__init__.py | 0 .../handlers/data_handler/__init__.py | 5 - .../handlers/error_handler/__init__.py | 0 .../handlers/error_handler/error.py | 53 ----- .../handlers/log_handler/__init__.py | 0 .../{data_handler => }/milvus_handler.py | 4 +- .../{data_handler => }/sql_data_handler.py | 6 +- .../{schemas/base.py => handlers/table.py} | 28 --- .../{data_handler => }/video_handler.py | 6 +- .../src/omagent_core/handlers/video_scenes.py | 2 +- .../data_handler => memories/ltms}/ltm.py | 0 .../src/omagent_core/models/asr}/stt.py | 2 +- .../conqueror => models/encoders}/__init__.py | 0 .../{core/encoder => models/encoders}/base.py | 2 +- .../encoders}/openai_encoder.py | 0 .../dnc/divider => models/llms}/__init__.py | 0 .../{core/llm => models/llms}/azure_gpt.py | 2 +- .../{core/llm => models/llms}/base.py | 10 +- .../{core/llm => models/llms}/openai_gpt.py | 2 +- .../{core => models/llms}/prompt/__init__.py | 0 .../{core => models/llms}/prompt/base.py | 2 +- .../{core => models/llms}/prompt/formatter.py | 0 .../{core => models/llms}/prompt/parser.py | 2 +- .../{core => models/llms}/prompt/prompt.py | 2 +- .../dev.py => models/llms/schemas.py} | 46 ++--- .../src/omagent_core/models/od/schemas.py | 19 ++ .../src/omagent_core/schemas/__init__.py | 3 - omagent-core/src/omagent_core/schemas/opt.py | 36 ---- .../{core => }/tool_system/__init__.py | 2 +- .../{core => }/tool_system/base.py | 10 +- .../{core => }/tool_system/manager.py | 10 +- .../{core => }/tool_system/sys_prompt.prompt | 0 .../misc => tool_system/tools}/__init__.py | 0 .../tools/calculator}/calculator.py | 2 +- .../code_interpreter}/code_interpreter.py | 2 +- .../tool_system/tools/face_rec}/face_rec.py | 6 +- .../tools/file}/file_read.py | 2 +- .../tools/file}/file_write.py | 2 +- .../tool_system/tools/ovd}/ovd_tool.py | 8 +- .../tools/shell}/shell.py | 2 +- .../{core => }/tool_system/tools/utils.py | 0 .../tools/video_rewinder}/rewinder.py | 12 +- .../rewinder_sys_prompt.prompt | 0 .../rewinder_user_prompt.prompt | 0 .../tools/web_search}/search.py | 8 +- .../web_search}/search_sys_prompt.prompt | 0 .../web_search}/search_user_prompt.prompt | 0 .../tools/web_search}/text2image_search.py | 2 +- .../{core => }/tool_system/user_prompt.prompt | 0 omagent-core/src/omagent_core/utils/build.py | 9 +- omagent-core/src/omagent_core/utils/error.py | 39 ++++ .../src/omagent_core/utils/general.py | 79 +------- .../{handlers/log_handler => utils}/logger.py | 0 .../src/omagent_core/utils/registry.py | 9 +- .../src/omagent_core/utils/request.py | 66 +++++++ run.py | 12 +- 137 files changed, 365 insertions(+), 787 deletions(-) delete mode 100644 engine/loop/inf_loop.py delete mode 100644 engine/video_process/__init__.py rename {workflows/general => examples/dnc_loop}/config.yml (100%) rename {workflows/general => examples/dnc_loop}/llms/gpt4o.json (100%) rename {workflows/general => examples/dnc_loop}/llms/json_res.json (100%) rename {workflows/general => examples/dnc_loop}/llms/text_res.json (100%) rename {workflows/general => examples/dnc_loop}/main.json (100%) rename {workflows/general => examples/dnc_loop}/nodes/task_conqueror.json (100%) rename {workflows/general => examples/dnc_loop}/nodes/task_divider.json (100%) rename {workflows/general => examples/dnc_loop}/nodes/task_rescue.json (100%) rename {workflows/general => examples/dnc_loop}/tools/all_tools.json (100%) rename {engine => examples/video_understanding/agent/conqueror}/__init__.py (100%) rename {engine/node/video_qa => examples/video_understanding/agent}/conqueror/conqueror.py (95%) rename {engine/node/video_qa => examples/video_understanding/agent}/conqueror/sys_prompt.prompt (100%) rename {engine/node/video_qa => examples/video_understanding/agent}/conqueror/user_prompt.prompt (100%) rename {engine/loop => examples/video_understanding/agent/divider}/__init__.py (100%) rename {engine/node/video_qa => examples/video_understanding/agent}/divider/divider.py (88%) rename {engine/node/video_qa => examples/video_understanding/agent}/divider/sys_prompt.prompt (100%) rename {engine/node/video_qa => examples/video_understanding/agent}/divider/user_prompt.prompt (100%) rename {engine/node/video_qa => examples/video_understanding/agent}/qa.py (85%) rename {engine/node/video_qa => examples/video_understanding/agent}/sys_prompt.prompt (100%) rename {engine/node/video_qa => examples/video_understanding/agent}/user_prompt.prompt (100%) rename {workflows => examples}/video_understanding/config.yml (100%) rename {workflows => examples}/video_understanding/llms/gpt4o.json (100%) rename {workflows => examples}/video_understanding/llms/json_res.json (100%) rename {workflows => examples}/video_understanding/llms/text_res.json (100%) rename {workflows => examples}/video_understanding/loops/dnc_loop.json (100%) rename {workflows => examples}/video_understanding/loops/inf_qa_loop.json (100%) rename {workflows => examples}/video_understanding/ltm.json (100%) rename {workflows => examples}/video_understanding/main.json (100%) rename {workflows => examples}/video_understanding/nodes/video_conqueror.json (100%) rename {workflows => examples}/video_understanding/nodes/video_divider.json (100%) rename {workflows => examples}/video_understanding/nodes/video_qa.json (100%) rename {workflows => examples}/video_understanding/tools/video_tools.json (100%) rename engine/node/__init__.py => omagent-core/src/omagent_core/advanced_components/__init__ copy.py (100%) mode change 100755 => 100644 rename {engine/node/conclude => omagent-core/src/omagent_core/advanced_components}/__init__.py (100%) mode change 100755 => 100644 create mode 100644 omagent-core/src/omagent_core/advanced_components/node/Infinite_loop/inf_loop.py rename {engine/node/video_preprocess => omagent-core/src/omagent_core/advanced_components/node}/__init__.py (100%) mode change 100755 => 100644 rename {engine/node/video_qa/conqueror => omagent-core/src/omagent_core/advanced_components/node/conclude}/__init__.py (100%) rename {engine => omagent-core/src/omagent_core/advanced_components}/node/conclude/conclude.py (78%) rename {engine => omagent-core/src/omagent_core/advanced_components}/node/conclude/sys_prompt.prompt (100%) rename {engine => omagent-core/src/omagent_core/advanced_components}/node/conclude/user_prompt.prompt (100%) rename {engine/node/video_qa/divider => omagent-core/src/omagent_core/advanced_components/node/conqueror}/__init__.py (100%) mode change 100755 => 100644 rename omagent-core/src/omagent_core/{core/node/dnc => advanced_components/node}/conqueror/conqueror.py (95%) rename omagent-core/src/omagent_core/{core/node/dnc => advanced_components/node}/conqueror/sys_prompt.prompt (100%) rename omagent-core/src/omagent_core/{core/node/dnc => advanced_components/node}/conqueror/user_prompt.prompt (100%) rename {engine/tools => omagent-core/src/omagent_core/advanced_components/node/divider}/__init__.py (100%) rename omagent-core/src/omagent_core/{core/node/dnc => advanced_components/node}/divider/divider.py (88%) rename omagent-core/src/omagent_core/{core/node/dnc => advanced_components/node}/divider/sys_prompt.prompt (100%) rename omagent-core/src/omagent_core/{core/node/dnc => advanced_components/node}/divider/user_prompt.prompt (100%) rename {engine/loop => omagent-core/src/omagent_core/advanced_components/node/dnc_loop}/dnc_loop.py (71%) rename omagent-core/src/omagent_core/{core/encoder => advanced_components/node/video_preprocess}/__init__.py (100%) mode change 100644 => 100755 rename {engine => omagent-core/src/omagent_core/advanced_components}/node/video_preprocess/preprocess.py (95%) rename {engine => omagent-core/src/omagent_core/advanced_components}/node/video_preprocess/sys_prompt.prompt (100%) rename {engine => omagent-core/src/omagent_core/advanced_components}/node/video_preprocess/user_prompt.prompt (100%) rename omagent-core/src/omagent_core/{core => }/base.py (95%) rename omagent-core/src/omagent_core/{handlers/callback_handler => clients/base}/callback.py (95%) delete mode 100644 omagent-core/src/omagent_core/core/__init__.py delete mode 100644 omagent-core/src/omagent_core/core/llm/gpt.py delete mode 100644 omagent-core/src/omagent_core/core/node/dnc/__init__.py delete mode 100644 omagent-core/src/omagent_core/core/node/dnc/interface.py delete mode 100644 omagent-core/src/omagent_core/core/node/misc/rescue.py delete mode 100644 omagent-core/src/omagent_core/core/node/misc/sys_prompt.prompt delete mode 100644 omagent-core/src/omagent_core/core/node/misc/user_prompt.prompt delete mode 100644 omagent-core/src/omagent_core/core/tool_system/tools/__init__.py rename omagent-core/src/omagent_core/{core/llm => engine}/__init__.py (100%) rename omagent-core/src/omagent_core/{core/node/base => engine/node}/__init__.py (100%) rename omagent-core/src/omagent_core/{core/node/base => engine/node}/base.py (64%) rename omagent-core/src/omagent_core/{core/node/base => engine/node}/decider.py (82%) rename omagent-core/src/omagent_core/{core/node/base => engine/node}/loop.py (82%) rename omagent-core/src/omagent_core/{core/node/base => engine/node}/processor.py (74%) rename omagent-core/src/omagent_core/{core/node/dnc/schemas.py => engine/task/agent_task.py} (100%) rename omagent-core/src/omagent_core/{core/node => engine/workflow}/__init__.py (100%) create mode 100644 omagent-core/src/omagent_core/engine/workflow/context.py delete mode 100644 omagent-core/src/omagent_core/handlers/__init__.py delete mode 100644 omagent-core/src/omagent_core/handlers/callback_handler/__init__.py delete mode 100644 omagent-core/src/omagent_core/handlers/data_handler/__init__.py delete mode 100644 omagent-core/src/omagent_core/handlers/error_handler/__init__.py delete mode 100644 omagent-core/src/omagent_core/handlers/error_handler/error.py delete mode 100644 omagent-core/src/omagent_core/handlers/log_handler/__init__.py rename omagent-core/src/omagent_core/handlers/{data_handler => }/milvus_handler.py (99%) rename omagent-core/src/omagent_core/handlers/{data_handler => }/sql_data_handler.py (97%) rename omagent-core/src/omagent_core/{schemas/base.py => handlers/table.py} (51%) rename omagent-core/src/omagent_core/handlers/{data_handler => }/video_handler.py (97%) rename engine/video_process/scene.py => omagent-core/src/omagent_core/handlers/video_scenes.py (99%) mode change 100755 => 100644 rename omagent-core/src/omagent_core/{handlers/data_handler => memories/ltms}/ltm.py (100%) rename {engine/video_process => omagent-core/src/omagent_core/models/asr}/stt.py (97%) rename omagent-core/src/omagent_core/{core/node/dnc/conqueror => models/encoders}/__init__.py (100%) rename omagent-core/src/omagent_core/{core/encoder => models/encoders}/base.py (96%) rename omagent-core/src/omagent_core/{core/encoder => models/encoders}/openai_encoder.py (100%) rename omagent-core/src/omagent_core/{core/node/dnc/divider => models/llms}/__init__.py (100%) rename omagent-core/src/omagent_core/{core/llm => models/llms}/azure_gpt.py (99%) rename omagent-core/src/omagent_core/{core/llm => models/llms}/base.py (97%) rename omagent-core/src/omagent_core/{core/llm => models/llms}/openai_gpt.py (99%) rename omagent-core/src/omagent_core/{core => models/llms}/prompt/__init__.py (100%) rename omagent-core/src/omagent_core/{core => models/llms}/prompt/base.py (99%) rename omagent-core/src/omagent_core/{core => models/llms}/prompt/formatter.py (100%) rename omagent-core/src/omagent_core/{core => models/llms}/prompt/parser.py (98%) rename omagent-core/src/omagent_core/{core => models/llms}/prompt/prompt.py (99%) rename omagent-core/src/omagent_core/{schemas/dev.py => models/llms/schemas.py} (88%) create mode 100644 omagent-core/src/omagent_core/models/od/schemas.py delete mode 100644 omagent-core/src/omagent_core/schemas/__init__.py delete mode 100644 omagent-core/src/omagent_core/schemas/opt.py rename omagent-core/src/omagent_core/{core => }/tool_system/__init__.py (97%) rename omagent-core/src/omagent_core/{core => }/tool_system/base.py (97%) rename omagent-core/src/omagent_core/{core => }/tool_system/manager.py (98%) rename omagent-core/src/omagent_core/{core => }/tool_system/sys_prompt.prompt (100%) rename omagent-core/src/omagent_core/{core/node/misc => tool_system/tools}/__init__.py (100%) rename omagent-core/src/omagent_core/{core/tool_system/tools => tool_system/tools/calculator}/calculator.py (97%) rename omagent-core/src/omagent_core/{core/tool_system/tools => tool_system/tools/code_interpreter}/code_interpreter.py (98%) rename {engine/tools => omagent-core/src/omagent_core/tool_system/tools/face_rec}/face_rec.py (95%) rename omagent-core/src/omagent_core/{core/tool_system/tools => tool_system/tools/file}/file_read.py (91%) rename omagent-core/src/omagent_core/{core/tool_system/tools => tool_system/tools/file}/file_write.py (92%) rename {engine/tools => omagent-core/src/omagent_core/tool_system/tools/ovd}/ovd_tool.py (95%) rename omagent-core/src/omagent_core/{core/tool_system/tools => tool_system/tools/shell}/shell.py (93%) rename omagent-core/src/omagent_core/{core => }/tool_system/tools/utils.py (100%) rename {engine/tools => omagent-core/src/omagent_core/tool_system/tools/video_rewinder}/rewinder.py (91%) rename {engine/tools => omagent-core/src/omagent_core/tool_system/tools/video_rewinder}/rewinder_sys_prompt.prompt (100%) rename {engine/tools => omagent-core/src/omagent_core/tool_system/tools/video_rewinder}/rewinder_user_prompt.prompt (100%) rename omagent-core/src/omagent_core/{core/tool_system/tools => tool_system/tools/web_search}/search.py (98%) rename omagent-core/src/omagent_core/{core/tool_system/tools => tool_system/tools/web_search}/search_sys_prompt.prompt (100%) rename omagent-core/src/omagent_core/{core/tool_system/tools => tool_system/tools/web_search}/search_user_prompt.prompt (100%) rename omagent-core/src/omagent_core/{core/tool_system/tools => tool_system/tools/web_search}/text2image_search.py (99%) rename omagent-core/src/omagent_core/{core => }/tool_system/user_prompt.prompt (100%) create mode 100644 omagent-core/src/omagent_core/utils/error.py rename omagent-core/src/omagent_core/{handlers/log_handler => utils}/logger.py (100%) create mode 100644 omagent-core/src/omagent_core/utils/request.py diff --git a/.gitignore b/.gitignore index b0d11aa..972d185 100644 --- a/.gitignore +++ b/.gitignore @@ -150,4 +150,4 @@ tests data/ tests/mathvista running_logs/ -.db \ No newline at end of file +*.db \ No newline at end of file diff --git a/README.md b/README.md index 9b54356..b4d3a2a 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ For more details, check out our paper **[OmAgent: A Multi-modal Agent Framework logging.init_logger("omagent", "omagent", level="INFO") registry.import_module(project_root=Path(__file__).parent, custom=["./engine"]) bot_builder = Builder.from_file("workflows/general") # General task processing workflow configuration directory - input = DnCInterface(bot_id="1", task=AgentTask(id=0, task=task)) + input = BaseWorkflowContext(bot_id="1", task=AgentTask(id=0, task=task)) bot_builder.run_bot(input) return input.last_output @@ -136,7 +136,7 @@ For more details, check out our paper **[OmAgent: A Multi-modal Agent Framework logging.init_logger("omagent", "omagent", level="INFO") registry.import_module(project_root=Path(__file__).parent, custom=["./engine"]) bot_builder = Builder.from_file("workflows/video_understanding") # Video understanding task workflow configuration directory - input = DnCInterface(bot_id="1", task=AgentTask(id=0, task=task)) + input = BaseWorkflowContext(bot_id="1", task=AgentTask(id=0, task=task)) bot_builder.run_bot(input) return input.last_output diff --git a/README_FR.md b/README_FR.md index 804c125..a2ea6c6 100644 --- a/README_FR.md +++ b/README_FR.md @@ -75,7 +75,7 @@ Pour plus d'informations, consultez notre article : **[OmAgent : Un cadre d'agen logging.init_logger("omagent", "omagent", level="INFO") registry.import_module(project_root=Path(__file__).parent, custom=["./engine"]) bot_builder = Builder.from_file("workflows/general") - input = DnCInterface(bot_id="1", task=AgentTask(id=0, task=task)) + input = BaseWorkflowContext(bot_id="1", task=AgentTask(id=0, task=task)) bot_builder.run_bot(input) return input.last_output diff --git a/README_JP.md b/README_JP.md index b3833e5..58a78bc 100644 --- a/README_JP.md +++ b/README_JP.md @@ -65,7 +65,7 @@ OmAgentは3つの主要なコンポーネントで構成されています: logging.init_logger("omagent", "omagent", level="INFO") registry.import_module(project_root=Path(__file__).parent, custom=["./engine"]) bot_builder = Builder.from_file("workflows/general") # 一般タスク処理ワークフロー設定ディレクトリ - input = DnCInterface(bot_id="1", task=AgentTask(id=0, task=task)) + input = BaseWorkflowContext(bot_id="1", task=AgentTask(id=0, task=task)) bot_builder.run_bot(input) return input.last_output @@ -136,7 +136,7 @@ OmAgentは3つの主要なコンポーネントで構成されています: logging.init_logger("omagent", "omagent", level="INFO") registry.import_module(project_root=Path(__file__).parent, custom=["./engine"]) bot_builder = Builder.from_file("workflows/video_understanding") # Video understanding task workflow configuration directory - input = DnCInterface(bot_id="1", task=AgentTask(id=0, task=task)) + input = BaseWorkflowContext(bot_id="1", task=AgentTask(id=0, task=task)) bot_builder.run_bot(input) return input.last_output diff --git a/README_ZH.md b/README_ZH.md index db55ed7..d5f392f 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -64,7 +64,7 @@ OmAgent包括三个核心组成部分: logging.init_logger("omagent", "omagent", level="INFO") registry.import_module(project_root=Path(__file__).parent, custom=["./engine"]) bot_builder = Builder.from_file("workflows/general") # 通用任务处理workflow配置目录 - input = DnCInterface(bot_id="1", task=AgentTask(id=0, task=task)) + input = BaseWorkflowContext(bot_id="1", task=AgentTask(id=0, task=task)) bot_builder.run_bot(input) return input.last_output @@ -136,7 +136,7 @@ OmAgent包括三个核心组成部分: logging.init_logger("omagent", "omagent", level="INFO") registry.import_module(project_root=Path(__file__).parent, custom=["./engine"]) bot_builder = Builder.from_file("workflows/video_understanding") # 视频理解任务workflow配置目录 - input = DnCInterface(bot_id="1", task=AgentTask(id=0, task=task)) + input = BaseWorkflowContext(bot_id="1", task=AgentTask(id=0, task=task)) bot_builder.run_bot(input) return input.last_output diff --git a/engine/loop/inf_loop.py b/engine/loop/inf_loop.py deleted file mode 100644 index c18ebd4..0000000 --- a/engine/loop/inf_loop.py +++ /dev/null @@ -1,12 +0,0 @@ -from omagent_core.core.node.base import BaseLoop, Node -from omagent_core.handlers.data_handler.ltm import LTM -from omagent_core.schemas.base import BaseInterface -from omagent_core.utils.registry import registry - - -@registry.register_node() -class InfLoop(BaseLoop): - loop_body: Node - - def post_loop_exit(self, args: BaseInterface, ltm: LTM) -> bool: - return False diff --git a/engine/video_process/__init__.py b/engine/video_process/__init__.py deleted file mode 100644 index 28633be..0000000 --- a/engine/video_process/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from .scene import VideoScenes - -__all__ = ["VideoScenes"] diff --git a/workflows/general/config.yml b/examples/dnc_loop/config.yml similarity index 100% rename from workflows/general/config.yml rename to examples/dnc_loop/config.yml diff --git a/workflows/general/llms/gpt4o.json b/examples/dnc_loop/llms/gpt4o.json similarity index 100% rename from workflows/general/llms/gpt4o.json rename to examples/dnc_loop/llms/gpt4o.json diff --git a/workflows/general/llms/json_res.json b/examples/dnc_loop/llms/json_res.json similarity index 100% rename from workflows/general/llms/json_res.json rename to examples/dnc_loop/llms/json_res.json diff --git a/workflows/general/llms/text_res.json b/examples/dnc_loop/llms/text_res.json similarity index 100% rename from workflows/general/llms/text_res.json rename to examples/dnc_loop/llms/text_res.json diff --git a/workflows/general/main.json b/examples/dnc_loop/main.json similarity index 100% rename from workflows/general/main.json rename to examples/dnc_loop/main.json diff --git a/workflows/general/nodes/task_conqueror.json b/examples/dnc_loop/nodes/task_conqueror.json similarity index 100% rename from workflows/general/nodes/task_conqueror.json rename to examples/dnc_loop/nodes/task_conqueror.json diff --git a/workflows/general/nodes/task_divider.json b/examples/dnc_loop/nodes/task_divider.json similarity index 100% rename from workflows/general/nodes/task_divider.json rename to examples/dnc_loop/nodes/task_divider.json diff --git a/workflows/general/nodes/task_rescue.json b/examples/dnc_loop/nodes/task_rescue.json similarity index 100% rename from workflows/general/nodes/task_rescue.json rename to examples/dnc_loop/nodes/task_rescue.json diff --git a/workflows/general/tools/all_tools.json b/examples/dnc_loop/tools/all_tools.json similarity index 100% rename from workflows/general/tools/all_tools.json rename to examples/dnc_loop/tools/all_tools.json diff --git a/engine/__init__.py b/examples/video_understanding/agent/conqueror/__init__.py similarity index 100% rename from engine/__init__.py rename to examples/video_understanding/agent/conqueror/__init__.py diff --git a/engine/node/video_qa/conqueror/conqueror.py b/examples/video_understanding/agent/conqueror/conqueror.py similarity index 95% rename from engine/node/video_qa/conqueror/conqueror.py rename to examples/video_understanding/agent/conqueror/conqueror.py index 1a384d7..78c581a 100755 --- a/engine/node/video_qa/conqueror/conqueror.py +++ b/examples/video_understanding/agent/conqueror/conqueror.py @@ -4,13 +4,13 @@ from typing import List, Tuple from colorama import Fore, Style -from omagent_core.core.node.dnc import TaskConqueror -from omagent_core.core.node.dnc.schemas import AgentTask, TaskStatus -from omagent_core.core.prompt.prompt import PromptTemplate -from omagent_core.core.tool_system.manager import ToolManager -from omagent_core.handlers.data_handler.ltm import LTM -from omagent_core.schemas.base import BaseInterface +from omagent_core.advanced_components.node.conqueror.conqueror import TaskConqueror +from omagent_core.engine.workflow.context import BaseWorkflowContext +from omagent_core.models.llms.prompt import PromptTemplate +from omagent_core.tool_system.manager import ToolManager +from omagent_core.memories.ltms.ltm import LTM from omagent_core.utils.env import EnvVar +from omagent_core.engine.task.agent_task import AgentTask, TaskStatus from omagent_core.utils.registry import registry from pydantic import Field from tenacity import ( @@ -45,7 +45,7 @@ class VideoConqueror(TaskConqueror): retry=retry_if_exception_message(message="LLM generation is not valid."), reraise=True, ) - def _run(self, args: BaseInterface, ltm: LTM) -> Tuple[BaseInterface, str]: + def _run(self, args: BaseWorkflowContext, ltm: LTM) -> Tuple[BaseWorkflowContext, str]: task: AgentTask = args.task task.status = TaskStatus.RUNNING @@ -197,7 +197,7 @@ def _run(self, args: BaseInterface, ltm: LTM) -> Tuple[BaseInterface, str]: retry=retry_if_exception_message(message="LLM generation is not valid."), reraise=True, ) - async def _arun(self, args: BaseInterface, ltm: LTM) -> Tuple[BaseInterface, str]: + async def _arun(self, args: BaseWorkflowContext, ltm: LTM) -> Tuple[BaseWorkflowContext, str]: task: AgentTask = args.task task.status = TaskStatus.RUNNING diff --git a/engine/node/video_qa/conqueror/sys_prompt.prompt b/examples/video_understanding/agent/conqueror/sys_prompt.prompt similarity index 100% rename from engine/node/video_qa/conqueror/sys_prompt.prompt rename to examples/video_understanding/agent/conqueror/sys_prompt.prompt diff --git a/engine/node/video_qa/conqueror/user_prompt.prompt b/examples/video_understanding/agent/conqueror/user_prompt.prompt similarity index 100% rename from engine/node/video_qa/conqueror/user_prompt.prompt rename to examples/video_understanding/agent/conqueror/user_prompt.prompt diff --git a/engine/loop/__init__.py b/examples/video_understanding/agent/divider/__init__.py similarity index 100% rename from engine/loop/__init__.py rename to examples/video_understanding/agent/divider/__init__.py diff --git a/engine/node/video_qa/divider/divider.py b/examples/video_understanding/agent/divider/divider.py similarity index 88% rename from engine/node/video_qa/divider/divider.py rename to examples/video_understanding/agent/divider/divider.py index 0e0b442..05787a1 100644 --- a/engine/node/video_qa/divider/divider.py +++ b/examples/video_understanding/agent/divider/divider.py @@ -3,13 +3,13 @@ from pathlib import Path from typing import List, Tuple -from omagent_core.core.llm.base import BaseLLMBackend -from omagent_core.core.node.base import BaseDecider -from omagent_core.core.node.dnc.interface import DnCInterface -from omagent_core.core.node.dnc.schemas import AgentTask -from omagent_core.core.prompt.prompt import PromptTemplate -from omagent_core.core.tool_system.manager import ToolManager -from omagent_core.handlers.data_handler.ltm import LTM +from omagent_core.models.llms.base import BaseLLMBackend +from omagent_core.engine.node import BaseDecider +from omagent_core.engine.workflow.context import BaseWorkflowContext +from omagent_core.engine.task.agent_task import AgentTask +from omagent_core.models.llms.prompt import PromptTemplate +from omagent_core.tool_system.manager import ToolManager +from omagent_core.memories.ltms.ltm import LTM from omagent_core.utils.env import EnvVar from omagent_core.utils.registry import registry from pydantic import Field @@ -45,7 +45,7 @@ class VideoDivider(BaseLLMBackend, BaseDecider): retry=retry_if_exception_message(message="LLM generation is not valid."), reraise=True, ) - def _run(self, args: DnCInterface, ltm: LTM) -> Tuple[DnCInterface, str]: + def _run(self, args: BaseWorkflowContext, ltm: LTM) -> Tuple[BaseWorkflowContext, str]: task: AgentTask = args.task if task.task_depth() >= EnvVar.MAX_TASK_DEPTH: args.last_output = "failed: Max subtask depth reached" @@ -97,7 +97,7 @@ def _run(self, args: DnCInterface, ltm: LTM) -> Tuple[DnCInterface, str]: retry=retry_if_exception_message(message="LLM generation is not valid."), reraise=True, ) - async def _arun(self, args: DnCInterface, ltm: LTM) -> Tuple[DnCInterface, str]: + async def _arun(self, args: BaseWorkflowContext, ltm: LTM) -> Tuple[BaseWorkflowContext, str]: task: AgentTask = args.task if task.task_depth() >= EnvVar.MAX_TASK_DEPTH: args.last_output = "failed: Max subtask depth reached" diff --git a/engine/node/video_qa/divider/sys_prompt.prompt b/examples/video_understanding/agent/divider/sys_prompt.prompt similarity index 100% rename from engine/node/video_qa/divider/sys_prompt.prompt rename to examples/video_understanding/agent/divider/sys_prompt.prompt diff --git a/engine/node/video_qa/divider/user_prompt.prompt b/examples/video_understanding/agent/divider/user_prompt.prompt similarity index 100% rename from engine/node/video_qa/divider/user_prompt.prompt rename to examples/video_understanding/agent/divider/user_prompt.prompt diff --git a/engine/node/video_qa/qa.py b/examples/video_understanding/agent/qa.py similarity index 85% rename from engine/node/video_qa/qa.py rename to examples/video_understanding/agent/qa.py index 4f6a6fc..b9a9cd3 100755 --- a/engine/node/video_qa/qa.py +++ b/examples/video_understanding/agent/qa.py @@ -3,11 +3,11 @@ from pathlib import Path from typing import List -from omagent_core.core.llm.base import BaseLLMBackend -from omagent_core.core.node.base import BaseProcessor -from omagent_core.core.node.dnc.interface import DnCInterface -from omagent_core.core.prompt.prompt import PromptTemplate -from omagent_core.handlers.data_handler.ltm import LTM +from omagent_core.models.llms.base import BaseLLMBackend +from omagent_core.engine.node import BaseProcessor +from omagent_core.engine.workflow.context import BaseWorkflowContext +from omagent_core.models.llms.prompt import PromptTemplate +from omagent_core.memories.ltms.ltm import LTM from omagent_core.utils.registry import registry from pydantic import Field @@ -27,7 +27,7 @@ class VideoQA(BaseProcessor, BaseLLMBackend): ] ) - def _run(self, args: DnCInterface, ltm: LTM) -> DnCInterface: + def _run(self, args: BaseWorkflowContext, ltm: LTM) -> BaseWorkflowContext: video_md5 = args.kwargs.get("video_md5", None) self.stm.image_cache.clear() self.stm.former_results = {} diff --git a/engine/node/video_qa/sys_prompt.prompt b/examples/video_understanding/agent/sys_prompt.prompt similarity index 100% rename from engine/node/video_qa/sys_prompt.prompt rename to examples/video_understanding/agent/sys_prompt.prompt diff --git a/engine/node/video_qa/user_prompt.prompt b/examples/video_understanding/agent/user_prompt.prompt similarity index 100% rename from engine/node/video_qa/user_prompt.prompt rename to examples/video_understanding/agent/user_prompt.prompt diff --git a/workflows/video_understanding/config.yml b/examples/video_understanding/config.yml similarity index 100% rename from workflows/video_understanding/config.yml rename to examples/video_understanding/config.yml diff --git a/workflows/video_understanding/llms/gpt4o.json b/examples/video_understanding/llms/gpt4o.json similarity index 100% rename from workflows/video_understanding/llms/gpt4o.json rename to examples/video_understanding/llms/gpt4o.json diff --git a/workflows/video_understanding/llms/json_res.json b/examples/video_understanding/llms/json_res.json similarity index 100% rename from workflows/video_understanding/llms/json_res.json rename to examples/video_understanding/llms/json_res.json diff --git a/workflows/video_understanding/llms/text_res.json b/examples/video_understanding/llms/text_res.json similarity index 100% rename from workflows/video_understanding/llms/text_res.json rename to examples/video_understanding/llms/text_res.json diff --git a/workflows/video_understanding/loops/dnc_loop.json b/examples/video_understanding/loops/dnc_loop.json similarity index 100% rename from workflows/video_understanding/loops/dnc_loop.json rename to examples/video_understanding/loops/dnc_loop.json diff --git a/workflows/video_understanding/loops/inf_qa_loop.json b/examples/video_understanding/loops/inf_qa_loop.json similarity index 100% rename from workflows/video_understanding/loops/inf_qa_loop.json rename to examples/video_understanding/loops/inf_qa_loop.json diff --git a/workflows/video_understanding/ltm.json b/examples/video_understanding/ltm.json similarity index 100% rename from workflows/video_understanding/ltm.json rename to examples/video_understanding/ltm.json diff --git a/workflows/video_understanding/main.json b/examples/video_understanding/main.json similarity index 100% rename from workflows/video_understanding/main.json rename to examples/video_understanding/main.json diff --git a/workflows/video_understanding/nodes/video_conqueror.json b/examples/video_understanding/nodes/video_conqueror.json similarity index 100% rename from workflows/video_understanding/nodes/video_conqueror.json rename to examples/video_understanding/nodes/video_conqueror.json diff --git a/workflows/video_understanding/nodes/video_divider.json b/examples/video_understanding/nodes/video_divider.json similarity index 100% rename from workflows/video_understanding/nodes/video_divider.json rename to examples/video_understanding/nodes/video_divider.json diff --git a/workflows/video_understanding/nodes/video_qa.json b/examples/video_understanding/nodes/video_qa.json similarity index 100% rename from workflows/video_understanding/nodes/video_qa.json rename to examples/video_understanding/nodes/video_qa.json diff --git a/workflows/video_understanding/tools/video_tools.json b/examples/video_understanding/tools/video_tools.json similarity index 100% rename from workflows/video_understanding/tools/video_tools.json rename to examples/video_understanding/tools/video_tools.json diff --git a/omagent-core/pyproject.toml b/omagent-core/pyproject.toml index 75b545a..d5a8230 100644 --- a/omagent-core/pyproject.toml +++ b/omagent-core/pyproject.toml @@ -8,7 +8,7 @@ version = "0.0.1" authors = [ { name = "panregedit", email = "panregedit@gmail.com" }, ] -description = "Core package for OMbots" +description = "Core package for OmAgent" readme = "README.md" requires-python = ">=3.10, <3.12" classifiers = [ @@ -40,4 +40,4 @@ dependencies = [ ] [project.urls] -"Homepage" = "https://git.linker.cc/research/misc/ombot_utils.git" \ No newline at end of file +"Homepage" = "https://github.com/om-ai-lab/OmAgent" \ No newline at end of file diff --git a/engine/node/__init__.py b/omagent-core/src/omagent_core/advanced_components/__init__ copy.py old mode 100755 new mode 100644 similarity index 100% rename from engine/node/__init__.py rename to omagent-core/src/omagent_core/advanced_components/__init__ copy.py diff --git a/engine/node/conclude/__init__.py b/omagent-core/src/omagent_core/advanced_components/__init__.py old mode 100755 new mode 100644 similarity index 100% rename from engine/node/conclude/__init__.py rename to omagent-core/src/omagent_core/advanced_components/__init__.py diff --git a/omagent-core/src/omagent_core/advanced_components/node/Infinite_loop/inf_loop.py b/omagent-core/src/omagent_core/advanced_components/node/Infinite_loop/inf_loop.py new file mode 100644 index 0000000..1ed5d97 --- /dev/null +++ b/omagent-core/src/omagent_core/advanced_components/node/Infinite_loop/inf_loop.py @@ -0,0 +1,12 @@ +from ....engine.node import BaseLoop, Node +from ....memories.ltms.ltm import LTM +from ....engine.workflow.context import BaseWorkflowContext +from ....utils.registry import registry + + +@registry.register_node() +class InfLoop(BaseLoop): + loop_body: Node + + def post_loop_exit(self, args: BaseWorkflowContext, ltm: LTM) -> bool: + return False diff --git a/engine/node/video_preprocess/__init__.py b/omagent-core/src/omagent_core/advanced_components/node/__init__.py old mode 100755 new mode 100644 similarity index 100% rename from engine/node/video_preprocess/__init__.py rename to omagent-core/src/omagent_core/advanced_components/node/__init__.py diff --git a/engine/node/video_qa/conqueror/__init__.py b/omagent-core/src/omagent_core/advanced_components/node/conclude/__init__.py similarity index 100% rename from engine/node/video_qa/conqueror/__init__.py rename to omagent-core/src/omagent_core/advanced_components/node/conclude/__init__.py diff --git a/engine/node/conclude/conclude.py b/omagent-core/src/omagent_core/advanced_components/node/conclude/conclude.py similarity index 78% rename from engine/node/conclude/conclude.py rename to omagent-core/src/omagent_core/advanced_components/node/conclude/conclude.py index 0120019..f7d499d 100644 --- a/engine/node/conclude/conclude.py +++ b/omagent-core/src/omagent_core/advanced_components/node/conclude/conclude.py @@ -1,12 +1,12 @@ from pathlib import Path from typing import List -from omagent_core.core.llm.base import BaseLLMBackend -from omagent_core.core.node.base import BaseProcessor -from omagent_core.core.node.dnc.interface import DnCInterface -from omagent_core.core.prompt.prompt import PromptTemplate -from omagent_core.handlers.data_handler.ltm import LTM -from omagent_core.utils.registry import registry +from ....models.llms.base import BaseLLMBackend +from ....engine.node import BaseProcessor +from ....engine.workflow.context import BaseWorkflowContext +from ....models.llms.prompt import PromptTemplate +from ....memories.ltms.ltm import LTM +from ....utils.registry import registry from pydantic import Field CURRENT_PATH = root_path = Path(__file__).parents[0] @@ -25,7 +25,7 @@ class Conclude(BaseLLMBackend, BaseProcessor): ] ) - def _run(self, args: DnCInterface, ltm: LTM) -> DnCInterface: + def _run(self, args: BaseWorkflowContext, ltm: LTM) -> BaseWorkflowContext: chat_complete_res = self.simple_infer( task=args.task.find_root_task().task, result=args.last_output, @@ -40,7 +40,7 @@ def _run(self, args: DnCInterface, ltm: LTM) -> DnCInterface: print(f"Usage of {key}: {value}") return args - async def _arun(self, args: DnCInterface, ltm: LTM) -> DnCInterface: + async def _arun(self, args: BaseWorkflowContext, ltm: LTM) -> BaseWorkflowContext: chat_complete_res = await self.simple_ainfer( task=args.task.find_root_task().task, result=args.last_output, diff --git a/engine/node/conclude/sys_prompt.prompt b/omagent-core/src/omagent_core/advanced_components/node/conclude/sys_prompt.prompt similarity index 100% rename from engine/node/conclude/sys_prompt.prompt rename to omagent-core/src/omagent_core/advanced_components/node/conclude/sys_prompt.prompt diff --git a/engine/node/conclude/user_prompt.prompt b/omagent-core/src/omagent_core/advanced_components/node/conclude/user_prompt.prompt similarity index 100% rename from engine/node/conclude/user_prompt.prompt rename to omagent-core/src/omagent_core/advanced_components/node/conclude/user_prompt.prompt diff --git a/engine/node/video_qa/divider/__init__.py b/omagent-core/src/omagent_core/advanced_components/node/conqueror/__init__.py old mode 100755 new mode 100644 similarity index 100% rename from engine/node/video_qa/divider/__init__.py rename to omagent-core/src/omagent_core/advanced_components/node/conqueror/__init__.py diff --git a/omagent-core/src/omagent_core/core/node/dnc/conqueror/conqueror.py b/omagent-core/src/omagent_core/advanced_components/node/conqueror/conqueror.py similarity index 95% rename from omagent-core/src/omagent_core/core/node/dnc/conqueror/conqueror.py rename to omagent-core/src/omagent_core/advanced_components/node/conqueror/conqueror.py index 5a3d860..f8161cb 100644 --- a/omagent-core/src/omagent_core/core/node/dnc/conqueror/conqueror.py +++ b/omagent-core/src/omagent_core/advanced_components/node/conqueror/conqueror.py @@ -12,15 +12,15 @@ stop_after_delay, ) -from .....handlers.data_handler.ltm import LTM -from .....schemas.base import BaseInterface -from .....utils.env import EnvVar -from .....utils.registry import registry -from ....llm.base import BaseLLMBackend -from ....prompt.prompt import PromptTemplate +from ....memories.ltms.ltm import LTM +from ....engine.workflow.context import BaseWorkflowContext +from ....utils.env import EnvVar +from ....utils.registry import registry +from ....models.llms.base import BaseLLMBackend +from ....models.llms.prompt.prompt import PromptTemplate from ....tool_system.manager import ToolManager -from ...base import BaseDecider -from ..schemas import AgentTask, TaskStatus +from ....engine.node.decider import BaseDecider +from ....engine.task.agent_task import AgentTask, TaskStatus CURRENT_PATH = Path(__file__).parents[0] @@ -47,7 +47,7 @@ class TaskConqueror(BaseLLMBackend, BaseDecider): retry=retry_if_exception_message(message="LLM generation is not valid."), reraise=True, ) - def _run(self, args: BaseInterface, ltm: LTM) -> Tuple[BaseInterface, str]: + def _run(self, args: BaseWorkflowContext, ltm: LTM) -> Tuple[BaseWorkflowContext, str]: task: AgentTask = args.task task.status = TaskStatus.RUNNING @@ -190,7 +190,7 @@ def _run(self, args: BaseInterface, ltm: LTM) -> Tuple[BaseInterface, str]: retry=retry_if_exception_message(message="LLM generation is not valid."), reraise=True, ) - async def _arun(self, args: BaseInterface, ltm: LTM) -> Tuple[BaseInterface, str]: + async def _arun(self, args: BaseWorkflowContext, ltm: LTM) -> Tuple[BaseWorkflowContext, str]: task: AgentTask = args.task task.status = TaskStatus.RUNNING diff --git a/omagent-core/src/omagent_core/core/node/dnc/conqueror/sys_prompt.prompt b/omagent-core/src/omagent_core/advanced_components/node/conqueror/sys_prompt.prompt similarity index 100% rename from omagent-core/src/omagent_core/core/node/dnc/conqueror/sys_prompt.prompt rename to omagent-core/src/omagent_core/advanced_components/node/conqueror/sys_prompt.prompt diff --git a/omagent-core/src/omagent_core/core/node/dnc/conqueror/user_prompt.prompt b/omagent-core/src/omagent_core/advanced_components/node/conqueror/user_prompt.prompt similarity index 100% rename from omagent-core/src/omagent_core/core/node/dnc/conqueror/user_prompt.prompt rename to omagent-core/src/omagent_core/advanced_components/node/conqueror/user_prompt.prompt diff --git a/engine/tools/__init__.py b/omagent-core/src/omagent_core/advanced_components/node/divider/__init__.py similarity index 100% rename from engine/tools/__init__.py rename to omagent-core/src/omagent_core/advanced_components/node/divider/__init__.py diff --git a/omagent-core/src/omagent_core/core/node/dnc/divider/divider.py b/omagent-core/src/omagent_core/advanced_components/node/divider/divider.py similarity index 88% rename from omagent-core/src/omagent_core/core/node/dnc/divider/divider.py rename to omagent-core/src/omagent_core/advanced_components/node/divider/divider.py index 8cd44d3..55e4fff 100644 --- a/omagent-core/src/omagent_core/core/node/dnc/divider/divider.py +++ b/omagent-core/src/omagent_core/advanced_components/node/divider/divider.py @@ -11,15 +11,15 @@ stop_after_delay, ) -from .....handlers.data_handler.ltm import LTM -from .....utils.env import EnvVar -from .....utils.registry import registry -from ....llm.base import BaseLLMBackend -from ....prompt.prompt import PromptTemplate +from ....memories.ltms.ltm import LTM +from ....utils.env import EnvVar +from ....utils.registry import registry +from ....models.llms.base import BaseLLMBackend +from ....models.llms.prompt.prompt import PromptTemplate from ....tool_system.manager import ToolManager -from ...base import BaseDecider -from ..interface import DnCInterface -from ..schemas import AgentTask +from ....engine.node.decider import BaseDecider +from ....engine.workflow.context import BaseWorkflowContext +from ....engine.task.agent_task import AgentTask CURRENT_PATH = Path(__file__).parents[0] @@ -46,7 +46,7 @@ class TaskDivider(BaseLLMBackend, BaseDecider): retry=retry_if_exception_message(message="LLM generation is not valid."), reraise=True, ) - def _run(self, args: DnCInterface, ltm: LTM) -> Tuple[DnCInterface, str]: + def _run(self, args: BaseWorkflowContext, ltm: LTM) -> Tuple[BaseWorkflowContext, str]: task: AgentTask = args.task if task.task_depth() >= EnvVar.MAX_TASK_DEPTH: args.last_output = "failed: Max subtask depth reached" @@ -97,7 +97,7 @@ def _run(self, args: DnCInterface, ltm: LTM) -> Tuple[DnCInterface, str]: retry=retry_if_exception_message(message="LLM generation is not valid."), reraise=True, ) - async def _arun(self, args: DnCInterface, ltm: LTM) -> Tuple[DnCInterface, str]: + async def _arun(self, args: BaseWorkflowContext, ltm: LTM) -> Tuple[BaseWorkflowContext, str]: task: AgentTask = args.task if task.task_depth() >= EnvVar.MAX_TASK_DEPTH: args.last_output = "failed: Max subtask depth reached" diff --git a/omagent-core/src/omagent_core/core/node/dnc/divider/sys_prompt.prompt b/omagent-core/src/omagent_core/advanced_components/node/divider/sys_prompt.prompt similarity index 100% rename from omagent-core/src/omagent_core/core/node/dnc/divider/sys_prompt.prompt rename to omagent-core/src/omagent_core/advanced_components/node/divider/sys_prompt.prompt diff --git a/omagent-core/src/omagent_core/core/node/dnc/divider/user_prompt.prompt b/omagent-core/src/omagent_core/advanced_components/node/divider/user_prompt.prompt similarity index 100% rename from omagent-core/src/omagent_core/core/node/dnc/divider/user_prompt.prompt rename to omagent-core/src/omagent_core/advanced_components/node/divider/user_prompt.prompt diff --git a/engine/loop/dnc_loop.py b/omagent-core/src/omagent_core/advanced_components/node/dnc_loop/dnc_loop.py similarity index 71% rename from engine/loop/dnc_loop.py rename to omagent-core/src/omagent_core/advanced_components/node/dnc_loop/dnc_loop.py index 22cb162..cf5c426 100644 --- a/engine/loop/dnc_loop.py +++ b/omagent-core/src/omagent_core/advanced_components/node/dnc_loop/dnc_loop.py @@ -1,14 +1,14 @@ -from omagent_core.core.node.base import BaseLoop, Node -from omagent_core.core.node.dnc import DnCInterface -from omagent_core.handlers.data_handler.ltm import LTM -from omagent_core.utils.registry import registry +from ....engine.node import BaseLoop, Node +from ....memories.ltms.ltm import LTM +from ....engine.workflow.context import BaseWorkflowContext +from ....utils.registry import registry @registry.register_node() class DnCLoop(BaseLoop): loop_body: Node - def post_loop_exit(self, args: DnCInterface, ltm: LTM) -> bool: + def post_loop_exit(self, args: BaseWorkflowContext, ltm: LTM) -> bool: # self.stm.image_cache.clear() if args.task.status == "failed": return True diff --git a/omagent-core/src/omagent_core/core/encoder/__init__.py b/omagent-core/src/omagent_core/advanced_components/node/video_preprocess/__init__.py old mode 100644 new mode 100755 similarity index 100% rename from omagent-core/src/omagent_core/core/encoder/__init__.py rename to omagent-core/src/omagent_core/advanced_components/node/video_preprocess/__init__.py diff --git a/engine/node/video_preprocess/preprocess.py b/omagent-core/src/omagent_core/advanced_components/node/video_preprocess/preprocess.py similarity index 95% rename from engine/node/video_preprocess/preprocess.py rename to omagent-core/src/omagent_core/advanced_components/node/video_preprocess/preprocess.py index 426852a..06979d3 100755 --- a/engine/node/video_preprocess/preprocess.py +++ b/omagent-core/src/omagent_core/advanced_components/node/video_preprocess/preprocess.py @@ -3,22 +3,22 @@ from pathlib import Path from typing import List -from omagent_core.core.llm.base import BaseLLMBackend -from omagent_core.core.node.base import BaseProcessor -from omagent_core.core.prompt.parser import DictParser -from omagent_core.core.prompt.prompt import PromptTemplate -from omagent_core.handlers.data_handler.ltm import LTM -from omagent_core.handlers.log_handler.logger import logging -from omagent_core.schemas.base import BaseInterface -from omagent_core.utils.registry import registry +from ....models.llms.base import BaseLLMBackend +from ....engine.node import BaseProcessor +from ....models.llms.prompt.parser import DictParser +from ....models.llms.prompt import PromptTemplate +from ....memories.ltms.ltm import LTM +from ....engine.workflow.context import BaseWorkflowContext +from ....utils.logger import logging +from ....utils.registry import registry from pydantic import Field, field_validator from pydub import AudioSegment from pydub.effects import normalize from scenedetect import open_video -from engine.video_process.stt import STT +from ....models.asr.stt import STT -from ...video_process import VideoScenes +from ....handlers.video_scenes import VideoScenes CURRENT_PATH = root_path = Path(__file__).parents[0] PARSER = DictParser() @@ -65,7 +65,7 @@ def calculate_md5(self, file_path): # 返回MD5哈希值 return md5_hash.hexdigest() - def _run(self, args: BaseInterface, ltm: LTM) -> BaseInterface: + def _run(self, args: BaseWorkflowContext, ltm: LTM) -> BaseWorkflowContext: video_path = input("Please input the video path:") video_md5 = self.calculate_md5(video_path) args.kwargs["video_md5"] = video_md5 @@ -212,7 +212,7 @@ def _run(self, args: BaseInterface, ltm: LTM) -> BaseInterface: pickle.dump(video.scenes, f) return args - async def _arun(self, args: BaseInterface, ltm: LTM) -> BaseInterface: + async def _arun(self, args: BaseWorkflowContext, ltm: LTM) -> BaseWorkflowContext: video_path = input("Please input the video path:") video_md5 = self.calculate_md5(video_path) args.kwargs["video_md5"] = video_md5 diff --git a/engine/node/video_preprocess/sys_prompt.prompt b/omagent-core/src/omagent_core/advanced_components/node/video_preprocess/sys_prompt.prompt similarity index 100% rename from engine/node/video_preprocess/sys_prompt.prompt rename to omagent-core/src/omagent_core/advanced_components/node/video_preprocess/sys_prompt.prompt diff --git a/engine/node/video_preprocess/user_prompt.prompt b/omagent-core/src/omagent_core/advanced_components/node/video_preprocess/user_prompt.prompt similarity index 100% rename from engine/node/video_preprocess/user_prompt.prompt rename to omagent-core/src/omagent_core/advanced_components/node/video_preprocess/user_prompt.prompt diff --git a/omagent-core/src/omagent_core/core/base.py b/omagent-core/src/omagent_core/base.py similarity index 95% rename from omagent-core/src/omagent_core/core/base.py rename to omagent-core/src/omagent_core/base.py index bd100e8..0263b8b 100644 --- a/omagent-core/src/omagent_core/core/base.py +++ b/omagent-core/src/omagent_core/base.py @@ -5,7 +5,7 @@ from pydantic import BaseModel, Field, field_validator -from ..handlers.callback_handler.callback import BaseCallback, DefaultCallback +from .clients.base.callback import BaseCallback, DefaultCallback REQUEST_ID = contextvars.ContextVar("request_id") diff --git a/omagent-core/src/omagent_core/handlers/callback_handler/callback.py b/omagent-core/src/omagent_core/clients/base/callback.py similarity index 95% rename from omagent-core/src/omagent_core/handlers/callback_handler/callback.py rename to omagent-core/src/omagent_core/clients/base/callback.py index 8268fbb..2b46253 100644 --- a/omagent-core/src/omagent_core/handlers/callback_handler/callback.py +++ b/omagent-core/src/omagent_core/clients/base/callback.py @@ -8,13 +8,12 @@ from time import time from typing import Any, ClassVar -import omagent_core.core.base from colorama import Fore, Style from pydantic import BaseModel, model_validator -from ..error_handler.error import VQLError -from ..log_handler.logger import logging - +from ...utils.error import VQLError +from ...utils.logger import logging +import omagent_core.base class BaseCallback(BaseModel, ABC): bot_id: str @@ -69,7 +68,7 @@ def get_calling_class(self): each.frame.f_locals.get("self").__class__.__name__ for each in stack[2:] if isinstance( - each.frame.f_locals.get("self"), omagent_core.core.base.BotBase + each.frame.f_locals.get("self"), omagent_core.base.BotBase ) ] ) @@ -119,7 +118,7 @@ def send_block(self, msg): ) if len(calling_chain) > 0: if len(calling_chain) == 1 and isinstance( - caller, omagent_core.core.node.base.BaseLoop + caller, omagent_core.engine.node.BaseLoop ): Path( f"{self.folder_name}/{'/'.join(calling_chain)}/{self.loop_count[calling_chain[-1]]}" @@ -130,7 +129,7 @@ def send_block(self, msg): calling_chain.insert( calling_chain.index(each) + 1, str(self.loop_count[each] - 1) ) - if isinstance(caller, omagent_core.core.llm.base.BaseLLM): + if isinstance(caller, omagent_core.models.llms.base.BaseLLM): Path(f"{self.folder_name}/{'/'.join(calling_chain[:-1])}").mkdir( parents=True, exist_ok=True ) diff --git a/omagent-core/src/omagent_core/core/__init__.py b/omagent-core/src/omagent_core/core/__init__.py deleted file mode 100644 index 950b2ca..0000000 --- a/omagent-core/src/omagent_core/core/__init__.py +++ /dev/null @@ -1,18 +0,0 @@ -from .encoder.base import EncoderBase -from .llm.base import BaseLLM, BaseLLMBackend -from .node.base import BaseDecider, BaseLoop, BaseProcessor -from .node.base.base import Node -from .prompt.base import BasePromptTemplate -from .prompt.prompt import PromptTemplate - -__all__ = [ - "EncoderBase", - "BaseLLM", - "Node", - "BaseProcessor", - "BaseLoop", - "BaseDecider", - "BasePromptTemplate", - "PromptTemplate", - "BaseLLMBackend", -] diff --git a/omagent-core/src/omagent_core/core/llm/gpt.py b/omagent-core/src/omagent_core/core/llm/gpt.py deleted file mode 100644 index 8226828..0000000 --- a/omagent-core/src/omagent_core/core/llm/gpt.py +++ /dev/null @@ -1,186 +0,0 @@ -import os -import sysconfig -from datetime import datetime -from typing import Dict, List - -import geocoder -from pydantic import ConfigDict - -from ...handlers.log_handler.logger import logging -from ...schemas.dev import Content, Message -from ...schemas.opt import OPT -from ...utils.general import arequest, encode_image, request -from ...utils.registry import registry -from .base import BaseLLM - -BASIC_SYS_PROMPT = """You are an intelligent agent that can help in many regions. -Flowing are some basic information about your working environment, please try your best to answer the questions based on them if needed. -Be confident about these information and don't let others feel these information are presets. -Be concise. ----BASIC IMFORMATION--- -Current Datetime: {} -Region: {} -Operating System: {}""" - - -@registry.register_llm() -class GPTLLM(BaseLLM): - model_config = ConfigDict(protected_namespaces=()) - model_id: str - endpoint: str = "https://api.openai.com/v1/chat/completions" - api_key: str - temperature: float = 1.0 - max_tokens: int = 2048 - use_default_sys_prompt: bool = True - response_format: str = "text" - - def _call(self, records: List[Message], **kwargs) -> Dict: - if self.api_key is None or self.api_key == "": - raise ValueError("api_key is required") - - if len(self.stm.image_cache): - for record in records: - record.combine_image_message( - image_cache={ - key: encode_image(value) - for key, value in self.stm.image_cache.items() - } - ) - elif len(kwargs.get("images", [])): - image_cache = {} - for index, each in enumerate(kwargs["images"]): - image_cache[f""] = each - for record in records: - record.combine_image_message( - image_cache={ - key: encode_image(value) for key, value in image_cache.items() - } - ) - body = self._msg2req(records) - if kwargs.get("tool_choice"): - body["tool_choice"] = kwargs["tool_choice"] - if kwargs.get("tools"): - body["tools"] = kwargs["tools"] - - res = request( - url=self.endpoint, - json=body, - headers={ - "Content-Type": "application/json", - "Authorization": f"Bearer {self.api_key}", - }, - ) - # logging.debug("GPTLLM input [{}] result [{}]".format(body, res)) - body.update({"response": res}) - self.callback.send_block(body) - return res - - async def _acall(self, records: List[Message], **kwargs) -> Dict: - if self.api_key is None or self.api_key == "": - raise ValueError("api_key is required") - if (images := kwargs.get("images")) is not None: - records.append( - Message( - role=OPT.ROLE.USER, - message_type=OPT.MESSAGE_TYPE.IMAGE, - content=[ - { - "type": "image_url", - "image_url": {"url": f"data:image/jpeg;base64,{item}"}, - } - for item in images - ], - ) - ) - body = self._msg2req(records) - if kwargs.get("tool_choice"): - body["tool_choice"] = kwargs["tool_choice"] - if kwargs.get("tools"): - body["tools"] = kwargs["tools"] - - res = arequest( - url=self.endpoint, - json=body, - headers={ - "Content-Type": "application/json", - "Authorization": f"Bearer {self.api_key}", - }, - ) - logging.debug("GPTLLM input [{}] result [{}]".format(body, res)) - body.update({"response": res}) - self.callback.send_block(body) - return res - - def _msg2req(self, records: List[Message]) -> dict: - def get_content(msg: List[Content] | Content) -> List[dict] | str: - if isinstance(msg, list): - return [c.model_dump(exclude_none=True) for c in msg] - elif isinstance(msg, Content) and msg.type == "text": - return msg.text - else: - raise ValueError("Invalid message type") - - messages = [ - {"role": message.role, "content": get_content(message.content)} - for message in records - ] - if "vision" in self.model_id: - processed_messages = [] - for message in messages: - if message["role"] == "user": - if isinstance(message["content"], str): - message["content"] = [ - {"type": "text", "text": message["content"]} - ] - merged_dict = {} - for message in messages: - if message["role"] == "user": - merged_dict["role"] = message["role"] - if "content" in merged_dict: - merged_dict["content"] += message["content"] - else: - merged_dict["content"] = message["content"] - else: - processed_messages.append(message) - processed_messages.append(merged_dict) - messages = processed_messages - if self.use_default_sys_prompt: - messages = [self._generate_default_sys_prompt()] + messages - body = { - "model": self.model_id, - "messages": messages, - "temperature": self.temperature, - "max_tokens": self.max_tokens, - } - if self.response_format != "text": - body["response_format"] = {"type": self.response_format} - return body - - def _generate_default_sys_prompt(self) -> Dict: - loc = self._get_location() - os = self._get_linux_distribution() - current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") - promt_str = BASIC_SYS_PROMPT.format(loc, os, current_time) - return {"role": "system", "content": promt_str} - - def _get_linux_distribution(self) -> str: - platform = sysconfig.get_platform() - if "linux" in platform: - if os.path.exists("/etc/lsb-release"): - with open("/etc/lsb-release", "r") as f: - for line in f: - if line.startswith("DISTRIB_DESCRIPTION="): - return line.split("=")[1].strip() - elif os.path.exists("/etc/os-release"): - with open("/etc/os-release", "r") as f: - for line in f: - if line.startswith("PRETTY_NAME="): - return line.split("=")[1].strip() - return platform - - def _get_location(self) -> str: - g = geocoder.ip("me") - if g.ok: - return g.city + "," + g.country - else: - return "unknown" diff --git a/omagent-core/src/omagent_core/core/node/dnc/__init__.py b/omagent-core/src/omagent_core/core/node/dnc/__init__.py deleted file mode 100644 index f1bb7d6..0000000 --- a/omagent-core/src/omagent_core/core/node/dnc/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -from .conqueror.conqueror import TaskConqueror -from .divider.divider import TaskDivider -from .interface import DnCInterface -from .schemas import AgentTask, TaskStatus - -__all__ = ["TaskDivider", "TaskConqueror", "DnCInterface", "AgentTask", "TaskStatus"] diff --git a/omagent-core/src/omagent_core/core/node/dnc/interface.py b/omagent-core/src/omagent_core/core/node/dnc/interface.py deleted file mode 100644 index c69ce61..0000000 --- a/omagent-core/src/omagent_core/core/node/dnc/interface.py +++ /dev/null @@ -1,6 +0,0 @@ -from ....schemas.base import BaseInterface -from .schemas import AgentTask - - -class DnCInterface(BaseInterface): - task: AgentTask diff --git a/omagent-core/src/omagent_core/core/node/misc/rescue.py b/omagent-core/src/omagent_core/core/node/misc/rescue.py deleted file mode 100644 index 69ff732..0000000 --- a/omagent-core/src/omagent_core/core/node/misc/rescue.py +++ /dev/null @@ -1,119 +0,0 @@ -import json -from pathlib import Path -from typing import List, Tuple - -from colorama import Fore, Style -from omagent_core.core.node.dnc.schemas import TaskStatus -from pydantic import Field -from tenacity import ( - retry, - retry_if_exception_message, - stop_after_attempt, - stop_after_delay, -) - -from ....core.llm.base import BaseLLMBackend -from ....core.node.base import BaseDecider -from ....core.node.dnc.interface import DnCInterface -from ....core.prompt.prompt import PromptTemplate -from ....handlers.data_handler.ltm import LTM -from ....utils.env import EnvVar -from ....utils.registry import registry -from ...tool_system.manager import ToolManager - -CURRENT_PATH = root_path = Path(__file__).parents[0] - - -@registry.register_node() -class TaskRescue(BaseLLMBackend, BaseDecider): - prompts: List[PromptTemplate] = Field( - default=[ - PromptTemplate.from_file( - CURRENT_PATH.joinpath("sys_prompt.prompt"), role="system" - ), - PromptTemplate.from_file( - CURRENT_PATH.joinpath("user_prompt.prompt"), role="user" - ), - ] - ) - tool_manager: ToolManager - - @retry( - stop=( - stop_after_delay(EnvVar.STOP_AFTER_DELAY) - | stop_after_attempt(EnvVar.STOP_AFTER_ATTEMPT) - ), - retry=retry_if_exception_message(message="LLM generation is not valid."), - reraise=True, - ) - def _run(self, args: DnCInterface, ltm: LTM) -> Tuple[DnCInterface, str]: - toolcall_content = self.stm.former_results.get("tool_call", None) - if toolcall_content is not None: - del self.stm.former_results["tool_call"] - chat_complete_res = self.simple_infer( - task=args.task.task, - failed_detail=self.stm.former_results["failed_detail"], - ) - self.stm.former_results["failed_detail"] = chat_complete_res["choices"][0][ - "message" - ]["content"] - - rescue_execution_status, rescue_execution_results = ( - self.tool_manager.execute_task( - toolcall_content, related_info=self.stm.former_results - ) - ) - if rescue_execution_status == "success": - toolcall_rescue_output_structure = { - "tool_status": rescue_execution_status, - "tool_result": rescue_execution_results, - } - self.callback.send_block( - f'{Fore.WHITE}\n{"-=" * 5}Tool Call {Fore.RED}Rescue{Style.RESET_ALL} Output{"=-" * 5}{Style.RESET_ALL}\n' - f"{Fore.BLUE}{json.dumps(toolcall_rescue_output_structure, indent=2, ensure_ascii=False)}{Style.RESET_ALL}" - ) - del self.stm.former_results["failed_detail"] - self.stm.former_results["rescue_detail"] = rescue_execution_results - return args, "success" - - else: - args.task.status = TaskStatus.RUNNING - return args, "failure" - else: - return args, "failure" - - async def _arun(self, args: DnCInterface, ltm: LTM) -> Tuple[DnCInterface, str]: - toolcall_content = self.stm.former_results.get("tool_call", None) - if toolcall_content is not None: - del self.stm.former_results["tool_call"] - chat_complete_res = await self.simple_ainfer( - task=args.task.task, - failed_detail=self.stm.former_results["failed_detail"], - ) - self.stm.former_results["failed_detail"] = chat_complete_res["choices"][0][ - "message" - ]["content"] - - rescue_execution_status, rescue_execution_results = ( - await self.tool_manager.aexecute_task( - toolcall_content, related_info=self.stm.former_results - ) - ) - if rescue_execution_status == "success": - toolcall_rescue_output_structure = { - "tool_status": rescue_execution_status, - "tool_result": rescue_execution_results, - } - self.callback.send_block( - f'{Fore.WHITE}\n{"-=" * 5}Tool Call {Fore.RED}Rescue{Style.RESET_ALL} Output{"=-" * 5}{Style.RESET_ALL}\n' - f"{Fore.BLUE}{json.dumps(toolcall_rescue_output_structure, indent=2, ensure_ascii=False)}{Style.RESET_ALL}" - ) - del self.stm.former_results["failed_detail"] - self.stm.former_results["rescue_detail"] = rescue_execution_results - return args, "success" - - else: - args.task.status = TaskStatus.RUNNING - return args, "failure" - else: - return args, "failure" diff --git a/omagent-core/src/omagent_core/core/node/misc/sys_prompt.prompt b/omagent-core/src/omagent_core/core/node/misc/sys_prompt.prompt deleted file mode 100644 index edab211..0000000 --- a/omagent-core/src/omagent_core/core/node/misc/sys_prompt.prompt +++ /dev/null @@ -1,5 +0,0 @@ -As the rescue section, your role is to try your best to identify and fix the error in provided failed detail. -Your task includes three parts: -1. Based on the original question, analyze whether the current operation can meet the requirements of the question. -2. Based on the provided failed detail, analyze the problem and consider all possible solutions. -3. Select the best solution from all possible solutions and provide the modified **correct** answer. diff --git a/omagent-core/src/omagent_core/core/node/misc/user_prompt.prompt b/omagent-core/src/omagent_core/core/node/misc/user_prompt.prompt deleted file mode 100644 index 8028c91..0000000 --- a/omagent-core/src/omagent_core/core/node/misc/user_prompt.prompt +++ /dev/null @@ -1,6 +0,0 @@ -Now, it's your turn to complete the task. - -Task (The task you need to complete.): {{task}} -Failed detail (The result from former agents.): {{failed_detail}} - -Now show your super capability as a super agent that beyond regular AIs or LLMs! \ No newline at end of file diff --git a/omagent-core/src/omagent_core/core/tool_system/tools/__init__.py b/omagent-core/src/omagent_core/core/tool_system/tools/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/omagent-core/src/omagent_core/core/llm/__init__.py b/omagent-core/src/omagent_core/engine/__init__.py similarity index 100% rename from omagent-core/src/omagent_core/core/llm/__init__.py rename to omagent-core/src/omagent_core/engine/__init__.py diff --git a/omagent-core/src/omagent_core/core/node/base/__init__.py b/omagent-core/src/omagent_core/engine/node/__init__.py similarity index 100% rename from omagent-core/src/omagent_core/core/node/base/__init__.py rename to omagent-core/src/omagent_core/engine/node/__init__.py diff --git a/omagent-core/src/omagent_core/core/node/base/base.py b/omagent-core/src/omagent_core/engine/node/base.py similarity index 64% rename from omagent-core/src/omagent_core/core/node/base/base.py rename to omagent-core/src/omagent_core/engine/node/base.py index 7b6f99d..d7762ea 100644 --- a/omagent-core/src/omagent_core/core/node/base/base.py +++ b/omagent-core/src/omagent_core/engine/node/base.py @@ -1,8 +1,8 @@ from abc import ABC, abstractmethod from typing import Any -from ....handlers.data_handler.ltm import LTM -from ....schemas.base import BaseInterface +from ...memories.ltms.ltm import LTM +from ..workflow.context import BaseWorkflowContext from ...base import BotBase @@ -12,30 +12,30 @@ class Node(BotBase, ABC): """ @abstractmethod - def _run(self, args: BaseInterface, ltm: LTM) -> Any: + def _run(self, args: BaseWorkflowContext, ltm: LTM) -> Any: """Run the Node.""" - async def _arun(self, args: BaseInterface, ltm: LTM) -> Any: + async def _arun(self, args: BaseWorkflowContext, ltm: LTM) -> Any: """Run the Node.""" raise NotImplementedError( f"Async run not implemented for {type(self).__name__} Node." ) - def run(self, args: BaseInterface, ltm: LTM): + def run(self, args: BaseWorkflowContext, ltm: LTM): res = self._run(args, ltm) assert type(args) == type(res) self._forward(res, ltm) - async def arun(self, args: BaseInterface, ltm: LTM): + async def arun(self, args: BaseWorkflowContext, ltm: LTM): res = await self._arun(args, ltm) assert type(args) == type(res) await self._aforward(res, ltm) @abstractmethod - def _forward(self, args: BaseInterface, ltm: LTM): + def _forward(self, args: BaseWorkflowContext, ltm: LTM): """Process to next Node""" - async def _aforward(self, args: BaseInterface, ltm: LTM): + async def _aforward(self, args: BaseWorkflowContext, ltm: LTM): """Run the Node.""" raise NotImplementedError( f"Async run not implemented for {type(self).__name__} Node." diff --git a/omagent-core/src/omagent_core/core/node/base/decider.py b/omagent-core/src/omagent_core/engine/node/decider.py similarity index 82% rename from omagent-core/src/omagent_core/core/node/base/decider.py rename to omagent-core/src/omagent_core/engine/node/decider.py index 14afca2..48ab783 100644 --- a/omagent-core/src/omagent_core/core/node/base/decider.py +++ b/omagent-core/src/omagent_core/engine/node/decider.py @@ -3,10 +3,10 @@ from pydantic import field_validator -from ....handlers import VQLError -from ....handlers.data_handler.ltm import LTM -from ....schemas.base import BaseInterface -from ....utils.registry import registry +from ...utils.error import VQLError +from ...memories.ltms.ltm import LTM +from ..workflow.context import BaseWorkflowContext +from ...utils.registry import registry from .base import Node @@ -40,26 +40,26 @@ def init_next_step(cls, next_step: Dict[str, Union[Node, Dict]]) -> Dict[str, No return next_step @abstractmethod - def _run(self, args: BaseInterface, ltm: LTM) -> Tuple[BaseInterface, str]: + def _run(self, args: BaseWorkflowContext, ltm: LTM) -> Tuple[BaseWorkflowContext, str]: """Run the Node.""" - async def _arun(self, args: BaseInterface, ltm: LTM) -> Tuple[BaseInterface, str]: + async def _arun(self, args: BaseWorkflowContext, ltm: LTM) -> Tuple[BaseWorkflowContext, str]: """Run the Node.""" raise NotImplementedError( f"Async run not implemented for {type(self).__name__} Node." ) - def run(self, args: BaseInterface, ltm: LTM): + def run(self, args: BaseWorkflowContext, ltm: LTM): res, next_key = self._run(args, ltm) assert type(args) == type(res) self._forward(next_key, res, ltm) - async def arun(self, args: BaseInterface, ltm: LTM): + async def arun(self, args: BaseWorkflowContext, ltm: LTM): res, next_key = await self._arun(args, ltm) assert type(args) == type(res) await self._aforward(next_key, res, ltm) - def _forward(self, next_key: str, args: BaseInterface, ltm: LTM): + def _forward(self, next_key: str, args: BaseWorkflowContext, ltm: LTM): """Process to next Node""" if not self.next_step: self.callback.finish() @@ -78,7 +78,7 @@ def _forward(self, next_key: str, args: BaseInterface, ltm: LTM): ) next_step.run(args, ltm) - async def _aforward(self, next_key: str, args: BaseInterface, ltm: LTM): + async def _aforward(self, next_key: str, args: BaseWorkflowContext, ltm: LTM): """Process to next Node""" if not self.next_step: self.callback.finish() diff --git a/omagent-core/src/omagent_core/core/node/base/loop.py b/omagent-core/src/omagent_core/engine/node/loop.py similarity index 82% rename from omagent-core/src/omagent_core/core/node/base/loop.py rename to omagent-core/src/omagent_core/engine/node/loop.py index ca78ac2..ba7bea1 100644 --- a/omagent-core/src/omagent_core/core/node/base/loop.py +++ b/omagent-core/src/omagent_core/engine/node/loop.py @@ -4,10 +4,10 @@ from pydantic import field_validator from pydantic._internal._model_construction import ModelMetaclass -from ....handlers.data_handler.ltm import LTM -from ....schemas.base import BaseInterface -from ....utils.registry import registry -from ..base.base import Node +from ...memories.ltms.ltm import LTM +from ..workflow.context import BaseWorkflowContext +from ...utils.registry import registry +from .base import Node from .processor import BaseProcessor @@ -45,7 +45,7 @@ def init_loop_body(cls, loop_body: Union[Node, Dict]) -> Node: ) ) - def run(self, args: BaseInterface, ltm: LTM): + def run(self, args: BaseWorkflowContext, ltm: LTM): while not self.pre_loop_exit(args, ltm): self.callback.send_block(self.name) self.loop_body.run(args, ltm) @@ -54,7 +54,7 @@ def run(self, args: BaseInterface, ltm: LTM): self._forward(args, ltm) - async def arun(self, args: BaseInterface, ltm: LTM): + async def arun(self, args: BaseWorkflowContext, ltm: LTM): while not self.pre_loop_exit(args, ltm): await self.loop_body.arun(args, ltm) if self.post_loop_exit(args, ltm): @@ -62,7 +62,7 @@ async def arun(self, args: BaseInterface, ltm: LTM): await self._aforward(args, ltm) - def pre_loop_exit(self, args: BaseInterface, ltm: LTM) -> bool: + def pre_loop_exit(self, args: BaseWorkflowContext, ltm: LTM) -> bool: """This function is used to set a breakpoint for the loop before every time the loop_body is executed. Returns: @@ -70,7 +70,7 @@ def pre_loop_exit(self, args: BaseInterface, ltm: LTM) -> bool: """ return False - def post_loop_exit(self, args: BaseInterface, ltm: LTM) -> bool: + def post_loop_exit(self, args: BaseWorkflowContext, ltm: LTM) -> bool: """This function is used to set a breakpoint for the loop after every time the loop_body is executed. Returns: @@ -78,5 +78,5 @@ def post_loop_exit(self, args: BaseInterface, ltm: LTM) -> bool: """ return False - def _run(self, args: BaseInterface, ltm: LTM) -> BaseInterface: + def _run(self, args: BaseWorkflowContext, ltm: LTM) -> BaseWorkflowContext: pass diff --git a/omagent-core/src/omagent_core/core/node/base/processor.py b/omagent-core/src/omagent_core/engine/node/processor.py similarity index 74% rename from omagent-core/src/omagent_core/core/node/base/processor.py rename to omagent-core/src/omagent_core/engine/node/processor.py index af481dd..7066476 100644 --- a/omagent-core/src/omagent_core/core/node/base/processor.py +++ b/omagent-core/src/omagent_core/engine/node/processor.py @@ -3,9 +3,9 @@ from pydantic import field_validator -from ....handlers.data_handler.ltm import LTM -from ....schemas.base import BaseInterface -from ....utils.registry import registry +from ...memories.ltms.ltm import LTM +from ..workflow.context import BaseWorkflowContext +from ...utils.registry import registry from .base import Node @@ -29,26 +29,26 @@ def init_next_step(cls, next_step: Union[Node, None]) -> Union[Node, None]: ) @abstractmethod - def _run(self, args: BaseInterface, ltm: LTM) -> BaseInterface: + def _run(self, args: BaseWorkflowContext, ltm: LTM) -> BaseWorkflowContext: """Run the Node.""" - async def _arun(self, args: BaseInterface, ltm: LTM) -> BaseInterface: + async def _arun(self, args: BaseWorkflowContext, ltm: LTM) -> BaseWorkflowContext: """Run the Node.""" raise NotImplementedError( f"Async run not implemented for {type(self).__name__} Node." ) - def run(self, args: BaseInterface, ltm: LTM): + def run(self, args: BaseWorkflowContext, ltm: LTM): res = self._run(args, ltm) assert type(args) == type(res) self._forward(res, ltm) - async def arun(self, args: BaseInterface, ltm: LTM): + async def arun(self, args: BaseWorkflowContext, ltm: LTM): res = await self._arun(args, ltm) assert type(args) == type(res) await self._aforward(res, ltm) - def _forward(self, args: BaseInterface, ltm: LTM): + def _forward(self, args: BaseWorkflowContext, ltm: LTM): """Process to next Node""" if not self.next_step: self.callback.finish() @@ -56,7 +56,7 @@ def _forward(self, args: BaseInterface, ltm: LTM): else: self.next_step.run(args, ltm) - async def _aforward(self, args: BaseInterface, ltm: LTM): + async def _aforward(self, args: BaseWorkflowContext, ltm: LTM): """Process to next Node""" if not self.next_step: self.callback.finish() diff --git a/omagent-core/src/omagent_core/core/node/dnc/schemas.py b/omagent-core/src/omagent_core/engine/task/agent_task.py similarity index 100% rename from omagent-core/src/omagent_core/core/node/dnc/schemas.py rename to omagent-core/src/omagent_core/engine/task/agent_task.py diff --git a/omagent-core/src/omagent_core/core/node/__init__.py b/omagent-core/src/omagent_core/engine/workflow/__init__.py similarity index 100% rename from omagent-core/src/omagent_core/core/node/__init__.py rename to omagent-core/src/omagent_core/engine/workflow/__init__.py diff --git a/omagent-core/src/omagent_core/engine/workflow/context.py b/omagent-core/src/omagent_core/engine/workflow/context.py new file mode 100644 index 0000000..80346e7 --- /dev/null +++ b/omagent-core/src/omagent_core/engine/workflow/context.py @@ -0,0 +1,16 @@ +from pydantic import BaseModel +from abc import ABC +from typing import Any, Dict, Optional + +from ..task.agent_task import AgentTask + +class BaseWorkflowContext(BaseModel, ABC): + class Config: + """Configuration for this pydantic object.""" + + extra = "allow" + arbitrary_types_allowed = True + + last_output: Any = None + kwargs: dict = {} + task: AgentTask \ No newline at end of file diff --git a/omagent-core/src/omagent_core/handlers/__init__.py b/omagent-core/src/omagent_core/handlers/__init__.py deleted file mode 100644 index 5d0a9f4..0000000 --- a/omagent-core/src/omagent_core/handlers/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -from .error_handler.error import VQLError -from .log_handler.logger import logging - -# from .callback_handler.callback import Callback - -__all__ = ["VQLError", "logging", "Callback"] diff --git a/omagent-core/src/omagent_core/handlers/callback_handler/__init__.py b/omagent-core/src/omagent_core/handlers/callback_handler/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/omagent-core/src/omagent_core/handlers/data_handler/__init__.py b/omagent-core/src/omagent_core/handlers/data_handler/__init__.py deleted file mode 100644 index 8d40acb..0000000 --- a/omagent-core/src/omagent_core/handlers/data_handler/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -# from .character_data_handler import CharacterDataHandler -# from .memory_data_handler import MemoryDataHandler -# from .event_data_handler import EventDataHandler - -# __all_ = ['CharacterDataHandler', 'MemoryDataHandler', 'EventDataHandler'] diff --git a/omagent-core/src/omagent_core/handlers/error_handler/__init__.py b/omagent-core/src/omagent_core/handlers/error_handler/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/omagent-core/src/omagent_core/handlers/error_handler/error.py b/omagent-core/src/omagent_core/handlers/error_handler/error.py deleted file mode 100644 index adc292f..0000000 --- a/omagent-core/src/omagent_core/handlers/error_handler/error.py +++ /dev/null @@ -1,53 +0,0 @@ -class VQLError(Exception): - def __init__(self, code, msg=None, detail=""): - """ - :param code: Error code - :param msg: Error message, for system display. - :param detail: Error detail, for debugging. - - 500: "内部错误", - - 501: "图片错误: 无法读取", - - 502: "图片错误: 图片损坏", - - 503: "图片错误: 无法获取", - - 504: "图片错误: 无法识别", - - 505: "图片错误: 不存在的key", - - 506: "图片错误: 无法连接数据库", - - 511: "请求错误: 服务处理失败", - - 515: "请求错误: 超过重试次数,无法访问地址", - - 516: "请求错误: 不存在的地址", - - 517: "请求错误: 错误的请求格式", - - 518: "请求错误: 非法的请求地址", - - 550: "IBase错误", - - 570: "回调错误: 处理结果回调失败" - """ - - code2msg = { - 500: "内部错误", - 501: "图片错误: 无法读取", # 图片文件无法读取 - 502: "图片错误: 图片损坏", # 图片文件损坏 - 503: "图片错误: 无法获取", # 图片获取失败 - 504: "图片错误: 无法识别", # 图片文件不支持 - 505: "图片错误: 不存在的key", # Redis模式获取数据时key不存在 - 506: "图片错误: 无法连接数据库", # Redis模式获取数据时,无法连接Redis - 511: "请求错误: 服务处理失败", # 不明原因的Atom报错 - 515: "请求错误: 超过重试次数,无法访问地址", # API的URL或端口错误,无法访问 - 516: "请求错误: 错误的地址", # API的路由地址错误 - 517: "请求错误: 错误的请求格式", # 入参格式错误 - 518: "请求错误: 非法的请求地址", # atom的api地址格式错误 - 550: "IBase错误", # R2Base 错误 - 570: "回调错误: 处理结果回调失败", # 算法处理结果回调时发生错误 - 800: "llm错误: 非预期的返回结果", # llm返回结果不符合预期 - } - - self.code = code - self.detail = detail - if msg: - self.msg = msg - else: - self.msg = code2msg[code] - - def __str__(self): - return repr( - "Code: {} | message: {} | detail:{}".format( - self.code, self.msg, self.detail - ) - ) diff --git a/omagent-core/src/omagent_core/handlers/log_handler/__init__.py b/omagent-core/src/omagent_core/handlers/log_handler/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/omagent-core/src/omagent_core/handlers/data_handler/milvus_handler.py b/omagent-core/src/omagent_core/handlers/milvus_handler.py similarity index 99% rename from omagent-core/src/omagent_core/handlers/data_handler/milvus_handler.py rename to omagent-core/src/omagent_core/handlers/milvus_handler.py index 74bbf75..3937c97 100644 --- a/omagent-core/src/omagent_core/handlers/data_handler/milvus_handler.py +++ b/omagent-core/src/omagent_core/handlers/milvus_handler.py @@ -6,8 +6,8 @@ from pymilvus import Collection, DataType, MilvusClient, connections, utility from pymilvus.client import types -from ...utils.registry import registry -from ..error_handler.error import VQLError +from ..utils.registry import registry +from ..utils.error import VQLError @registry.register_handler() diff --git a/omagent-core/src/omagent_core/handlers/data_handler/sql_data_handler.py b/omagent-core/src/omagent_core/handlers/sql_data_handler.py similarity index 97% rename from omagent-core/src/omagent_core/handlers/data_handler/sql_data_handler.py rename to omagent-core/src/omagent_core/handlers/sql_data_handler.py index 4eedb4c..0240ac1 100644 --- a/omagent-core/src/omagent_core/handlers/data_handler/sql_data_handler.py +++ b/omagent-core/src/omagent_core/handlers/sql_data_handler.py @@ -5,9 +5,9 @@ from sqlalchemy_utils import create_database, database_exists from sqlmodel import Session, SQLModel, create_engine, delete, select -from ...schemas.base import BaseTable -from ..error_handler.error import VQLError -from ..log_handler.logger import logging +from .table import BaseTable +from ..utils.error import VQLError +from ..utils.logger import logging class SQLDataHandler(BaseModel): diff --git a/omagent-core/src/omagent_core/schemas/base.py b/omagent-core/src/omagent_core/handlers/table.py similarity index 51% rename from omagent-core/src/omagent_core/schemas/base.py rename to omagent-core/src/omagent_core/handlers/table.py index 2c0fc8a..d7487cc 100644 --- a/omagent-core/src/omagent_core/schemas/base.py +++ b/omagent-core/src/omagent_core/handlers/table.py @@ -1,38 +1,10 @@ from abc import ABC -# from sqlalchemy import Column, Text from datetime import datetime from typing import Any, Dict, Optional -from pydantic import BaseModel from sqlmodel import Column, DateTime, Field, SQLModel, func - -class STM(BaseModel): - class Config: - """Configuration for this pydantic object.""" - - extra = "allow" - arbitrary_types_allowed = True - - tasks: Dict = {} - memory: Dict = {} - knowledge: Dict = {} - summary: Dict = {} - kwargs: Dict = {} - - -class BaseInterface(BaseModel, ABC): - class Config: - """Configuration for this pydantic object.""" - - extra = "allow" - arbitrary_types_allowed = True - - last_output: Any = None - kwargs: dict = {} - - class BaseTable(SQLModel): id: Optional[int] = Field(default=None, primary_key=True) bot_id: str = Field(index=True, nullable=False) diff --git a/omagent-core/src/omagent_core/handlers/data_handler/video_handler.py b/omagent-core/src/omagent_core/handlers/video_handler.py similarity index 97% rename from omagent-core/src/omagent_core/handlers/data_handler/video_handler.py rename to omagent-core/src/omagent_core/handlers/video_handler.py index 6ff668b..ec78559 100644 --- a/omagent-core/src/omagent_core/handlers/data_handler/video_handler.py +++ b/omagent-core/src/omagent_core/handlers/video_handler.py @@ -3,9 +3,9 @@ from pydantic import field_validator from pymilvus import CollectionSchema, DataType, FieldSchema -from ...core.encoder.base import EncoderBase -from ...utils.registry import registry -from ..error_handler.error import VQLError +from ..models.encoders.base import EncoderBase +from ..utils.registry import registry +from ..utils.error import VQLError from .milvus_handler import MilvusHandler diff --git a/engine/video_process/scene.py b/omagent-core/src/omagent_core/handlers/video_scenes.py old mode 100755 new mode 100644 similarity index 99% rename from engine/video_process/scene.py rename to omagent-core/src/omagent_core/handlers/video_scenes.py index 241a3ad..2250561 --- a/engine/video_process/scene.py +++ b/omagent-core/src/omagent_core/handlers/video_scenes.py @@ -1,7 +1,7 @@ from typing import Dict, List, Optional, Tuple, Union import cv2 -from omagent_core.handlers.log_handler.logger import logging +from ..utils.logger import logging from PIL import Image from pydantic import BaseModel from pydub import AudioSegment diff --git a/omagent-core/src/omagent_core/handlers/data_handler/ltm.py b/omagent-core/src/omagent_core/memories/ltms/ltm.py similarity index 100% rename from omagent-core/src/omagent_core/handlers/data_handler/ltm.py rename to omagent-core/src/omagent_core/memories/ltms/ltm.py diff --git a/engine/video_process/stt.py b/omagent-core/src/omagent_core/models/asr/stt.py similarity index 97% rename from engine/video_process/stt.py rename to omagent-core/src/omagent_core/models/asr/stt.py index 01467c0..90c65b5 100644 --- a/engine/video_process/stt.py +++ b/omagent-core/src/omagent_core/models/asr/stt.py @@ -1,7 +1,7 @@ import io from typing import Any, Optional -from omagent_core.core.base import BotBase +from ...base import BotBase from openai import NOT_GIVEN, AsyncOpenAI, OpenAI from pydub import AudioSegment diff --git a/omagent-core/src/omagent_core/core/node/dnc/conqueror/__init__.py b/omagent-core/src/omagent_core/models/encoders/__init__.py similarity index 100% rename from omagent-core/src/omagent_core/core/node/dnc/conqueror/__init__.py rename to omagent-core/src/omagent_core/models/encoders/__init__.py diff --git a/omagent-core/src/omagent_core/core/encoder/base.py b/omagent-core/src/omagent_core/models/encoders/base.py similarity index 96% rename from omagent-core/src/omagent_core/core/encoder/base.py rename to omagent-core/src/omagent_core/models/encoders/base.py index f52c354..2c386bf 100644 --- a/omagent-core/src/omagent_core/core/encoder/base.py +++ b/omagent-core/src/omagent_core/models/encoders/base.py @@ -1,7 +1,7 @@ from abc import ABC, abstractmethod from typing import List -from ...core.base import BotBase +from ...base import BotBase from ...utils.general import chunks diff --git a/omagent-core/src/omagent_core/core/encoder/openai_encoder.py b/omagent-core/src/omagent_core/models/encoders/openai_encoder.py similarity index 100% rename from omagent-core/src/omagent_core/core/encoder/openai_encoder.py rename to omagent-core/src/omagent_core/models/encoders/openai_encoder.py diff --git a/omagent-core/src/omagent_core/core/node/dnc/divider/__init__.py b/omagent-core/src/omagent_core/models/llms/__init__.py similarity index 100% rename from omagent-core/src/omagent_core/core/node/dnc/divider/__init__.py rename to omagent-core/src/omagent_core/models/llms/__init__.py diff --git a/omagent-core/src/omagent_core/core/llm/azure_gpt.py b/omagent-core/src/omagent_core/models/llms/azure_gpt.py similarity index 99% rename from omagent-core/src/omagent_core/core/llm/azure_gpt.py rename to omagent-core/src/omagent_core/models/llms/azure_gpt.py index 94fd5dc..698ee45 100644 --- a/omagent-core/src/omagent_core/core/llm/azure_gpt.py +++ b/omagent-core/src/omagent_core/models/llms/azure_gpt.py @@ -6,7 +6,7 @@ import geocoder from openai import AsyncAzureOpenAI, AzureOpenAI -from ...schemas.dev import Content, Message +from .schemas import Content, Message from ...utils.general import encode_image from ...utils.registry import registry from .base import BaseLLM diff --git a/omagent-core/src/omagent_core/core/llm/base.py b/omagent-core/src/omagent_core/models/llms/base.py similarity index 97% rename from omagent-core/src/omagent_core/core/llm/base.py rename to omagent-core/src/omagent_core/models/llms/base.py index 1e207c1..db1fa52 100644 --- a/omagent-core/src/omagent_core/core/llm/base.py +++ b/omagent-core/src/omagent_core/models/llms/base.py @@ -8,14 +8,14 @@ from pydantic import Field, field_validator from tenacity import retry, stop_after_attempt, stop_after_delay -from ...schemas.dev import Message +from .schemas import Message from ...utils.env import EnvVar from ...utils.general import LRUCache from ...utils.registry import registry -from ..base import BotBase -from ..prompt.base import _OUTPUT_PARSER, StrParser -from ..prompt.parser import BaseOutputParser -from ..prompt.prompt import PromptTemplate +from ...base import BotBase +from .prompt.base import _OUTPUT_PARSER, StrParser +from .prompt.parser import BaseOutputParser +from .prompt.prompt import PromptTemplate T = TypeVar("T", str, dict, list) diff --git a/omagent-core/src/omagent_core/core/llm/openai_gpt.py b/omagent-core/src/omagent_core/models/llms/openai_gpt.py similarity index 99% rename from omagent-core/src/omagent_core/core/llm/openai_gpt.py rename to omagent-core/src/omagent_core/models/llms/openai_gpt.py index 5c1509b..1069ae5 100644 --- a/omagent-core/src/omagent_core/core/llm/openai_gpt.py +++ b/omagent-core/src/omagent_core/models/llms/openai_gpt.py @@ -6,7 +6,7 @@ import geocoder from openai import AsyncOpenAI, OpenAI -from ...schemas.dev import Content, Message +from .schemas import Content, Message from ...utils.general import encode_image from ...utils.registry import registry from .base import BaseLLM diff --git a/omagent-core/src/omagent_core/core/prompt/__init__.py b/omagent-core/src/omagent_core/models/llms/prompt/__init__.py similarity index 100% rename from omagent-core/src/omagent_core/core/prompt/__init__.py rename to omagent-core/src/omagent_core/models/llms/prompt/__init__.py diff --git a/omagent-core/src/omagent_core/core/prompt/base.py b/omagent-core/src/omagent_core/models/llms/prompt/base.py similarity index 99% rename from omagent-core/src/omagent_core/core/prompt/base.py rename to omagent-core/src/omagent_core/models/llms/prompt/base.py index 982c3b1..e24f468 100644 --- a/omagent-core/src/omagent_core/core/prompt/base.py +++ b/omagent-core/src/omagent_core/models/llms/prompt/base.py @@ -12,7 +12,7 @@ import yaml from pydantic import Field -from ..base import BotBase +from ....base import BotBase from .formatter import FStringFormatter, JinjiaFormatter from .parser import BaseOutputParser, DictParser, ListParser, StrParser diff --git a/omagent-core/src/omagent_core/core/prompt/formatter.py b/omagent-core/src/omagent_core/models/llms/prompt/formatter.py similarity index 100% rename from omagent-core/src/omagent_core/core/prompt/formatter.py rename to omagent-core/src/omagent_core/models/llms/prompt/formatter.py diff --git a/omagent-core/src/omagent_core/core/prompt/parser.py b/omagent-core/src/omagent_core/models/llms/prompt/parser.py similarity index 98% rename from omagent-core/src/omagent_core/core/prompt/parser.py rename to omagent-core/src/omagent_core/models/llms/prompt/parser.py index c390821..07cd5f4 100644 --- a/omagent-core/src/omagent_core/core/prompt/parser.py +++ b/omagent-core/src/omagent_core/models/llms/prompt/parser.py @@ -3,7 +3,7 @@ from abc import ABC, abstractmethod from typing import Generic, Optional, TypeVar -from ...handlers.error_handler.error import VQLError +from ....utils.error import VQLError from ..base import BotBase T = TypeVar("T") diff --git a/omagent-core/src/omagent_core/core/prompt/prompt.py b/omagent-core/src/omagent_core/models/llms/prompt/prompt.py similarity index 99% rename from omagent-core/src/omagent_core/core/prompt/prompt.py rename to omagent-core/src/omagent_core/models/llms/prompt/prompt.py index e325d06..8a3335e 100644 --- a/omagent-core/src/omagent_core/core/prompt/prompt.py +++ b/omagent-core/src/omagent_core/models/llms/prompt/prompt.py @@ -6,7 +6,7 @@ from pydantic import model_validator -from ...utils.registry import registry +from ....utils.registry import registry from .base import ( DEFAULT_FORMATTER_MAPPING, BasePromptTemplate, diff --git a/omagent-core/src/omagent_core/schemas/dev.py b/omagent-core/src/omagent_core/models/llms/schemas.py similarity index 88% rename from omagent-core/src/omagent_core/schemas/dev.py rename to omagent-core/src/omagent_core/models/llms/schemas.py index e8d1294..1d2720c 100644 --- a/omagent-core/src/omagent_core/schemas/dev.py +++ b/omagent-core/src/omagent_core/models/llms/schemas.py @@ -1,26 +1,22 @@ import re from typing import Dict, List, Optional +from ..od.schemas import Target from pydantic import BaseModel, field_validator, model_validator -from .opt import MessageType, Role +from enum import Enum +class Role(str, Enum): + USER = "user" + ASSISTANT = "assistant" + SYSTEM = "system" -class Target(BaseModel): - """ - - bbox (List[float]): Bounding box of an object. - - polygon (List[List[float]]): Polygon of an object. - - label (str): Object label. - - conf (float): Object confidence. - - attr (List[str]): Object attributes. - """ - - bbox: Optional[List[float]] = None - polygon: Optional[List[List[float]]] = None - label: Optional[str] = None - conf: Optional[float] = None - attr: Optional[List[str]] = None +class MessageType(str, Enum): + IMAGE = "image" + TEXT = "text" + File = "file" + MIXED = "mixed" class ImageUrl(BaseModel): url: str @@ -66,7 +62,7 @@ def validate(self): class Message(BaseModel): """ - - role (str): The role of this message. Choose from 'user', 'assistant', 'system', 'thinking'. + - role (str): The role of this message. Choose from 'user', 'assistant', 'system'. - message_type (str): Type of the message. Choose from 'text', 'image' and 'mixed'. - src_type (str): Type of the message content. If message is text, src_type='text'. If message is image, Choose from 'url', 'base64', 'local' and 'redis'. - content (str): Message content. @@ -177,20 +173,4 @@ def combine_image_message(self, **kwargs): else: modified_content.append(Content(type="text", text=segment)) self.content = modified_content - self.message_type = MessageType.MIXED - - -class MQLinkage(BaseModel): - """ - - mq_user (str): MQ username. - - mq_password (str): MQ password. - - mq_host (str): MQ host. - - mq_port (str): MQ port. - - que_id (str): MQ queue id. - """ - - username: str - password: str - host: str - port: str - queue: str + self.message_type = MessageType.MIXED \ No newline at end of file diff --git a/omagent-core/src/omagent_core/models/od/schemas.py b/omagent-core/src/omagent_core/models/od/schemas.py new file mode 100644 index 0000000..37a8e9f --- /dev/null +++ b/omagent-core/src/omagent_core/models/od/schemas.py @@ -0,0 +1,19 @@ +from typing import List, Optional + +from pydantic import BaseModel + + +class Target(BaseModel): + """ + - bbox (List[float]): Bounding box of an object. + - polygon (List[List[float]]): Polygon of an object. + - label (str): Object label. + - conf (float): Object confidence. + - attr (List[str]): Object attributes. + """ + + bbox: Optional[List[float]] = None + polygon: Optional[List[List[float]]] = None + label: Optional[str] = None + conf: Optional[float] = None + attr: Optional[List[str]] = None \ No newline at end of file diff --git a/omagent-core/src/omagent_core/schemas/__init__.py b/omagent-core/src/omagent_core/schemas/__init__.py deleted file mode 100644 index 76826ea..0000000 --- a/omagent-core/src/omagent_core/schemas/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from .base import STM, BaseInterface, BaseTable - -__all__ = ["BaseInterface", "BaseTable", "STM"] diff --git a/omagent-core/src/omagent_core/schemas/opt.py b/omagent-core/src/omagent_core/schemas/opt.py deleted file mode 100644 index 71ec558..0000000 --- a/omagent-core/src/omagent_core/schemas/opt.py +++ /dev/null @@ -1,36 +0,0 @@ -from enum import Enum - - -class ChatStatus(str, Enum): - INCOMPLETE = "incomplete" - END_BLOCK = "end_block" - END_ANSWER = "end_answer" - - -class Role(str, Enum): - USER = "user" - ASSISTANT = "assistant" - SYSTEM = "system" - THINKING = "thinking" - - -class MessageType(str, Enum): - IMAGE = "image" - TEXT = "text" - File = "file" - MIXED = "mixed" - - -class SrcType(str, Enum): - TEXT = "text" - URL = "url" - BASE64 = "base64" - REDIS = "redis" - LOCAL = "local" - - -class OPT: - CHAT_STATUS = ChatStatus - ROLE = Role - MESSAGE_TYPE = MessageType - SRC_TYPE = SrcType diff --git a/omagent-core/src/omagent_core/core/tool_system/__init__.py b/omagent-core/src/omagent_core/tool_system/__init__.py similarity index 97% rename from omagent-core/src/omagent_core/core/tool_system/__init__.py rename to omagent-core/src/omagent_core/tool_system/__init__.py index 0e750d2..56793a3 100644 --- a/omagent-core/src/omagent_core/core/tool_system/__init__.py +++ b/omagent-core/src/omagent_core/tool_system/__init__.py @@ -1,6 +1,6 @@ from pydantic import BaseModel -from ...utils.registry import registry +from ..utils.registry import registry from .base import BaseTool diff --git a/omagent-core/src/omagent_core/core/tool_system/base.py b/omagent-core/src/omagent_core/tool_system/base.py similarity index 97% rename from omagent-core/src/omagent_core/core/tool_system/base.py rename to omagent-core/src/omagent_core/tool_system/base.py index 4960429..1dae262 100644 --- a/omagent-core/src/omagent_core/core/tool_system/base.py +++ b/omagent-core/src/omagent_core/tool_system/base.py @@ -8,11 +8,11 @@ from PIL import Image from pydantic import BaseModel, model_validator -from ...handlers.data_handler.sql_data_handler import SQLDataHandler -from ...handlers.error_handler.error import VQLError -from ...handlers.log_handler.logger import logging -from ...schemas.dev import Target -from ...utils.plot import Annotator +from ..handlers.sql_data_handler import SQLDataHandler +from ..utils.error import VQLError +from ..utils.logger import logging +from ..models.od.schemas import Target +from ..utils.plot import Annotator from ..base import BotBase diff --git a/omagent-core/src/omagent_core/core/tool_system/manager.py b/omagent-core/src/omagent_core/tool_system/manager.py similarity index 98% rename from omagent-core/src/omagent_core/core/tool_system/manager.py rename to omagent-core/src/omagent_core/tool_system/manager.py index 47560b0..8e3b842 100644 --- a/omagent-core/src/omagent_core/core/tool_system/manager.py +++ b/omagent-core/src/omagent_core/tool_system/manager.py @@ -5,11 +5,11 @@ import yaml from pydantic import Field, field_validator -from ...handlers.log_handler.logger import logging -from ...schemas.dev import Message -from ...utils.registry import registry -from ..llm.base import BaseLLM, BaseLLMBackend -from ..prompt.prompt import PromptTemplate +from ..utils.logger import logging +from ..models.llms.schemas import Message +from ..utils.registry import registry +from ..models.llms.base import BaseLLM, BaseLLMBackend +from ..models.llms.prompt.prompt import PromptTemplate from .base import BaseTool CURRENT_PATH = Path(__file__).parents[0] diff --git a/omagent-core/src/omagent_core/core/tool_system/sys_prompt.prompt b/omagent-core/src/omagent_core/tool_system/sys_prompt.prompt similarity index 100% rename from omagent-core/src/omagent_core/core/tool_system/sys_prompt.prompt rename to omagent-core/src/omagent_core/tool_system/sys_prompt.prompt diff --git a/omagent-core/src/omagent_core/core/node/misc/__init__.py b/omagent-core/src/omagent_core/tool_system/tools/__init__.py similarity index 100% rename from omagent-core/src/omagent_core/core/node/misc/__init__.py rename to omagent-core/src/omagent_core/tool_system/tools/__init__.py diff --git a/omagent-core/src/omagent_core/core/tool_system/tools/calculator.py b/omagent-core/src/omagent_core/tool_system/tools/calculator/calculator.py similarity index 97% rename from omagent-core/src/omagent_core/core/tool_system/tools/calculator.py rename to omagent-core/src/omagent_core/tool_system/tools/calculator/calculator.py index 756ce59..0911bc0 100644 --- a/omagent-core/src/omagent_core/core/tool_system/tools/calculator.py +++ b/omagent-core/src/omagent_core/tool_system/tools/calculator/calculator.py @@ -2,7 +2,7 @@ import subprocess from ....utils.registry import registry -from ..base import ArgSchema, BaseTool +from ...base import ArgSchema, BaseTool ARGSCHEMA = { "code": { diff --git a/omagent-core/src/omagent_core/core/tool_system/tools/code_interpreter.py b/omagent-core/src/omagent_core/tool_system/tools/code_interpreter/code_interpreter.py similarity index 98% rename from omagent-core/src/omagent_core/core/tool_system/tools/code_interpreter.py rename to omagent-core/src/omagent_core/tool_system/tools/code_interpreter/code_interpreter.py index d0a0e79..d12e4b5 100644 --- a/omagent-core/src/omagent_core/core/tool_system/tools/code_interpreter.py +++ b/omagent-core/src/omagent_core/tool_system/tools/code_interpreter/code_interpreter.py @@ -3,7 +3,7 @@ import subprocess from ....utils.registry import registry -from ..base import ArgSchema, BaseTool +from ...base import ArgSchema, BaseTool ARGSCHEMA = { "code": {"type": "string", "description": "Code block to be executed"}, diff --git a/engine/tools/face_rec.py b/omagent-core/src/omagent_core/tool_system/tools/face_rec/face_rec.py similarity index 95% rename from engine/tools/face_rec.py rename to omagent-core/src/omagent_core/tool_system/tools/face_rec/face_rec.py index 6145e03..2ab7d9a 100755 --- a/engine/tools/face_rec.py +++ b/omagent-core/src/omagent_core/tool_system/tools/face_rec/face_rec.py @@ -5,9 +5,9 @@ import cv2 import face_recognition import numpy as np -from omagent_core.core.tool_system.base import ArgSchema, BaseModelTool -from omagent_core.schemas.dev import Target -from omagent_core.utils.registry import registry +from ...base import ArgSchema, BaseModelTool +from ....models.od.schemas import Target +from ....utils.registry import registry from PIL import Image from pydantic import model_validator diff --git a/omagent-core/src/omagent_core/core/tool_system/tools/file_read.py b/omagent-core/src/omagent_core/tool_system/tools/file/file_read.py similarity index 91% rename from omagent-core/src/omagent_core/core/tool_system/tools/file_read.py rename to omagent-core/src/omagent_core/tool_system/tools/file/file_read.py index a7d0958..7ccdeba 100644 --- a/omagent-core/src/omagent_core/core/tool_system/tools/file_read.py +++ b/omagent-core/src/omagent_core/tool_system/tools/file/file_read.py @@ -1,6 +1,6 @@ import os -from omagent_core.core.tool_system.base import ArgSchema, BaseTool +from ...base import ArgSchema, BaseTool from ....utils.registry import registry diff --git a/omagent-core/src/omagent_core/core/tool_system/tools/file_write.py b/omagent-core/src/omagent_core/tool_system/tools/file/file_write.py similarity index 92% rename from omagent-core/src/omagent_core/core/tool_system/tools/file_write.py rename to omagent-core/src/omagent_core/tool_system/tools/file/file_write.py index 0766989..a970a56 100644 --- a/omagent-core/src/omagent_core/core/tool_system/tools/file_write.py +++ b/omagent-core/src/omagent_core/tool_system/tools/file/file_write.py @@ -1,4 +1,4 @@ -from omagent_core.core.tool_system.base import ArgSchema, BaseTool +from ...base import ArgSchema, BaseTool from ....utils.registry import registry diff --git a/engine/tools/ovd_tool.py b/omagent-core/src/omagent_core/tool_system/tools/ovd/ovd_tool.py similarity index 95% rename from engine/tools/ovd_tool.py rename to omagent-core/src/omagent_core/tool_system/tools/ovd/ovd_tool.py index a917fd5..6b59df8 100755 --- a/engine/tools/ovd_tool.py +++ b/omagent-core/src/omagent_core/tool_system/tools/ovd/ovd_tool.py @@ -2,10 +2,10 @@ from typing import List import requests -from omagent_core.core.tool_system.base import ArgSchema, BaseModelTool -from omagent_core.schemas.dev import Target -from omagent_core.utils.general import encode_image -from omagent_core.utils.registry import registry +from ...base import ArgSchema, BaseModelTool +from ....models.od.schemas import Target +from ....utils.general import encode_image +from ....utils.registry import registry from PIL import Image from scenedetect import FrameTimecode diff --git a/omagent-core/src/omagent_core/core/tool_system/tools/shell.py b/omagent-core/src/omagent_core/tool_system/tools/shell/shell.py similarity index 93% rename from omagent-core/src/omagent_core/core/tool_system/tools/shell.py rename to omagent-core/src/omagent_core/tool_system/tools/shell/shell.py index a015bb9..2a21411 100644 --- a/omagent-core/src/omagent_core/core/tool_system/tools/shell.py +++ b/omagent-core/src/omagent_core/tool_system/tools/shell/shell.py @@ -1,6 +1,6 @@ import subprocess -from omagent_core.core.tool_system.base import ArgSchema, BaseTool +from ...base import ArgSchema, BaseTool from ....utils.registry import registry diff --git a/omagent-core/src/omagent_core/core/tool_system/tools/utils.py b/omagent-core/src/omagent_core/tool_system/tools/utils.py similarity index 100% rename from omagent-core/src/omagent_core/core/tool_system/tools/utils.py rename to omagent-core/src/omagent_core/tool_system/tools/utils.py diff --git a/engine/tools/rewinder.py b/omagent-core/src/omagent_core/tool_system/tools/video_rewinder/rewinder.py similarity index 91% rename from engine/tools/rewinder.py rename to omagent-core/src/omagent_core/tool_system/tools/video_rewinder/rewinder.py index 2ab238e..54a16f2 100755 --- a/engine/tools/rewinder.py +++ b/omagent-core/src/omagent_core/tool_system/tools/video_rewinder/rewinder.py @@ -3,15 +3,15 @@ from pathlib import Path from typing import List -from omagent_core.core.llm.base import BaseLLMBackend -from omagent_core.core.prompt.prompt import PromptTemplate -from omagent_core.core.tool_system.base import ArgSchema, BaseTool -from omagent_core.handlers.log_handler.logger import logging -from omagent_core.utils.registry import registry +from ....models.llms.base import BaseLLMBackend +from ....models.llms.prompt import PromptTemplate +from ...base import ArgSchema, BaseTool +from ....utils.logger import logging +from ....utils.registry import registry from pydantic import Field from scenedetect import FrameTimecode -from ..video_process import VideoScenes +from ....handlers.video_scenes import VideoScenes CURRENT_PATH = Path(__file__).parents[0] diff --git a/engine/tools/rewinder_sys_prompt.prompt b/omagent-core/src/omagent_core/tool_system/tools/video_rewinder/rewinder_sys_prompt.prompt similarity index 100% rename from engine/tools/rewinder_sys_prompt.prompt rename to omagent-core/src/omagent_core/tool_system/tools/video_rewinder/rewinder_sys_prompt.prompt diff --git a/engine/tools/rewinder_user_prompt.prompt b/omagent-core/src/omagent_core/tool_system/tools/video_rewinder/rewinder_user_prompt.prompt similarity index 100% rename from engine/tools/rewinder_user_prompt.prompt rename to omagent-core/src/omagent_core/tool_system/tools/video_rewinder/rewinder_user_prompt.prompt diff --git a/omagent-core/src/omagent_core/core/tool_system/tools/search.py b/omagent-core/src/omagent_core/tool_system/tools/web_search/search.py similarity index 98% rename from omagent-core/src/omagent_core/core/tool_system/tools/search.py rename to omagent-core/src/omagent_core/tool_system/tools/web_search/search.py index 660dab6..9e20edf 100644 --- a/omagent-core/src/omagent_core/core/tool_system/tools/search.py +++ b/omagent-core/src/omagent_core/tool_system/tools/web_search/search.py @@ -7,11 +7,11 @@ from duckduckgo_search import DDGS from pydantic import Field, field_validator -from ....handlers.log_handler.logger import logging +from ....utils.logger import logging from ....utils.registry import registry -from ...llm.base import BaseLLMBackend -from ...prompt.prompt import PromptTemplate -from ..base import ArgSchema, BaseTool +from ....models.llms.base import BaseLLMBackend +from ....models.llms.prompt import PromptTemplate +from ...base import ArgSchema, BaseTool CURRENT_PATH = Path(__file__).parents[0] diff --git a/omagent-core/src/omagent_core/core/tool_system/tools/search_sys_prompt.prompt b/omagent-core/src/omagent_core/tool_system/tools/web_search/search_sys_prompt.prompt similarity index 100% rename from omagent-core/src/omagent_core/core/tool_system/tools/search_sys_prompt.prompt rename to omagent-core/src/omagent_core/tool_system/tools/web_search/search_sys_prompt.prompt diff --git a/omagent-core/src/omagent_core/core/tool_system/tools/search_user_prompt.prompt b/omagent-core/src/omagent_core/tool_system/tools/web_search/search_user_prompt.prompt similarity index 100% rename from omagent-core/src/omagent_core/core/tool_system/tools/search_user_prompt.prompt rename to omagent-core/src/omagent_core/tool_system/tools/web_search/search_user_prompt.prompt diff --git a/omagent-core/src/omagent_core/core/tool_system/tools/text2image_search.py b/omagent-core/src/omagent_core/tool_system/tools/web_search/text2image_search.py similarity index 99% rename from omagent-core/src/omagent_core/core/tool_system/tools/text2image_search.py rename to omagent-core/src/omagent_core/tool_system/tools/web_search/text2image_search.py index 22e1653..a7173f1 100644 --- a/omagent-core/src/omagent_core/core/tool_system/tools/text2image_search.py +++ b/omagent-core/src/omagent_core/tool_system/tools/web_search/text2image_search.py @@ -8,7 +8,7 @@ from pydantic import field_validator from ....utils.registry import registry -from ..base import ArgSchema, BaseTool +from ...base import ArgSchema, BaseTool CURRENT_PATH = Path(__file__).parents[0] diff --git a/omagent-core/src/omagent_core/core/tool_system/user_prompt.prompt b/omagent-core/src/omagent_core/tool_system/user_prompt.prompt similarity index 100% rename from omagent-core/src/omagent_core/core/tool_system/user_prompt.prompt rename to omagent-core/src/omagent_core/tool_system/user_prompt.prompt diff --git a/omagent-core/src/omagent_core/utils/build.py b/omagent-core/src/omagent_core/utils/build.py index a5c1101..4651ed7 100644 --- a/omagent-core/src/omagent_core/utils/build.py +++ b/omagent-core/src/omagent_core/utils/build.py @@ -8,10 +8,9 @@ import yaml -from ..core.node.base import BaseDecider, BaseLoop, BaseProcessor -from ..core.node.base.base import Node -from ..handlers.data_handler.ltm import LTM -from ..schemas import BaseInterface +from ..engine.node import Node, BaseDecider, BaseLoop, BaseProcessor +from ..memories.ltms.ltm import LTM +from ..engine.workflow.context import BaseWorkflowContext from .env import EnvVar from .registry import registry @@ -25,7 +24,7 @@ def __init__(self, main_conf: dict, ltm_config: list) -> None: config["name"], registry.get_handler(config["name"])(**config) ) - def run_bot(self, input: BaseInterface): + def run_bot(self, input: BaseWorkflowContext): self.bot.set_request_id(str(uuid4())) self.bot.run(input, self.ltm) diff --git a/omagent-core/src/omagent_core/utils/error.py b/omagent-core/src/omagent_core/utils/error.py new file mode 100644 index 0000000..1391f8c --- /dev/null +++ b/omagent-core/src/omagent_core/utils/error.py @@ -0,0 +1,39 @@ +class VQLError(Exception): + def __init__(self, code, msg=None, detail=""): + """ + :param code: Error code + :param msg: Error message, for system display. + :param detail: Error detail, for debugging. + """ + + code2msg = { + 500: "Internal Error", + 501: "Image Error: Unable to Read", # Unable to read image file + 502: "Image Error: Corrupted Image", # Image file is corrupted + 503: "Image Error: Unable to Retrieve", # Failed to retrieve image + 504: "Image Error: Unrecognized Format", # Unsupported image file format + 505: "Image Error: Key Not Found", # Key does not exist when retrieving data in Redis mode + 506: "Image Error: Unable to Connect to Database", # Unable to connect to Redis when retrieving data in Redis mode + 511: "Request Error: Service Processing Failed", # Atom error for unknown reasons + 515: "Request Error: Max Retries Exceeded, Unable to Access Address", # API URL or port error, unable to access + 516: "Request Error: Invalid Address", # Incorrect API route address + 517: "Request Error: Invalid Request Format", # Input parameter format error + 518: "Request Error: Illegal Request Address", # Incorrect format of atom API address + 550: "Vector Database Error", + 570: "Callback Error: Failed to Process Result Callback", # Error occurred during algorithm result callback + 800: "LLM Error: Unexpected Return Result", # LLM return result does not meet expectations + } + + self.code = code + self.detail = detail + if msg: + self.msg = msg + else: + self.msg = code2msg[code] + + def __str__(self): + return repr( + "Code: {} | message: {} | detail:{}".format( + self.code, self.msg, self.detail + ) + ) diff --git a/omagent-core/src/omagent_core/utils/general.py b/omagent-core/src/omagent_core/utils/general.py index af93f73..17cd795 100644 --- a/omagent-core/src/omagent_core/utils/general.py +++ b/omagent-core/src/omagent_core/utils/general.py @@ -2,16 +2,11 @@ from collections import OrderedDict from io import BytesIO from typing import Sequence - -import httpx -import requests - -from ..handlers.error_handler.error import VQLError -from ..handlers.log_handler.logger import logging +import platform class LRUCache: - # initialising capacity + # initializing capacity def __init__(self, capacity: int): self.cache = OrderedDict() self.capacity = capacity @@ -46,68 +41,6 @@ def pop(self, key, value): self.cache.pop(key, None) -def request( - json: dict, - url: str, - headers: dict | None = None, -) -> dict: - try: - res = requests.post(url=url, json=json, headers=headers) - except Exception as error: - logging.error( - "Request URL: {} | Request body: {} | Error: {}".format(url, json, error) - ) - raise VQLError(511, detail=str(error)) - if res.status_code < 299: - return res.json() - elif res.status_code == 404: - logging.error("Request URL: {} | Error[404]: 请求错误: 错误的地址".format(url)) - raise VQLError(516) - elif res.status_code == 422: - logging.error( - "Request URL: {} | Request body: {} | Error[422]: 请求错误: 错误的请求格式".format( - url, json - ) - ) - raise VQLError(517) - else: - info = res.json() - logging.error( - "Request URL: {} | Request body: {} | Error: {}".format(url, json, info) - ) - raise VQLError(511, detail=info) - - -async def arequest(url: str, json: dict, headers: dict | None = None) -> dict: - try: - async with httpx.AsyncClient() as client: - res = await client.post(url=url, json=json, headers=headers, timeout=30) - except Exception as error: - logging.error( - "Request URL: {} | Request body: {} | Error: {}".format(url, json, error) - ) - raise VQLError(511, detail=str(error)) - - if res.status_code < 299: - return res.json() - elif res.status_code == 404: - logging.error("Request URL: {} | Error[404]: 请求错误: 错误的地址".format(url)) - raise VQLError(516) - elif res.status_code == 422: - logging.error( - "Request URL: {} | Request body: {} | Error[422]: 请求错误: 错误的请求格式".format( - url, json - ) - ) - raise VQLError(517) - else: - info = res.json() - logging.error( - "Request URL: {} | Request body: {} | Error: {}".format(url, json, info) - ) - raise VQLError(511, detail=info) - - def chunks(l: Sequence, win_len: int, stride_len: int): s_id = 0 e_id = min(len(l), win_len) @@ -139,3 +72,11 @@ def _encode(img): return res else: return _encode(input) + + +def get_platform() -> str: + """Get platform.""" + system = platform.system() + if system == "Darwin": + return "MacOS" + return system diff --git a/omagent-core/src/omagent_core/handlers/log_handler/logger.py b/omagent-core/src/omagent_core/utils/logger.py similarity index 100% rename from omagent-core/src/omagent_core/handlers/log_handler/logger.py rename to omagent-core/src/omagent_core/utils/logger.py diff --git a/omagent-core/src/omagent_core/utils/registry.py b/omagent-core/src/omagent_core/utils/registry.py index ebb182c..c5aea4e 100644 --- a/omagent-core/src/omagent_core/utils/registry.py +++ b/omagent-core/src/omagent_core/utils/registry.py @@ -71,12 +71,11 @@ def get_encoder(self, name): def import_module(self, project_root: str = None, custom: List[str] = []): root_path = Path(__file__).parents[1] default_path = [ - root_path.joinpath("core/prompt"), - root_path.joinpath("core/llm"), - root_path.joinpath("core/node"), - root_path.joinpath("core/encoder"), - root_path.joinpath("core/tool_system/tools"), + root_path.joinpath("models"), + root_path.joinpath("engine/node"), + root_path.joinpath("tool_system/tools"), root_path.joinpath("handlers"), + root_path.joinpath("advanced_components"), ] for path in default_path: for module in path.rglob("*.[ps][yo]"): diff --git a/omagent-core/src/omagent_core/utils/request.py b/omagent-core/src/omagent_core/utils/request.py new file mode 100644 index 0000000..e1bbaf7 --- /dev/null +++ b/omagent-core/src/omagent_core/utils/request.py @@ -0,0 +1,66 @@ +import httpx +import requests + +from .error import VQLError +from .logger import logging + +def request( + json: dict, + url: str, + headers: dict | None = None, +) -> dict: + try: + res = requests.post(url=url, json=json, headers=headers) + except Exception as error: + logging.error( + "Request URL: {} | Request body: {} | Error: {}".format(url, json, error) + ) + raise VQLError(511, detail=str(error)) + if res.status_code < 299: + return res.json() + elif res.status_code == 404: + logging.error("Request URL: {} | Error[404]: 请求错误: 错误的地址".format(url)) + raise VQLError(516) + elif res.status_code == 422: + logging.error( + "Request URL: {} | Request body: {} | Error[422]: 请求错误: 错误的请求格式".format( + url, json + ) + ) + raise VQLError(517) + else: + info = res.json() + logging.error( + "Request URL: {} | Request body: {} | Error: {}".format(url, json, info) + ) + raise VQLError(511, detail=info) + + +async def arequest(url: str, json: dict, headers: dict | None = None) -> dict: + try: + async with httpx.AsyncClient() as client: + res = await client.post(url=url, json=json, headers=headers, timeout=30) + except Exception as error: + logging.error( + "Request URL: {} | Request body: {} | Error: {}".format(url, json, error) + ) + raise VQLError(511, detail=str(error)) + + if res.status_code < 299: + return res.json() + elif res.status_code == 404: + logging.error("Request URL: {} | Error[404]: 请求错误: 错误的地址".format(url)) + raise VQLError(516) + elif res.status_code == 422: + logging.error( + "Request URL: {} | Request body: {} | Error[422]: 请求错误: 错误的请求格式".format( + url, json + ) + ) + raise VQLError(517) + else: + info = res.json() + logging.error( + "Request URL: {} | Request body: {} | Error: {}".format(url, json, info) + ) + raise VQLError(511, detail=info) \ No newline at end of file diff --git a/run.py b/run.py index 3a7bbe2..65b288e 100755 --- a/run.py +++ b/run.py @@ -1,17 +1,17 @@ from pathlib import Path -from omagent_core.core.node.dnc.interface import DnCInterface -from omagent_core.core.node.dnc.schemas import AgentTask -from omagent_core.handlers.log_handler.logger import logging +from omagent_core.engine.workflow.context import BaseWorkflowContext +from omagent_core.engine.task.agent_task import AgentTask +from omagent_core.utils.logger import logging from omagent_core.utils.build import Builder from omagent_core.utils.registry import registry def run_agent(task): logging.init_logger("omagent", "omagent", level="INFO") - registry.import_module(project_root=Path(__file__).parent, custom=["./engine"]) - bot_builder = Builder.from_file("workflows/video_understanding") - input = DnCInterface(bot_id="1", task=AgentTask(id=0, task=task)) + registry.import_module(project_root=Path(__file__).parent, custom=["./examples"]) + bot_builder = Builder.from_file("examples/video_understanding") + input = BaseWorkflowContext(bot_id="1", task=AgentTask(id=0, task=task)) bot_builder.run_bot(input) return input.last_output