Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

82 lines
2.7KB

  1. #!/bin/bash
  2. set -e
  3. # build prefix
  4. CHATGPT_ON_WECHAT_PREFIX=${CHATGPT_ON_WECHAT_PREFIX:-""}
  5. # path to config.json
  6. CHATGPT_ON_WECHAT_CONFIG_PATH=${CHATGPT_ON_WECHAT_CONFIG_PATH:-""}
  7. # execution command line
  8. CHATGPT_ON_WECHAT_EXEC=${CHATGPT_ON_WECHAT_EXEC:-""}
  9. OPEN_AI_API_KEY=${OPEN_AI_API_KEY:-""}
  10. SINGLE_CHAT_PREFIX=${SINGLE_CHAT_PREFIX:-""}
  11. SINGLE_CHAT_REPLY_PREFIX=${SINGLE_CHAT_REPLY_PREFIX:-""}
  12. GROUP_CHAT_PREFIX=${GROUP_CHAT_PREFIX:-""}
  13. GROUP_NAME_WHITE_LIST=${GROUP_NAME_WHITE_LIST:-""}
  14. IMAGE_CREATE_PREFIX=${IMAGE_CREATE_PREFIX:-""}
  15. CONVERSATION_MAX_TOKENS=${CONVERSATION_MAX_TOKENS:-""}
  16. CHARACTER_DESC=${CHARACTER_DESC:-""}
  17. # CHATGPT_ON_WECHAT_PREFIX is empty, use /app
  18. if [ "$CHATGPT_ON_WECHAT_PREFIX" == "" ] ; then
  19. CHATGPT_ON_WECHAT_PREFIX=/app
  20. fi
  21. # CHATGPT_ON_WECHAT_CONFIG_PATH is empty, use '/app/config.json'
  22. if [ "$CHATGPT_ON_WECHAT_CONFIG_PATH" == "" ] ; then
  23. CHATGPT_ON_WECHAT_CONFIG_PATH=$CHATGPT_ON_WECHAT_PREFIX/config.json
  24. fi
  25. # CHATGPT_ON_WECHAT_EXEC is empty, use ‘python app.py’
  26. if [ "$CHATGPT_ON_WECHAT_EXEC" == "" ] ; then
  27. CHATGPT_ON_WECHAT_EXEC="python app.py"
  28. fi
  29. # modify content in config.json
  30. if [ "$OPEN_AI_API_KEY" != "" ] ; then
  31. sed -i "2c \"open_ai_api_key\": \"$OPEN_AI_API_KEY\"," $CHATGPT_ON_WECHAT_CONFIG_PATH
  32. else
  33. echo -e "\033[31m[Warning] You need to set OPEN_AI_API_KEY before running!\033[0m"
  34. fi
  35. if [ "$WECHATY_PUPPET_SERVICE_TOKEN" != "" ] ; then
  36. sed -i "3c \"wechaty_puppet_service_token\": \"$WECHATY_PUPPET_SERVICE_TOKEN\"," $CHATGPT_ON_WECHAT_CONFIG_PATH
  37. else
  38. echo -e "\033[31m[Info] You need to set WECHATY_PUPPET_SERVICE_TOKEN if you use wechaty!\033[0m"
  39. fi
  40. if [ "$SINGLE_CHAT_PREFIX" != "" ] ; then
  41. sed -i "4c \"single_chat_prefix\": $SINGLE_CHAT_PREFIX," $CHATGPT_ON_WECHAT_CONFIG_PATH
  42. fi
  43. if [ "$SINGLE_CHAT_REPLY_PREFIX" != "" ] ; then
  44. sed -i "5c \"single_chat_reply_prefix\": $SINGLE_CHAT_REPLY_PREFIX," $CHATGPT_ON_WECHAT_CONFIG_PATH
  45. fi
  46. if [ "$GROUP_CHAT_PREFIX" != "" ] ; then
  47. sed -i "6c \"group_chat_prefix\": $GROUP_CHAT_PREFIX," $CHATGPT_ON_WECHAT_CONFIG_PATH
  48. fi
  49. if [ "$GROUP_NAME_WHITE_LIST" != "" ] ; then
  50. sed -i "7c \"group_name_white_list\": $GROUP_NAME_WHITE_LIST," $CHATGPT_ON_WECHAT_CONFIG_PATH
  51. fi
  52. if [ "$IMAGE_CREATE_PREFIX" != "" ] ; then
  53. sed -i "8c \"image_create_prefix\": $IMAGE_CREATE_PREFIX," $CHATGPT_ON_WECHAT_CONFIG_PATH
  54. fi
  55. if [ "$CONVERSATION_MAX_TOKENS" != "" ] ; then
  56. sed -i "9c \"conversation_max_tokens\": $CONVERSATION_MAX_TOKENS," $CHATGPT_ON_WECHAT_CONFIG_PATH
  57. fi
  58. if [ "$CHARACTER_DESC" != "" ] ; then
  59. sed -i "10c \"character_desc\": \"$CHARACTER_DESC\"" $CHATGPT_ON_WECHAT_CONFIG_PATH
  60. fi
  61. # go to prefix dir
  62. cd $CHATGPT_ON_WECHAT_PREFIX
  63. # excute
  64. $CHATGPT_ON_WECHAT_EXEC