(improvement)(project) rename llm to llmParser and optimizing python start scripts and optimizing and optimizing build/start scripts (#91)

This commit is contained in:
lexluo09
2023-09-14 22:30:06 +08:00
committed by GitHub
parent bc69d2221a
commit 30f5fc9ab1
35 changed files with 237 additions and 507 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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 &

View File

@@ -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

View File

@@ -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}

View File

@@ -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

View File

@@ -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)
print('CHROMA_DB_PERSIST_PATH: ', CHROMA_DB_PERSIST_PATH)
print('LLMPARSER_HOST: ', LLMPARSER_HOST)
print('LLMPARSER_PORT: ', LLMPARSER_PORT)

View File

@@ -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)

View File

@@ -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)