更新pyproject.toml和uv.lock文件,新增ijson和langfuse依赖,同时在对话到工单的分析流程中添加时间范围过滤功能,优化日志记录,支持按时间范围过滤会话数据。新增获取工作流运行信息的方法,并更新意图识别API以支持使用jieba分词。
This commit is contained in:
@@ -84,17 +84,18 @@ async def health_check():
|
||||
return {"status": "ok"}
|
||||
|
||||
@app.get("/query_type", summary="异步检索API")
|
||||
async def query_type(query: str, query_type: str):
|
||||
async def query_type(query: str, query_type: str, workflow_run_id:str):
|
||||
try:
|
||||
# 记录请求
|
||||
logger.info(f"接收到请求: {query}, 类型: {query_type}")
|
||||
logger.info(f"接收到请求: {query}, 类型: {query_type}, workflow_run_id: {workflow_run_id}")
|
||||
|
||||
# 保存 提问、问题类型、当前时间戳到json
|
||||
timestamp = datetime.datetime.now().isoformat()
|
||||
query_data = {
|
||||
"query": query,
|
||||
"query_type": query_type,
|
||||
"timestamp": timestamp
|
||||
"timestamp": timestamp,
|
||||
"workflow_run_id": workflow_run_id
|
||||
}
|
||||
success = True
|
||||
try:
|
||||
|
||||
@@ -197,6 +197,8 @@ class DifyQueryRetrieval:
|
||||
# 将去重后的文档转换为列表
|
||||
deduplicated_documents = list(unique_documents.values())
|
||||
|
||||
if len(deduplicated_documents) == 0:
|
||||
return []
|
||||
# 对所有检索出来的文档进行重排序
|
||||
time_start = time.time()
|
||||
processed_documents = await self.data_post_processor_async(original_query, deduplicated_documents, top_k)
|
||||
|
||||
@@ -244,6 +244,29 @@ class PgSql:
|
||||
raise Exception(f"Error while getting conversation_messages: {error}")
|
||||
return rating
|
||||
|
||||
def get_workflow_run_info(self, workflow_run_id):
|
||||
"""
|
||||
通过msg_id从message_feedbacks中找到对应的rating。
|
||||
:param msg_id: 消息ID (UUID格式)
|
||||
:return: rating 字符串
|
||||
"""
|
||||
with self.pg_sql_lock:
|
||||
rating = None
|
||||
try:
|
||||
with self.connection.cursor() as cursor:
|
||||
# 构建查询语句
|
||||
cursor.execute("""
|
||||
SELECT * FROM workflow_runs WHERE id=%s;
|
||||
""",
|
||||
(workflow_run_id,))
|
||||
# 执行查询
|
||||
result = cursor.fetchone()
|
||||
if result:
|
||||
colnames = [desc[0] for desc in cursor.description]
|
||||
return dict(zip(colnames, result))
|
||||
except (Exception, psycopg2.Error) as error:
|
||||
raise Exception(f"Error while getting conversation_messages: {error}")
|
||||
return None
|
||||
|
||||
class DifyTool:
|
||||
"""
|
||||
@@ -337,6 +360,9 @@ class DifyTool:
|
||||
def get_message_rating(self, msg_id):
|
||||
return self.dify_pgsql.get_message_rating(msg_id)
|
||||
|
||||
def get_workflow_run_info(self, workflow_run_id):
|
||||
return self.dify_pgsql.get_workflow_run_info(workflow_run_id)
|
||||
|
||||
class BaseWorkflowChat:
|
||||
"""
|
||||
工作流对话基类,封装了与Dify API交互的基本功能
|
||||
|
||||
@@ -109,7 +109,7 @@ async def intent_recognize(request: IntentRecognizeRequest):
|
||||
conversation_context=request.conversation_context,
|
||||
chat_history=request.chat_history,
|
||||
previous_slots=request.previous_slots,
|
||||
use_jieba=False,
|
||||
use_jieba=True,
|
||||
enable_query_expansion=True
|
||||
)
|
||||
|
||||
@@ -175,7 +175,7 @@ if __name__ == "__main__":
|
||||
"rag2_0.dify.intent_recognition_api:app",
|
||||
host="0.0.0.0",
|
||||
port=8001,
|
||||
reload=False, # 开发环境启用热重载
|
||||
reload=True, # 开发环境启用热重载
|
||||
workers=1 # 生产环境可以增加worker数量
|
||||
)
|
||||
# 生产环境可以使用以下命令启动:
|
||||
|
||||
Reference in New Issue
Block a user