添加日志输出

main
fanpt 1 year ago
parent 3fe1eb0f67
commit dbd1d36344

@ -78,8 +78,9 @@ def update_kb(kb_name, qa_service, path, max_knowledge_bases):
save_knowledge_bases(recent_knowledge_bases)
os.remove(path)
logger.info(f"Knowledge base updated: {kb_name}")
return {"status": "success", "message": "数据库正在更新中"}
logger.info(f"Knowledge base updated: {kb_name}\n"
f"Please wait while the database is being updated···")
def fetch_and_write_data(api_url, path):
"""从API获取数据并写入文件"""
@ -93,7 +94,6 @@ def fetch_and_write_data(api_url, path):
with open(path, "w", encoding="utf-8") as file:
json.dump(question_items, file, ensure_ascii=False, indent=2)
logger.info(f"Data fetched and written to file: {path}")
return True
else:
logger.error(f"Failed to fetch data from API. Status code: {response.status_code}, Response data: {response_data}")
@ -122,8 +122,7 @@ async def save_to_json(question_items: list[QuestionItem], background_tasks: Bac
update_kb, kb_name, qa_service, path, max_knowledge_bases
)
logger.info(f"Data saved to file: {path}, Knowledge base update task scheduled: {kb_name}")
return {"status": "success", "message": "数据库正在更新中"}
return {"status": "success", "message": "Please wait while the database is being updated···"}
except Exception as e:
logger.error(f"Error saving data to file or scheduling knowledge base update task: {e}")
@ -148,7 +147,11 @@ def match_question(request: QuestionRequest):
response = QuestionResponse(code=200, msg="success", data=result)
stop_time = time.time()
logger.info(f"Matched question in {stop_time - start_time} seconds")
duration = stop_time - start_time
logger.info(f"Matched question in {duration} seconds. "
f"Request: {request} - {query}, "
f"Response: {result}")
return response
except Exception as e:

Loading…
Cancel
Save