Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 初版 WechatBot ,聊天数据统计、定时聊天总结、用户调用总结、聊天权限管理功能 #2

Merged
merged 44 commits into from
Nov 2, 2024

Conversation

HKAI-Bot
Copy link

@HKAI-Bot HKAI-Bot commented Sep 9, 2024

该版本的机器人具有以下功能:

  • 聊天数据统计
  • 定时聊天总结
  • 用户调用总结
  • 聊天权限管理

Caltucy and others added 26 commits July 19, 2024 11:35
@HKAI-Bot HKAI-Bot added do not merge 【pr使用】添加该标签后,merge-bot 不会合并pr waitForMerge 【pr使用】等待合并 labels Sep 9, 2024
同时修改了原本代码的一处注释错误
…t/doc-optimize

Doc: 修改 README 文档
Copy link
Member

@WendaoLee WendaoLee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我草草看了一下代码,你可以参考其中给出的一些意见进行修改。

之后你如果有空可以看一下相关的代码规范优化你的代码。

"""
conf:字典包含初始的配置信息

"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以考虑参考 Google 的规范 进行注释。

"""
conf:字典包含初始的配置信息

"""
def __init__(self, conf: dict) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对于 dict 的具体结构,你可以试着用 TypedDict 进行定义:

from typing import TypedDict, Optional

class ConfDict(TypedDict):
    key: Optional[str]
    api: Optional[str]

    def __init__(self, conf: ConfDict) -> None:
        self.key = conf.get("key")
        self.api = conf.get("api")

@@ -110,7 +125,55 @@ def get_summary2(self, messages,roomid):
self.LOG.error(f"本次生成总结时出错:{str(e)}")
return "本次无法生成总结。"


def get_summary_of_partly(self, summaries, roomid):
"""根据微信群聊消息列表生成总结,由一名经验丰富的大学物理教授执行。"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

存在奇奇怪怪的内容

@@ -114,6 +117,46 @@ def get_summary2(self, messages,roomid):
self.LOG.error(f"本次生成总结时出错:{str(e)}")
return "本次无法生成总结。"

def get_summary_of_partly(self, summaries, roomid):
"""根据微信群聊消息列表生成总结,由一名经验丰富的大学物理教授执行。"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上,好奇怪

将 roomid, summary 和 ts 插入到 'summary' 表中,其中 date 由 ts 计算得出。
"""
# 连接到数据库
conn = sqlite3.connect(db_path)
Copy link
Member

@WendaoLee WendaoLee Sep 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是一个普遍存在的问题:

对于数据库相关的处理代码你没有放在 try except 中,于是错误的抛出会被上层的捕捉,当错误消息本身没有说明清除时。在日志中难以体现错误发生在哪里。

上面的 store_message 中的:

 model_name = get_gptmodel_name()
 token = num_tokens_from_string(msg.get('content'), model_name)

就是因为这个问题,在用户的模型存在问题时会抛出让人难以定位的消息。

Copy link
Member

@WendaoLee WendaoLee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我尝试部署你这版wechatbot时发现的问题

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

由于github review 只能在变动的更改上评论,所以我就在这里说了:

store_message 这个函数存在问题:

def store_message(msg):
    """将消息存储到数据库的 'messages' 表中"""
    conn = sqlite3.connect(db_path)
    c = conn.cursor()
    model_name = get_gptmodel_name()
    token = num_tokens_from_string(msg.get('content'), model_name)
    msg_data = (
        msg.get('id'),
        msg.get('type'),
        msg.get('sender'),
        msg.get('roomid'),
        msg.get('content'),
        msg.get('thumb'),
        msg.get('extra'),
        msg.get('sign'),
        msg.get('ts'),
        msg.get('xml'),
        int(msg.get('is_self', False)),
        int(msg.get('is_group', True)),
        token
    )

token = num_tokens_from_string(msg.get('content'), model_name) 只能对 gpt 系的模型生效。因此 moonshot 之类的模型会因为模型名不匹配出问题。

@WendaoLee WendaoLee added readyForMerge 【pr使用】以普通merge方式合并分支 and removed do not merge 【pr使用】添加该标签后,merge-bot 不会合并pr labels Nov 2, 2024
@WendaoLee WendaoLee merged commit c1062cd into master Nov 2, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
readyForMerge 【pr使用】以普通merge方式合并分支 waitForMerge 【pr使用】等待合并
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants