mirror of
https://github.com/agentuniverse-ai/agentUniverse.git
synced 2026-02-09 01:59:19 +08:00
BIN
docs/guidebook/_picture/react_chat_bot_tool.png
Normal file
BIN
docs/guidebook/_picture/react_chat_bot_tool.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 380 KiB |
BIN
docs/guidebook/_picture/react_input_tool.png
Normal file
BIN
docs/guidebook/_picture/react_input_tool.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 910 KiB |
146
docs/guidebook/zh/react_chat_bot_快速开始.md
Normal file
146
docs/guidebook/zh/react_chat_bot_快速开始.md
Normal file
@@ -0,0 +1,146 @@
|
||||
# react chat bot 快速开始
|
||||
为了帮助大家快速体验aU,我们提供了一个react 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.ps1 安装一个python环境。使用之前请先安装conda。
|
||||
```shell
|
||||
quick_start.ps1
|
||||
```
|
||||
运行成功后,会启动一个服务,服务地址为:http://127.0.0.1:8888/
|
||||
|
||||
### 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/custom_key.yaml.sample 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 example_start.sh
|
||||
```
|
||||
或者
|
||||
|
||||
```shell
|
||||
cd app/examples
|
||||
export PYTHONPATH=$PWD/../../../..
|
||||
python react_chat_bot.py
|
||||
```
|
||||
|
||||
对于 Windows 系统,运行如下命令:
|
||||
```shell
|
||||
cd app/examples
|
||||
set PYTHONPATH=%CD%\..\..\..\..\
|
||||
example_start.ps1
|
||||
```
|
||||
|
||||
或者
|
||||
|
||||
```shell
|
||||
cd app/examples
|
||||
set PYTHONPATH=%CD%\..\..\..\..\
|
||||
python react_chat_bot.py
|
||||
```
|
||||
|
||||
在 vscode或者pycharm中可以直接通过打开想要运行的文件,点击右上角中的调试或者运行按钮,即可进行启动进行调试。
|
||||
|
||||
## 4.为agent添加工具
|
||||
当前bot当中已经配置了一个google工具,可以通过修改agent配置来修改或添加工具。针对当前的ragchatbot所绑定的agent,修改agent配置文件config/agent_config.yaml,
|
||||
其配置文件为:agentUniverse/sample_standard_app/app/core/agent/react_agent_case/demo_react_agent.yaml,新增一个human_input_run工具,可以让模型询问用户问题。
|
||||

|
||||
重新测试,修改问题为: 我想知道我的公历生日对应的农历生日是哪一天?
|
||||
```shell
|
||||
cd app/examples
|
||||
export PYTHONPATH=$PWD/../../../..
|
||||
python react_chat_bot.py --question "我可以购买好医保么,你可以询问我的健康状况,但是每次只能询问一个问题"
|
||||
```
|
||||

|
||||
@@ -6,7 +6,8 @@ profile:
|
||||
llm_model:
|
||||
name: 'qwen_llm'
|
||||
model_name: 'qwen-max'
|
||||
temperature: 0
|
||||
stop: 'Observation'
|
||||
temperature: 0.1
|
||||
action:
|
||||
tool:
|
||||
- 'google_search_tool'
|
||||
|
||||
96
sample_standard_app/app/examples/example_start.ps1
Normal file
96
sample_standard_app/app/examples/example_start.ps1
Normal file
@@ -0,0 +1,96 @@
|
||||
# 忽略管道错误,PowerShell中一般不会出现类似的问题,所以可以忽略
|
||||
|
||||
# 判断conda命令是否存在,如果不存在,则检查%USERPROFILE%\miniconda3\bin是否存在,如果存在则将conda添加到路径中
|
||||
if (-not (Get-Command conda -ErrorAction SilentlyContinue)) {
|
||||
if (Test-Path "$env:USERPROFILE\miniconda3\Scripts\conda.exe") {
|
||||
Write-Output "conda already installed. Adding $env:USERPROFILE\miniconda3\Scripts to PATH..."
|
||||
$env:PATH = "$env:USERPROFILE\miniconda3\Scripts;$env:PATH"
|
||||
} else {
|
||||
Write-Output "conda is not installed..."
|
||||
}
|
||||
} else {
|
||||
Write-Output "conda is already installed."
|
||||
}
|
||||
|
||||
# 定义安装conda的函数
|
||||
function Install-Conda {
|
||||
if (-not (Get-Command conda -ErrorAction SilentlyContinue)) {
|
||||
Write-Output "conda is not installed. Please install conda first, and try again"
|
||||
New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\miniconda3"
|
||||
|
||||
curl https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_24.3.0-0-Windows-x86_64.exe -o miniconda.exe
|
||||
./miniconda.exe
|
||||
exit
|
||||
|
||||
# # 静默安装Miniconda
|
||||
# Start-Process -Wait -FilePath "$env:USERPROFILE\miniconda3\miniconda.exe" -ArgumentList "/InstallationType=JustMe", "/RegisterPython=0", "/AddToPath=0", "/S", "/D=$env:USERPROFILE\miniconda3"
|
||||
# $env:PATH = "$env:USERPROFILE\miniconda3\Scripts;$env:USERPROFILE\miniconda3;$env:PATH"
|
||||
# Remove-Item "$env: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/
|
||||
# Write-Output "conda is installed."
|
||||
}
|
||||
}
|
||||
|
||||
# 检查Python是否安装,如果没有安装则安装它,或者Python的版本小于3.10
|
||||
if (-not (Get-Command python -ErrorAction SilentlyContinue)) {
|
||||
Write-Output "Python is not installed. Installing Python..."
|
||||
Install-Conda
|
||||
}
|
||||
# 获取当前的Python版本
|
||||
$pythonVersion = & python --version 2>&1
|
||||
|
||||
# 如果Python版本不是3.10,则安装Python 3.10
|
||||
if ($pythonVersion -notmatch "3\.10") {
|
||||
if (-not (Get-Command conda -ErrorAction SilentlyContinue)) {
|
||||
Write-Output "conda is not installed. Please install conda and try again."
|
||||
Install-Conda
|
||||
}
|
||||
|
||||
# 检查是否已经有名为python_au3.10的环境
|
||||
if (-not (& conda env list | Select-String -Pattern "python_au3.10")) {
|
||||
Write-Output "Python 3.10 environment is not installed. Installing Python 3.10 environment..."
|
||||
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/
|
||||
conda create -n python_au3.10 python=3.10 -y
|
||||
}
|
||||
|
||||
# 获取Conda的基础路径并设置PATH变量
|
||||
$CONDA_BASE = & conda info --base
|
||||
$env:PATH = "$CONDA_BASE\envs\python_au3.10\Scripts;$CONDA_BASE\envs\python_au3.10;$env:PATH"
|
||||
}
|
||||
|
||||
# 切换到Python 3.10的环境
|
||||
conda activate python_au3.10
|
||||
|
||||
python --version
|
||||
|
||||
# 判断pip是否已经安装了agentUniverse
|
||||
if (-not (& pip list | Select-String -Pattern "agentUniverse")) {
|
||||
pip install agentUniverse -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
}
|
||||
|
||||
# 检查 custom_key 文件是否存在,如果不存在,从样本复制一份
|
||||
if (-not (Test-Path "..\..\config\custom_key.toml")) {
|
||||
Copy-Item "..\..\config\custom_key.toml.sample" "..\..\config\custom_key.toml"
|
||||
}
|
||||
|
||||
# 替换 config.toml 中的 #custom_key_path 为 custom_key_path
|
||||
# 确保设置 custom_key_path 正确引用 config 目录下的文件
|
||||
(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"
|
||||
|
||||
# 设置PYTHONPATH为当前工作目录的上级目录
|
||||
# 获取当前目录的上两级目录的绝对路径
|
||||
$upperTwoLevels = Resolve-Path (Join-Path (Get-Location) "..\..\")
|
||||
|
||||
# 设置 PYTHONPATH 环境变量
|
||||
$env:PYTHONPATH = $upperTwoLevels.Path
|
||||
|
||||
# 启动服务
|
||||
python -u .\react_chat_bot.py
|
||||
98
sample_standard_app/app/examples/example_start.sh
Normal file
98
sample_standard_app/app/examples/example_start.sh
Normal 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,linux,x86_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
|
||||
|
||||
38
sample_standard_app/app/examples/react_chat_bot.py
Normal file
38
sample_standard_app/app/examples/react_chat_bot.py
Normal 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代码")
|
||||
86
sample_standard_app/quick_start.bat
Normal file
86
sample_standard_app/quick_start.bat
Normal file
@@ -0,0 +1,86 @@
|
||||
@echo off
|
||||
|
||||
rem Ignore broken pipe errors
|
||||
rem Windows doesn't need to handle PIPE errors like Unix, so this can be ignored.
|
||||
|
||||
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...
|
||||
)
|
||||
) else (
|
||||
echo conda is already installed.
|
||||
)
|
||||
|
||||
: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.
|
||||
)
|
||||
|
||||
rem 检查Python是否安装,如果没有安装则安装它,或者python的版本小于3.10
|
||||
where python >nul 2>&1
|
||||
if %errorlevel% neq 0 (
|
||||
echo Python is not installed. Installing Python...
|
||||
call :install_conda
|
||||
)
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
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
|
||||
96
sample_standard_app/quick_start.ps1
Normal file
96
sample_standard_app/quick_start.ps1
Normal file
@@ -0,0 +1,96 @@
|
||||
# 忽略管道错误,PowerShell中一般不会出现类似的问题,所以可以忽略
|
||||
|
||||
# 判断conda命令是否存在,如果不存在,则检查%USERPROFILE%\miniconda3\bin是否存在,如果存在则将conda添加到路径中
|
||||
if (-not (Get-Command conda -ErrorAction SilentlyContinue)) {
|
||||
if (Test-Path "$env:USERPROFILE\miniconda3\Scripts\conda.exe") {
|
||||
Write-Output "conda already installed. Adding $env:USERPROFILE\miniconda3\Scripts to PATH..."
|
||||
$env:PATH = "$env:USERPROFILE\miniconda3\Scripts;$env:PATH"
|
||||
} else {
|
||||
Write-Output "conda is not installed..."
|
||||
}
|
||||
} else {
|
||||
Write-Output "conda is already installed."
|
||||
}
|
||||
|
||||
# 定义安装conda的函数
|
||||
function Install-Conda {
|
||||
if (-not (Get-Command conda -ErrorAction SilentlyContinue)) {
|
||||
Write-Output "conda is not installed. Installing conda..."
|
||||
New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\miniconda3"
|
||||
|
||||
# 根据系统类型下载Miniconda
|
||||
if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64" -and $env:OS -eq "Windows_NT") {
|
||||
Invoke-WebRequest -Uri "https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_24.3.0-0-Windows-x86_64.exe" -OutFile "$env:USERPROFILE\miniconda3\miniconda.exe"
|
||||
} else {
|
||||
# 如果有其他架构需求,可以在这里处理
|
||||
}
|
||||
|
||||
# 静默安装Miniconda
|
||||
Start-Process -Wait -FilePath "$env:USERPROFILE\miniconda3\miniconda.exe" -ArgumentList "/InstallationType=JustMe", "/RegisterPython=0", "/AddToPath=0", "/S", "/D=$env:USERPROFILE\miniconda3"
|
||||
$env:PATH = "$env:USERPROFILE\miniconda3\Scripts;$env:USERPROFILE\miniconda3;$env:PATH"
|
||||
Remove-Item "$env: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/
|
||||
Write-Output "conda is installed."
|
||||
}
|
||||
}
|
||||
|
||||
# 检查Python是否安装,如果没有安装则安装它,或者Python的版本小于3.10
|
||||
if (-not (Get-Command python -ErrorAction SilentlyContinue)) {
|
||||
Write-Output "Python is not installed. Installing Python..."
|
||||
Install-Conda
|
||||
}
|
||||
# 获取当前的Python版本
|
||||
$pythonVersion = & python --version 2>&1
|
||||
|
||||
# 如果Python版本不是3.10,则安装Python 3.10
|
||||
if ($pythonVersion -notmatch "3\.10") {
|
||||
if (-not (Get-Command conda -ErrorAction SilentlyContinue)) {
|
||||
Write-Output "conda is not installed. Please install conda and try again."
|
||||
Install-Conda
|
||||
}
|
||||
|
||||
# 检查是否已经有名为python_au3.10的环境
|
||||
if (-not (& conda env list | Select-String -Pattern "python_au3.10")) {
|
||||
Write-Output "Python 3.10 environment is not installed. Installing Python 3.10 environment..."
|
||||
conda create -n python_au3.10 python=3.10 -y
|
||||
}
|
||||
|
||||
# 获取Conda的基础路径并设置PATH变量
|
||||
$CONDA_BASE = & conda info --base
|
||||
$env:PATH = "$CONDA_BASE\envs\python_au3.10\Scripts;$CONDA_BASE\envs\python_au3.10;$env:PATH"
|
||||
}
|
||||
|
||||
# 切换到Python 3.10的环境
|
||||
conda activate python_au3.10
|
||||
|
||||
python --version
|
||||
|
||||
# 判断pip是否已经安装了agentUniverse
|
||||
if (-not (& pip list | Select-String -Pattern "agentUniverse")) {
|
||||
pip install agentUniverse -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
}
|
||||
|
||||
# 检查 custom_key 文件是否存在,如果不存在,从样本复制一份
|
||||
if (-not (Test-Path "config\custom_key.toml")) {
|
||||
Copy-Item "config\custom_key.toml.sample" "config\custom_key.toml"
|
||||
}
|
||||
|
||||
# 替换 config.toml 中的 #custom_key_path 为 custom_key_path
|
||||
# 确保设置 custom_key_path 正确引用 config 目录下的文件
|
||||
(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"
|
||||
|
||||
# 设置PYTHONPATH为当前工作目录的上级目录
|
||||
# 获取当前目录的上两级目录的绝对路径
|
||||
$upperTwoLevels = Resolve-Path (Join-Path (Get-Location) "..")
|
||||
|
||||
# 设置 PYTHONPATH 环境变量
|
||||
$env:PYTHONPATH = $upperTwoLevels.Path
|
||||
|
||||
# 启动服务
|
||||
Set-Location ".\app\bootstrap"
|
||||
python -u server_application.py
|
||||
102
sample_standard_app/quick_start.sh
Executable file
102
sample_standard_app/quick_start.sh
Executable file
@@ -0,0 +1,102 @@
|
||||
#!/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,linux,x86_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 activate python_au3.10
|
||||
# conda info --base
|
||||
# 使用conda info --base 获取conda的安装路径,并拼接envs/python_au3.10/bin到环境变量
|
||||
export PATH="$(conda info --base)/envs/python_au3.10/bin:$PATH"
|
||||
fi
|
||||
python --version
|
||||
# <<< conda initialize <<<
|
||||
# 判断 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
|
||||
|
||||
#把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
|
||||
|
||||
Reference in New Issue
Block a user