Skip to content

Commit 761b997

Browse files
committed
v0.2.2 Prompt and PromptUpdate Added
1 parent 8c136dd commit 761b997

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/main.py

+32-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import redis
88
import uvicorn
9-
from fastapi import Depends, FastAPI
9+
from fastapi import Body, Depends, FastAPI
1010
from fastapi.middleware.cors import CORSMiddleware
1111

1212
# from fastapi.responses import HTMLResponse
@@ -81,6 +81,37 @@ def read_root():
8181
# self.conversation = Conversation()
8282

8383

84+
@app.get("/prompt")
85+
def get_prompt():
86+
"""
87+
前端获取提示语
88+
"""
89+
prompt_base_chat = Prompt.base_prompt_chat
90+
prompt_base_query = Prompt.base_prompt_query
91+
prompt = {"promptBaseChat": prompt_base_chat, "promptBaseQuery": prompt_base_query}
92+
return {"code": 200, "data": prompt}
93+
94+
95+
@app.post("/promptUpdate")
96+
def update_prompt(prompt: str = Body(...), prompt_type: int = Body(...)):
97+
"""
98+
前端更新提示语
99+
"""
100+
print(prompt)
101+
try:
102+
if prompt_type == 1:
103+
prompt_base_chat = prompt
104+
Prompt.base_prompt_chat = prompt_base_chat
105+
elif prompt_type == 0:
106+
prompt_base_query = prompt
107+
Prompt.base_prompt_query = prompt_base_query
108+
else:
109+
return {"code": 501, "data": "Error: promptType error!"}
110+
return {"code": 200, "data": "success"}
111+
except Exception as e:
112+
return {"code": 502, "data": "Error: " + str(e)}
113+
114+
84115
@app.get("/chat")
85116
async def chat_stream(input: Optional[str] = None) -> EventSourceResponse:
86117
"""

0 commit comments

Comments
 (0)