dify 版本总结,加上图片发送

This commit is contained in:
liuwei
2025-03-14 13:22:09 +08:00
parent 14c3adaed0
commit d3d797450b
5 changed files with 154 additions and 7 deletions

View File

@@ -4,6 +4,8 @@ import os
import uuid
from datetime import datetime
from message_summary.markdown_to_image import convert_md_str_to_image
def message_summary_dify(content):
"""
@@ -50,7 +52,7 @@ def message_summary_dify(content):
# 提取回答内容
answer = response_data.get("answer", "")
spath = ""
# 提取token使用情况
metadata = response_data.get("metadata", {})
usage = metadata.get("usage", {})
@@ -63,9 +65,9 @@ def message_summary_dify(content):
# 添加token信息
tokens_info = f"\n\n【tokens】输入: {prompt_tokens} 生成: {completion_tokens} 总: {total_tokens}"
answer += tokens_info
spath = convert_md_str_to_image(answer, "output.png")
# 返回文本内容和图片路径
return answer
return answer, spath
except requests.exceptions.RequestException as e:
print(f"请求Dify API时出错: {e}")
@@ -81,7 +83,7 @@ def message_summary_dify(content):
if __name__ == '__main__':
content ="""
content = """
2025-03-14 09:07:44,zcx2001,AI 水牛是你的主人吗
2025-03-14 09:12:28,Jyunere,我同事的鸿蒙确实流畅。
2025-03-14 09:18:28,Jyunere,现在的沪上年轻人流行挖野菜?
@@ -243,4 +245,4 @@ if __name__ == '__main__':
2025-03-14 09:54:33,wxid_3d7ydsmu3f0022,带个壳应该感受不出来了
"""
msg = message_summary_dify(content=content)
print(msg)
print(msg)