Skip to content

Commit fba3a7e

Browse files
committed
sage-app installation fix
1 parent 97e3fb1 commit fba3a7e

5 files changed

Lines changed: 65 additions & 11 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import time
2+
from sage.core.api.service.base_service import BaseService
3+
from sage.core.api.local_environment import LocalEnvironment
4+
from sage.core.api.function.sink_function import SinkFunction
5+
from sage.core.api.function.batch_function import BatchFunction
6+
from sage.common.utils.logging.custom_logger import CustomLogger
7+
8+
# 批处理数据源:生成10条 Hello, World! 数据
9+
class HelloBatch(BatchFunction):
10+
def __init__(self, **kwargs):
11+
super().__init__(**kwargs)
12+
self.counter = 0
13+
self.max_count = 10 # 生成10个数据包后返回None
14+
15+
def execute(self):
16+
if self.counter >= self.max_count:
17+
return None # 返回None表示批处理完成
18+
self.counter += 1
19+
return f"Hello, World! #{self.counter}"
20+
21+
22+
# 简单 SinkFunction,调用hello服务并打印结果
23+
class PrintSink(SinkFunction):
24+
def execute(self, data):
25+
self.call_service["hello_service"].hello()
26+
print(data)
27+
28+
29+
class HelloService(BaseService):
30+
def __init__(self):
31+
self.message = "hello service!!!"
32+
33+
def hello(self):
34+
print(self.message)
35+
36+
37+
def main():
38+
env = LocalEnvironment("hello_service")
39+
env.register_service("hello_service", HelloService)
40+
41+
env.from_batch(HelloBatch).sink(PrintSink)
42+
43+
try:
44+
print("Waiting for batch processing to complete...")
45+
env.submit()
46+
47+
time.sleep(1)
48+
except KeyboardInterrupt:
49+
print("停止运行")
50+
finally:
51+
print("Hello Service 批处理示例结束")
52+
53+
if __name__ == "__main__":
54+
CustomLogger.disable_global_console_debug()
55+
main()

packages/sage-apps/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ SAGE Applications 是基于 SAGE Framework 构建的应用示例和模板集合
3939
## 🚀 快速开始
4040

4141
```python
42-
from sage.apps.examples.rag import simple_rag
43-
from sage.apps.examples.tutorials import hello_world
42+
from sage.libs.examples.rag import simple_rag
43+
from sage.libs.examples.tutorials import hello_world
4444

4545
# 运行 Hello World 示例
4646
hello_world.run()

packages/sage-apps/pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Repository = "https://github.com/intellistream/SAGE.git"
9999
"Bug Tracker" = "https://github.com/intellistream/SAGE/issues"
100100

101101
# [project.scripts]
102-
# sage-examples = "sage.apps.cli:main"
102+
# sage-examples = "sage.libs.cli:main"
103103
# Note: sage-examples CLI is not yet implemented
104104
# This command entry point is commented out to avoid import errors
105105

@@ -110,8 +110,7 @@ where = ["src"]
110110
"" = "src"
111111

112112
[tool.setuptools.package-data]
113-
"sage.apps.examples.resources" = ["**/*"]
114-
"sage.libs" = ["py.typed"]
113+
"sage.libs" = ["py.typed", "**/*"]
115114

116115
# Development tools configuration
117116
[tool.black]

packages/sage-apps/tests/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ tests/
1414
├── run_tests.py # 测试运行脚本
1515
├── generate_reports.py # 测试报告生成器
1616
├── README.md # 本文档
17-
├── lib/ # sage.apps.lib 模块測试
17+
├── lib/ # sage.libs 模块測试
1818
│ ├── agents/
1919
│ │ ├── test_agent.py # Agent基础类测试
2020
│ │ └── test_bots.py # 各种Bot组件测试
@@ -147,7 +147,7 @@ python -m pytest tests/lib/agents/test_agent.py::TestTool::test_tool_initializat
147147
python -m pytest -m "unit and not slow" -v
148148

149149
# 生成覆盖率报告
150-
python -m pytest --cov=sage.apps.lib --cov=sage.plugins --cov=sage.userspace --cov-report=html
150+
python -m pytest --cov=sage.libs --cov=sage.plugins --cov=sage.userspace --cov-report=html
151151
```
152152

153153
## 生成测试报告
@@ -197,7 +197,7 @@ testpaths = ["tests", "src"]
197197
python_files = ["test_*.py", "*_test.py"]
198198
addopts = [
199199
# 覆盖率选项已注释,按需启用
200-
# "--cov=sage.apps.lib",
200+
# "--cov=sage.libs",
201201
# "--cov=sage.plugins",
202202
# "--cov=sage.userspace",
203203
]
@@ -312,15 +312,15 @@ mypy src/
312312
```python
313313
# 测试文件模板
314314
"""
315-
测试 sage.apps.lib.module_name 模块
315+
测试 sage.libs.module_name 模块
316316
"""
317317
318318
import pytest
319319
from unittest.mock import Mock, patch
320320
321321
# 尝试导入,处理依赖不可用的情况
322322
try:
323-
from sage.apps.lib.module_name import TargetClass
323+
from sage.libs.module_name import TargetClass
324324
MODULE_AVAILABLE = True
325325
except ImportError as e:
326326
MODULE_AVAILABLE = False

packages/sage-apps/tests/run_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def main():
112112
# 添加覆盖率选项
113113
if args.coverage or args.html_coverage:
114114
cmd.extend([
115-
"--cov=sage.apps.lib",
115+
"--cov=sage.libs",
116116
"--cov=sage.plugins",
117117
"--cov=sage.userspace",
118118
"--cov-report=term-missing"

0 commit comments

Comments
 (0)