From 58f50220945b263fa7efabf6afe6f3b8435e0c82 Mon Sep 17 00:00:00 2001 From: houxu Date: Wed, 20 Aug 2025 15:54:59 +0800 Subject: [PATCH] update deploy shell path --- .../deploy/3-install-server/init_config.sh | 17 +++++++++-- scripts/deploy/5-resource/config.toml | 20 ++++++------- scripts/deploy/5-resource/token.py | 30 ++++++++++++++++++- scripts/deploy/deploy.sh | 4 +-- scripts/deploy/deploy.spec | 23 +++++++------- ...50\347\275\262\346\211\213\345\206\214.md" | 16 +++++----- 6 files changed, 77 insertions(+), 33 deletions(-) diff --git a/scripts/deploy/3-install-server/init_config.sh b/scripts/deploy/3-install-server/init_config.sh index d8cb0a9..4c8ed37 100644 --- a/scripts/deploy/3-install-server/init_config.sh +++ b/scripts/deploy/3-install-server/init_config.sh @@ -521,7 +521,11 @@ setup_tiktoken_cache() { cp $token_py_file $FILE echo -e "${COLOR_SUCCESS}[Success] tiktoken缓存已配置: $target_file${COLOR_RESET}" } - +generate_random_password2() { + # 生成24位随机密码(包含大小写字母、数字和特殊字符) + local password=$(tr -dc 'A-Za-z0-9' int: """使用ChatGPT的cl100k tokenizer,估算Token消耗量""" result = 0 @@ -24,3 +25,30 @@ class TokenCalculator(metaclass=SingletonMeta): result += len(self._encoder.encode(msg["content"])) return result + + @staticmethod + def get_k_tokens_words_from_content(content: str, k: int | None = None) -> str: + """获取k个token的词""" + if k is None: + return content + if k <= 0: + return "" + try: + if TokenCalculator().calculate_token_length(messages=[ + {"role": "user", "content": content}, + ], pure_text=True) <= k: + return content + l = 0 + r = len(content) + while l + 1 < r: + mid = (l + r) // 2 + if TokenCalculator().calculate_token_length(messages=[ + {"role": "user", "content": content[:mid]}, + ], pure_text=True) <= k: + l = mid + else: + r = mid + return content[:l] + except Exception: + logger.exception("[RAG] 获取k个token的词失败") + return "" \ No newline at end of file diff --git a/scripts/deploy/deploy.sh b/scripts/deploy/deploy.sh index 8baccb0..799b2c2 100644 --- a/scripts/deploy/deploy.sh +++ b/scripts/deploy/deploy.sh @@ -300,7 +300,7 @@ agent_manager() { # 获取主脚本绝对路径并切换到所在目录 MAIN_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) if [ "${MAIN_DIR}" = "/usr/bin" ]; then - cd /usr/lib/deploy/scripts || exit 1 + cd /usr/lib/openeuler-intelligence/scripts || exit 1 else cd "$MAIN_DIR" || exit 1 fi @@ -332,7 +332,7 @@ fi # 获取主脚本绝对路径并切换到所在目录 MAIN_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) if [ "${MAIN_DIR}" = "/usr/bin" ]; then - cd /usr/lib/deploy/scripts || exit 1 + cd /usr/lib/openeuler-intelligence/scripts || exit 1 else cd "$MAIN_DIR" || exit 1 fi diff --git a/scripts/deploy/deploy.spec b/scripts/deploy/deploy.spec index 10e46ad..a027d6b 100644 --- a/scripts/deploy/deploy.spec +++ b/scripts/deploy/deploy.spec @@ -1,6 +1,6 @@ -Name: openEuler-Intelligence-Install +Name: openEuler-Intelligence-Installer Version: 1.0 -Release: 1.oe2403sp2%{?dist} +Release: 2 Summary: Deployment scripts package for openEuler 24.03 SP2 License: MIT @@ -17,20 +17,23 @@ This package contains deployment scripts and resources. %install # 创建安装目录 -mkdir -p %{buildroot}/usr/lib/deploy/{scripts,resources} +mkdir -p %{buildroot}/usr/lib/openeuler-intelligence/{scripts,resources} # 复制脚本和资源 -install -m 755 deploy.sh %{buildroot}/usr/lib/deploy/scripts/deploy -cp -r 0-one-click-deploy 1-check-env 2-install-dependency 3-install-server 4-other-script 5-resource %{buildroot}/usr/lib/deploy/scripts/ -chmod -R +x %{buildroot}/usr/lib/deploy/scripts/ +install -m 755 deploy.sh %{buildroot}/usr/lib/openeuler-intelligence/scripts/deploy +cp -r 0-one-click-deploy 1-check-env 2-install-dependency 3-install-server 4-other-script 5-resource %{buildroot}/usr/lib/openeuler-intelligence/scripts/ +chmod -R +x %{buildroot}/usr/lib/openeuler-intelligence/scripts/ mkdir -p %{buildroot}/usr/bin -ln -sf /usr/lib/deploy/scripts/deploy %{buildroot}/usr/bin/openEuler-Intelligence-Install +ln -sf /usr/lib/openeuler-intelligence/scripts/deploy %{buildroot}/usr/bin/openEuler-Intelligence-Installer %files -/usr/lib/deploy -/usr/bin/openEuler-Intelligence-Install +/usr/lib/openeuler-intelligence +/usr/bin/openEuler-Intelligence-Installer %changelog -* Mon Jul 21 2025 houxu 'houxu5@h-partners.com' - 1.0-1.oe2403sp2 +* Wed Aug 20 2025 houxu 'houxu5@h-partners.com' - 1.0-2 +- update scripts path + +* Mon Jul 21 2025 houxu 'houxu5@h-partners.com' - 1.0-1 - Initial package \ No newline at end of file diff --git "a/scripts/deploy/\345\256\211\350\243\205\351\203\250\347\275\262\346\211\213\345\206\214.md" "b/scripts/deploy/\345\256\211\350\243\205\351\203\250\347\275\262\346\211\213\345\206\214.md" index 79093ee..c20b795 100644 --- "a/scripts/deploy/\345\256\211\350\243\205\351\203\250\347\275\262\346\211\213\345\206\214.md" +++ "b/scripts/deploy/\345\256\211\350\243\205\351\203\250\347\275\262\346\211\213\345\206\214.md" @@ -42,11 +42,11 @@ openEuler Intelligence 是一款智能问答工具,使用 openEuler Intelligen - 建议通过调用 OpenAI 接口来实现功能。 ## 快速开始 #### 1. 获取轻量化部署客户端 -- dnf install openEuler-Intelligence-Install +- dnf install openEuler-Intelligence-Installer #### 2. 修改基础配置文件 ~~~bash -[root@localhost 5-resource]# cd /usr/lib/deploy/scripts/5-resource/ +[root@localhost 5-resource]# cd /usr/lib/openeuler-intelligence/scripts/5-resource/ [root@localhost 5-resource]# ll 总计 65828 -rwxr-xr-x. 1 root root 1681126 2025年 7月16日 9b5ad71b2ce5302211f9c61530b329a4922fc6a4 @@ -100,7 +100,7 @@ domain = '192.168.2.112' #修改ip为部署服务器ip #### 3. 执行一键部署 ~~~bash -[root@localhost 5-resource]# openEuler-Intelligence-Install #启动后直接输入 0 开启一键部署 等待部署完成,视网络情况好坏,大概在10~40分钟 +[root@localhost 5-resource]# openEuler-Intelligence-Installer #启动后直接输入 0 开启一键部署 等待部署完成,视网络情况好坏,大概在10~40分钟 一键部署菜单 0) 自动部署 1) 手动部署 @@ -117,7 +117,7 @@ domain = '192.168.2.112' #修改ip为部署服务器ip #### 4. 初始化mcp agent ~~~bash #创建mcp服务 -openEuler-Intelligence-Install --a init config.json +openEuler-Intelligence-Installer --a init config.json #config.json 为copilot对应的mcp服务配置文件,参考如下,传入全路径 { "name": "systrace_mcp_server", @@ -137,7 +137,7 @@ openEuler-Intelligence-Install --a init config.json } #说明:init 多次调用会删除之前注册的mcp 服务,重新注册 #创建一一对应的agent应用 -openEuler-Intelligence-Install --a create config.json +openEuler-Intelligence-Installer --a create config.json #config.json 同上,是调用init之后,会在原始json里面添加serviceId字段标识mcp服务 { "name": "systrace_mcp_server", @@ -157,7 +157,7 @@ openEuler-Intelligence-Install --a create config.json "serviceId":"p2qQke" } #创建多对一的agent应用 -openEuler-Intelligence-Install --a comb config.json +openEuler-Intelligence-Installer --a comb config.json #config.json是组合多个mcp创建agent { "appType": "agent", #应用类型,不需要修改 @@ -184,7 +184,7 @@ openEuler-Intelligence-Install --a comb config.json ~~~ ~~~ -[root@localhost deploy]# openEuler-Intelligence-Install --a init /root/mcp_config/perf_mcp/config.json +[root@localhost deploy]# openEuler-Intelligence-Installer --a init /root/mcp_config/perf_mcp/config.json 2025-08-15 09:49:54,874 - mcp_manager - INFO - 成功加载配置文件: /root/mcp_config/perf_mcp/config.json 2025-08-15 09:49:54,874 - mcp_manager - INFO - 删除MCP服务: dJsLV4 2025-08-15 09:49:54,960 - mcp_manager - INFO - 已删除旧的MCP服务ID @@ -192,7 +192,7 @@ openEuler-Intelligence-Install --a comb config.json 2025-08-15 09:49:55,060 - mcp_manager - INFO - MCP服务创建成功,service_id: XMZ7Pb 2025-08-15 09:49:55,061 - mcp_manager - INFO - 配置文件已更新: /root/mcp_config/perf_mcp/config.json 2025-08-15 09:49:55,061 - mcp_manager - INFO - 操作执行成功 -[root@localhost deploy]# openEuler-Intelligence-Install --a create /root/mcp_config/perf_mcp/config.json +[root@localhost deploy]# openEuler-Intelligence-Installer --a create /root/mcp_config/perf_mcp/config.json 2025-08-15 09:50:03,819 - mcp_manager - INFO - 成功加载配置文件: /root/mcp_config/perf_mcp/config.json 2025-08-15 09:50:03,819 - mcp_manager - INFO - 安装MCP服务: XMZ7Pb 2025-08-15 09:50:04,052 - mcp_manager - INFO - 等待MCP服务就绪: XMZ7Pb -- Gitee