Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

96 Zeilen
3.3KB

  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. # CHATGPT_ON_WECHAT_PREFIX is empty, use /app
  21. if [ "$CHATGPT_ON_WECHAT_PREFIX" == "" ] ; then
  22. CHATGPT_ON_WECHAT_PREFIX=/app
  23. fi
  24. # CHATGPT_ON_WECHAT_CONFIG_PATH is empty, use '/app/config.json'
  25. if [ "$CHATGPT_ON_WECHAT_CONFIG_PATH" == "" ] ; then
  26. CHATGPT_ON_WECHAT_CONFIG_PATH=$CHATGPT_ON_WECHAT_PREFIX/config.json
  27. fi
  28. # CHATGPT_ON_WECHAT_EXEC is empty, use ‘python app.py’
  29. if [ "$CHATGPT_ON_WECHAT_EXEC" == "" ] ; then
  30. CHATGPT_ON_WECHAT_EXEC="python app.py"
  31. fi
  32. # modify content in config.json
  33. if [ "$OPEN_AI_API_KEY" != "" ] ; then
  34. sed -i "s/\"open_ai_api_key\".*,$/\"open_ai_api_key\": \"$OPEN_AI_API_KEY\",/" $CHATGPT_ON_WECHAT_CONFIG_PATH
  35. else
  36. echo -e "\033[31m[Warning] You need to set OPEN_AI_API_KEY before running!\033[0m"
  37. fi
  38. # use http_proxy as default
  39. if [ "$HTTP_PROXY" != "" ] ; then
  40. sed -i "s/\"proxy\".*,$/\"proxy\": \"$HTTP_PROXY\",/" $CHATGPT_ON_WECHAT_CONFIG_PATH
  41. fi
  42. if [ "$OPEN_AI_PROXY" != "" ] ; then
  43. sed -i "s/\"proxy\".*,$/\"proxy\": \"$OPEN_AI_PROXY\",/" $CHATGPT_ON_WECHAT_CONFIG_PATH
  44. fi
  45. if [ "$SINGLE_CHAT_PREFIX" != "" ] ; then
  46. sed -i "s/\"single_chat_prefix\".*,$/\"single_chat_prefix\": $SINGLE_CHAT_PREFIX,/" $CHATGPT_ON_WECHAT_CONFIG_PATH
  47. fi
  48. if [ "$SINGLE_CHAT_REPLY_PREFIX" != "" ] ; then
  49. sed -i "s/\"single_chat_reply_prefix\".*,$/\"single_chat_reply_prefix\": $SINGLE_CHAT_REPLY_PREFIX,/" $CHATGPT_ON_WECHAT_CONFIG_PATH
  50. fi
  51. if [ "$GROUP_CHAT_PREFIX" != "" ] ; then
  52. sed -i "s/\"group_chat_prefix\".*,$/\"group_chat_prefix\": $GROUP_CHAT_PREFIX,/" $CHATGPT_ON_WECHAT_CONFIG_PATH
  53. fi
  54. if [ "$GROUP_NAME_WHITE_LIST" != "" ] ; then
  55. sed -i "s/\"group_name_white_list\".*,$/\"group_name_white_list\": $GROUP_NAME_WHITE_LIST,/" $CHATGPT_ON_WECHAT_CONFIG_PATH
  56. fi
  57. if [ "$IMAGE_CREATE_PREFIX" != "" ] ; then
  58. sed -i "s/\"image_create_prefix\".*,$/\"image_create_prefix\": $IMAGE_CREATE_PREFIX,/" $CHATGPT_ON_WECHAT_CONFIG_PATH
  59. fi
  60. if [ "$CONVERSATION_MAX_TOKENS" != "" ] ; then
  61. sed -i "s/\"conversation_max_tokens\".*,$/\"conversation_max_tokens\": $CONVERSATION_MAX_TOKENS,/" $CHATGPT_ON_WECHAT_CONFIG_PATH
  62. fi
  63. if [ "$SPEECH_RECOGNITION" != "" ] ; then
  64. sed -i "s/\"speech_recognition\".*,$/\"speech_recognition\": $SPEECH_RECOGNITION,/" $CHATGPT_ON_WECHAT_CONFIG_PATH
  65. fi
  66. if [ "$CHARACTER_DESC" != "" ] ; then
  67. sed -i "s/\"character_desc\".*,$/\"character_desc\": \"$CHARACTER_DESC\",/" $CHATGPT_ON_WECHAT_CONFIG_PATH
  68. fi
  69. if [ "$EXPIRES_IN_SECONDS" != "" ] ; then
  70. sed -i "s/\"expires_in_seconds\".*$/\"expires_in_seconds\": $EXPIRES_IN_SECONDS/" $CHATGPT_ON_WECHAT_CONFIG_PATH
  71. fi
  72. # go to prefix dir
  73. cd $CHATGPT_ON_WECHAT_PREFIX
  74. # excute
  75. $CHATGPT_ON_WECHAT_EXEC