by Devin Yang
(This article was automatically translated.)

Published - 1 year ago ( Updated - 1 year ago )

If you log in to the openai website, you can see the official teaching instructions here
https://beta.openai.com/docs/quickstart/build-your-application

API KEY application is on this page There is a button below

+ Create new secret key

This article teaches you to use Docker to run the official OpenAI execution environment.

official version:

git clone https://github.com/openai/openai-quickstart-python.git
cd openai-quickstart-python
cp.env.example.env
python -m venv venv
.venv/bin/activate
pip install -r requirements.txt
flask run

But if you just want to try it out during the free period, you can also use docker to quickly install it on your own MacOS.

git clone https://github.com/openai/openai-quickstart-python.git
cd openai-quickstart-python
# One more step, run Docker first
docker run --rm -v $(pwd):/app -w /app -p 5001:5000 -ti python:3.10.9 bash
#Skip the installation of venv, run the container without venv, install it directly
pip install -r requirements.txt
#The container cannot listen to 127.0.0.1, so there is one more parameter --host
flask run --host 0.0.0.0

After completion, remember to set your Token in .env, and you can use it.

FLASK_APP=app
FLASK_ENV=development
OPENAI_API_KEY=

Because the AirPlay receiver will consume 5000 and 7000, it must avoid conflicts, so I changed the Port on the host side to 5001
for use Open the screen in the browser, and you can test it. Remember that the Docker port is opened at 5001.

http://127.0.0.1:5001

If there is no problem, remember to commit as image, so you don’t have to reinstall all the time. The garbled code here is the hostname of the container, please don’t copy it My.

docker commit 520ad08c41e2 openai

Leave the container and restart with our commit image

 docker run --rm - v $(pwd):/app -w /app -p 5001:5000 -ti openai flask \
 run --host 0.0.0.0

You should see the following screen:

$docker run --rm -v $(pwd):/app -w /app -p 5001:5000 -ti openai flask\
 run --host 0.0.0.0
 * Serving Flask app 'app' (lazy loading)
 * Environment: development
 * Debug mode: on
 * Running on all addresses.
   WARNING: This is a development server. Do not use it in a production deployment.
 * Running on http://172.17.0.2:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 130-035-104

Tags: openai flax docker

Devin Yang

Feel free to ask me, if you don't get it.:)

No Comment

Post your comment

Login is required to leave comments

Similar Stories


certbot,docker,ftp

curlftpfs introduction and manual certificate application

Situation sharing, imagine that you have WebHosting, which only provides FTP connection, and then you want to apply for a certificate manually. In this article, I share how I use Docker to install curlftpfs, mount the FTP folder of the remote host, and then execute certbot in the container to apply for an SSL certificate. Leaving aside the certificate application, when I first discovered the curlftpfs command, I found it very interesting, especially if you are a MacOS user and do not have a satisfactory FTP software at hand. You love scrolling through the command line as much as I do, so maybe you should love this command too. 🤭

laravel,docker

How to customize Laravel pagination

Recently, I have been free, and I want to adjust the arrows on the upper and lower pages of the website. If you don’t know how to customize Laravel’s pagination, You can take a look at a short three-minute introduction on how I customize Laravel's pagination.

php,docker,dlaravel

A brief introduction to the phpenv container environment I built

I don't have time to shoot an introduction video, so I'll just grab some pictures and introduce the container environment deviny/phpenv I use. https://github.com/DevinY/phpenvphpenv can be regarded as an evolutionary version of my previous D-Laravel open source project, conceptually extending the use of many Dlaravel operation methods. The update of the container tends to be controlled by the user to build his own image, so I am not very good at changing the version number. In fact, the php version number of D-Laravel seems to have not been changed for a long time:p