No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

118 líneas
4.0KB

  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. OPEN_AI_PROXY=${OPEN_AI_PROXY:-""}
  11. SINGLE_CHAT_PREFIX=${SINGLE_CHAT_PREFIX:-""}
  12. SINGLE_CHAT_REPLY_PREFIX=${SINGLE_CHAT_REPLY_PREFIX:-""}
  13. GROUP_CHAT_PREFIX=${GROUP_CHAT_PREFIX:-""}
  14. GROUP_NAME_WHITE_LIST=${GROUP_NAME_WHITE_LIST:-""}
  15. IMAGE_CREATE_PREFIX=${IMAGE_CREATE_PREFIX:-""}
  16. CONVERSATION_MAX_TOKENS=${CONVERSATION_MAX_TOKENS:-""}
  17. SPEECH_RECOGNITION=${SPEECH_RECOGNITION:-""}
  18. CHARACTER_DESC=${CHARACTER_DESC:-""}
  19. EXPIRES_IN_SECONDS=${EXPIRES_IN_SECONDS:-""}
  20. VOICE_REPLY_VOICE=${VOICE_REPLY_VOICE:-""}
  21. BAIDU_APP_ID=${BAIDU_APP_ID:-""}
  22. BAIDU_API_KEY=${BAIDU_API_KEY:-""}
  23. BAIDU_SECRET_KEY=${BAIDU_SECRET_KEY:-""}
  24. # CHATGPT_ON_WECHAT_PREFIX is empty, use /app
  25. if [ "$CHATGPT_ON_WECHAT_PREFIX" == "" ] ; then
  26. CHATGPT_ON_WECHAT_PREFIX=/app
  27. fi
  28. # CHATGPT_ON_WECHAT_CONFIG_PATH is empty, use '/app/config.json'
  29. if [ "$CHATGPT_ON_WECHAT_CONFIG_PATH" == "" ] ; then
  30. CHATGPT_ON_WECHAT_CONFIG_PATH=$CHATGPT_ON_WECHAT_PREFIX/config.json
  31. fi
  32. # CHATGPT_ON_WECHAT_EXEC is empty, use ‘python app.py’
  33. if [ "$CHATGPT_ON_WECHAT_EXEC" == "" ] ; then
  34. CHATGPT_ON_WECHAT_EXEC="python app.py"
  35. fi
  36. # modify content in config.json
  37. if [ "$OPEN_AI_API_KEY" != "" ] ; then
  38. sed -i "s/\"open_ai_api_key\".*,$/\"open_ai_api_key\": \"$OPEN_AI_API_KEY\",/" $CHATGPT_ON_WECHAT_CONFIG_PATH
  39. else
  40. echo -e "\033[31m[Warning] You need to set OPEN_AI_API_KEY before running!\033[0m"
  41. fi
  42. # use http_proxy as default
  43. if [ "$HTTP_PROXY" != "" ] ; then
  44. sed -i "s/\"proxy\".*,$/\"proxy\": \"$HTTP_PROXY\",/" $CHATGPT_ON_WECHAT_CONFIG_PATH
  45. fi
  46. if [ "$OPEN_AI_PROXY" != "" ] ; then
  47. sed -i "s/\"proxy\".*,$/\"proxy\": \"$OPEN_AI_PROXY\",/" $CHATGPT_ON_WECHAT_CONFIG_PATH
  48. fi
  49. if [ "$SINGLE_CHAT_PREFIX" != "" ] ; then
  50. sed -i "s/\"single_chat_prefix\".*,$/\"single_chat_prefix\": $SINGLE_CHAT_PREFIX,/" $CHATGPT_ON_WECHAT_CONFIG_PATH
  51. fi
  52. if [ "$SINGLE_CHAT_REPLY_PREFIX" != "" ] ; then
  53. sed -i "s/\"single_chat_reply_prefix\".*,$/\"single_chat_reply_prefix\": $SINGLE_CHAT_REPLY_PREFIX,/" $CHATGPT_ON_WECHAT_CONFIG_PATH
  54. fi
  55. if [ "$GROUP_CHAT_PREFIX" != "" ] ; then
  56. sed -i "s/\"group_chat_prefix\".*,$/\"group_chat_prefix\": $GROUP_CHAT_PREFIX,/" $CHATGPT_ON_WECHAT_CONFIG_PATH
  57. fi
  58. if [ "$GROUP_NAME_WHITE_LIST" != "" ] ; then
  59. sed -i "s/\"group_name_white_list\".*,$/\"group_name_white_list\": $GROUP_NAME_WHITE_LIST,/" $CHATGPT_ON_WECHAT_CONFIG_PATH
  60. fi
  61. if [ "$IMAGE_CREATE_PREFIX" != "" ] ; then
  62. sed -i "s/\"image_create_prefix\".*,$/\"image_create_prefix\": $IMAGE_CREATE_PREFIX,/" $CHATGPT_ON_WECHAT_CONFIG_PATH
  63. fi
  64. if [ "$CONVERSATION_MAX_TOKENS" != "" ] ; then
  65. sed -i "s/\"conversation_max_tokens\".*,$/\"conversation_max_tokens\": $CONVERSATION_MAX_TOKENS,/" $CHATGPT_ON_WECHAT_CONFIG_PATH
  66. fi
  67. if [ "$SPEECH_RECOGNITION" != "" ] ; then
  68. sed -i "s/\"speech_recognition\".*,$/\"speech_recognition\": $SPEECH_RECOGNITION,/" $CHATGPT_ON_WECHAT_CONFIG_PATH
  69. fi
  70. if [ "$CHARACTER_DESC" != "" ] ; then
  71. sed -i "s/\"character_desc\".*,$/\"character_desc\": \"$CHARACTER_DESC\",/" $CHATGPT_ON_WECHAT_CONFIG_PATH
  72. fi
  73. if [ "$EXPIRES_IN_SECONDS" != "" ] ; then
  74. sed -i "s/\"expires_in_seconds\".*$/\"expires_in_seconds\": $EXPIRES_IN_SECONDS/" $CHATGPT_ON_WECHAT_CONFIG_PATH
  75. fi
  76. # append
  77. if [ "$BAIDU_SECRET_KEY" != "" ] ; then
  78. sed -i "1a \ \ \"baidu_secret_key\": \"$BAIDU_SECRET_KEY\"," $CHATGPT_ON_WECHAT_CONFIG_PATH
  79. fi
  80. if [ "$BAIDU_API_KEY" != "" ] ; then
  81. sed -i "1a \ \ \"baidu_api_key\": \"$BAIDU_API_KEY\"," $CHATGPT_ON_WECHAT_CONFIG_PATH
  82. fi
  83. if [ "$BAIDU_APP_ID" != "" ] ; then
  84. sed -i "1a \ \ \"baidu_app_id\": \"$BAIDU_APP_ID\"," $CHATGPT_ON_WECHAT_CONFIG_PATH
  85. fi
  86. if [ "$VOICE_REPLY_VOICE" != "" ] ; then
  87. sed -i "1a \ \ \"voice_reply_voice\": $VOICE_REPLY_VOICE," $CHATGPT_ON_WECHAT_CONFIG_PATH
  88. fi
  89. # go to prefix dir
  90. cd $CHATGPT_ON_WECHAT_PREFIX
  91. # excute
  92. $CHATGPT_ON_WECHAT_EXEC