Last active
April 23, 2023 08:36
-
-
Save discountry/f93ddd8f4b4ec3f584501655c778c371 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from flask import Flask | |
| # Get from https://github.com/xtekky/gpt4free/blob/main/ora/README.md | |
| import ora | |
| app = Flask(__name__) | |
| # create model | |
| gpt4_chatbot_ids = ['b8b12eaa-5d47-44d3-92a6-4d706f2bcacf', 'fbe53266-673c-4b70-9d2d-d247785ccd91', 'bd5781cf-727a-45e9-80fd-a3cfce1350c6', '993a0102-d397-47f6-98c3-2587f2c9ec3a', 'ae5c524e-d025-478b-ad46-8843a5745261', 'cc510743-e4ab-485e-9191-76960ecb6040', 'a5cd2481-8e24-4938-aa25-8e26d6233390', '6bca5930-2aa1-4bf4-96a7-bea4d32dcdac', '884a5f2b-47a2-47a5-9e0f-851bbe76b57c', 'd5f3c491-0e74-4ef7-bdca-b7d27c59e6b3', 'd72e83f6-ef4e-4702-844f-cf4bd432eef7', '6e80b170-11ed-4f1a-b992-fd04d7a9e78c', '8ef52d68-1b01-466f-bfbf-f25c13ff4a72', 'd0674e11-f22e-406b-98bc-c1ba8564f749', 'a051381d-6530-463f-be68-020afddf6a8f', '99c0afa1-9e32-4566-8909-f4ef9ac06226', '1be65282-9c59-4a96-99f8-d225059d9001', 'dba16bd8-5785-4248-a8e9-b5d1ecbfdd60', '1731450d-3226-42d0-b41c-4129fe009524', '8e74635d-000e-4819-ab2c-4e986b7a0f48', 'afe7ed01-c1ac-4129-9c71-2ca7f3800b30', 'e374c37a-8c44-4f0e-9e9f-1ad4609f24f5'] | |
| chatbot_id = gpt4_chatbot_ids[0] | |
| model = ora.CompletionModel.load(chatbot_id, 'gpt-4') | |
| @app.route("/") | |
| def index(): | |
| return "<p>Hello, World!</p>" | |
| @app.route("/chat/<chatid>/<message>") | |
| def receive(chatid, message): | |
| try: | |
| response = ora.Completion.create( | |
| model = model, | |
| prompt = message) | |
| reply = response.completion.choices[0].text | |
| return {"chatid": chatid, "reply": reply} | |
| except: | |
| return {"chatid": chatid, "reply": "ChatGPT service error."} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Unit] | |
| Description=gunicorn daemon | |
| Requires=gunicorn.socket | |
| After=network.target | |
| [Service] | |
| Type=notify | |
| # the specific user that our service will run as | |
| User=dev | |
| Group=dev | |
| # another option for an even more restricted service is | |
| # DynamicUser=yes | |
| # see http://0pointer.net/blog/dynamic-users-with-systemd.html | |
| RuntimeDirectory=gunicorn | |
| WorkingDirectory=/home/xxx/gpt4free/client | |
| ExecStart=/home/xxx/.local/bin/gunicorn 'app:app' | |
| ExecReload=/bin/kill -s HUP $MAINPID | |
| KillMode=mixed | |
| TimeoutStopSec=5 | |
| PrivateTmp=true | |
| [Install] | |
| WantedBy=multi-user.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Unit] | |
| Description=gunicorn socket | |
| [Socket] | |
| ListenStream=/run/gunicorn.sock | |
| # Our service won't need permissions for the socket, since it | |
| # inherits the file descriptor by socket activation | |
| # only the nginx daemon will need access to the socket | |
| SocketUser=www-data | |
| # Optionally restrict the socket permissions even more. | |
| # SocketMode=600 | |
| [Install] | |
| WantedBy=sockets.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| user www-data; | |
| ... | |
| http { | |
| server { | |
| listen 8000; | |
| server_name 127.0.0.1; | |
| location / { | |
| proxy_pass http://unix:/run/gunicorn.sock; | |
| } | |
| } | |
| } | |
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| systemctl enable --now gunicorn.socket | |
| # test | |
| sudo -u www-data curl --unix-socket /run/gunicorn.sock http | |
| # nginx | |
| systemctl enable nginx.service | |
| systemctl start nginx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment