From 30f5fc9ab148482a387373a9a9490225d1655c98 Mon Sep 17 00:00:00 2001 From: lexluo09 <39718951+lexluo09@users.noreply.github.com> Date: Thu, 14 Sep 2023 22:30:06 +0800 Subject: [PATCH] (improvement)(project) rename llm to llmParser and optimizing python start scripts and optimizing and optimizing build/start scripts (#91) --- assembly/bin/supersonic-build.sh | 12 +- assembly/bin/supersonic-daemon.sh | 262 +++++++++++++----- assembly/build/build.xml | 10 +- chat/core/src/main/python/bin/env.sh | 10 - chat/core/src/main/python/bin/install.sh | 22 -- chat/core/src/main/python/bin/run.sh | 31 --- chat/core/src/main/python/bin/service.sh | 53 ---- .../src/main/python/bin/text2sql_resetting.sh | 12 - .../few_shot_example/sql_exampler.py | 0 .../{llm => }/plugin_call/prompt_construct.py | 0 .../main/python/{llm => }/plugin_call/run.py | 0 .../preset_retrieval/preset_query_db.py | 0 .../python/{llm => }/preset_retrieval/run.py | 0 chat/core/src/main/python/requirements.txt | 3 +- .../src/main/python/{llm => }/run_config.py | 7 +- .../main/python/{llm => }/sql/constructor.py | 0 .../{llm => }/sql/examples_reload_run.py | 14 +- .../python/{llm => }/sql/output_parser.py | 0 .../main/python/{llm => }/sql/prompt_maker.py | 0 .../core/src/main/python/{llm => }/sql/run.py | 0 ...api_service.py => supersonic_llmparser.py} | 8 + .../{llm => }/util/chromadb_instance.py | 0 .../python/{llm => }/util/llm_instance.py | 0 .../main/python/{llm => }/util/text2vec.py | 0 launchers/chat/src/main/bin/env.sh | 3 - launchers/chat/src/main/bin/run.sh | 38 --- launchers/chat/src/main/bin/service.sh | 55 ---- .../src/main/resources/application-local.yaml | 2 +- .../main/resources/optimization.properties | 10 + launchers/semantic/src/main/bin/env.sh | 3 - launchers/semantic/src/main/bin/run.sh | 38 --- launchers/semantic/src/main/bin/service.sh | 55 ---- launchers/standalone/src/main/bin/env.sh | 3 - launchers/standalone/src/main/bin/run.sh | 38 --- launchers/standalone/src/main/bin/service.sh | 55 ---- 35 files changed, 237 insertions(+), 507 deletions(-) delete mode 100644 chat/core/src/main/python/bin/env.sh delete mode 100755 chat/core/src/main/python/bin/install.sh delete mode 100755 chat/core/src/main/python/bin/run.sh delete mode 100755 chat/core/src/main/python/bin/service.sh delete mode 100644 chat/core/src/main/python/bin/text2sql_resetting.sh rename chat/core/src/main/python/{llm => }/few_shot_example/sql_exampler.py (100%) rename chat/core/src/main/python/{llm => }/plugin_call/prompt_construct.py (100%) rename chat/core/src/main/python/{llm => }/plugin_call/run.py (100%) rename chat/core/src/main/python/{llm => }/preset_retrieval/preset_query_db.py (100%) rename chat/core/src/main/python/{llm => }/preset_retrieval/run.py (100%) rename chat/core/src/main/python/{llm => }/run_config.py (75%) rename chat/core/src/main/python/{llm => }/sql/constructor.py (100%) rename chat/core/src/main/python/{llm => }/sql/examples_reload_run.py (72%) rename chat/core/src/main/python/{llm => }/sql/output_parser.py (100%) rename chat/core/src/main/python/{llm => }/sql/prompt_maker.py (100%) rename chat/core/src/main/python/{llm => }/sql/run.py (100%) rename chat/core/src/main/python/{llm/api_service.py => supersonic_llmparser.py} (96%) rename chat/core/src/main/python/{llm => }/util/chromadb_instance.py (100%) rename chat/core/src/main/python/{llm => }/util/llm_instance.py (100%) rename chat/core/src/main/python/{llm => }/util/text2vec.py (100%) delete mode 100644 launchers/chat/src/main/bin/env.sh delete mode 100755 launchers/chat/src/main/bin/run.sh delete mode 100755 launchers/chat/src/main/bin/service.sh create mode 100644 launchers/chat/src/main/resources/optimization.properties delete mode 100644 launchers/semantic/src/main/bin/env.sh delete mode 100755 launchers/semantic/src/main/bin/run.sh delete mode 100755 launchers/semantic/src/main/bin/service.sh delete mode 100644 launchers/standalone/src/main/bin/env.sh delete mode 100755 launchers/standalone/src/main/bin/run.sh delete mode 100755 launchers/standalone/src/main/bin/service.sh diff --git a/assembly/bin/supersonic-build.sh b/assembly/bin/supersonic-build.sh index 8d7f5b585..6a11b2165 100644 --- a/assembly/bin/supersonic-build.sh +++ b/assembly/bin/supersonic-build.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash +# pip path +pip_path="/usr/local/bin/pip3" + sbinDir=$(cd "$(dirname "$0")"; pwd) baseDir=$(cd "$sbinDir/.." && pwd -P) runtimeDir=$baseDir/runtime @@ -14,7 +17,9 @@ rm -fr dist mvn -f $baseDir/../ clean package -DskipTests #2. move package to build -cp $baseDir/../launchers/standalone/target/*.tar.gz ${buildDir}/supersonic.tar.gz +cp $baseDir/../launchers/semantic/target/*.tar.gz ${buildDir}/supersonic-semantic.tar.gz +cp $baseDir/../launchers/chat/target/*.tar.gz ${buildDir}/supersonic-chat.tar.gz +cp $baseDir/../launchers/standalone/target/*.tar.gz ${buildDir}/supersonic-standalone.tar.gz #3. build frontend webapp chmod +x $baseDir/../webapp/start-fe-prod.sh @@ -27,3 +32,8 @@ cd $buildDir tar xvf supersonic-webapp.tar.gz mv supersonic-webapp webapp mv webapp ../../launchers/standalone/target/classes + +#5. build backend python modules +requirementPath=$baseDir/../chat/core/src/main/python/requirements.txt +${pip_path} install -r ${requirementPath} +echo "install python modules success" \ No newline at end of file diff --git a/assembly/bin/supersonic-daemon.sh b/assembly/bin/supersonic-daemon.sh index bed31a4fd..42a4a7e9b 100644 --- a/assembly/bin/supersonic-daemon.sh +++ b/assembly/bin/supersonic-daemon.sh @@ -1,5 +1,15 @@ #!/usr/bin/env bash +python_path="/usr/local/bin/python3" +readonly CHAT_APP_NAME="supersonic_chat" +readonly SEMANTIC_APP_NAME="supersonic_semantic" +readonly LLMPARSER_APP_NAME="supersonic_llmparser" +readonly STANDALONE_APP_NAME="supersonic_standalone" +readonly CHAT_SERVICE="chat" +readonly SEMANTIC_SERVICE="semantic" +readonly LLMPARSER_SERVICE="llmparser" +readonly STANDALONE_SERVICE="standalone" + sbinDir=$(cd "$(dirname "$0")"; pwd) baseDir=$(cd "$sbinDir/.." && pwd -P) runtimeDir=$baseDir/../runtime @@ -8,91 +18,203 @@ buildDir=$baseDir/build command=$1 service=$2 +if [ -z "$service" ]; then + service=${STANDALONE_SERVICE} +fi + +app_name=$STANDALONE_APP_NAME +main_class="com.tencent.supersonic.StandaloneLauncher" +model_name=$service + +if [ "$service" == "llmparser" ]; then + model_name=${STANDALONE_SERVICE} +fi + cd $baseDir -if [[ "$service" == "semantic" || -z "$service" ]] && [ "$command" != "stop" ]; then - #1. clear file - mkdir -p ${runtimeDir} - rm -fr ${runtimeDir}/* - #2. package lib - tar -zxvf ${buildDir}/supersonic.tar.gz -C ${runtimeDir} - mv ${runtimeDir}/launchers-standalone-* ${runtimeDir}/supersonic-standalone - tar -zxvf ${buildDir}/supersonic-webapp.tar.gz -C ${buildDir} - mkdir -p ${runtimeDir}/supersonic-standalone/webapp - cp -fr ${buildDir}/supersonic-webapp/* ${runtimeDir}/supersonic-standalone/webapp - rm -fr ${buildDir}/supersonic-webapp -fi -if [[ "$service" == "semantic" ]]; then - json=$(cat ${runtimeDir}/supersonic-semantic/webapp/supersonic.config.json) - json=$(echo $json | jq '.env="semantic"') - echo $json > ${runtimeDir}/supersonic-semantic/webapp/supersonic.config.json -fi +function setMainClass { + if [ "$service" == $CHAT_SERVICE ]; then + main_class="com.tencent.supersonic.ChatLauncher" + elif [ "$service" == $SEMANTIC_SERVICE ]; then + main_class="com.tencent.supersonic.SemanticLauncher" + fi +} + +function setAppName { + if [ "$service" == $CHAT_SERVICE ]; then + app_name=$CHAT_APP_NAME + elif [ "$service" == $SEMANTIC_SERVICE ]; then + app_name=$SEMANTIC_APP_NAME + elif [ "$service" == $LLMPARSER_SERVICE ]; then + app_name=$LLMPARSER_APP_NAME + fi +} + +function setEnvToWeb { + if [[ "$service" == $CHAT_SERVICE || "$service" == $SEMANTIC_SERVICE ]]; then + json='{"env": "'$service'"}' + echo $json > ${runtimeDir}/supersonic-${model_name}/webapp/supersonic.config.json + fi +} + +function resetEnvironment { + if [[ "$command" == "start" || "$command" == "restart" ]]; then + #1. clear file + mkdir -p ${runtimeDir} + rm -fr ${runtimeDir}/supersonic-${model_name} + #2. package lib + tar -zxvf ${buildDir}/supersonic-${model_name}.tar.gz -C ${runtimeDir} + mv ${runtimeDir}/launchers-${model_name}-* ${runtimeDir}/supersonic-${model_name} + + tar -zxvf ${buildDir}/supersonic-webapp.tar.gz -C ${buildDir} + mkdir -p ${runtimeDir}/supersonic-${model_name}/webapp + cp -fr ${buildDir}/supersonic-webapp/* ${runtimeDir}/supersonic-${model_name}/webapp + rm -fr ${buildDir}/supersonic-webapp + fi +} + +setAppName +resetEnvironment +setEnvToWeb +setMainClass + +function runJavaService { + javaRunDir=${runtimeDir}/supersonic-${model_name} + local_app_name=$1 + libDir=$javaRunDir/lib + confDir=$javaRunDir/conf + + CLASSPATH="" + CLASSPATH=$CLASSPATH:$confDir + + for jarPath in $libDir/*.jar; do + CLASSPATH=$CLASSPATH:$jarPath + done + + export CLASSPATH + export LANG="zh_CN.UTF-8" + + cd $javaRunDir + if [[ "$JAVA_HOME" == "" ]]; then + JAVA_HOME=$(ls /usr/jdk64/jdk* -d 2>/dev/null | xargs | awk '{print "'$local_app_name'"}') + fi + export PATH=$JAVA_HOME/bin:$PATH + command="-Dfile.encoding="UTF-8" -Duser.language="Zh" -Duser.region="CN" -Duser.timezone="GMT+08" -Dapp_name=${local_app_name} -Xms1024m -Xmx2048m "$main_class + + mkdir -p $javaRunDir/logs + if [[ "$is_test" == "true" ]]; then + java -Dspring.profiles.active="dev" $command >/dev/null 2>$javaRunDir/logs/error.log & + else + java $command $javaRunDir >/dev/null 2>$javaRunDir/logs/error.log & + fi +} + +function runPythonService { + pythonRunDir=${runtimeDir}/supersonic-${model_name}/llmparser + cd $pythonRunDir + nohup ${python_path} supersonic_llmparser.py > $pythonRunDir/llmparser.log 2>&1 & + sleep 4 +} + +function reloadExamples { + pythonRunDir=${runtimeDir}/supersonic-${model_name}/llmparser + cd $pythonRunDir/sql + ${python_path} examples_reload_run.py +} + +function getProcesName { + process_name=$main_class + if [[ ${app_name} == $LLMPARSER_APP_NAME ]]; then + process_name=$app_name + fi + echo $process_name +} + +function start() +{ + local_app_name=$1 + pid=$(ps aux |grep ${local_app_name} | grep -v grep | awk '{print $2}') + if [[ "$pid" == "" ]]; then + if [[ ${local_app_name} == $LLMPARSER_APP_NAME ]]; then + runPythonService ${local_app_name} + else + runJavaService ${local_app_name} + fi + else + echo "Process (PID = $pid) is running." + return 1 + fi +} + +function stop() +{ + pid=$(ps aux | grep $1 | grep -v grep | awk '{print $2}') + if [[ "$pid" == "" ]]; then + echo "Process $1 is not running !" + return 1 + else + kill -9 $pid + echo "Process (PID = $pid) is killed !" + return 0 + fi +} + +function reload() +{ + if [[ $1 == $LLMPARSER_APP_NAME ]]; then + reloadExamples + fi +} -if [[ "$service" == "chat" ]]; then - json=$(cat ${runtimeDir}/supersonic-chat/webapp/supersonic.config.json) - json=$(echo $json | jq '.env="chat"') - echo $json > ${runtimeDir}/supersonic-chat/webapp/supersonic.config.json -fi -echo $command -echo $service case "$command" in start) - if [[ "$service" == "semantic" ]];then - echo -e "Starting semantic java service" - sh ${runtimeDir}/supersonic-semantic/bin/service.sh start - elif [[ "$service" == "chat" ]];then - echo -e "Starting chat java service" - sh ${runtimeDir}/supersonic-chat/bin/service.sh start - elif [[ "$service" == "llmparser" ]];then - echo -e "Starting llmparser python service" - sh ${runtimeDir}/supersonic-standalone/llm/bin/service.sh start - elif [[ -z "$service" ]]; then - echo -e "Starting supersonic services" - sh ${runtimeDir}/supersonic-standalone/bin/service.sh start - sh ${runtimeDir}/supersonic-standalone/llm/bin/service.sh start + if [ "$service" == $STANDALONE_SERVICE ]; then + echo "Starting $LLMPARSER_APP_NAME" + start $LLMPARSER_APP_NAME + echo "Starting $app_name" + start $app_name else - echo "Use command {chat|semantic|llmparser} to run." + echo "Starting $app_name" + start $app_name fi + echo "Start success" ;; stop) - if [[ "$service" == "semantic" ]];then - echo -e "Stopping semantic java service" - sh ${runtimeDir}/supersonic-semantic/bin/service.sh stop - elif [[ "$service" == "chat" ]];then - echo -e "Stopping chat java service" - sh ${runtimeDir}/supersonic-chat/bin/service.sh stop - elif [[ "$service" == "llmparser" ]];then - echo -e "Stopping llmparser python service" - sh ${runtimeDir}/supersonic-standalone/llm/bin/service.sh stop - elif [[ -z "$service" ]]; then - echo -e "Stopping supersonic services" - sh ${runtimeDir}/supersonic-standalone/bin/service.sh stop - sh ${runtimeDir}/supersonic-standalone/llm/bin/service.sh stop + if [ "$service" == $STANDALONE_SERVICE ]; then + echo "Stopping $LLMPARSER_APP_NAME" + stop $LLMPARSER_APP_NAME + echo "Stopping $app_name" + stop $app_name else - echo "Use command {chat|semantic|llmparser} to run." + echo "Stopping $app_name" + stop ${app_name} fi + echo "Stop success" + ;; + reload) + echo "Reloading ${app_name}" + reload ${app_name} + echo "Reload success" ;; restart) - if [[ "$service" == "semantic" ]];then - echo -e "Restarting semantic java service" - sh ${runtimeDir}/supersonic-semantic/bin/service.sh restart - elif [[ "$service" == "chat" ]];then - echo -e "Restarting chat java service" - sh ${runtimeDir}/supersonic-chat/bin/service.sh restart - elif [[ "$service" == "llmparser" ]];then - echo -e "Restarting llmparser python service" - sh ${runtimeDir}/supersonic-standalone/llm/bin/service.sh restart - elif [[ -z "$service" ]]; then - echo -e "Restarting supersonic services" - sh ${runtimeDir}/supersonic-standalone/bin/service.sh restart - sh ${runtimeDir}/supersonic-standalone/llm/bin/service.sh restart + if [ "$service" == $STANDALONE_SERVICE ]; then + echo "Stopping ${app_name}" + stop ${app_name} + echo "Stopping ${LLMPARSER_APP_NAME}" + stop $LLMPARSER_APP_NAME + echo "Starting ${LLMPARSER_APP_NAME}" + start $LLMPARSER_APP_NAME + echo "Starting ${app_name}" + start ${app_name} else - echo "Use command {chat|semantic|llmparser} to run." + echo "Stopping ${app_name}" + stop ${app_name} + echo "Starting ${app_name}" + start ${app_name} fi + echo "Restart success" ;; *) - echo "Use command {start|stop|status|restart} to run." + echo "Use command {start|stop|restart} to run." exit 1 -esac - -exit 0 +esac \ No newline at end of file diff --git a/assembly/build/build.xml b/assembly/build/build.xml index 29d0806a6..2e3341a92 100644 --- a/assembly/build/build.xml +++ b/assembly/build/build.xml @@ -6,14 +6,6 @@ tar.gz - - - ${project.basedir}/src/main/bin - bin - 0777 - 0755 - - ${project.basedir}/src/main/resources conf @@ -30,7 +22,7 @@ ${project.basedir}/../../chat/core/src/main/python - llm + llmparser 0777 0755 diff --git a/chat/core/src/main/python/bin/env.sh b/chat/core/src/main/python/bin/env.sh deleted file mode 100644 index 7043edb16..000000000 --- a/chat/core/src/main/python/bin/env.sh +++ /dev/null @@ -1,10 +0,0 @@ -# python path -export python_path="/usr/local/bin/python3" -# pip path -export pip_path="/usr/local/bin/pip3" -# host -export llm_host="127.0.0.1" -# port -export llm_port=9092 -# start name -export start_name=api_service \ No newline at end of file diff --git a/chat/core/src/main/python/bin/install.sh b/chat/core/src/main/python/bin/install.sh deleted file mode 100755 index 9e68a6fd2..000000000 --- a/chat/core/src/main/python/bin/install.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash - -binDir=$(cd "$(dirname "$0")"; pwd) -baseDir=$(cd "$binDir/.." && pwd -P) -echo $binDir - -source ${binDir}/env.sh - -${pip_path} install -r $baseDir/requirements.txt - -if ${python_path} -c "import langchain,fastapi,chromadb,tiktoken,uvicorn" >/dev/null 2>&1 -then - echo "install ok, will pass" -else - if [ $? -eq 0 ]; then - echo "install ok" - else - echo "install fail ,pls check your install error log. cmd is : " - echo ${pip_path} install -r $baseDir/requirements.txt - exit 1 - fi -fi \ No newline at end of file diff --git a/chat/core/src/main/python/bin/run.sh b/chat/core/src/main/python/bin/run.sh deleted file mode 100755 index 8f7af2f23..000000000 --- a/chat/core/src/main/python/bin/run.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash - -llm_host=$1 -llm_port=$2 - -binDir=$(cd "$(dirname "$0")"; pwd) -baseDir=$(cd "$binDir/.." && pwd -P) - -source ${baseDir}/bin/env.sh - -if [ "${llm_host}" = "" ] || [ "${llm_port}" = "" ] -then - echo "llm_host llm_port is not set" - exit 1 -fi - - -if [ "${python_path}" = "" ] || [ "${pip_path}" = "" ] -then - echo "please set env value python_path , pip_path to python, pip path by export cmd " - exit 1 -fi - -chmod +x $binDir/install.sh -$binDir/install.sh -if [ $? -ne 0 ]; then - exit 1 -fi - -cd $baseDir/llm -nohup ${python_path} -m uvicorn ${start_name}:app --port ${llm_port} --host ${llm_host} > $baseDir/llm.log 2>&1 & \ No newline at end of file diff --git a/chat/core/src/main/python/bin/service.sh b/chat/core/src/main/python/bin/service.sh deleted file mode 100755 index a1788b5fb..000000000 --- a/chat/core/src/main/python/bin/service.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env bash - -binDir=$(cd "$(dirname "$0")"; pwd) -baseDir=$(cd "$binDir/.." && pwd -P) -source ${baseDir}/bin/env.sh - -command=$1 - -function start() -{ - pid=$(ps aux |grep ${start_name} | grep -v grep ) - if [[ "$pid" == "" ]]; then - $baseDir/bin/run.sh && echo "Process started." - return 0 - else - echo "Process (PID = $pid) is running." - return 1 - fi -} - -function stop() -{ - pid=$(ps aux | grep ${start_name} | grep -v grep | awk '{print $2}') - if [[ "$pid" == "" ]]; then - echo "Process is not running !" - return 1 - else - kill -9 $pid - echo "Process (PID = $pid) is killed !" - return 0 - fi -} - -case "$command" in - start) - echo -e "Starting ${start_name}" - start - ;; - stop) - echo -e "Stopping ${start_name}" - stop - ;; - restart) - echo -e "Resetting ${start_name}E" - stop - start - ;; - *) - echo "Use command {start|stop|status|restart} to run." - exit 1 -esac - -exit 0 diff --git a/chat/core/src/main/python/bin/text2sql_resetting.sh b/chat/core/src/main/python/bin/text2sql_resetting.sh deleted file mode 100644 index ed0146a50..000000000 --- a/chat/core/src/main/python/bin/text2sql_resetting.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -llm_host=$1 -llm_port=$2 - -baseDir=$(cd "$binDir/.." && pwd -P) - -cd $baseDir/llm/sql - -${python_path} examples_reload_run.py ${llm_port} ${llm_host} - - - diff --git a/chat/core/src/main/python/llm/few_shot_example/sql_exampler.py b/chat/core/src/main/python/few_shot_example/sql_exampler.py similarity index 100% rename from chat/core/src/main/python/llm/few_shot_example/sql_exampler.py rename to chat/core/src/main/python/few_shot_example/sql_exampler.py diff --git a/chat/core/src/main/python/llm/plugin_call/prompt_construct.py b/chat/core/src/main/python/plugin_call/prompt_construct.py similarity index 100% rename from chat/core/src/main/python/llm/plugin_call/prompt_construct.py rename to chat/core/src/main/python/plugin_call/prompt_construct.py diff --git a/chat/core/src/main/python/llm/plugin_call/run.py b/chat/core/src/main/python/plugin_call/run.py similarity index 100% rename from chat/core/src/main/python/llm/plugin_call/run.py rename to chat/core/src/main/python/plugin_call/run.py diff --git a/chat/core/src/main/python/llm/preset_retrieval/preset_query_db.py b/chat/core/src/main/python/preset_retrieval/preset_query_db.py similarity index 100% rename from chat/core/src/main/python/llm/preset_retrieval/preset_query_db.py rename to chat/core/src/main/python/preset_retrieval/preset_query_db.py diff --git a/chat/core/src/main/python/llm/preset_retrieval/run.py b/chat/core/src/main/python/preset_retrieval/run.py similarity index 100% rename from chat/core/src/main/python/llm/preset_retrieval/run.py rename to chat/core/src/main/python/preset_retrieval/run.py diff --git a/chat/core/src/main/python/requirements.txt b/chat/core/src/main/python/requirements.txt index 44750f464..a5a48d046 100644 --- a/chat/core/src/main/python/requirements.txt +++ b/chat/core/src/main/python/requirements.txt @@ -4,5 +4,4 @@ fastapi==0.95.1 chromadb==0.3.21 tiktoken==0.3.3 uvicorn[standard]==0.21.1 - - +pandas==1.5.3 \ No newline at end of file diff --git a/chat/core/src/main/python/llm/run_config.py b/chat/core/src/main/python/run_config.py similarity index 75% rename from chat/core/src/main/python/llm/run_config.py rename to chat/core/src/main/python/run_config.py index b5a0a9c1b..e0fe5f1aa 100644 --- a/chat/core/src/main/python/llm/run_config.py +++ b/chat/core/src/main/python/run_config.py @@ -3,6 +3,9 @@ import os PROJECT_DIR_PATH = os.path.dirname(os.path.abspath(__file__)) +LLMPARSER_HOST = "127.0.0.1" +LLMPARSER_PORT = 9092 + MODEL_NAME = "gpt-3.5-turbo-16k" OPENAI_API_KEY = "YOUR_API_KEY" @@ -20,4 +23,6 @@ HF_TEXT2VEC_MODEL_NAME = "GanymedeNil/text2vec-large-chinese" if __name__ == '__main__': print('PROJECT_DIR_PATH: ', PROJECT_DIR_PATH) print('EMB_MODEL_PATH: ', HF_TEXT2VEC_MODEL_NAME) - print('CHROMA_DB_PERSIST_PATH: ', CHROMA_DB_PERSIST_PATH) \ No newline at end of file + print('CHROMA_DB_PERSIST_PATH: ', CHROMA_DB_PERSIST_PATH) + print('LLMPARSER_HOST: ', LLMPARSER_HOST) + print('LLMPARSER_PORT: ', LLMPARSER_PORT) \ No newline at end of file diff --git a/chat/core/src/main/python/llm/sql/constructor.py b/chat/core/src/main/python/sql/constructor.py similarity index 100% rename from chat/core/src/main/python/llm/sql/constructor.py rename to chat/core/src/main/python/sql/constructor.py diff --git a/chat/core/src/main/python/llm/sql/examples_reload_run.py b/chat/core/src/main/python/sql/examples_reload_run.py similarity index 72% rename from chat/core/src/main/python/llm/sql/examples_reload_run.py rename to chat/core/src/main/python/sql/examples_reload_run.py index 5d7b72621..65f1e3bed 100644 --- a/chat/core/src/main/python/llm/sql/examples_reload_run.py +++ b/chat/core/src/main/python/sql/examples_reload_run.py @@ -10,11 +10,15 @@ sys.path.append(os.path.dirname(os.path.abspath(__file__))) from run_config import TEXT2DSL_FEW_SHOTS_EXAMPLE_NUM from few_shot_example.sql_exampler import examplars as sql_examplars +from run_config import LLMPARSER_HOST +from run_config import LLMPARSER_PORT -def text2dsl_setting_update(llm_host:str, llm_port:str, + +def text2dsl_setting_update(llm_parser_host:str, llm_parser_port:str, sql_examplars:List[Mapping[str, str]], example_nums:int): - url = f"http://{llm_host}:{llm_port}/query2sql_setting_update/" + url = f"http://{llm_parser_host}:{llm_parser_port}/query2sql_setting_update/" + print("url: ", url) payload = {"sqlExamplars":sql_examplars, "exampleNums":example_nums} headers = {'content-type': 'application/json'} response = requests.post(url, data=json.dumps(payload), headers=headers) @@ -23,9 +27,5 @@ def text2dsl_setting_update(llm_host:str, llm_port:str, if __name__ == "__main__": arguments = sys.argv - - llm_host = str(arguments[1]) - llm_port = str(arguments[2]) - - text2dsl_setting_update(llm_host, llm_port, + text2dsl_setting_update(LLMPARSER_HOST, LLMPARSER_PORT, sql_examplars, TEXT2DSL_FEW_SHOTS_EXAMPLE_NUM) diff --git a/chat/core/src/main/python/llm/sql/output_parser.py b/chat/core/src/main/python/sql/output_parser.py similarity index 100% rename from chat/core/src/main/python/llm/sql/output_parser.py rename to chat/core/src/main/python/sql/output_parser.py diff --git a/chat/core/src/main/python/llm/sql/prompt_maker.py b/chat/core/src/main/python/sql/prompt_maker.py similarity index 100% rename from chat/core/src/main/python/llm/sql/prompt_maker.py rename to chat/core/src/main/python/sql/prompt_maker.py diff --git a/chat/core/src/main/python/llm/sql/run.py b/chat/core/src/main/python/sql/run.py similarity index 100% rename from chat/core/src/main/python/llm/sql/run.py rename to chat/core/src/main/python/sql/run.py diff --git a/chat/core/src/main/python/llm/api_service.py b/chat/core/src/main/python/supersonic_llmparser.py similarity index 96% rename from chat/core/src/main/python/llm/api_service.py rename to chat/core/src/main/python/supersonic_llmparser.py index 4e3140b00..963328a27 100644 --- a/chat/core/src/main/python/llm/api_service.py +++ b/chat/core/src/main/python/supersonic_llmparser.py @@ -2,6 +2,7 @@ import os import logging import sys +import uvicorn sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.append(os.path.dirname(os.path.abspath(__file__))) @@ -20,9 +21,13 @@ from preset_retrieval.preset_query_db import (add2preset_query_collection, updat from plugin_call.run import plugin_selection_run +from run_config import LLMPARSER_HOST +from run_config import LLMPARSER_PORT + app = FastAPI() + @app.post("/query2sql/") async def din_query2sql(query_body: Mapping[str, Any]): if 'queryText' not in query_body: @@ -147,3 +152,6 @@ async def tool_selection(query_body: Mapping[str, Any]): resp = plugin_selection_run(query_text=query_text, plugin_configs=plugin_configs) return resp + +if __name__ == "__main__": + uvicorn.run(app, host=LLMPARSER_HOST, port=LLMPARSER_PORT) diff --git a/chat/core/src/main/python/llm/util/chromadb_instance.py b/chat/core/src/main/python/util/chromadb_instance.py similarity index 100% rename from chat/core/src/main/python/llm/util/chromadb_instance.py rename to chat/core/src/main/python/util/chromadb_instance.py diff --git a/chat/core/src/main/python/llm/util/llm_instance.py b/chat/core/src/main/python/util/llm_instance.py similarity index 100% rename from chat/core/src/main/python/llm/util/llm_instance.py rename to chat/core/src/main/python/util/llm_instance.py diff --git a/chat/core/src/main/python/llm/util/text2vec.py b/chat/core/src/main/python/util/text2vec.py similarity index 100% rename from chat/core/src/main/python/llm/util/text2vec.py rename to chat/core/src/main/python/util/text2vec.py diff --git a/launchers/chat/src/main/bin/env.sh b/launchers/chat/src/main/bin/env.sh deleted file mode 100644 index a5aa5f98e..000000000 --- a/launchers/chat/src/main/bin/env.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash -export APP_NAME=supersonic-chat -export MAIN_CLASS=com.tencent.supersonic.ChatLauncher \ No newline at end of file diff --git a/launchers/chat/src/main/bin/run.sh b/launchers/chat/src/main/bin/run.sh deleted file mode 100755 index 694b87156..000000000 --- a/launchers/chat/src/main/bin/run.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash - -binDir=$(cd "$(dirname "$0")"; pwd) -baseDir=$(cd "$sbinDir/.." && pwd -P) -libDir=$baseDir/lib -confDir=$baseDir/conf -webDir=$baseDir/webapp - -source ${baseDir}/bin/env.sh - - -CLASSPATH="" -CLASSPATH=$CLASSPATH:$confDir - -for jarPath in $libDir/*.jar; do - CLASSPATH=$CLASSPATH:$jarPath -done - - - -export CLASSPATH -export LANG="zh_CN.UTF-8" - -cd $baseDir - -if [[ "$JAVA_HOME" == "" ]]; then - JAVA_HOME=$(ls /usr/jdk64/jdk* -d 2>/dev/null | xargs | awk '{print "'$APP_NAME'"}') -fi -export PATH=$JAVA_HOME/bin:$PATH - -command="-Dfile.encoding="UTF-8" -Duser.language="Zh" -Duser.region="CN" -Duser.timezone="GMT+08" -Xms1024m -Xmx2048m "$MAIN_CLASS - -mkdir -p $baseDir/logs -if [[ "$is_test" == "true" ]]; then - java -Dspring.profiles.active="dev" $command >/dev/null 2>$baseDir/logs/error.log & -else - java $command $baseDir >/dev/null 2>$baseDir/logs/error.log & -fi diff --git a/launchers/chat/src/main/bin/service.sh b/launchers/chat/src/main/bin/service.sh deleted file mode 100755 index 24c32d098..000000000 --- a/launchers/chat/src/main/bin/service.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env bash - -binDir=$(cd "$(dirname "$0")"; pwd) -baseDir=$(cd "$sbinDir/.." && pwd -P) -confDir=$baseDir/conf -source ${baseDir}/bin/env.sh - -command=$1 - -function start() -{ - pid=$(ps aux | grep $MAIN_CLASS | grep -v grep |grep $baseDir | awk '{print "'$APP_NAME'"}') - if [[ "$pid" == "" ]]; then - logs=$baseDir/logs/service.sh.log - env DEPLOY=true $baseDir/bin/run.sh $MAIN_CLASS && echo "Process started, see logs/error with logs/error command" - return 0 - else - echo "Process (PID = $pid) is running." - return 1 - fi -} - -function stop() -{ - pid=$(ps aux | grep $MAIN_CLASS | grep -v grep|grep $baseDir| awk '{print $2}') - if [[ "$pid" == "" ]]; then - echo "Process is not running !" - return 1 - else - kill -9 $pid - echo "Process (PID = $pid) is killed !" - return 0 - fi -} - -case "$command" in - start) - echo -e "Starting $APP_NAME" - start - ;; - stop) - echo -e "Stopping $APP_NAME" - stop - ;; - restart) - echo -e "Resetting $APP_NAME" - stop - start - ;; - *) - echo "Use command {start|stop|status|restart} to run." - exit 1 -esac - -exit 0 diff --git a/launchers/chat/src/main/resources/application-local.yaml b/launchers/chat/src/main/resources/application-local.yaml index ce58b30a1..56919ce15 100644 --- a/launchers/chat/src/main/resources/application-local.yaml +++ b/launchers/chat/src/main/resources/application-local.yaml @@ -13,7 +13,7 @@ spring: password: chat server: - port: 9080 + port: 9082 authentication: enable: true diff --git a/launchers/chat/src/main/resources/optimization.properties b/launchers/chat/src/main/resources/optimization.properties new file mode 100644 index 000000000..bd4e14d4e --- /dev/null +++ b/launchers/chat/src/main/resources/optimization.properties @@ -0,0 +1,10 @@ +one.detection.size=8 +one.detection.max.size=20 +metric.dimension.min.threshold=0.3 +metric.dimension.threshold=0.3 +dimension.value.threshold=0.5 +function.bonus.threshold=201 +long.text.threshold=0.8 +short.text.threshold=0.5 +query.text.length.threshold=10 +candidate.threshold=0.2 diff --git a/launchers/semantic/src/main/bin/env.sh b/launchers/semantic/src/main/bin/env.sh deleted file mode 100644 index 667a9986e..000000000 --- a/launchers/semantic/src/main/bin/env.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash -export APP_NAME=supersonic-semantic -export MAIN_CLASS=com.tencent.supersonic.SemanticLauncher \ No newline at end of file diff --git a/launchers/semantic/src/main/bin/run.sh b/launchers/semantic/src/main/bin/run.sh deleted file mode 100755 index 79a06ca90..000000000 --- a/launchers/semantic/src/main/bin/run.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash - -binDir=$(cd "$(dirname "$0")"; pwd) -baseDir=$(cd "$binDir/.." && pwd -P) -libDir=$baseDir/lib -confDir=$baseDir/conf -webDir=$baseDir/webapp - -source ${baseDir}/bin/env.sh - - -CLASSPATH="" -CLASSPATH=$CLASSPATH:$confDir - -for jarPath in $libDir/*.jar; do - CLASSPATH=$CLASSPATH:$jarPath -done - - - -export CLASSPATH -export LANG="zh_CN.UTF-8" - -cd $baseDir - -if [[ "$JAVA_HOME" == "" ]]; then - JAVA_HOME=$(ls /usr/jdk64/jdk* -d 2>/dev/null | xargs | awk '{print "'$APP_NAME'"}') -fi -export PATH=$JAVA_HOME/bin:$PATH - -command="-Dfile.encoding="UTF-8" -Duser.language="Zh" -Duser.region="CN" -Duser.timezone="GMT+08" -Xms1024m -Xmx2048m "$MAIN_CLASS - -mkdir -p $baseDir/logs -if [[ "$is_test" == "true" ]]; then - java -Dspring.profiles.active="dev" $command >/dev/null 2>$baseDir/logs/error.log & -else - java $command $baseDir >/dev/null 2>$baseDir/logs/error.log & -fi diff --git a/launchers/semantic/src/main/bin/service.sh b/launchers/semantic/src/main/bin/service.sh deleted file mode 100755 index f3374d01e..000000000 --- a/launchers/semantic/src/main/bin/service.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env bash - -binDir=$(cd "$(dirname "$0")"; pwd) -baseDir=$(cd "$binDir/.." && pwd -P) -confDir=$baseDir/conf -source ${baseDir}/bin/env.sh - -command=$1 - -function start() -{ - pid=$(ps aux | grep $MAIN_CLASS | grep -v grep |grep $baseDir | awk '{print "'$APP_NAME'"}') - if [[ "$pid" == "" ]]; then - logs=$baseDir/logs/service.sh.log - env DEPLOY=true $baseDir/bin/run.sh $MAIN_CLASS && echo "Process started, see logs/error with logs/error command" - return 0 - else - echo "Process (PID = $pid) is running." - return 1 - fi -} - -function stop() -{ - pid=$(ps aux | grep $MAIN_CLASS | grep -v grep|grep $baseDir| awk '{print $2}') - if [[ "$pid" == "" ]]; then - echo "Process is not running !" - return 1 - else - kill -9 $pid - echo "Process (PID = $pid) is killed !" - return 0 - fi -} - -case "$command" in - start) - echo -e "Starting $APP_NAME" - start - ;; - stop) - echo -e "Stopping $APP_NAME" - stop - ;; - restart) - echo -e "Resetting $APP_NAME" - stop - start - ;; - *) - echo "Use command {start|stop|status|restart} to run." - exit 1 -esac - -exit 0 diff --git a/launchers/standalone/src/main/bin/env.sh b/launchers/standalone/src/main/bin/env.sh deleted file mode 100644 index 2ef70172e..000000000 --- a/launchers/standalone/src/main/bin/env.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash -export APP_NAME=supersonic-standalone -export MAIN_CLASS=com.tencent.supersonic.StandaloneLauncher diff --git a/launchers/standalone/src/main/bin/run.sh b/launchers/standalone/src/main/bin/run.sh deleted file mode 100755 index 79a06ca90..000000000 --- a/launchers/standalone/src/main/bin/run.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash - -binDir=$(cd "$(dirname "$0")"; pwd) -baseDir=$(cd "$binDir/.." && pwd -P) -libDir=$baseDir/lib -confDir=$baseDir/conf -webDir=$baseDir/webapp - -source ${baseDir}/bin/env.sh - - -CLASSPATH="" -CLASSPATH=$CLASSPATH:$confDir - -for jarPath in $libDir/*.jar; do - CLASSPATH=$CLASSPATH:$jarPath -done - - - -export CLASSPATH -export LANG="zh_CN.UTF-8" - -cd $baseDir - -if [[ "$JAVA_HOME" == "" ]]; then - JAVA_HOME=$(ls /usr/jdk64/jdk* -d 2>/dev/null | xargs | awk '{print "'$APP_NAME'"}') -fi -export PATH=$JAVA_HOME/bin:$PATH - -command="-Dfile.encoding="UTF-8" -Duser.language="Zh" -Duser.region="CN" -Duser.timezone="GMT+08" -Xms1024m -Xmx2048m "$MAIN_CLASS - -mkdir -p $baseDir/logs -if [[ "$is_test" == "true" ]]; then - java -Dspring.profiles.active="dev" $command >/dev/null 2>$baseDir/logs/error.log & -else - java $command $baseDir >/dev/null 2>$baseDir/logs/error.log & -fi diff --git a/launchers/standalone/src/main/bin/service.sh b/launchers/standalone/src/main/bin/service.sh deleted file mode 100755 index f3374d01e..000000000 --- a/launchers/standalone/src/main/bin/service.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env bash - -binDir=$(cd "$(dirname "$0")"; pwd) -baseDir=$(cd "$binDir/.." && pwd -P) -confDir=$baseDir/conf -source ${baseDir}/bin/env.sh - -command=$1 - -function start() -{ - pid=$(ps aux | grep $MAIN_CLASS | grep -v grep |grep $baseDir | awk '{print "'$APP_NAME'"}') - if [[ "$pid" == "" ]]; then - logs=$baseDir/logs/service.sh.log - env DEPLOY=true $baseDir/bin/run.sh $MAIN_CLASS && echo "Process started, see logs/error with logs/error command" - return 0 - else - echo "Process (PID = $pid) is running." - return 1 - fi -} - -function stop() -{ - pid=$(ps aux | grep $MAIN_CLASS | grep -v grep|grep $baseDir| awk '{print $2}') - if [[ "$pid" == "" ]]; then - echo "Process is not running !" - return 1 - else - kill -9 $pid - echo "Process (PID = $pid) is killed !" - return 0 - fi -} - -case "$command" in - start) - echo -e "Starting $APP_NAME" - start - ;; - stop) - echo -e "Stopping $APP_NAME" - stop - ;; - restart) - echo -e "Resetting $APP_NAME" - stop - start - ;; - *) - echo "Use command {start|stop|status|restart} to run." - exit 1 -esac - -exit 0