FoloToy / folotoy-server-self-hosting

Config files for self-hosting the FoloToy Server. Documents: https://docs.folotoy.com
https://tool.folotoy.com
GNU General Public License v3.0
469 stars 85 forks source link

通过MQTT动态加载角色配置出错 #179

Open deerleo opened 5 months ago

deerleo commented 5 months ago

校验过,也能正常使用,但是通过mqtt发送load_roles_config消息之后无法加载,报错

folotoy-1  | 2024-06-04 12:58:34,812 - DEBUG - Received /sys/config: message data: {"msgId":901541,"identifier":"load_roles_config"}
folotoy-1  | Exception in thread paho-mqtt-client-folotoy:
folotoy-1  | Traceback (most recent call last):
folotoy-1  |   File "/usr/local/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
folotoy-1  |     self.run()
folotoy-1  |   File "/usr/local/lib/python3.11/threading.py", line 975, in run
folotoy-1  |     self._target(*self._args, **self._kwargs)
folotoy-1  |   File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 4517, in _thread_main
folotoy-1  |     self.loop_forever(retry_first_connection=True)
folotoy-1  |   File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 2291, in loop_forever
folotoy-1  |     rc = self._loop(timeout)
folotoy-1  |          ^^^^^^^^^^^^^^^^^^^
folotoy-1  |   File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 1680, in _loop
folotoy-1  |     rc = self.loop_read()
folotoy-1  |          ^^^^^^^^^^^^^^^^
folotoy-1  |   File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 2094, in loop_read
folotoy-1  |     rc = self._packet_read()
folotoy-1  |          ^^^^^^^^^^^^^^^^^^^
folotoy-1  |   File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 3137, in _packet_read
folotoy-1  |     rc = self._packet_handle()
folotoy-1  |          ^^^^^^^^^^^^^^^^^^^^^
folotoy-1  |   File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 3803, in _packet_handle
folotoy-1  |     return self._handle_publish()
folotoy-1  |            ^^^^^^^^^^^^^^^^^^^^^^
folotoy-1  |   File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 4140, in _handle_publish
folotoy-1  |     self._handle_on_message(message)
folotoy-1  |   File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 4496, in _handle_on_message
folotoy-1  |     on_message(self, self._userdata, message)
folotoy-1  |   File "core/folotoy_app.py", line 130, in core.folotoy_app.FolotoyApp.start.on_message
folotoy-1  |   File "core/folotoy_app.py", line 106, in core.folotoy_app.FolotoyApp.process_mqtt_message
folotoy-1  |   File "core/folotoy_msg_processor.py", line 121, in core.folotoy_msg_processor.FolotoyMsgProcessor.process_system_config
folotoy-1  | AttributeError: 'str' object has no attribute 'get'

以下是Roles.json

(SN和Key等信息已经用****号脱敏代替),以下是Json文件

{
    "1": {
        "start_text": "你好,我是陪伴兔,请问有什么我可以帮助你的吗?",
        "prompt": "你扮演一个孩子的小伙伴,名字叫陪伴兔,性格和善,说话活泼可爱,对孩子充满爱心,经常赞赏和鼓励孩子,用5岁孩子容易理解语言提供有趣和创新的回答,每次回复根据聊天主题询问她的看法以激发她的思考和好奇心。"
    },
    "2": {
        "start_text": "你好,俺是东北兔,请问有什么俺可以帮助你的吗?",
        "prompt": "你是一个知识渊博,乐于助人的智能机器人,你的名字叫“东北兔”,你的任务是陪我聊天,请用简短的对话方式,用中文讲一段话,每次回答不超过50个字!"
    },
    "3": {
        "start_text": "Hi, I'm Fofo. Nice to meet you.",
        "prompt": "You're a knowledgeable and helpful AI named \"Fofo\". Your task is to chat with me. Please respond in English, keeping your answers brief – no more than 50 words each time!"
    },
    "4": {
        "start_text": "你好,额是夸夸兔,请问有什么额可以帮助你的吗? ",
        "prompt": "夸夸我"
    },
    "5": {
        "start_text": "你好,我是口算兔,我们一起来玩玩口算游戏吧?",
        "prompt": "我是一个6岁小朋友,你陪我玩口算游戏。你出题,我回答结果。如果答对了你就说好棒,答错了你就告诉我正确答案,并且鼓励我。你一题一题的出,我一个个回答。不要有太多的解释说明。明白了吗?"
    },
    "6": {
        "start_text": "你好,我是台湾兔,请问有什么我可以帮助你的吗?",
        "prompt": "你是一个知识渊博,乐于助人的智能机器人,你的名字叫“台湾兔”,你的任务是陪我聊天,请用简短的对话方式,用中文讲一段话,每次回答不超过50个字!"
    },
    "7": {
        "start_text": "你好,我是小兔,请问有什么我可以帮助你的吗?",
        "prompt": "你是一个知识渊博,乐于助人的智能机器人,你的名字叫“小兔”,你的任务是陪我聊天,请用简短的对话方式,用中文讲一段话,每次回答不超过50个字!"
    },
    "toys": {
        "ec64c98e****": {
            "1": {
                "start_text": "我是来自**",
                "prompt": "你叫太阳,是一只小狗",
                "max_message_count": 5,
                "tts_type": "volcengine-tts",
                "tts_config": {
                    "app_id": "**********",
                    "cluster_id": "volcano_tts",
                    "access_token": "**********",
                    "voice_type": "BV051_streaming",
                    "emotion": "happy",
                    "language": "cn"
                },
                "llm_type": "moonshot",
                "llm_config": {
                    "model": "moonshot-v1-8k",
                    "key": "**********"
                },
                "stt_type": "volcengine-asr",
                "stt_config": {
                    "app_id": "**********",
                    "cluster_id": "volcengine_input_common",
                    "access_token": "**********"
                }
            }
        },
        "30c922f1****": {
            "1": {
                "start_text": "卡通形象——“**”",
                "prompt": "你是**,你是卡通形象",
                "max_message_count": 5,
                "tts_type": "volcengine-tts",
                "tts_config": {
                    "app_id": "**********",
                    "cluster_id": "volcano_tts",
                    "access_token": "**********",
                    "voice_type": "BV051_streaming",
                    "emotion": "happy",
                    "language": "cn"
                },
                "llm_type": "moonshot",
                "llm_config": {
                    "model": "moonshot-v1-8k",
                    "key": "**********"
                },
                "stt_type": "volcengine-asr",
                "stt_config": {
                    "app_id": "**********",
                    "cluster_id": "volcengine_input_common",
                    "access_token": "**********"
                }
            }
        },
        "30c922f1**68": {
            "1": {
                "start_text": "我是12生肖的**",
                "prompt": "你是中国传统文化生肖中的猪属相,昵称是**",
                "max_message_count": 5,
                "tts_type": "volcengine-tts",
                "tts_config": {
                    "app_id": "**********",
                    "cluster_id": "volcano_tts",
                    "access_token": "**********",
                    "voice_type": "BV051_streaming",
                    "emotion": "happy",
                    "language": "cn"
                },
                "llm_type": "moonshot",
                "llm_config": {
                    "model": "moonshot-v1-8k",
                    "key": "**********"
                },
                "stt_type": "volcengine-asr",
                "stt_config": {
                    "app_id": "**********",
                    "cluster_id": "volcengine_input_common",
                    "access_token": "**********"
                }
            }
        },
        "30c922f1**a8": {
            "1": {
                "start_text": "我是**,虚拟形象大使",
                "prompt": "你是小狗,非常可爱",
                "max_message_count": 5,
                "tts_type": "volcengine-tts",
                "tts_config": {
                    "app_id": "**********",
                    "cluster_id": "volcano_tts",
                    "access_token": "**********",
                    "voice_type": "BV051_streaming",
                    "emotion": "happy",
                    "language": "cn"
                },
                "llm_type": "moonshot",
                "llm_config": {
                    "model": "moonshot-v1-8k",
                    "key": "**********"
                },
                "stt_type": "volcengine-asr",
                "stt_config": {
                    "app_id": "**********",
                    "cluster_id": "volcengine_input_common",
                    "access_token": "**********"
                }
            }
        }
    }
}
deerleo commented 5 months ago

提供一些背景信息:

因为roles.json是我们开发的另外一套系统生成的角色配置代码,且不在同一台服务器上,所以用了oss来管理这个roles.json,用ossfs挂载了oss的存储桶,映射到folotoy服务器的/config/roles.json里(权限已修改为666),但是更新完了roles.json并用mqtt发送消息让他重新加载json的时候,这里会报错。如果直接重启容器的话,是没问题,可以正常加载roles.json的配置;

尝试过从oss复制一份roles.json,并保存到和docker-compose同级的config/json文件夹里,但是发送load_roles_config也会出错(这里尚未确认这个复制过来的roles.json权限是否是666,我会重新测试一遍)

Docker-Compose配置如下所示:

version: '3'
volumes:
  emqx-etc: null
  emqx-data: null
  emqx-log: null
services:
  emqx:
    image: emqx/emqx:latest
    restart: always
    ports:
      - 1883:1883/tcp
      - 18083:18083/tcp
      - 8083:8083/tcp
    volumes:
      - emqx-etc:/opt/emqx/etc
      - emqx-data:/opt/emqx/data
      - emqx-log:/opt/emqx/log
    environment:
      EMQX_NODE_NAME: emqx@node1.emqx.io
  nginx:
    image: nginx:latest
    restart: always
    ports:
      - 8082:80/tcp
    volumes:
      - ./audio:/usr/share/nginx/html
  folotoy:
    image: lewangdev/folotoy-server:latest
    restart: always
    ports:
      - 8085:8085/udp
    volumes:
      - ./audio:/audio
      - ./config:/config
      - ../ossfile/20240601/3ed092d92db14dda8ce236d72c488836.json:/config/roles.json
    environment:
    ... 环境变量部分省略
lewangdev commented 5 months ago

把映射直接改成试试:

    volumes:
      - ./audio:/audio
      - ../ossfile/20240601:/config

    environment:
      TZ: Asia/Shanghai

      LOG_LEVEL: DEBUG

      ROLES_FILE_PATH: /config/3ed092d92db14dda8ce236d72c488836.json