新增对reload信号的处理,实现对systemctl reload的响应
This commit is contained in:
parent
d661cad5ca
commit
97eef02a92
32
main.py
32
main.py
@ -3,14 +3,36 @@ from fastapi.responses import StreamingResponse, HTMLResponse
|
|||||||
from typing import List
|
from typing import List
|
||||||
import base64
|
import base64
|
||||||
import openai
|
import openai
|
||||||
|
import signal
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
with open("key", "r") as k:
|
key = ""
|
||||||
key = k.read()
|
prompt = ""
|
||||||
|
|
||||||
|
|
||||||
|
def get_key():
|
||||||
|
with open("key", "r") as f:
|
||||||
|
k = f.read()
|
||||||
|
return k
|
||||||
|
|
||||||
|
|
||||||
|
def get_prompt():
|
||||||
|
with open("prompt", "r", encoding="utf-8") as f:
|
||||||
|
p = f.read()
|
||||||
|
return p
|
||||||
|
|
||||||
|
|
||||||
|
def load_config():
|
||||||
|
global key, prompt
|
||||||
|
key = get_key()
|
||||||
|
prompt = get_prompt()
|
||||||
|
|
||||||
|
|
||||||
|
signal.signal(signal.SIGHUP, load_config())
|
||||||
|
|
||||||
|
load_config()
|
||||||
client = openai.OpenAI(api_key=key,
|
client = openai.OpenAI(api_key=key,
|
||||||
base_url="https://open.bigmodel.cn/api/paas/v4/")
|
base_url="https://open.bigmodel.cn/api/paas/v4/")
|
||||||
with open("prompt", "r", encoding="utf-8") as p:
|
|
||||||
prompt = p.read()
|
|
||||||
|
|
||||||
|
|
||||||
# WebSocket连接管理器
|
# WebSocket连接管理器
|
||||||
@ -67,7 +89,7 @@ async def predict(file: UploadFile = File(...)):
|
|||||||
"content": [
|
"content": [
|
||||||
{
|
{
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"text": prompt,
|
"text": get_prompt(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "image_url",
|
"type": "image_url",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user