Open AI RESTful API sample for Python
Make sure you have the following software installed:
Create and activate a virtual environment. and Install the required packages.
poetry install
docker compose build
docker compose up
python main.py
uvicorn main:app --reload
setting for environments.py
OPENAI_API_KEY: str = os.getenv('OPENAI_API_KEY', 'your openai api key')
OPENAI_ORGANIZATION: str = os.getenv('OPENAI_ORGANIZATION', 'your openai organization')
OPENAI_MODEL: str = os.getenv('OPENAI_MODEL', 'gpt-3.5-turbo') # Use to Open AI Model(default: 3.5)
DOCS_OPENAPI_URL: str = os.getenv("DOCS_OPENAPI_URL") # OpenAPI docs url(default: None)
- GET
/
- Get status(use to healthcheck) - POST
/openai/chat
- Create a new messages, use to Create chat completion
poetry run mypy .
poetry run black .
poetry run pytest .
create repository for artifacts
gcloud artifacts repositories create restful-openapi \
--repository-format=Docker \
--location=asia-northeast1 \
--description="Open AI RESTful API sample for Python" \
--async
image build and deploy
sh ./deploy_cloudrun.sh ${your google cloud project id} ${imagetag}