Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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