bugfix
This commit is contained in:
parent
f4179ad700
commit
69bbe0a9d2
33
app/sage.py
33
app/sage.py
@ -4,11 +4,12 @@ from appPublic.log import MyLogger, info, debug, warning
|
|||||||
from appPublic.folderUtils import ProgramPath
|
from appPublic.folderUtils import ProgramPath
|
||||||
from appPublic.jsonConfig import getConfig
|
from appPublic.jsonConfig import getConfig
|
||||||
from appPublic.registerfunction import RegisterFunction
|
from appPublic.registerfunction import RegisterFunction
|
||||||
from ahserver.configuredServer import ConfiguredServer
|
from bricks_for_python.init import load_pybricks
|
||||||
|
from ahserver.webapp import webapp
|
||||||
from ahserver.serverenv import ServerEnv
|
from ahserver.serverenv import ServerEnv
|
||||||
from rbac.init import load_rbac
|
from rbac.init import load_rbac
|
||||||
from appbase.init import load_appbase
|
from appbase.init import load_appbase
|
||||||
from basellm.init import load_basellm
|
from llmage.init import load_llmage
|
||||||
from filemgr.init import load_filemgr
|
from filemgr.init import load_filemgr
|
||||||
from uapi.init import load_uapi
|
from uapi.init import load_uapi
|
||||||
|
|
||||||
@ -20,35 +21,19 @@ from ext import *
|
|||||||
from rf import *
|
from rf import *
|
||||||
__version__ = '0.0.1'
|
__version__ = '0.0.1'
|
||||||
|
|
||||||
if __name__ == '__main__':
|
def init():
|
||||||
parser = argparse.ArgumentParser(prog="Sage")
|
|
||||||
parser.add_argument('-w', '--workdir')
|
|
||||||
parser.add_argument('-p', '--port')
|
|
||||||
args = parser.parse_args()
|
|
||||||
workdir = args.workdir or os.getcwd()
|
|
||||||
p = ProgramPath()
|
|
||||||
config = getConfig(workdir, NS={'workdir':workdir, 'ProgramPath':p})
|
|
||||||
if config.logger:
|
|
||||||
logger = MyLogger(config.logger.name or 'sage',
|
|
||||||
levelname=config.logger.levelname or 'debug',
|
|
||||||
logfile=config.logger.logfile or None)
|
|
||||||
else:
|
|
||||||
logger = MyLogger('sage', levelname='debug')
|
|
||||||
|
|
||||||
info(f'====================sage version={__version__}')
|
|
||||||
# server = ConfiguredServer(auth_klass=MyAuthAPI, workdir=workdir)
|
|
||||||
server = ConfiguredServer(workdir=workdir)
|
|
||||||
rf = RegisterFunction()
|
rf = RegisterFunction()
|
||||||
set_globalvariable()
|
set_globalvariable()
|
||||||
|
load_pybricks()
|
||||||
load_appbase()
|
load_appbase()
|
||||||
load_rbac()
|
load_rbac()
|
||||||
load_accounting()
|
load_accounting()
|
||||||
load_pf_pay()
|
load_pf_pay()
|
||||||
load_platformbiz()
|
load_platformbiz()
|
||||||
load_basellm()
|
load_llmage()
|
||||||
load_filemgr()
|
load_filemgr()
|
||||||
load_uapi()
|
load_uapi()
|
||||||
port = args.port or config.website.port or 8080
|
|
||||||
port = int(port)
|
if __name__ == '__main__':
|
||||||
server.run(port=port)
|
webapp(init)
|
||||||
|
|
||||||
|
|||||||
72
build.sh
Executable file
72
build.sh
Executable file
@ -0,0 +1,72 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# clone from git@git.opencomputing.cn/yumoqing/sage
|
||||||
|
# git clone https://git.opencomputing.cn/yumoqing/sage
|
||||||
|
cdir=$(pwd)
|
||||||
|
uname=$(id -un)
|
||||||
|
gname=$(id -gn)
|
||||||
|
python3 -m venv py3
|
||||||
|
source py3/bin/activate
|
||||||
|
$cdir/py3/bin/pip install -r requirements.txt
|
||||||
|
mkdir pkgs
|
||||||
|
cd pkgs
|
||||||
|
dir=$(pwd)
|
||||||
|
for m in appbase rbac accounting llmage platformbiz pf_pay filemgr dapi uapi
|
||||||
|
do
|
||||||
|
echo "install $m module..."
|
||||||
|
cd $dir
|
||||||
|
git clone https://git.opencomputing.cn/yumoqing/$m
|
||||||
|
cd $dir/$m
|
||||||
|
$cdir/py3/bin/pip install .
|
||||||
|
cd $dir/$m/models
|
||||||
|
xls2ddl mysql . > mysql.ddl.sql
|
||||||
|
mysql -h db -utest -ptest123 sage < mysql.ddl.sql
|
||||||
|
cd $dir/$m/json
|
||||||
|
./build.sh
|
||||||
|
rm $cdir/wwwroot/$m
|
||||||
|
ln -s $dir/$m/wwwroot $cdir/wwwroot/$m
|
||||||
|
done
|
||||||
|
rm $cdir/wwwroot/bricks
|
||||||
|
ln -s /d/public/bricks $cdir/wwwroot
|
||||||
|
cd $cdir
|
||||||
|
cat > $cdir/sage.service <<EOF
|
||||||
|
[Unit]
|
||||||
|
Wants=systemd-networkd.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
User=$uname
|
||||||
|
Group=$gname
|
||||||
|
Type=forking
|
||||||
|
WorkingDirectory=$cdir
|
||||||
|
ExecStart=$cdir/start.sh
|
||||||
|
ExecStop=$cdir/stop.sh
|
||||||
|
StandardOutput=append:/var/log/sage/sage.log
|
||||||
|
StandardError=append:/var/log/sage/sage.log
|
||||||
|
SyslogIdentifier=sage
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF
|
||||||
|
cat > $cdir/start.sh <<EOF
|
||||||
|
#!/usr/bin/bash
|
||||||
|
cd $cdir
|
||||||
|
$cdir/py3/bin/python $cdir/app/sage.py -p 9180 -w $cdir &
|
||||||
|
$cdir/py3/bin/python $cdir/app/sage.py -p 9181 -w $cdir &
|
||||||
|
exit 0
|
||||||
|
EOF
|
||||||
|
cat > $cdir/stop.sh <<EOF
|
||||||
|
PORT=9182
|
||||||
|
PID=\$(lsof -t -i:\$PORT)
|
||||||
|
|
||||||
|
if [ -n "\$PID" ]; then
|
||||||
|
echo "找到端口 $PORT 的进程: PID=\$PID"
|
||||||
|
kill -9 \$PID
|
||||||
|
echo "已终止端口 $PORT 的进程"
|
||||||
|
else
|
||||||
|
echo "未找到端口 $PORT 的进程"
|
||||||
|
fi
|
||||||
|
EOF
|
||||||
|
chmod +x $cdir/start.sh stop.sh
|
||||||
|
sudo mkdir /var/log/sage
|
||||||
|
sudo cp sage.service /etc/systemd/system
|
||||||
|
sudo systemctl enable sage
|
||||||
|
sudo systemctl restart sage
|
||||||
18
initln
18
initln
@ -1,9 +1,17 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
for m in accounting appbase basellm filemgr msp platformbiz rag rbac uapi
|
for m in apppublic sqlor ahserver accounting appbase basellm filemgr msp platformbiz rag rbac uapi
|
||||||
do
|
do
|
||||||
cd ~/py/$m/json
|
echo $m ...............
|
||||||
sh ./build.sh
|
cd ~/py/$m
|
||||||
cd ~/py/sage/wwwroot
|
git pull
|
||||||
ln -s ~/py/$m/wwwroot $m
|
if [ -f "setup.cfg" ];then
|
||||||
|
pip install .
|
||||||
|
fi
|
||||||
|
if [ -d "json" ];then
|
||||||
|
cd ~/py/$m/json
|
||||||
|
sh ./build.sh
|
||||||
|
cd ~/py/sage/wwwroot
|
||||||
|
ln -s ~/py/$m/wwwroot $m
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
@ -1,56 +0,0 @@
|
|||||||
import sys
|
|
||||||
from ahserver.serverenv import ServerEnv
|
|
||||||
from appPublic.dictObject import DictObject
|
|
||||||
import time
|
|
||||||
import jwt
|
|
||||||
|
|
||||||
def generate_zhipuai_token(apikey: str, exp_seconds: int=86400):
|
|
||||||
try:
|
|
||||||
id, secret = apikey.split(".")
|
|
||||||
except Exception as e:
|
|
||||||
raise Exception("invalid apikey", e)
|
|
||||||
|
|
||||||
payload = {
|
|
||||||
"api_key": id,
|
|
||||||
"exp": int(round(time.time() * 1000)) + exp_seconds * 1000,
|
|
||||||
"timestamp": int(round(time.time() * 1000)),
|
|
||||||
}
|
|
||||||
|
|
||||||
return jwt.encode(
|
|
||||||
payload,
|
|
||||||
secret,
|
|
||||||
algorithm="HS256",
|
|
||||||
headers={"alg": "HS256", "sign_type": "SIGN"},
|
|
||||||
)
|
|
||||||
|
|
||||||
async def get_llm_user_apikey(apiname, user):
|
|
||||||
if apiname == 'qianwen':
|
|
||||||
return DictObject(apikey='sk-ca5dfeb58d494f32a9cf1e9f064370c8')
|
|
||||||
|
|
||||||
if apiname=='baiduqianfan':
|
|
||||||
return DictObject(apikey='SjAN4GHU07LuB8ZYOIstB31G',
|
|
||||||
secretkey='QbakADoGJsM2qjUzIogTkBZruToxYAve')
|
|
||||||
if apiname=='baichuanai':
|
|
||||||
return DictObject(apikey='sk-f1fca6335df32d13c096e5f2e72821db')
|
|
||||||
if apiname=='deepseek':
|
|
||||||
return DictObject(apikey='sk-a6a2d5eca1b7419b95f2c263c362be1e')
|
|
||||||
|
|
||||||
if apiname == 'minimax':
|
|
||||||
return DictObject(apikey='eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJHcm91cE5hbWUiOiJtb3FpbmcgeXUiLCJVc2VyTmFtZSI6Im1vcWluZyB5dSIsIkFjY291bnQiOiIiLCJTdWJqZWN0SUQiOiIxNzY4NTM3NjQ1ODMyNDg3NjAyIiwiUGhvbmUiOiIxMzgwMTAxNTI5MiIsIkdyb3VwSUQiOiIxNzY4NTM3NjQ1ODI4MjkyOTMwIiwiUGFnZU5hbWUiOiIiLCJNYWlsIjoiIiwiQ3JlYXRlVGltZSI6IjIwMjQtMDQtMTAgMTg6MDA6NTMiLCJpc3MiOiJtaW5pbWF4In0.VaRRHr9XMUSYhZOKVS2PRZv6Y9VCaW4JX2ks4QZX3aFr_emjnDbGv5HfNskf54piflEAeTMW4Qw1nG7bqhYea7N5LKHGf0YpesPGSoqxwyZUR4oaJNNVUsSe6eiLbdYSDO2wMb_hV5xyawh-lYe1reBKWaPVuOjfTrDhxzA0IBmzl-jAQhL8-kIZet2uX-p3NjxElpo_zjmVV_hA1BJEvTwuAk8ka-1SBZmXciMhBi1fJG4jcqoHCCN_JHJ7pgjKr5bk2Zw5qCqiU2Ecsc-kPIEK1SI5EYoLszT43UpJ8_wV4Pm07UBCn3vktAa0fjKDSUArPkBoYWSkgKDMWlmxig', groupid='1768537645828292930')
|
|
||||||
if apiname == 'zhipuai':
|
|
||||||
return DictObject(token=generate_zhipuai_token('ffd0affcb6b5f9368f517c09c75a6817.jp9DdpcgwdxXvDiT'))
|
|
||||||
if apiname == 'moonshot':
|
|
||||||
return DictObject(apikey='sk-fHOyIKC2mlIDfGwUQV6SwjwVJkjBJgkNWYv82yt3OdpYh592')
|
|
||||||
if apiname == 'openai':
|
|
||||||
return DictObject(apikey='sk-proj-gFbYlxVnhmfqf8MXhX42T3BlbkFJprO7jXabkwtjmrNeH77Z')
|
|
||||||
if apiname == 'doubao':
|
|
||||||
return DictObject(apikey='a2fddeaa-c31c-4cbe-aacb-732318408dac')
|
|
||||||
|
|
||||||
if apiname == 'tianqi':
|
|
||||||
return DictObject(apikey='94b72c37e62e49f796502d29955447ab', secretkey='afcac498e0a74302bec06d22dcdff213')
|
|
||||||
|
|
||||||
print(f'{user=} not have apikey for {apiname=}')
|
|
||||||
return DictObject()
|
|
||||||
|
|
||||||
g = ServerEnv()
|
|
||||||
g.get_llm_user_apikey = get_llm_user_apikey
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
import itchat
|
|
||||||
from appPublic.worker import awaitify
|
|
||||||
from appPublic.dictObject import DictObject
|
|
||||||
from appPublic.background import Background
|
|
||||||
from ahserver.globalEnv import GlobalEnv
|
|
||||||
|
|
||||||
def wechat_login(login_callback, qr_callback):
|
|
||||||
Background(itchat.login, login_callback=login_callback,
|
|
||||||
qr_callback=qr_callback)
|
|
||||||
g = GlobalEnv()
|
|
||||||
g.wechat_login = wechat_login
|
|
||||||
@ -1,19 +1,6 @@
|
|||||||
alibabacloud_tea_openapi
|
alibabacloud_tea_openapi
|
||||||
alibabacloud_dysmsapi20170525
|
alibabacloud_dysmsapi20170525
|
||||||
PyJWT
|
|
||||||
itchat
|
|
||||||
git+https://git.kaiyuancloud.cn/yumoqing/accounting
|
|
||||||
git+https://git.kaiyuancloud.cn/yumoqing/ahserver
|
|
||||||
git+https://git.kaiyuancloud.cn/yumoqing/appbase
|
|
||||||
git+https://git.kaiyuancloud.cn/yumoqing/apppublic
|
git+https://git.kaiyuancloud.cn/yumoqing/apppublic
|
||||||
git+https://git.kaiyuancloud.cn/yumoqing/basellm
|
git+https://git.kaiyuancloud.cn/yumoqing/ahserver
|
||||||
git+https://git.kaiyuancloud.cn/yumoqing/bricks-for-python
|
git+https://git.kaiyuancloud.cn/yumoqing/bricks-for-python
|
||||||
git+https://git.kaiyuancloud.cn/yumoqing/filemgr
|
|
||||||
git+https://git.kaiyuancloud.cn/yumoqing/msp
|
|
||||||
git+https://git.kaiyuancloud.cn/yumoqing/pf_pay
|
|
||||||
git+https://git.kaiyuancloud.cn/yumoqing/platformbiz
|
|
||||||
git+https://git.kaiyuancloud.cn/yumoqing/rag
|
|
||||||
git+https://git.kaiyuancloud.cn/yumoqing/rbac
|
|
||||||
git+https://git.kaiyuancloud.cn/yumoqing/sage
|
|
||||||
git+https://git.kaiyuancloud.cn/yumoqing/sqlor
|
git+https://git.kaiyuancloud.cn/yumoqing/sqlor
|
||||||
git+https://git.kaiyuancloud.cn/yumoqing/uapi
|
|
||||||
|
|||||||
@ -94,6 +94,22 @@
|
|||||||
}
|
}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if 'reseller.operator' in roles or 'customer.operator' in roles or 'owner.operator' in roles %}
|
{% if 'reseller.operator' in roles or 'customer.operator' in roles or 'owner.operator' in roles %}
|
||||||
|
,{
|
||||||
|
"name": "msp",
|
||||||
|
"label": "服务管理",
|
||||||
|
"items":[
|
||||||
|
{
|
||||||
|
"name":"devgroup",
|
||||||
|
"label":"设备组",
|
||||||
|
"url":"{{entire_url('msp/devgroup')}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name":"service",
|
||||||
|
"label":"服务目录",
|
||||||
|
"url":"{{entire_url('msp/mspcatelog')}}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
,{
|
,{
|
||||||
"name": "upappconfig",
|
"name": "upappconfig",
|
||||||
"label": "统一API",
|
"label": "统一API",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user