sycommon-python-lib 0.1.56b8__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.
- sycommon_python_lib-0.1.56b8/PKG-INFO +135 -0
- sycommon_python_lib-0.1.56b8/README.md +107 -0
- sycommon_python_lib-0.1.56b8/pyproject.toml +39 -0
- sycommon_python_lib-0.1.56b8/setup.cfg +4 -0
- sycommon_python_lib-0.1.56b8/src/command/cli.py +167 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/__init__.py +0 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/config/Config.py +91 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/config/DatabaseConfig.py +34 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/config/EmbeddingConfig.py +15 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/config/LLMConfig.py +16 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/config/MQConfig.py +15 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/config/RerankerConfig.py +14 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/config/SentryConfig.py +13 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/config/__init__.py +0 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/database/async_base_db_service.py +36 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/database/async_database_service.py +96 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/database/base_db_service.py +30 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/database/database_service.py +84 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/health/__init__.py +0 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/health/health_check.py +17 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/health/metrics.py +13 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/health/ping.py +13 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/llm/__init__.py +0 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/llm/embedding.py +149 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/llm/get_llm.py +246 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/llm/llm_logger.py +126 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/llm/llm_tokens.py +119 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/logging/__init__.py +0 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/logging/async_sql_logger.py +65 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/logging/kafka_log.py +309 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/logging/logger_levels.py +23 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/logging/logger_wrapper.py +19 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/logging/sql_logger.py +53 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/middleware/__init__.py +0 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/middleware/context.py +5 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/middleware/cors.py +16 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/middleware/docs.py +30 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/middleware/exception.py +79 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/middleware/middleware.py +47 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/middleware/monitor_memory.py +22 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/middleware/mq.py +9 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/middleware/timeout.py +20 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/middleware/traceid.py +295 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/models/__init__.py +0 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/models/base_http.py +101 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/models/log.py +30 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/models/mqlistener_config.py +39 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/models/mqmsg_model.py +11 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/models/mqsend_config.py +8 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/models/sso_user.py +60 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/notice/__init__.py +0 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/notice/uvicorn_monitor.py +200 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/rabbitmq/rabbitmq_client.py +514 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/rabbitmq/rabbitmq_pool.py +370 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/rabbitmq/rabbitmq_service.py +59 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/rabbitmq/rabbitmq_service_client_manager.py +212 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/rabbitmq/rabbitmq_service_connection_monitor.py +73 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/rabbitmq/rabbitmq_service_consumer_manager.py +283 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/rabbitmq/rabbitmq_service_core.py +117 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/rabbitmq/rabbitmq_service_producer_manager.py +235 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/sentry/__init__.py +0 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/sentry/sy_sentry.py +34 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/services.py +275 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/sse/__init__.py +0 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/sse/event.py +97 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/sse/sse.py +278 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/synacos/__init__.py +0 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/synacos/example.py +153 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/synacos/example2.py +129 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/synacos/feign.py +190 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/synacos/feign_client.py +335 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/synacos/nacos_client_base.py +119 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/synacos/nacos_config_manager.py +106 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/synacos/nacos_heartbeat_manager.py +142 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/synacos/nacos_service.py +150 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/synacos/nacos_service_discovery.py +138 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/synacos/nacos_service_registration.py +252 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/synacos/param.py +75 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/tools/__init__.py +0 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/tools/docs.py +42 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/tools/merge_headers.py +97 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/tools/snowflake.py +300 -0
- sycommon_python_lib-0.1.56b8/src/sycommon/tools/timing.py +73 -0
- sycommon_python_lib-0.1.56b8/src/sycommon_python_lib.egg-info/PKG-INFO +135 -0
- sycommon_python_lib-0.1.56b8/src/sycommon_python_lib.egg-info/SOURCES.txt +87 -0
- sycommon_python_lib-0.1.56b8/src/sycommon_python_lib.egg-info/dependency_links.txt +1 -0
- sycommon_python_lib-0.1.56b8/src/sycommon_python_lib.egg-info/entry_points.txt +2 -0
- sycommon_python_lib-0.1.56b8/src/sycommon_python_lib.egg-info/requires.txt +21 -0
- sycommon_python_lib-0.1.56b8/src/sycommon_python_lib.egg-info/top_level.txt +2 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sycommon-python-lib
|
|
3
|
+
Version: 0.1.56b8
|
|
4
|
+
Summary: Add your description here
|
|
5
|
+
Requires-Python: >=3.11
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: aio-pika>=9.5.8
|
|
8
|
+
Requires-Dist: aiohttp>=3.13.2
|
|
9
|
+
Requires-Dist: aiomysql>=0.3.2
|
|
10
|
+
Requires-Dist: decorator>=5.2.1
|
|
11
|
+
Requires-Dist: fastapi>=0.127.0
|
|
12
|
+
Requires-Dist: kafka-python>=2.3.0
|
|
13
|
+
Requires-Dist: langchain>=1.2.0
|
|
14
|
+
Requires-Dist: langchain-core>=1.2.6
|
|
15
|
+
Requires-Dist: langchain-openai>=1.1.6
|
|
16
|
+
Requires-Dist: langgraph>=1.0.5
|
|
17
|
+
Requires-Dist: loguru>=0.7.3
|
|
18
|
+
Requires-Dist: mysql-connector-python>=9.5.0
|
|
19
|
+
Requires-Dist: nacos-sdk-python<3.0,>=2.0.9
|
|
20
|
+
Requires-Dist: psutil>=7.1.3
|
|
21
|
+
Requires-Dist: pydantic>=2.12.5
|
|
22
|
+
Requires-Dist: python-dotenv>=1.2.1
|
|
23
|
+
Requires-Dist: pyyaml>=6.0.3
|
|
24
|
+
Requires-Dist: sentry-sdk[fastapi]>=2.48.0
|
|
25
|
+
Requires-Dist: sqlalchemy[asyncio]>=2.0.45
|
|
26
|
+
Requires-Dist: starlette>=0.50.0
|
|
27
|
+
Requires-Dist: uvicorn>=0.40.0
|
|
28
|
+
|
|
29
|
+
# sycommon-python-lib
|
|
30
|
+
|
|
31
|
+
常用 python 依赖库
|
|
32
|
+
|
|
33
|
+
pip install sycommon-python-lib -i http://192.168.2.174:8081/repository/pypy-group/simple/ --trusted-host 192.168.2.174
|
|
34
|
+
|
|
35
|
+
## Getting started
|
|
36
|
+
|
|
37
|
+
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
|
38
|
+
|
|
39
|
+
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
|
40
|
+
|
|
41
|
+
## Add your files
|
|
42
|
+
|
|
43
|
+
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
|
44
|
+
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
cd existing_repo
|
|
48
|
+
git remote add origin http://git.syf.com/syai/sycommon-python-lib.git
|
|
49
|
+
git branch -M main
|
|
50
|
+
git push -uf origin main
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Integrate with your tools
|
|
54
|
+
|
|
55
|
+
- [ ] [Set up project integrations](http://git.syf.com/syai/sycommon-python-lib/-/settings/integrations)
|
|
56
|
+
|
|
57
|
+
## Collaborate with your team
|
|
58
|
+
|
|
59
|
+
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
|
60
|
+
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
|
61
|
+
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
|
62
|
+
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
|
63
|
+
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
|
|
64
|
+
|
|
65
|
+
## Test and Deploy
|
|
66
|
+
|
|
67
|
+
Use the built-in continuous integration in GitLab.
|
|
68
|
+
|
|
69
|
+
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
|
|
70
|
+
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
|
71
|
+
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
|
72
|
+
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
|
73
|
+
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
# Editing this README
|
|
78
|
+
|
|
79
|
+
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
|
80
|
+
|
|
81
|
+
## Suggestions for a good README
|
|
82
|
+
|
|
83
|
+
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
|
84
|
+
|
|
85
|
+
## Name
|
|
86
|
+
|
|
87
|
+
Choose a self-explaining name for your project.
|
|
88
|
+
|
|
89
|
+
## Description
|
|
90
|
+
|
|
91
|
+
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
|
92
|
+
|
|
93
|
+
## Badges
|
|
94
|
+
|
|
95
|
+
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
|
96
|
+
|
|
97
|
+
## Visuals
|
|
98
|
+
|
|
99
|
+
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
|
100
|
+
|
|
101
|
+
## Installation
|
|
102
|
+
|
|
103
|
+
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
|
104
|
+
|
|
105
|
+
## Usage
|
|
106
|
+
|
|
107
|
+
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
|
108
|
+
|
|
109
|
+
## Support
|
|
110
|
+
|
|
111
|
+
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
|
112
|
+
|
|
113
|
+
## Roadmap
|
|
114
|
+
|
|
115
|
+
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
|
116
|
+
|
|
117
|
+
## Contributing
|
|
118
|
+
|
|
119
|
+
State if you are open to contributions and what your requirements are for accepting them.
|
|
120
|
+
|
|
121
|
+
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
|
122
|
+
|
|
123
|
+
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
|
124
|
+
|
|
125
|
+
## Authors and acknowledgment
|
|
126
|
+
|
|
127
|
+
Show your appreciation to those who have contributed to the project.
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
For open source projects, say how it is licensed.
|
|
132
|
+
|
|
133
|
+
## Project status
|
|
134
|
+
|
|
135
|
+
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# sycommon-python-lib
|
|
2
|
+
|
|
3
|
+
常用 python 依赖库
|
|
4
|
+
|
|
5
|
+
pip install sycommon-python-lib -i http://192.168.2.174:8081/repository/pypy-group/simple/ --trusted-host 192.168.2.174
|
|
6
|
+
|
|
7
|
+
## Getting started
|
|
8
|
+
|
|
9
|
+
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
|
10
|
+
|
|
11
|
+
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
|
12
|
+
|
|
13
|
+
## Add your files
|
|
14
|
+
|
|
15
|
+
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
|
16
|
+
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
cd existing_repo
|
|
20
|
+
git remote add origin http://git.syf.com/syai/sycommon-python-lib.git
|
|
21
|
+
git branch -M main
|
|
22
|
+
git push -uf origin main
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Integrate with your tools
|
|
26
|
+
|
|
27
|
+
- [ ] [Set up project integrations](http://git.syf.com/syai/sycommon-python-lib/-/settings/integrations)
|
|
28
|
+
|
|
29
|
+
## Collaborate with your team
|
|
30
|
+
|
|
31
|
+
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
|
32
|
+
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
|
33
|
+
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
|
34
|
+
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
|
35
|
+
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
|
|
36
|
+
|
|
37
|
+
## Test and Deploy
|
|
38
|
+
|
|
39
|
+
Use the built-in continuous integration in GitLab.
|
|
40
|
+
|
|
41
|
+
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
|
|
42
|
+
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
|
43
|
+
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
|
44
|
+
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
|
45
|
+
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
# Editing this README
|
|
50
|
+
|
|
51
|
+
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
|
52
|
+
|
|
53
|
+
## Suggestions for a good README
|
|
54
|
+
|
|
55
|
+
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
|
56
|
+
|
|
57
|
+
## Name
|
|
58
|
+
|
|
59
|
+
Choose a self-explaining name for your project.
|
|
60
|
+
|
|
61
|
+
## Description
|
|
62
|
+
|
|
63
|
+
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
|
64
|
+
|
|
65
|
+
## Badges
|
|
66
|
+
|
|
67
|
+
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
|
68
|
+
|
|
69
|
+
## Visuals
|
|
70
|
+
|
|
71
|
+
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
|
72
|
+
|
|
73
|
+
## Installation
|
|
74
|
+
|
|
75
|
+
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
|
76
|
+
|
|
77
|
+
## Usage
|
|
78
|
+
|
|
79
|
+
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
|
80
|
+
|
|
81
|
+
## Support
|
|
82
|
+
|
|
83
|
+
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
|
84
|
+
|
|
85
|
+
## Roadmap
|
|
86
|
+
|
|
87
|
+
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
|
88
|
+
|
|
89
|
+
## Contributing
|
|
90
|
+
|
|
91
|
+
State if you are open to contributions and what your requirements are for accepting them.
|
|
92
|
+
|
|
93
|
+
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
|
94
|
+
|
|
95
|
+
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
|
96
|
+
|
|
97
|
+
## Authors and acknowledgment
|
|
98
|
+
|
|
99
|
+
Show your appreciation to those who have contributed to the project.
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
For open source projects, say how it is licensed.
|
|
104
|
+
|
|
105
|
+
## Project status
|
|
106
|
+
|
|
107
|
+
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "sycommon-python-lib"
|
|
3
|
+
version = "0.1.56-beta8"
|
|
4
|
+
description = "Add your description here"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.11"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"aio-pika>=9.5.8",
|
|
9
|
+
"aiohttp>=3.13.2",
|
|
10
|
+
"aiomysql>=0.3.2",
|
|
11
|
+
"decorator>=5.2.1",
|
|
12
|
+
"fastapi>=0.127.0",
|
|
13
|
+
"kafka-python>=2.3.0",
|
|
14
|
+
"langchain>=1.2.0",
|
|
15
|
+
"langchain-core>=1.2.6",
|
|
16
|
+
"langchain-openai>=1.1.6",
|
|
17
|
+
"langgraph>=1.0.5",
|
|
18
|
+
"loguru>=0.7.3",
|
|
19
|
+
"mysql-connector-python>=9.5.0",
|
|
20
|
+
"nacos-sdk-python>=2.0.9,<3.0",
|
|
21
|
+
"psutil>=7.1.3",
|
|
22
|
+
"pydantic>=2.12.5",
|
|
23
|
+
"python-dotenv>=1.2.1",
|
|
24
|
+
"pyyaml>=6.0.3",
|
|
25
|
+
"sentry-sdk[fastapi]>=2.48.0",
|
|
26
|
+
"sqlalchemy[asyncio]>=2.0.45",
|
|
27
|
+
"starlette>=0.50.0",
|
|
28
|
+
"uvicorn>=0.40.0",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[tool.setuptools]
|
|
32
|
+
packages = {find = {where = ["src"]}}
|
|
33
|
+
|
|
34
|
+
[build-system]
|
|
35
|
+
requires = ["setuptools"]
|
|
36
|
+
build-backend = "setuptools.build_meta"
|
|
37
|
+
|
|
38
|
+
[project.scripts]
|
|
39
|
+
sycommon = "command.cli:main"
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import os
|
|
3
|
+
import datetime
|
|
4
|
+
import re
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from importlib.resources import files
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def get_all_files_in_directory(directory: Path) -> list[tuple[Path, str]]:
|
|
10
|
+
"""
|
|
11
|
+
获取目录下所有文件的相对路径(忽略__pycache__目录)
|
|
12
|
+
返回值: 元组列表 (模板文件路径, 相对目标路径)
|
|
13
|
+
"""
|
|
14
|
+
file_mappings = []
|
|
15
|
+
if not directory.exists() or not directory.is_dir():
|
|
16
|
+
return file_mappings
|
|
17
|
+
|
|
18
|
+
# 遍历目录下所有文件
|
|
19
|
+
for root, _, files in os.walk(directory):
|
|
20
|
+
# 跳过包含__pycache__的目录
|
|
21
|
+
if "__pycache__" in root:
|
|
22
|
+
continue
|
|
23
|
+
|
|
24
|
+
for file in files:
|
|
25
|
+
# 获取文件的绝对路径
|
|
26
|
+
file_path = Path(root) / file
|
|
27
|
+
# 计算相对模板目录的路径
|
|
28
|
+
rel_path = file_path.relative_to(directory)
|
|
29
|
+
# 添加到映射列表
|
|
30
|
+
file_mappings.append((file_path, str(rel_path)))
|
|
31
|
+
|
|
32
|
+
return file_mappings
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def init_project(project_name: str, project_type: str) -> None:
|
|
36
|
+
"""
|
|
37
|
+
初始化项目,自动读取模板文件并替换占位符
|
|
38
|
+
"""
|
|
39
|
+
project_path = Path(os.getcwd()) / project_name
|
|
40
|
+
if project_path.exists():
|
|
41
|
+
print(f"❌ 错误:工程 '{project_path}' 已存在")
|
|
42
|
+
return
|
|
43
|
+
|
|
44
|
+
template_root = files("command.templates")
|
|
45
|
+
if not template_root.is_dir():
|
|
46
|
+
print("❌ 错误:未找到模板文件目录(command/templates)")
|
|
47
|
+
return
|
|
48
|
+
|
|
49
|
+
# 处理项目名称
|
|
50
|
+
short_project_name = project_name.replace("shengye-platform-", "")
|
|
51
|
+
short_project_name_upper = short_project_name.upper()
|
|
52
|
+
|
|
53
|
+
# 定义模板变量
|
|
54
|
+
context = {
|
|
55
|
+
"__cli__.project_name": project_name,
|
|
56
|
+
"__cli__.short_project_name": short_project_name,
|
|
57
|
+
"__cli__.short_project_name_upper": short_project_name_upper,
|
|
58
|
+
"__cli__.project_type": project_type,
|
|
59
|
+
"__cli__.create_time": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
|
60
|
+
"__cli__.author": os.getlogin(),
|
|
61
|
+
"__cli__.default_port": 8080
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# 自动获取基础模板文件和特定类型模板文件
|
|
65
|
+
base_dir = template_root / "base"
|
|
66
|
+
type_dir = template_root / project_type
|
|
67
|
+
|
|
68
|
+
base_files = get_all_files_in_directory(base_dir)
|
|
69
|
+
type_specific_files = get_all_files_in_directory(type_dir)
|
|
70
|
+
|
|
71
|
+
# 合并所有文件映射
|
|
72
|
+
file_mappings = base_files + type_specific_files
|
|
73
|
+
copied_files = 0
|
|
74
|
+
|
|
75
|
+
# 处理每个文件
|
|
76
|
+
for template_file, target_rel_path in file_mappings:
|
|
77
|
+
try:
|
|
78
|
+
# 1. 读取模板内容
|
|
79
|
+
template_content = template_file.read_text(encoding="utf-8")
|
|
80
|
+
|
|
81
|
+
# 2. 替换所有占位符(包含花括号)
|
|
82
|
+
rendered_content = template_content
|
|
83
|
+
for key, value in context.items():
|
|
84
|
+
# 精确匹配带有花括号的占位符
|
|
85
|
+
pattern = re.compile(rf'{{\s*{re.escape(key)}\s*}}')
|
|
86
|
+
rendered_content = pattern.sub(str(value), rendered_content)
|
|
87
|
+
|
|
88
|
+
# 3. 清理引号(针对YAML键值对格式)
|
|
89
|
+
rendered_content = re.sub(
|
|
90
|
+
r'(\w+)\s*:\s*["\']([^"\']+)["\']',
|
|
91
|
+
r'\1: \2',
|
|
92
|
+
rendered_content
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
# 4. 最后检查并移除任何残留的花括号
|
|
96
|
+
for value in context.values():
|
|
97
|
+
rendered_content = re.sub(
|
|
98
|
+
rf'{{+{re.escape(str(value))}+}}',
|
|
99
|
+
str(value),
|
|
100
|
+
rendered_content
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
# 5. 处理文件后缀:直接移除.tpl后缀
|
|
104
|
+
if target_rel_path.endswith('.tpl'):
|
|
105
|
+
target_rel_path = target_rel_path[:-4]
|
|
106
|
+
|
|
107
|
+
# 6. 写入文件
|
|
108
|
+
target_file = project_path / target_rel_path
|
|
109
|
+
target_file.parent.mkdir(parents=True, exist_ok=True)
|
|
110
|
+
target_file.write_text(rendered_content, encoding="utf-8")
|
|
111
|
+
|
|
112
|
+
copied_files += 1
|
|
113
|
+
except Exception as e:
|
|
114
|
+
print(f"❌ 处理模板 {template_file} 失败: {str(e)}")
|
|
115
|
+
|
|
116
|
+
if copied_files > 0:
|
|
117
|
+
print(f"✅ 模板{project_type}工程 {project_name} 创建完成!")
|
|
118
|
+
print(f"📁 工程路径:{project_path}")
|
|
119
|
+
print(f"📊 共创建 {copied_files} 个文件")
|
|
120
|
+
else:
|
|
121
|
+
print(f"\n⚠️ 未创建任何文件,可能是缺少模板文件或模板路径配置错误")
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def main() -> None:
|
|
125
|
+
parser = argparse.ArgumentParser(
|
|
126
|
+
prog="sycommon",
|
|
127
|
+
description="sycommon 工具集 - 项目初始化工具",
|
|
128
|
+
formatter_class=argparse.RawTextHelpFormatter
|
|
129
|
+
)
|
|
130
|
+
subparsers = parser.add_subparsers(
|
|
131
|
+
dest="command", required=True, help="子命令(当前支持:init)"
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
init_parser = subparsers.add_parser(
|
|
135
|
+
"init",
|
|
136
|
+
help="创建Web/Agent类型项目模板",
|
|
137
|
+
formatter_class=argparse.RawTextHelpFormatter,
|
|
138
|
+
epilog="示例:\n"
|
|
139
|
+
" sycommon init web my_project # 创建Web类型项目\n"
|
|
140
|
+
" sycommon init agent my_project # 创建AI Agent类型项目"
|
|
141
|
+
)
|
|
142
|
+
init_parser.add_argument(
|
|
143
|
+
"project_type",
|
|
144
|
+
choices=["web", "agent"],
|
|
145
|
+
help="项目类型:web - Web服务项目;agent - AI Agent服务项目"
|
|
146
|
+
)
|
|
147
|
+
init_parser.add_argument(
|
|
148
|
+
"project_name",
|
|
149
|
+
help="工程名称(如 my_web_project,将创建同名根目录)"
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
try:
|
|
153
|
+
args = parser.parse_args()
|
|
154
|
+
if args.command == "init":
|
|
155
|
+
init_project(args.project_name, args.project_type)
|
|
156
|
+
except argparse.ArgumentError as e:
|
|
157
|
+
print(f"❌ 错误:{e}\n")
|
|
158
|
+
print(
|
|
159
|
+
f"请使用 {parser.prog} {args.command if 'args' in locals() else ''} -h 查看帮助")
|
|
160
|
+
except SystemExit:
|
|
161
|
+
pass
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
if __name__ == "__main__":
|
|
165
|
+
# uv pip install -e .
|
|
166
|
+
# sycommon init web my_project
|
|
167
|
+
main()
|
|
File without changes
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import yaml
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class SingletonMeta(type):
|
|
5
|
+
_instances = {}
|
|
6
|
+
|
|
7
|
+
def __call__(cls, *args, **kwargs):
|
|
8
|
+
if cls not in cls._instances:
|
|
9
|
+
cls._instances[cls] = super().__call__(*args, **kwargs)
|
|
10
|
+
return cls._instances[cls]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Config(metaclass=SingletonMeta):
|
|
14
|
+
def __init__(self, config_file='app.yaml'):
|
|
15
|
+
with open(config_file, 'r', encoding='utf-8') as f:
|
|
16
|
+
self.config = yaml.safe_load(f)
|
|
17
|
+
self.MaxBytes = self.config.get('MaxBytes', 209715200)
|
|
18
|
+
self.Timeout = self.config.get('Timeout', 600000)
|
|
19
|
+
self.MaxRetries = self.config.get('MaxRetries', 3)
|
|
20
|
+
self.llm_configs = []
|
|
21
|
+
self.embedding_configs = []
|
|
22
|
+
self.reranker_configs = []
|
|
23
|
+
self.sentry_configs = []
|
|
24
|
+
self._process_config()
|
|
25
|
+
|
|
26
|
+
def get_llm_config(self, model_name):
|
|
27
|
+
for llm in self.llm_configs:
|
|
28
|
+
if llm.get('model') == model_name:
|
|
29
|
+
return llm
|
|
30
|
+
raise ValueError(f"No configuration found for model: {model_name}")
|
|
31
|
+
|
|
32
|
+
def get_embedding_config(self, model_name):
|
|
33
|
+
for llm in self.embedding_configs:
|
|
34
|
+
if llm.get('model') == model_name:
|
|
35
|
+
return llm
|
|
36
|
+
raise ValueError(f"No configuration found for model: {model_name}")
|
|
37
|
+
|
|
38
|
+
def get_reranker_config(self, model_name):
|
|
39
|
+
for llm in self.reranker_configs:
|
|
40
|
+
if llm.get('model') == model_name:
|
|
41
|
+
return llm
|
|
42
|
+
raise ValueError(f"No configuration found for model: {model_name}")
|
|
43
|
+
|
|
44
|
+
def get_sentry_config(self, name):
|
|
45
|
+
for sentry in self.sentry_configs:
|
|
46
|
+
if sentry.get('name') == name:
|
|
47
|
+
return sentry
|
|
48
|
+
raise ValueError(f"No configuration found for server: {name}")
|
|
49
|
+
|
|
50
|
+
def _process_config(self):
|
|
51
|
+
llm_config_list = self.config.get('LLMConfig', [])
|
|
52
|
+
for llm_config in llm_config_list:
|
|
53
|
+
try:
|
|
54
|
+
# 延迟导入 LLMConfigModel
|
|
55
|
+
from sycommon.config.LLMConfig import LLMConfig
|
|
56
|
+
validated_config = LLMConfig(**llm_config)
|
|
57
|
+
self.llm_configs.append(validated_config.model_dump())
|
|
58
|
+
except ValueError as e:
|
|
59
|
+
print(f"Invalid LLM configuration: {e}")
|
|
60
|
+
|
|
61
|
+
embedding_config_list = self.config.get('EmbeddingConfig', [])
|
|
62
|
+
for embedding_config in embedding_config_list:
|
|
63
|
+
try:
|
|
64
|
+
from sycommon.config.EmbeddingConfig import EmbeddingConfig
|
|
65
|
+
validated_config = EmbeddingConfig(**embedding_config)
|
|
66
|
+
self.embedding_configs.append(validated_config.model_dump())
|
|
67
|
+
except ValueError as e:
|
|
68
|
+
print(f"Invalid LLM configuration: {e}")
|
|
69
|
+
|
|
70
|
+
reranker_config_list = self.config.get('RerankerConfig', [])
|
|
71
|
+
for reranker_config in reranker_config_list:
|
|
72
|
+
try:
|
|
73
|
+
from sycommon.config.RerankerConfig import RerankerConfig
|
|
74
|
+
validated_config = RerankerConfig(**reranker_config)
|
|
75
|
+
self.reranker_configs.append(validated_config.model_dump())
|
|
76
|
+
except ValueError as e:
|
|
77
|
+
print(f"Invalid LLM configuration: {e}")
|
|
78
|
+
|
|
79
|
+
sentry_config_list = self.config.get('SentryConfig', [])
|
|
80
|
+
for sentry_config in sentry_config_list:
|
|
81
|
+
try:
|
|
82
|
+
from sycommon.config.SentryConfig import SentryConfig
|
|
83
|
+
validated_config = SentryConfig(**sentry_config)
|
|
84
|
+
self.sentry_configs.append(validated_config.model_dump())
|
|
85
|
+
except ValueError as e:
|
|
86
|
+
print(f"Invalid Sentry configuration: {e}")
|
|
87
|
+
|
|
88
|
+
def set_attr(self, share_configs: dict):
|
|
89
|
+
self.config = {**self.config, **
|
|
90
|
+
share_configs.get('llm', {}), **share_configs}
|
|
91
|
+
self._process_config()
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from pydantic import BaseModel
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class HikariConfig(BaseModel):
|
|
5
|
+
minimum_idle: int
|
|
6
|
+
maximum_pool_size: int
|
|
7
|
+
idle_timeout: int
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class DatabaseConfig(BaseModel):
|
|
11
|
+
url: str
|
|
12
|
+
username: str
|
|
13
|
+
password: str
|
|
14
|
+
driver_class_name: str
|
|
15
|
+
time_between_eviction_runs_millis: int
|
|
16
|
+
min_evictable_idle_time_millis: int
|
|
17
|
+
validation_query: str
|
|
18
|
+
test_while_idle: bool
|
|
19
|
+
test_on_borrow: bool
|
|
20
|
+
test_on_return: bool
|
|
21
|
+
hikari: HikariConfig
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def convert_key_to_snake_case(key):
|
|
25
|
+
import re
|
|
26
|
+
# 处理驼峰命名转换为下划线命名
|
|
27
|
+
key = re.sub(r'(?<!^)(?=[A-Z])', '_', key).lower()
|
|
28
|
+
return key.replace('-', '_')
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def convert_dict_keys(d):
|
|
32
|
+
if isinstance(d, dict):
|
|
33
|
+
return {convert_key_to_snake_case(k): convert_dict_keys(v) for k, v in d.items()}
|
|
34
|
+
return d
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from pydantic import BaseModel
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class EmbeddingConfig(BaseModel):
|
|
5
|
+
model: str
|
|
6
|
+
provider: str
|
|
7
|
+
baseUrl: str
|
|
8
|
+
maxTokens: int
|
|
9
|
+
dimension: int
|
|
10
|
+
|
|
11
|
+
@classmethod
|
|
12
|
+
def from_config(cls, model_name: str):
|
|
13
|
+
from sycommon.config.Config import Config
|
|
14
|
+
llm_config = Config().get_embedding_config(model_name)
|
|
15
|
+
return cls(**llm_config)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from pydantic import BaseModel
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class LLMConfig(BaseModel):
|
|
5
|
+
model: str
|
|
6
|
+
provider: str
|
|
7
|
+
baseUrl: str
|
|
8
|
+
maxTokens: int
|
|
9
|
+
vision: bool
|
|
10
|
+
callFunction: bool
|
|
11
|
+
|
|
12
|
+
@classmethod
|
|
13
|
+
def from_config(cls, model_name: str):
|
|
14
|
+
from sycommon.config.Config import Config
|
|
15
|
+
llm_config = Config().get_llm_config(model_name)
|
|
16
|
+
return cls(**llm_config)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from pydantic import BaseModel
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class RerankerConfig(BaseModel):
|
|
5
|
+
model: str
|
|
6
|
+
provider: str
|
|
7
|
+
baseUrl: str
|
|
8
|
+
maxTokens: int
|
|
9
|
+
|
|
10
|
+
@classmethod
|
|
11
|
+
def from_config(cls, model_name: str):
|
|
12
|
+
from sycommon.config.Config import Config
|
|
13
|
+
llm_config = Config().get_reranker_config(model_name)
|
|
14
|
+
return cls(**llm_config)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from pydantic import BaseModel
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class SentryConfig(BaseModel):
|
|
5
|
+
name: str
|
|
6
|
+
dsn: str
|
|
7
|
+
enable: bool
|
|
8
|
+
|
|
9
|
+
@classmethod
|
|
10
|
+
def from_config(cls, server_name: str):
|
|
11
|
+
from sycommon.config.Config import Config
|
|
12
|
+
sentry_config = Config().get_sentry_config(server_name)
|
|
13
|
+
return cls(**sentry_config)
|
|
File without changes
|