cota 1.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. cota-1.0.1/LICENSE +21 -0
  2. cota-1.0.1/PKG-INFO +205 -0
  3. cota-1.0.1/README.md +158 -0
  4. cota-1.0.1/cota/__init__.py +1 -0
  5. cota-1.0.1/cota/__main__.py +284 -0
  6. cota-1.0.1/cota/actions/__init__.py +6 -0
  7. cota-1.0.1/cota/actions/action.py +93 -0
  8. cota-1.0.1/cota/actions/bot_utter.py +118 -0
  9. cota-1.0.1/cota/actions/constant.py +0 -0
  10. cota-1.0.1/cota/actions/executors/base.py +63 -0
  11. cota-1.0.1/cota/actions/executors/http.py +44 -0
  12. cota-1.0.1/cota/actions/executors/plugin.py +109 -0
  13. cota-1.0.1/cota/actions/executors/python.py +55 -0
  14. cota-1.0.1/cota/actions/executors/script.py +62 -0
  15. cota-1.0.1/cota/actions/form.py +235 -0
  16. cota-1.0.1/cota/actions/plugins/base.py +35 -0
  17. cota-1.0.1/cota/actions/plugins/example.py +36 -0
  18. cota-1.0.1/cota/actions/rag.py +57 -0
  19. cota-1.0.1/cota/actions/selector.py +102 -0
  20. cota-1.0.1/cota/actions/user_utter.py +88 -0
  21. cota-1.0.1/cota/agent.py +401 -0
  22. cota-1.0.1/cota/channels/__init__.py +6 -0
  23. cota-1.0.1/cota/channels/channel.py +141 -0
  24. cota-1.0.1/cota/channels/cmdline.py +73 -0
  25. cota-1.0.1/cota/channels/connection.py +120 -0
  26. cota-1.0.1/cota/channels/room.py +161 -0
  27. cota-1.0.1/cota/channels/socketio.py +272 -0
  28. cota-1.0.1/cota/channels/sse.py +316 -0
  29. cota-1.0.1/cota/channels/utils.py +48 -0
  30. cota-1.0.1/cota/channels/websocket.py +277 -0
  31. cota-1.0.1/cota/constant.py +174 -0
  32. cota-1.0.1/cota/dpl/__init__.py +0 -0
  33. cota-1.0.1/cota/dpl/dpl.py +137 -0
  34. cota-1.0.1/cota/dpl/llm.py +307 -0
  35. cota-1.0.1/cota/dpl/match.py +132 -0
  36. cota-1.0.1/cota/dpl/trigger.py +175 -0
  37. cota-1.0.1/cota/dst.py +464 -0
  38. cota-1.0.1/cota/http_client.py +48 -0
  39. cota-1.0.1/cota/knowledge/__init__.py +5 -0
  40. cota-1.0.1/cota/knowledge/knowledge.py +131 -0
  41. cota-1.0.1/cota/knowledge/llm_knowledge.py +127 -0
  42. cota-1.0.1/cota/llm/__init__.py +20 -0
  43. cota-1.0.1/cota/llm/base.py +36 -0
  44. cota-1.0.1/cota/llm/custom.py +88 -0
  45. cota-1.0.1/cota/llm/factory.py +61 -0
  46. cota-1.0.1/cota/llm/llm.py +51 -0
  47. cota-1.0.1/cota/llm/openai.py +139 -0
  48. cota-1.0.1/cota/message/message.py +53 -0
  49. cota-1.0.1/cota/processor.py +155 -0
  50. cota-1.0.1/cota/server.py +99 -0
  51. cota-1.0.1/cota/store.py +277 -0
  52. cota-1.0.1/cota/task.py +216 -0
  53. cota-1.0.1/cota/utils/__init__.py +0 -0
  54. cota-1.0.1/cota/utils/common.py +115 -0
  55. cota-1.0.1/cota/utils/http/__init__.py +4 -0
  56. cota-1.0.1/cota/utils/http/client.py +153 -0
  57. cota-1.0.1/cota/utils/http/manager.py +54 -0
  58. cota-1.0.1/cota/utils/io.py +14 -0
  59. cota-1.0.1/cota/utils/parser.py +67 -0
  60. cota-1.0.1/pyproject.toml +58 -0
cota-1.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 MingGuangShao
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
cota-1.0.1/PKG-INFO ADDED
@@ -0,0 +1,205 @@
1
+ Metadata-Version: 2.4
2
+ Name: cota
3
+ Version: 1.0.1
4
+ Summary: Chain of Thought Agent Platform for Industrial-Grade Dialogue Systems
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Keywords: chatbot,dialogue,agent,llm,chain-of-thought
8
+ Author: MingGuangShao
9
+ Author-email: 690714362@qq.com
10
+ Requires-Python: >=3.12
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Dist: aiohttp (>=3.9,<4.0)
21
+ Requires-Dist: asyncio (>=3.4.3,<4.0.0)
22
+ Requires-Dist: cpm-kernels (>=1.0.11,<2.0.0)
23
+ Requires-Dist: dashscope (>=1.20.0)
24
+ Requires-Dist: faiss-cpu (>=1.8.0.post1,<2.0.0)
25
+ Requires-Dist: gunicorn (>=21.2.0,<22.0.0)
26
+ Requires-Dist: numpy (>=1.21.4,<2.0.0)
27
+ Requires-Dist: openai (>=1.31.1)
28
+ Requires-Dist: protobuf (>=4.22.1,<5.0.0)
29
+ Requires-Dist: psycopg2-binary (>=2.9.9,<3.0.0)
30
+ Requires-Dist: pymysql (>=1.1.1,<2.0.0)
31
+ Requires-Dist: pytest (>=7.3.1,<8.0.0)
32
+ Requires-Dist: python-socketio (>=4.4,<6)
33
+ Requires-Dist: pyyaml (>=6.0.1,<7.0.0)
34
+ Requires-Dist: questionary (>=1.5.1,<1.11.0)
35
+ Requires-Dist: sanic (>=23.12,<23.13)
36
+ Requires-Dist: sanic-cors (>=2.0.0,<2.1.0)
37
+ Requires-Dist: sanic-jwt (>=1.6.0,<2.0.0)
38
+ Requires-Dist: sanic-routing (>=23.12.0)
39
+ Requires-Dist: setuptools (>=70.1.1,<71.0.0)
40
+ Requires-Dist: sqlalchemy (>=2.0.22,<3.0.0)
41
+ Requires-Dist: websockets (>=10.0,<11.0)
42
+ Project-URL: Documentation, https://cotaai.github.io/cota/
43
+ Project-URL: Homepage, https://github.com/CotaAI/cota
44
+ Project-URL: Repository, https://github.com/CotaAI/cota
45
+ Description-Content-Type: text/markdown
46
+
47
+ <div align="center">
48
+
49
+ # COTA
50
+ **Chain of Thought Agent Platform for Industrial-Grade Dialogue Systems**
51
+
52
+ *Simple configuration, reliable performance, powered by annotated policy learning*
53
+
54
+ [![License](https://img.shields.io/github/license/CotaAI/cota?style=for-the-badge)](https://github.com/CotaAI/cota/blob/main/LICENSE)
55
+ [![Python](https://img.shields.io/badge/Python-3.12+-blue?style=for-the-badge&logo=python&logoColor=white)](https://www.python.org/)
56
+ [![Documentation](https://img.shields.io/badge/Documentation-Available-green?style=for-the-badge)](https://cotaai.github.io/cota/)
57
+
58
+ [![GitHub Stars](https://img.shields.io/github/stars/CotaAI/cota?style=for-the-badge&logo=github)](https://github.com/CotaAI/cota/stargazers)
59
+ [![GitHub Issues](https://img.shields.io/github/issues/CotaAI/cota?style=for-the-badge)](https://github.com/CotaAI/cota/issues)
60
+
61
+
62
+ **[简体中文](#简体中文)** | **[Documentation](https://cotaai.github.io/cota/)**
63
+
64
+ </div>
65
+
66
+ ## 简体中文
67
+
68
+ > [!Note]
69
+ > 完整的用户文档请访问 [COTA Documentation](https://cotaai.github.io/cota/)
70
+
71
+ COTA (Chain of Thought Agent) 是一个基于大语言模型的智能体平台,通过**思维链推理**和**标注式策略学习**,让开发者以简单的方式构建可靠的工业级对话系统。
72
+
73
+ ### 💡 核心特征
74
+
75
+ - **🧠 Chain of Thought 驱动**: 基于思维链推理机制,让AI具备类人的逻辑推理能力
76
+ - **📝 标注式策略学习**: 通过标注policies中的thought,训练可靠的对话策略(DPL)
77
+ - **🎯 简单易用**: 低代码配置,快速构建生产级智能体
78
+
79
+ ### 📄 许可证
80
+
81
+ #### 代码许可
82
+ 代码使用 `MIT License` 发布,允许商业使用和修改。
83
+
84
+ ---
85
+
86
+ ## 🚀 快速开始
87
+
88
+ ### 环境要求
89
+
90
+ - **Python 3.12+**
91
+ - **Poetry** (推荐) 或 pip
92
+ - **Git** 用于代码管理
93
+
94
+ ### 🔧 安装
95
+
96
+ #### 方法1: 通过Poetry安装 (推荐)
97
+
98
+ ```bash
99
+ # 1. 克隆仓库
100
+ git clone https://github.com/CotaAI/cota.git
101
+ cd cota
102
+
103
+ # 2. 安装Poetry
104
+ pip install poetry
105
+
106
+ # 3. 安装依赖
107
+ poetry install
108
+
109
+ # 4. 激活虚拟环境
110
+ poetry shell
111
+ ```
112
+
113
+ #### 方法2: 通过pip安装
114
+
115
+ ```bash
116
+ # 1. 创建虚拟环境
117
+ python3 -m venv ./venv
118
+ source ./venv/bin/activate # Linux/macOS
119
+ # 或 .\venv\Scripts\activate # Windows
120
+
121
+ # 2. 克隆仓库
122
+ git clone https://github.com/CotaAI/cota.git
123
+ cd cota
124
+
125
+ # 3. 安装依赖
126
+ pip install -r requirements.txt
127
+ pip install -e .
128
+ ```
129
+
130
+ ### ⚡ 快速体验
131
+
132
+ > 确保你在项目根目录下执行以下命令
133
+
134
+ #### 1. 初始化项目
135
+ ```bash
136
+ # 创建示例机器人配置
137
+ cota init
138
+ cd cota_projects/simplebot
139
+
140
+ # 配置API密钥
141
+ cp endpoints.yml.example endpoints.yml
142
+ # 编辑 endpoints.yml,添加你的LLM API密钥
143
+ ```
144
+
145
+ #### 2. 启动命令行对话
146
+ ```bash
147
+ # 启动交互式命令行
148
+ cota shell --config=.
149
+
150
+ # 或启动Web服务
151
+ cota run --channel=socket.io --port=5005
152
+ ```
153
+
154
+ #### 3. 启动Web界面
155
+ ```bash
156
+ # 启动WebSocket服务
157
+ cota run --channel=websocket --host=localhost --port=5005
158
+
159
+ # 访问 http://localhost:5005 开始对话
160
+ ```
161
+
162
+ ## 📚 文档和教程
163
+
164
+ - **[📖 完整文档](https://cotaai.github.io/cota/)** - 详细的使用指南和API文档
165
+ - **[🚀 快速入门](https://cotaai.github.io/cota/tutorial/quick_start.html)** - 5分钟上手指南
166
+ - **[⚙️ 配置说明](https://cotaai.github.io/cota/configuration/)** - 智能体和系统配置
167
+ - **[🏗️ 架构设计](https://cotaai.github.io/cota/architecture/)** - 深入了解系统架构
168
+ - **[🚀 部署指南](https://cotaai.github.io/cota/deployment/)** - 生产环境部署
169
+
170
+ ## 🤝 贡献指南
171
+
172
+ 我们欢迎所有形式的贡献!
173
+
174
+ 1. **Fork** 本仓库
175
+ 2. 创建你的特性分支 (`git checkout -b feature/AmazingFeature`)
176
+ 3. 提交你的更改 (`git commit -m 'Add some AmazingFeature'`)
177
+ 4. 推送到分支 (`git push origin feature/AmazingFeature`)
178
+ 5. 开启一个 **Pull Request**
179
+
180
+
181
+ ## 📞 联系我们
182
+
183
+ > GitHub Issues 和 Pull Requests 随时欢迎!
184
+
185
+ #### 正式咨询
186
+ 有关项目和商业合作的正式咨询,请联系:**690714362@qq.com**
187
+
188
+ #### 社区讨论
189
+ ##### 1. GitHub Discussions
190
+ 参与项目讨论:[GitHub Discussions](https://github.com/CotaAI/cota/discussions)
191
+
192
+ ---
193
+
194
+ <div align="center">
195
+
196
+ ---
197
+
198
+ **⭐ 如果COTA对你有帮助,请给我们一个Star!**
199
+
200
+ **⭐ If COTA helps you, please give us a Star!**
201
+
202
+ ![Visitor Count](https://komarev.com/ghpvc/?username=CotaAI&repo=cota&color=blue&style=flat-square)
203
+
204
+ </div>
205
+
cota-1.0.1/README.md ADDED
@@ -0,0 +1,158 @@
1
+ <div align="center">
2
+
3
+ # COTA
4
+ **Chain of Thought Agent Platform for Industrial-Grade Dialogue Systems**
5
+
6
+ *Simple configuration, reliable performance, powered by annotated policy learning*
7
+
8
+ [![License](https://img.shields.io/github/license/CotaAI/cota?style=for-the-badge)](https://github.com/CotaAI/cota/blob/main/LICENSE)
9
+ [![Python](https://img.shields.io/badge/Python-3.12+-blue?style=for-the-badge&logo=python&logoColor=white)](https://www.python.org/)
10
+ [![Documentation](https://img.shields.io/badge/Documentation-Available-green?style=for-the-badge)](https://cotaai.github.io/cota/)
11
+
12
+ [![GitHub Stars](https://img.shields.io/github/stars/CotaAI/cota?style=for-the-badge&logo=github)](https://github.com/CotaAI/cota/stargazers)
13
+ [![GitHub Issues](https://img.shields.io/github/issues/CotaAI/cota?style=for-the-badge)](https://github.com/CotaAI/cota/issues)
14
+
15
+
16
+ **[简体中文](#简体中文)** | **[Documentation](https://cotaai.github.io/cota/)**
17
+
18
+ </div>
19
+
20
+ ## 简体中文
21
+
22
+ > [!Note]
23
+ > 完整的用户文档请访问 [COTA Documentation](https://cotaai.github.io/cota/)
24
+
25
+ COTA (Chain of Thought Agent) 是一个基于大语言模型的智能体平台,通过**思维链推理**和**标注式策略学习**,让开发者以简单的方式构建可靠的工业级对话系统。
26
+
27
+ ### 💡 核心特征
28
+
29
+ - **🧠 Chain of Thought 驱动**: 基于思维链推理机制,让AI具备类人的逻辑推理能力
30
+ - **📝 标注式策略学习**: 通过标注policies中的thought,训练可靠的对话策略(DPL)
31
+ - **🎯 简单易用**: 低代码配置,快速构建生产级智能体
32
+
33
+ ### 📄 许可证
34
+
35
+ #### 代码许可
36
+ 代码使用 `MIT License` 发布,允许商业使用和修改。
37
+
38
+ ---
39
+
40
+ ## 🚀 快速开始
41
+
42
+ ### 环境要求
43
+
44
+ - **Python 3.12+**
45
+ - **Poetry** (推荐) 或 pip
46
+ - **Git** 用于代码管理
47
+
48
+ ### 🔧 安装
49
+
50
+ #### 方法1: 通过Poetry安装 (推荐)
51
+
52
+ ```bash
53
+ # 1. 克隆仓库
54
+ git clone https://github.com/CotaAI/cota.git
55
+ cd cota
56
+
57
+ # 2. 安装Poetry
58
+ pip install poetry
59
+
60
+ # 3. 安装依赖
61
+ poetry install
62
+
63
+ # 4. 激活虚拟环境
64
+ poetry shell
65
+ ```
66
+
67
+ #### 方法2: 通过pip安装
68
+
69
+ ```bash
70
+ # 1. 创建虚拟环境
71
+ python3 -m venv ./venv
72
+ source ./venv/bin/activate # Linux/macOS
73
+ # 或 .\venv\Scripts\activate # Windows
74
+
75
+ # 2. 克隆仓库
76
+ git clone https://github.com/CotaAI/cota.git
77
+ cd cota
78
+
79
+ # 3. 安装依赖
80
+ pip install -r requirements.txt
81
+ pip install -e .
82
+ ```
83
+
84
+ ### ⚡ 快速体验
85
+
86
+ > 确保你在项目根目录下执行以下命令
87
+
88
+ #### 1. 初始化项目
89
+ ```bash
90
+ # 创建示例机器人配置
91
+ cota init
92
+ cd cota_projects/simplebot
93
+
94
+ # 配置API密钥
95
+ cp endpoints.yml.example endpoints.yml
96
+ # 编辑 endpoints.yml,添加你的LLM API密钥
97
+ ```
98
+
99
+ #### 2. 启动命令行对话
100
+ ```bash
101
+ # 启动交互式命令行
102
+ cota shell --config=.
103
+
104
+ # 或启动Web服务
105
+ cota run --channel=socket.io --port=5005
106
+ ```
107
+
108
+ #### 3. 启动Web界面
109
+ ```bash
110
+ # 启动WebSocket服务
111
+ cota run --channel=websocket --host=localhost --port=5005
112
+
113
+ # 访问 http://localhost:5005 开始对话
114
+ ```
115
+
116
+ ## 📚 文档和教程
117
+
118
+ - **[📖 完整文档](https://cotaai.github.io/cota/)** - 详细的使用指南和API文档
119
+ - **[🚀 快速入门](https://cotaai.github.io/cota/tutorial/quick_start.html)** - 5分钟上手指南
120
+ - **[⚙️ 配置说明](https://cotaai.github.io/cota/configuration/)** - 智能体和系统配置
121
+ - **[🏗️ 架构设计](https://cotaai.github.io/cota/architecture/)** - 深入了解系统架构
122
+ - **[🚀 部署指南](https://cotaai.github.io/cota/deployment/)** - 生产环境部署
123
+
124
+ ## 🤝 贡献指南
125
+
126
+ 我们欢迎所有形式的贡献!
127
+
128
+ 1. **Fork** 本仓库
129
+ 2. 创建你的特性分支 (`git checkout -b feature/AmazingFeature`)
130
+ 3. 提交你的更改 (`git commit -m 'Add some AmazingFeature'`)
131
+ 4. 推送到分支 (`git push origin feature/AmazingFeature`)
132
+ 5. 开启一个 **Pull Request**
133
+
134
+
135
+ ## 📞 联系我们
136
+
137
+ > GitHub Issues 和 Pull Requests 随时欢迎!
138
+
139
+ #### 正式咨询
140
+ 有关项目和商业合作的正式咨询,请联系:**690714362@qq.com**
141
+
142
+ #### 社区讨论
143
+ ##### 1. GitHub Discussions
144
+ 参与项目讨论:[GitHub Discussions](https://github.com/CotaAI/cota/discussions)
145
+
146
+ ---
147
+
148
+ <div align="center">
149
+
150
+ ---
151
+
152
+ **⭐ 如果COTA对你有帮助,请给我们一个Star!**
153
+
154
+ **⭐ If COTA helps you, please give us a Star!**
155
+
156
+ ![Visitor Count](https://komarev.com/ghpvc/?username=CotaAI&repo=cota&color=blue&style=flat-square)
157
+
158
+ </div>
@@ -0,0 +1 @@
1
+ __version__ = "1.0.1" # same as pyproject.toml
@@ -0,0 +1,284 @@
1
+ # encoding:utf-8
2
+ import argparse
3
+ import os
4
+ import shutil
5
+ import sys
6
+ import logging
7
+ import ssl
8
+ from typing import Text, Optional, Dict, Any
9
+ from sanic import Sanic
10
+ import asyncio
11
+ from cota import server
12
+ from cota.task import Task
13
+ from cota.agent import Agent
14
+ from cota.channels import channel, socketio, websocket, cmdline, sse
15
+ from cota.utils.common import list_routes
16
+ from cota import __version__
17
+
18
+ logger = logging.getLogger(__name__)
19
+
20
+ def validate_ssl_files(cert_path: str, key_path: str) -> bool:
21
+ """Validate SSL certificate and key files"""
22
+ try:
23
+ if not os.path.exists(cert_path):
24
+ raise FileNotFoundError(f"SSL certificate file not found: {cert_path}")
25
+ if not os.path.exists(key_path):
26
+ raise FileNotFoundError(f"SSL key file not found: {key_path}")
27
+
28
+ context = ssl.create_default_context(purpose=ssl.Purpose.CLIENT_AUTH)
29
+ context.load_cert_chain(cert_path, keyfile=key_path)
30
+ return True
31
+ except (FileNotFoundError, ssl.SSLError) as e:
32
+ raise ValueError(f"Invalid SSL configuration: {str(e)}")
33
+
34
+ def create_server_config(args):
35
+ """Create server configuration including SSL settings"""
36
+ server_config = {
37
+ 'host': args.host,
38
+ 'port': args.port,
39
+ 'debug': args.debug
40
+ }
41
+
42
+ if args.ssl_cert and args.ssl_key:
43
+ # Validate SSL files before creating config
44
+ if validate_ssl_files(args.ssl_cert, args.ssl_key):
45
+ server_config['ssl'] = {
46
+ 'cert': args.ssl_cert,
47
+ 'key': args.ssl_key
48
+ }
49
+
50
+ return server_config
51
+
52
+ def run(args):
53
+ agent = Agent.load_from_path(path=args.config)
54
+ app = server.create_app(agent)
55
+
56
+ # Define channel configurations
57
+ channel_configs = {
58
+ 'socket.io': {
59
+ 'class': socketio.SocketIO,
60
+ 'kwargs': {},
61
+ 'register_kwargs': {'route': '/webhooks/'}
62
+ },
63
+ 'websocket': {
64
+ 'class': websocket.Websocket,
65
+ 'kwargs': {
66
+ 'connection_timeout': 1000,
67
+ 'room_timeout': 3600
68
+ },
69
+ 'register_kwargs': {}
70
+ },
71
+ 'sse': {
72
+ 'class': sse.SSE,
73
+ 'kwargs': {
74
+ 'connection_timeout': 1000,
75
+ 'room_timeout': 3600
76
+ },
77
+ 'register_kwargs': {}
78
+ }
79
+ }
80
+
81
+ # Initialize and register channel
82
+ if args.channel not in channel_configs:
83
+ raise ValueError(f"Unsupported channel: {args.channel}. "
84
+ f"Available channels: {list(channel_configs.keys())}")
85
+
86
+ config = channel_configs[args.channel]
87
+ channel_class = config['class']
88
+
89
+ try:
90
+ input_channels = channel_class(**config['kwargs'])
91
+ channel.register([input_channels], app, **config['register_kwargs'])
92
+
93
+ # Configure logging for the channel
94
+ logger = logging.getLogger(f"cota.channels.{args.channel}")
95
+ logger.info(f"Initialized {args.channel} channel")
96
+
97
+ list_routes(app)
98
+
99
+ # Run server with configuration
100
+ server_config = create_server_config(args)
101
+ app.run(**server_config)
102
+
103
+ except Exception as e:
104
+ logger.error(f"Failed to initialize {args.channel} channel: {e}")
105
+ raise
106
+
107
+
108
+ async def shell(args):
109
+ agent = Agent.load_from_path(path=args.config)
110
+ print("Agent loaded. Type a message and press enter.")
111
+
112
+ async def handler(message, channel):
113
+ await agent.processor.handle_message(message, channel)
114
+
115
+ cmdline_channel = cmdline.Cmdline(on_new_message=handler)
116
+ await cmdline_channel.on_connect()
117
+
118
+ async def task(args):
119
+ task = Task.load_from_path(path=args.config)
120
+ print("Task loaded.")
121
+ await task.run()
122
+
123
+ def init(args):
124
+ # Define the directory and files to be created
125
+ project_dir = "cota_projects"
126
+ template_dir = "bots" # Replace with the actual directory name
127
+
128
+ # Create the project directory
129
+ if not os.path.exists(project_dir):
130
+ os.makedirs(project_dir)
131
+ print(f"Created directory: {project_dir}")
132
+ else:
133
+ print(f"Directory {project_dir} already exists.")
134
+
135
+ # Copy the contents of the template directory
136
+ src_dir = os.path.join(os.path.dirname(__file__), template_dir)
137
+ if os.path.exists(src_dir):
138
+ for item in os.listdir(src_dir):
139
+ src_item = os.path.join(src_dir, item)
140
+ dst_item = os.path.join(project_dir, item)
141
+ if os.path.isdir(src_item):
142
+ shutil.copytree(src_item, dst_item)
143
+ else:
144
+ shutil.copy2(src_item, dst_item)
145
+ else:
146
+ print(f"Source directory {src_dir} does not exist.")
147
+
148
+ def configure_logging(log_level=logging.INFO):
149
+ """Configure logging with the specified level"""
150
+ # Set the root logger level
151
+ root_logger = logging.getLogger()
152
+ root_logger.setLevel(log_level)
153
+
154
+ # Configure basic logging format
155
+ formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
156
+
157
+ # Add console handler if not already present
158
+ if not root_logger.handlers:
159
+ console_handler = logging.StreamHandler()
160
+ console_handler.setFormatter(formatter)
161
+ root_logger.addHandler(console_handler)
162
+ else:
163
+ # Update existing handlers' formatters
164
+ for handler in root_logger.handlers:
165
+ handler.setFormatter(formatter)
166
+
167
+ # Set level for all handlers
168
+ for handler in root_logger.handlers:
169
+ handler.setLevel(log_level)
170
+
171
+ def create_argument_parser() -> argparse.ArgumentParser:
172
+ """ """
173
+ # create the top-level parser
174
+ parser = argparse.ArgumentParser(
175
+ prog="cota",
176
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter,
177
+ description="cota command line interface."
178
+ )
179
+
180
+ parser.add_argument(
181
+ "--version",
182
+ action="store_true",
183
+ default=argparse.SUPPRESS,
184
+ help="Print installed cota version"
185
+ )
186
+
187
+ parent_parser = argparse.ArgumentParser(add_help=False)
188
+ parent_parsers = [parent_parser]
189
+
190
+ subparsers = parser.add_subparsers(help="cota commands")
191
+
192
+ # create the parser for the "run" command
193
+ parser_run = subparsers.add_parser(
194
+ "run",
195
+ parents=parent_parsers,
196
+ conflict_handler="resolve",
197
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter,
198
+ help="Starts a cota server."
199
+ )
200
+
201
+ parser_run.add_argument('--host', default='0.0.0.0', type=str, help="Host to run the service")
202
+ parser_run.add_argument('--port', default=5005, type=int, help="Port to run the service")
203
+ parser_run.add_argument('--config', default='./', type=str, help="agent config")
204
+ parser_run.add_argument('--channel', default='socket.io', type=str, help="Message channel")
205
+ parser_run.add_argument('--debug', action='store_true', help="Enable debug mode (sets log level to DEBUG)")
206
+ parser_run.add_argument('--log', default='INFO', type=str, help="Set the logging level")
207
+ parser_run.add_argument('--ssl-cert', type=str, help="SSL certificate file path")
208
+ parser_run.add_argument('--ssl-key', type=str, help="SSL private key file path")
209
+ def run_with_debug(args):
210
+ if args.debug:
211
+ args.log = 'DEBUG'
212
+ configure_logging(getattr(logging, args.log.upper(), logging.INFO))
213
+ run(args)
214
+ parser_run.set_defaults(func=run_with_debug)
215
+
216
+ # create the parser for the "shell" command
217
+ parser_shell = subparsers.add_parser(
218
+ "shell",
219
+ parents=parent_parsers,
220
+ conflict_handler="resolve",
221
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter,
222
+ help="Interacting with cota by commandline."
223
+ )
224
+
225
+ parser_shell.add_argument('--config', default='./', type=str, help="agent config path")
226
+ parser_shell.add_argument('--log', default='INFO', type=str, help="Set the logging level")
227
+ parser_shell.add_argument('--debug', action='store_true', help="Enable debug mode (sets log level to DEBUG)")
228
+
229
+ def run_shell(args):
230
+ if args.debug:
231
+ args.log = 'DEBUG'
232
+ configure_logging(getattr(logging, args.log.upper(), logging.INFO))
233
+ return asyncio.run(shell(args))
234
+
235
+ parser_shell.set_defaults(func=run_shell)
236
+
237
+ # create the parser for the "task" command
238
+ parser_task = subparsers.add_parser(
239
+ "task",
240
+ parents=parent_parsers,
241
+ conflict_handler="resolve",
242
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter,
243
+ help="Executing cota in task mode."
244
+ )
245
+
246
+ parser_task.add_argument('--config', default='./', type=str, help="task config path")
247
+ parser_task.add_argument('--log', default='INFO', type=str, help="Set the logging level")
248
+ parser_task.add_argument('--debug', action='store_true', help="Enable debug mode (sets log level to DEBUG)")
249
+
250
+ def run_task(args):
251
+ if args.debug:
252
+ args.log = 'DEBUG'
253
+ configure_logging(getattr(logging, args.log.upper(), logging.INFO))
254
+ return asyncio.run(task(args))
255
+
256
+ parser_task.set_defaults(func=run_task)
257
+
258
+ # create the parser for the "init" command
259
+ parser_init = subparsers.add_parser(
260
+ "init",
261
+ parents=parent_parsers,
262
+ conflict_handler="resolve",
263
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter,
264
+ help="Initialize a new cota project."
265
+ )
266
+ parser_init.add_argument('--log', default='INFO', type=str, help="Set the logging level")
267
+ parser_init.set_defaults(func=init)
268
+
269
+ return parser
270
+
271
+ def main():
272
+ parser = create_argument_parser()
273
+ cmdline_arguments = parser.parse_args()
274
+
275
+ if hasattr(cmdline_arguments, "func"):
276
+ log_level = getattr(logging, cmdline_arguments.log.upper())
277
+ configure_logging(log_level)
278
+ cmdline_arguments.func(cmdline_arguments)
279
+ elif hasattr(cmdline_arguments, "version"):
280
+ print(f"Cota version: {__version__}")
281
+
282
+
283
+ if __name__ == "__main__":
284
+ main()
@@ -0,0 +1,6 @@
1
+ from cota.actions.action import Action
2
+ from cota.actions.user_utter import UserUtter
3
+ from cota.actions.bot_utter import BotUtter
4
+ from cota.actions.selector import Selector
5
+ from cota.actions.form import Form
6
+ from cota.actions.rag import RAG