by Devin Yang
(This article was automatically translated.)

Published - 2 years ago ( Updated - 2 years 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

Update docker-compose version with bash

Install the latest version of docker-compose

wordpress, d-laravel, docker, docker-compose

How to install Wordpress with D-Laravel

An 8-minute teaching video, introducing the installation of Wordpress on D-Laravel. D-Laravel is a docker-compose Laravel framework development environment, but it does not mean that it cannot be used to install other things. This video introduces the use of D-Laravel to install non-Laravel PHP projects, You can learn the usage of related instructions on D-Laravel: ./create --host usage, docker-compose up -d and ./console mysql usage, The database connection setting method after D-Laravel v1.0.0.

docker,laravel

How to use multiple YAML files to execute multiple docker container services

This video introduces how to use the docker-compose command to specify multiple YAML structure language configuration files to create container execution, and introduces how we simplify docker-compose by using .env in the D-Laravel environment Start command.