直接新建后端把所有逻辑做完了
This commit is contained in:
@@ -1,11 +1,19 @@
|
||||
def check_status(status_code: float, body: str):
|
||||
import json
|
||||
|
||||
def parse_response(status_code: float, body: str):
|
||||
'''
|
||||
检查状态码和约定的返回值
|
||||
并且返回正确的body
|
||||
'''
|
||||
if status_code != 200:
|
||||
raise Exception(f"注册任务失败,状态码:{status_code}")
|
||||
if "code" not in body or body["code"] != 1:
|
||||
|
||||
data = json.loads(body)
|
||||
|
||||
if "code" not in data or data["code"] != 1:
|
||||
raise Exception(f"注册任务失败,返回值:{body}")
|
||||
|
||||
return data["data"]
|
||||
|
||||
def format_rag_context(data: list) -> str:
|
||||
'''
|
||||
@@ -37,11 +45,10 @@ def format_rag_context(data: list) -> str:
|
||||
|
||||
def main(status_code: float, body: str):
|
||||
try:
|
||||
check_status(status_code, body)
|
||||
data = parse_response(status_code, body)
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
data = body["data"]
|
||||
rag_context = format_rag_context(data)
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user