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,cli

Docker container formatted display

I think if you want to write some automation functions, it may be useful to be able to format the output container content. The following are some reference examples of Docker container formatting and display instructions

docker, tinkerwell, tinker, laravel

Application of Tinkerwell and docker environment

In fact, I don't use Tinkerwell recently because it keeps costing me money to update. If you want to test the direct ssh host, it’s done, isn’t it?

docker,sqlserver

D-Laravel builds SQL Server environment

How to build D-Laravel's SQL Server environment