aaaa
This commit is contained in:
@@ -41,6 +41,9 @@ def chunks_embedding(texts: list[str], api_key: str) -> list[list[float]]:
|
||||
def main(text: str, api_key: str):
|
||||
|
||||
vector = chunks_embedding([text], api_key)[0]
|
||||
|
||||
return {
|
||||
'vector': vector
|
||||
'vector': {
|
||||
'vector': vector
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,27 @@
|
||||
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 main(status_code: float, body: str):
|
||||
try:
|
||||
check_status(status_code, body)
|
||||
data = parse_response(status_code, body)
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
urls = body["data"]["urls"]
|
||||
urls = data["urls"]
|
||||
|
||||
return {
|
||||
"urls": urls,
|
||||
|
||||
@@ -26,15 +26,4 @@ def main(status_code: float, body: str):
|
||||
return {
|
||||
"task_id": task_id,
|
||||
"is_new_task": is_new_task
|
||||
}
|
||||
|
||||
def test():
|
||||
import json
|
||||
with open("nodes\parse_register.json", "r") as f:
|
||||
data = json.load(f)
|
||||
status_code = data["status_code"]
|
||||
body = data["body"]
|
||||
res = main(status_code, body)
|
||||
print(res)
|
||||
|
||||
test()
|
||||
}
|
||||
@@ -1,20 +1,27 @@
|
||||
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 main(status_code: float, body: str):
|
||||
try:
|
||||
check_status(status_code, body)
|
||||
data = parse_response(status_code, body)
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
urls_result = body["data"]
|
||||
|
||||
return {
|
||||
"add_urls_result": urls_result
|
||||
"add_urls_result": data
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user