Bladeren bron

fix: support set_openai_api_key for all channels

lanvent 2 jaren geleden
bovenliggende
commit
45b89218de
5 gewijzigde bestanden met toevoegingen van 6 en 12 verwijderingen
  1. 2 0
      channel/chat_channel.py
  2. 0 4
      channel/wechatmp/active_reply.py
  3. 0 4
      channel/wechatmp/passive_reply.py
  4. 3 3
      docker/entrypoint.sh
  5. 1 1
      nixpacks.toml

+ 2 - 0
channel/chat_channel.py

@@ -48,6 +48,8 @@ class ChatChannel(Channel):
         if first_in:  # context首次传入时,receiver是None,根据类型设置receiver
         if first_in:  # context首次传入时,receiver是None,根据类型设置receiver
             config = conf()
             config = conf()
             cmsg = context["msg"]
             cmsg = context["msg"]
+            user_data = conf().get_user_data(cmsg.from_user_id)
+            context["openai_api_key"] = user_data.get("openai_api_key")
             if context.get("isgroup", False):
             if context.get("isgroup", False):
                 group_name = cmsg.other_user_nickname
                 group_name = cmsg.other_user_nickname
                 group_id = cmsg.other_user_id
                 group_id = cmsg.other_user_id

+ 0 - 4
channel/wechatmp/active_reply.py

@@ -55,10 +55,6 @@ class Query:
                 else:
                 else:
                     context = channel._compose_context(wechatmp_msg.ctype, content, isgroup=False, msg=wechatmp_msg)
                     context = channel._compose_context(wechatmp_msg.ctype, content, isgroup=False, msg=wechatmp_msg)
                 if context:
                 if context:
-                    # set private openai_api_key
-                    # if from_user is not changed in itchat, this can be placed at chat_channel
-                    user_data = conf().get_user_data(from_user)
-                    context["openai_api_key"] = user_data.get("openai_api_key")  # None or user openai_api_key
                     channel.produce(context)
                     channel.produce(context)
                 # The reply will be sent by channel.send() in another thread
                 # The reply will be sent by channel.send() in another thread
                 return "success"
                 return "success"

+ 0 - 4
channel/wechatmp/passive_reply.py

@@ -62,10 +62,6 @@ class Query:
                     logger.debug("[wechatmp] context: {} {} {}".format(context, wechatmp_msg, supported))
                     logger.debug("[wechatmp] context: {} {} {}".format(context, wechatmp_msg, supported))
 
 
                     if supported and context:
                     if supported and context:
-                        # set private openai_api_key
-                        # if from_user is not changed in itchat, this can be placed at chat_channel
-                        user_data = conf().get_user_data(from_user)
-                        context["openai_api_key"] = user_data.get("openai_api_key")
                         channel.running.add(from_user)
                         channel.running.add(from_user)
                         channel.produce(context)
                         channel.produce(context)
                     else:
                     else:

+ 3 - 3
docker/entrypoint.sh

@@ -38,9 +38,9 @@ if [ "$CHATGPT_ON_WECHAT_EXEC" == "" ] ; then
 fi
 fi
 
 
 # modify content in config.json
 # modify content in config.json
-if [ "$OPEN_AI_API_KEY" == "YOUR API KEY" ] || [ "$OPEN_AI_API_KEY" == "" ]; then
-    echo -e "\033[31m[Warning] You need to set OPEN_AI_API_KEY before running!\033[0m"
-fi
+# if [ "$OPEN_AI_API_KEY" == "YOUR API KEY" ] || [ "$OPEN_AI_API_KEY" == "" ]; then
+#     echo -e "\033[31m[Warning] You need to set OPEN_AI_API_KEY before running!\033[0m"
+# fi
 
 
 
 
 # go to prefix dir
 # go to prefix dir

+ 1 - 1
nixpacks.toml

@@ -2,6 +2,6 @@ providers = ['python']
 
 
 [phases.setup]
 [phases.setup]
 nixPkgs = ['python310']
 nixPkgs = ['python310']
-cmds = ['apt-get update','apt-get install -y --no-install-recommends ffmpeg espeak','python -m venv /opt/venv && . /opt/venv/bin/activate && pip install -r requirements-optional.txt']
+cmds = ['apt-get update','apt-get install -y --no-install-recommends ffmpeg espeak libavcodec-extra','python -m venv /opt/venv && . /opt/venv/bin/activate && pip install -r requirements-optional.txt']
 [start]
 [start]
 cmd = "python ./app.py"
 cmd = "python ./app.py"