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


docker,phpenv

Unable to ping host.docker.internal on Linux

You can check with docker version, confirm that the version is Docker v20.10+, you can add extra_hosts as follows:

d-laravel, docker, laravel, docker-compose

D-Laravel v1.0.0 release change description

In order to allow the container to be used more flexibly, D-Laravel has released version v1.0.0, which is not backward compatible. https://github.com/DevinY/dlaravel/releases/tag/v1.0.0 If you are using before v1.0.0, you need to modify the .env file of the Laravel project, change DB_HOST=127.0.0.1 to DB_HOST=db If you have a custom docker-compose-custom.yml file....more

laravel docker

About D-Laravel's project mode

If you are a new user, I suggest you use my latest environment phpenv instead. https://github.com/DevinY/phpenv