新增命令

This commit is contained in:
weizjajj
2024-08-22 15:29:49 +08:00
parent 1e1fe41e49
commit 7936404f2d
7 changed files with 539 additions and 49 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 910 KiB

View File

@@ -0,0 +1,164 @@
# rag chat bot 快速开始
为了帮助大家快速体验aU,我们提供了一个rag chat bot的快速开始的教程。
## 1. 环境准备
使用 git clone aU 项目,并进入到样例工程目录
```shell
git clone https://github.com/alipay/agentUniverse.git
cd agentUniverse/sample_standard_app
```
### 1.1 无有效Python环境
对于 Mac & Linux 系统, 可以直接使用提供的脚本quick_start.sh安装python环境,脚本会自动安装python环境与依赖包。
```shell
bash quick_start.sh
```
对于 Windows 系统, 可以使用 quick_start.bat 安装一个python环境。
```shell
quick_start.bat
```
运行成功后会启动一个服务服务地址为http://127.0.0.1:8080/
### 1.2 已有python环境
注意如果你已经有了一个有效的python环境且python 版本大于3.10可以直接安装agentuniverse依赖。
#### 1.2.1 针对Mac & Linux 系统
运行命令
```shell
pip install agentuniverse==0.0.12
export PYTHONPATH=$PWD/../..
cd app/bootstrap
python -u bootstrap.py
```
#### 1.2.2对于 Windows 系统
运行命令
```shell
pip install agentuniverse==0.0.12
set PYTHONPATH=%CD%\..\..\..\..\
python -u bootstrap.py
```
### 1.3 vscode 配置
如果想要使用vscode进行调试请先使用vscode打开au项目安装python插件创建一个名为.vscode的文件夹并在文件夹下创建一个名为launch.json的文件内容如下
```json
{
"version": "0.2.0",
"configurations": [
{
"name": "Python 调试程序: 当前文件",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"justMyCode": true,
"subProcess": true,
"python": "${command:python.interpreterPath}",
"env":{
"PYTHONPATH": "${workspaceFolder}"
},
"purpose": [
"debug-test"
]
}
]
}
```
使用命令command + shift + P命令或者打开一个py文件右下角选择你想要使用的python环境。在vscode的终端当中激活python环境并在vscode的命令行当中安装依赖
```shell
pip install agentuniverse==0.0.12
```
最后使用vscode调试打开sample_standard_app/app/bootstrap/server_application.py,点击右上角中的调试按钮,即可进行启动进行调试。
### 1.4 Pycharm 配置
如果使用pycharm请使用Pycharm打开agentUniverse项目点击右上角选择Python解释器选择你想使用的python环境。选择好python环境之后在terminal中运行命令
```shell
pip install agentuniverse==0.0.12
```
命令执行完成之后双击打开sample_standard_app/app/bootstrap/server_application.py点击右上角中的调试或者运行按钮即可进行启动进行调试。
## 2. 项目配置
复制一份config目录custom_key.toml.sample下的配置模板重命名为custom_key.yaml
```shell
cp config/config.yaml config/custom_key.yaml
```
配置文件在config.yaml中`#custom_key_path = './custom_key.toml'` 的注释删除,配置结果如下:
```toml
[SUB_CONFIG_PATH]
# Log config file path, an absolute path or a relative path based on the dir where the current config file is located.
log_config_path = './log_config.toml'
# Custom key file path, use to save your own secret key like open ai or sth else. REMEMBER TO ADD IT TO .gitignore.
custom_key_path = './custom_key.toml'
```
注意: 你已经使用过 quick_start.sh 脚本安装python环境,这里可以直接跳过
## 3. 运行案例
当前运行案例是基于千问大模型在使用案例之前必须在config/custom_key.toml中配置好DASHSCOPE_API_KEY
```toml
DASHSCOPE_API_KEY='sk-*****'
```
key的获取方式请参考[千问](https://dashscope.console.aliyun.com/apiKey)
进入到案例目录,对于 Mac & Linux 系统,运行如下命令:
```shell
source ~/.bashrc
cd app/examples
bash run_rag_chat_bot.sh
```
或者
```shell
cd app/examples
export PYTHONPATH=$PWD/../../../..
python react_chat_bot.py
```
对于 Windows 系统,运行如下命令:
```shell
cd app/examples
set PYTHONPATH=%CD%\..\..\..\..\
run_rag_chat_bot.bat
```
在 vscode或者pycharm中可以直接通过打开想要运行的文件点击右上角中的调试或者运行按钮即可进行启动进行调试。
## 4.为agent添加工具
当前bot当中已经配置了一个google工具可以通过修改agent配置来修改或添加工具。针对当前的ragchatbot所绑定的agent修改agent配置文件config/agent_config.yaml,
将agent_id修改为`react_chat_bot`其配置文件为agentUniverse/sample_standard_app/app/core/agent/react_agent_case/demo_react_agent.yaml新增一个human_input_run工具,可以让模型询问用户问题。
```yaml
info:
name: 'demo_react_agent'
description: 'react agent'
profile:
prompt_version: qwen_react_agent.cn
llm_model:
name: 'qwen_llm'
model_name: 'qwen-max'
stop: 'Observation'
temperature: 0.1
action:
tool:
- 'google_search_tool'
- 'python_runner'
- 'human_input_run'
knowledge:
- 'civil_law_knowledge'
- 'criminal_law_knowledge'
agent:
- 'law_rag_agent'
plan:
planner:
name: 'react_planner'
metadata:
type: 'AGENT'
module: 'agentuniverse.agent.default.react_agent.react_agent'
class: 'ReActAgent'
```
重新测试,修改问题为: 我想知道我的公历生日对应的阳历生日是哪一天?
```shell
cd app/examples
export PYTHONPATH=$PWD/../../../..
python react_chat_bot.py --question "我可以购买好医保么,你可以询问我的健康状况,但是每次只能询问一个问题"
```
![执行效果](../_picture/react_input_tool.png)

View File

@@ -0,0 +1,86 @@
@echo off
REM 忽略管道错误
setlocal EnableDelayedExpansion
set "PATH=%PATH%;%USERPROFILE%\miniconda3\Scripts;%USERPROFILE%\miniconda3"
REM 判断conda命令是否存在如果不存在则判断%USERPROFILE%\miniconda3\Scripts是否存在
where conda >nul 2>nul
if %errorlevel% neq 0 (
if exist "%USERPROFILE%\miniconda3\Scripts" (
echo conda已安装%USERPROFILE%\miniconda3\Scripts添加到PATH...
set "PATH=%USERPROFILE%\miniconda3\Scripts;%PATH%"
) else (
echo conda未安装...
)
) else (
echo conda已在环境变量中
)
REM 定义安装conda的函数
:install_conda
where conda >nul 2>nul
if %errorlevel% neq 0 (
echo conda未安装正在安装conda...
mkdir "%USERPROFILE%\miniconda3"
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
powershell -Command "Invoke-WebRequest -Uri https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_24.3.0-0-Windows-x86_64.exe -OutFile %USERPROFILE%\miniconda3\miniconda.exe"
) else (
powershell -Command "Invoke-WebRequest -Uri https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_24.3.0-0-Windows-x86_64.exe -OutFile %USERPROFILE%\miniconda3\miniconda.exe"
)
"%USERPROFILE%\miniconda3\miniconda.exe" /InstallationType=JustMe /RegisterPython=0 /AddToPath=0 /S /D=%USERPROFILE%\miniconda3
call "%USERPROFILE%\miniconda3\Scripts\conda.exe" init bash
call "%USERPROFILE%\miniconda3\Scripts\conda.exe" init powershell
set "PATH=%USERPROFILE%\miniconda3\Scripts;%PATH%"
del "%USERPROFILE%\miniconda3\miniconda.exe"
call conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
call conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
call conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
call conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
echo conda安装完成
)
REM 检查是否安装Python如果没有安装Python
where python >nul 2>nul
if %errorlevel% neq 0 (
echo 未检测到Python正在安装...
call :install_conda
)
REM 检查Python版本
for /f "tokens=2 delims==" %%i in ('python --version 2^>^&1') do set py_version=%%i
if not "%py_version%"=="3.10" (
where conda >nul 2>nul
if %errorlevel% neq 0 (
echo conda未安装请安装conda后重试。
call :install_conda
)
call conda env list | findstr "python_au3.10" >nul
if %errorlevel% neq 0 (
echo Python 3.10环境未安装,正在安装...
call conda create -n python_au3.10 python=3.10 -y
)
for /f "tokens=*" %%i in ('conda info --base') do set CONDA_BASE=%%i
set "PATH=%CONDA_BASE%\envs\python_au3.10\Scripts;%PATH%"
)
REM 检查agentUniverse是否已安装
pip list | findstr "agentUniverse" >nul
if %errorlevel% neq 0 (
pip install agentUniverse -i https://pypi.tuna.tsinghua.edu.cn/simple
)
REM 检查custom_key文件是否存在
if not exist "..\..\config\custom_key.toml" (
copy "..\..\config\custom_key.toml.sample" "..\..\config\custom_key.toml"
)
REM 修改config.toml文件
powershell -Command "(Get-Content ..\..\config\config.toml) -replace '^#custom_key_path = ''\.\/custom_key\.toml''', 'custom_key_path = ''\.\/custom_key\.toml''' | Set-Content ..\..\config\config.toml"
REM 设置PYTHONPATH
set PYTHONPATH=%CD%\..\..\..\..\
REM 启动服务
cd app\bootstrap
python -u rag_chat_bot.py

View File

@@ -0,0 +1,98 @@
#!/bin/sh
# Ignore broken pipe errors
trap '' PIPE
# 判断conda 命令是否存在,如果不存在,则判断$HOME/miniconda3/bin是否存在如果存在则export 一下conda
if ! command -v conda &> /dev/null; then
# Check if $HOME/miniconda3/bin exists
if [ -d "$HOME/miniconda3/bin" ]; then
# Add $HOME/miniconda3/bin to PATH
echo "conda already installed Adding $HOME/miniconda3/bin to PATH..."
export PATH="$HOME/miniconda3/bin:$PATH"
else
echo "conda is not installed...."
fi
#否则echo conda已在环境变量当中
else
echo "conda is already installed."
fi
function install_conda() {
if ! command -v conda &> /dev/null; then
echo "conda is not installed. Installing conda..."
mkdir -p ~/miniconda3
# If on macOS
# 根据cpu类型与系统类型mac,linuxx86_64,arm下载
if [[ "$(uname)" == "Darwin" ]]; then
if [[ "$(uname -m)" == "x86_64" ]]; then
curl -o ~/miniconda3/miniconda.sh https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_24.3.0-0-MacOSX-x86_64.sh
elif [[ "$(uname -m)" == "arm64" ]];then
curl -o ~/miniconda3/miniconda.sh https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_24.3.0-0-MacOSX-arm64.sh
fi
# If on Linux
elif [[ "$(uname)" == "Linux" ]]; then
if [[ "$(uname -m)" == "x86_64" ]]; then
curl -o ~/miniconda3/miniconda.sh https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_24.3.0-0-Linux-x86_64.sh
fi
if [[ "$(uname -m)" == "aarch64" ]];then
curl -o ~/miniconda3/miniconda.sh https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_24.3.0-0-Linux-aarch64.sh
fi
fi
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
$HOME/miniconda3/bin/conda init bash
$HOME/miniconda3/bin/conda init sh
# 配置conda环境变量
echo 'export PATH="$HOME/miniconda3/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
export PATH="$HOME/miniconda3/bin:$PATH"
rm -rf ~/miniconda3/miniconda.sh
# Configure Tsinghua mirrors
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
echo "conda is installed."
fi
}
# Check if Python is installed, if not, install it 或者python的版本小于3.10
if ! command -v python &> /dev/null; then
echo "Python is not installed. Installing Python..."
# Check if conda is installed
install_conda
fi
if ! python --version | grep -q "3.10"; then
# 判断是否存在conda 命令
if ! command -v conda &> /dev/null; then
echo "conda is not installed. Please install conda and try again."
install_conda
fi
# 判断conda中是否存在python_au3.10 环境
if ! conda env list | grep -q "python_au3.10"; then
echo "Python 3.10 environment is not installed. Installing Python 3.10 environment..."
conda create -n python_au3.10 python=3.10 -y
fi
# conda info --base
# 使用conda info --base 获取conda的安装路径,并拼接envs/python_au3.10/bin到环境变量
export PATH ="$(conda info --base)/envs/python_au3.10/bin:$PATH"
fi
# 判断 pip list 是否已安装 agentUniverse
if ! pip list | grep -q "agentUniverse"; then
pip install agentUniverse -i https://pypi.tuna.tsinghua.edu.cn/simple
fi
# Check if custom_key file exists, if not, copy from sample
if [ ! -f "../../config/custom_key.toml" ]; then
cp ../../config/custom_key.toml.sample ../../config/custom_key.toml
fi
sed -i '' 's/^#custom_key_path = '\''\.\/custom_key\.toml'\''/custom_key_path = '\''\.\/custom_key\.toml'\''/' ../../config/config.toml
# Set PYTHONPATH to the parent directory of the current working directory
export PYTHONPATH=$PWD/../../../..
# Start the service
cd app/bootstrap
python -u react_chat_bot.py

View File

@@ -0,0 +1,38 @@
# !/usr/bin/env python3
# -*- coding:utf-8 -*-
import argparse
# @Time : 2024/5/8 11:44
# @Author : wangchongshi
# @Email : wangchongshi.wcs@antgroup.com
# @FileName: rag_chat_bot.py
from agentuniverse.agent.output_object import OutputObject
from agentuniverse.agent.agent import Agent
from agentuniverse.agent.agent_manager import AgentManager
from agentuniverse.base.agentuniverse import AgentUniverse
AgentUniverse().start(config_path='../../config/config.toml')
def chat(question: str):
""" Rag agent example.
The rag agent in agentUniverse becomes a chatbot and can ask questions to get the answer.
"""
instance: Agent = AgentManager().get_instance_obj('demo_react_agent')
output_object: OutputObject = instance.run(input=question)
res_info = f"\nReact chat bot execution result is :\n"
res_info += output_object.get_data('output')
print(res_info)
if __name__ == '__main__':
# 获取python 命令直接执行时的 --question 参数
parser = argparse.ArgumentParser(description="Chat bot for answering questions about birthdays.")
parser.add_argument("--question", type=str, help="The question to ask.")
args = parser.parse_args()
if args.question:
chat(args.question)
else:
chat("请给我一段可以计算三数之和的python代码")

View File

@@ -1,58 +1,86 @@
@echo off
:: 忽略管道错误
SETLOCAL ENABLEEXTENSIONS
rem Ignore broken pipe errors
rem Windows doesn't need to handle PIPE errors like Unix, so this can be ignored.
:: 检查是否安装了Python如果没有安装则进行安装或者Python的版本小于3.10
python --version 2>nul | findstr /r "^Python 3\.1[0-9]" >nul
IF %ERRORLEVEL% NEQ 0 (
echo Python is not installed or the version is less than 3.10. Installing Python...
:: 检查是否安装了Conda
conda --version >nul 2>&1
IF %ERRORLEVEL% NEQ 0 (
echo conda is not installed. Installing conda...
md %USERPROFILE%\miniconda3
curl -o %USERPROFILE%\miniconda3\miniconda.exe https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_24.3.0-0-Windows-x86_64.exe
%USERPROFILE%\miniconda3\miniconda.exe /InstallationType=JustMe /RegisterPython=0 /AddToPath=0 /S /D=%USERPROFILE%\miniconda3
CALL %USERPROFILE%\miniconda3\Scripts\conda.exe init
SETX PATH "%USERPROFILE%\miniconda3\Scripts;%USERPROFILE%\miniconda3;%PATH%"
DEL %USERPROFILE%\miniconda3\miniconda.exe
:: 配置清华镜像源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
rem 判断conda命令是否存在如果不存在则判断%USERPROFILE%\miniconda3\bin是否存在如果存在则export一下conda
where conda >nul 2>&1
if %errorlevel% neq 0 (
if exist "%USERPROFILE%\miniconda3\Scripts\conda.exe" (
echo conda already installed. Adding %USERPROFILE%\miniconda3\Scripts to PATH...
set PATH=%USERPROFILE%\miniconda3\Scripts;%PATH%
) else (
echo conda is not installed...
)
:: 创建并激活Python 3.10环境
conda create -n python_au3.10 python=3.10 -y
conda config --set default_env python_au3.10
SET PATH=%USERPROFILE%\miniconda3\envs\python_au3.10\Scripts;%USERPROFILE%\miniconda3\envs\python_au3.10;%PATH%
echo Python 3.10 environment created and activated.
python --version
) else (
echo conda is already installed.
)
python --version 2>nul | findstr /r "^Python 3\.1[0-9]" >nul
IF %ERRORLEVEL% NEQ 0 (
echo Error: Python version is not 3.10. Please install Python 3.10 and try again.
exit /b 1
:install_conda
where conda >nul 2>&1
if %errorlevel% neq 0 (
echo conda is not installed. Installing conda...
mkdir %USERPROFILE%\miniconda3
rem 根据系统类型下载Miniconda
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
if "%OS%"=="Windows_NT" (
powershell -Command "Invoke-WebRequest -Uri https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_24.3.0-0-Windows-x86_64.exe -OutFile %USERPROFILE%\miniconda3\miniconda.exe"
)
) else (
rem Handle other architectures if needed
)
rem 静默安装Miniconda
%USERPROFILE%\miniconda3\miniconda.exe /InstallationType=JustMe /RegisterPython=0 /AddToPath=0 /S /D=%USERPROFILE%\miniconda3
set PATH=%USERPROFILE%\miniconda3\Scripts;%USERPROFILE%\miniconda3;%PATH%
del %USERPROFILE%\miniconda3\miniconda.exe
rem 配置清华源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
echo conda is installed.
)
:: 判断是否已安装 agentUniverse
pip list 2>nul | findstr /r "^agentUniverse" >nul
IF %ERRORLEVEL% NEQ 0 (
pip install agentUniverse
rem 检查Python是否安装如果没有安装则安装它或者python的版本小于3.10
where python >nul 2>&1
if %errorlevel% neq 0 (
echo Python is not installed. Installing Python...
call :install_conda
)
:: 检查 custom_key 文件是否存在,如果不存在,从示例复制
IF NOT EXIST "config\custom_key.toml" (
python --version 2>&1 | findstr /r "3\.10" >nul
if %errorlevel% neq 0 (
where conda >nul 2>&1
if %errorlevel% neq 0 (
echo conda is not installed. Please install conda and try again.
call :install_conda
)
conda env list | findstr "python_au3.10" >nul
if %errorlevel% neq 0 (
echo Python 3.10 environment is not installed. Installing Python 3.10 environment...
conda create -n python_au3.10 python=3.10 -y
)
for /f "delims=" %%i in ('conda info --base') do set CONDA_BASE=%%i
set PATH=%CONDA_BASE%\envs\python_au3.10\Scripts;%CONDA_BASE%\envs\python_au3.10;%PATH%
)
rem 判断 pip list 是否已安装 agentUniverse
pip list | findstr "agentUniverse" >nul
if %errorlevel% neq 0 (
pip install agentUniverse -i https://pypi.tuna.tsinghua.edu.cn/simple
)
rem Check if custom_key file exists, if not, copy from sample
if not exist "config\custom_key.toml" (
copy config\custom_key.toml.sample config\custom_key.toml
)
:: 设置 PYTHONPATH 为当前工作目录的父目录
SET PYTHONPATH=%CD%\..\..
rem 替换 config.toml 中的 #custom_key_path 为 custom_key_path
powershell -Command "(Get-Content -path .\config\config.toml) -replace '^#custom_key_path = ''\.\/custom_key\.toml''', 'custom_key_path = ''\.\/custom_key\.toml''' | Set-Content -path .\config\config.toml"
:: 启动服务
rem Set PYTHONPATH to the parent directory of the current working directory
set PYTHONPATH=%cd%\..\..
rem Start the service
cd app\bootstrap
python -u server_application.py

90
sample_standard_app/quick_start.sh Normal file → Executable file
View File

@@ -1,24 +1,100 @@
#!/bin/bash
#!/bin/sh
# Ignore broken pipe errors
trap '' PIPE
# 判断conda 命令是否存在,如果不存在,则判断$HOME/miniconda3/bin是否存在如果存在则export 一下conda
if ! command -v conda &> /dev/null; then
# Check if $HOME/miniconda3/bin exists
if [ -d "$HOME/miniconda3/bin" ]; then
# Add $HOME/miniconda3/bin to PATH
echo "conda already installed Adding $HOME/miniconda3/bin to PATH..."
export PATH="$HOME/miniconda3/bin:$PATH"
else
echo "conda is not installed...."
fi
#否则echo conda已在环境变量当中
else
echo "conda is already installed."
fi
function install_conda() {
if ! command -v conda &> /dev/null; then
echo "conda is not installed. Installing conda..."
mkdir -p ~/miniconda3
# If on macOS
# 根据cpu类型与系统类型mac,linuxx86_64,arm下载
if [[ "$(uname)" == "Darwin" ]]; then
if [[ "$(uname -m)" == "x86_64" ]]; then
curl -o ~/miniconda3/miniconda.sh https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_24.3.0-0-MacOSX-x86_64.sh
elif [[ "$(uname -m)" == "arm64" ]];then
curl -o ~/miniconda3/miniconda.sh https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_24.3.0-0-MacOSX-arm64.sh
fi
# If on Linux
elif [[ "$(uname)" == "Linux" ]]; then
if [[ "$(uname -m)" == "x86_64" ]]; then
curl -o ~/miniconda3/miniconda.sh https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_24.3.0-0-Linux-x86_64.sh
fi
if [[ "$(uname -m)" == "aarch64" ]];then
curl -o ~/miniconda3/miniconda.sh https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_24.3.0-0-Linux-aarch64.sh
fi
fi
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
$HOME/miniconda3/bin/conda init bash
$HOME/miniconda3/bin/conda init sh
# 配置conda环境变量
echo 'export PATH="$HOME/miniconda3/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
export PATH="$HOME/miniconda3/bin:$PATH"
rm -rf ~/miniconda3/miniconda.sh
# Configure Tsinghua mirrors
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
echo "conda is installed."
fi
}
# Check if Python is installed, if not, install it 或者python的版本小于3.10
if ! command -v python &> /dev/null; then
echo "Python is not installed. Installing Python..."
# Check if conda is installed
install_conda
fi
# 判断当前的python版本是否是3.10
if ! python --version | grep -q "3.10"; then
echo "Error: Python version is not 3.10. Please install Python 3.10 and try again."
exit 1
# 判断是否存在conda 命令
if ! command -v conda &> /dev/null; then
echo "conda is not installed. Please install conda and try again."
install_conda
fi
# 判断conda中是否存在python_au3.10 环境
if ! conda env list | grep -q "python_au3.10"; then
echo "Python 3.10 environment is not installed. Installing Python 3.10 environment..."
conda create -n python_au3.10 python=3.10 -y
fi
# conda info --base
# 使用conda info --base 获取conda的安装路径,并拼接envs/python_au3.10/bin到环境变量
export PATH ="$(conda info --base)/envs/python_au3.10/bin:$PATH"
fi
# 判断 pip list 是否已安装 agentUniverse
if ! pip list | grep -q "agentUniverse"; then
pip install agentUniverse
pip install agentUniverse -i https://pypi.tuna.tsinghua.edu.cn/simple
fi
# Check if custom_key file exists, if not, copy from sample
if [ ! -f "config/custom_key" ]; then
if [ ! -f "config/custom_key.toml" ]; then
cp config/custom_key.toml.sample config/custom_key.toml
fi
#把config目录下的config.toml文件中的#custom_key_path = './custom_key.toml' 替换为 custom_key_path = './custom_key.toml'
sed -i '' 's/^#custom_key_path = '\''\.\/custom_key\.toml'\''/custom_key_path = '\''\.\/custom_key\.toml'\''/' ./config/config.toml
# Set PYTHONPATH to the parent directory of the current working directory
export PYTHONPATH=$PWD/../..
# Start the service
cd app/bootstrap
python -u server_application.py
python -u server_application.py