Skip to content

Shinichi-Nakagawa/sample-restful-openai

Repository files navigation

Sample RESTful API for Open AI

Open AI RESTful API sample for Python

Prerequisites

Make sure you have the following software installed:

Installation

Local Use

Create and activate a virtual environment. and Install the required packages.

poetry install

Container(Docker)

docker compose build
docker compose up

Usage

Run the Application

python main.py

Run the Application(uvicorn)

uvicorn main:app --reload

Project Environment

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)

Endpoints

  • GET / - Get status(use to healthcheck)
  • POST /openai/chat - Create a new messages, use to Create chat completion

Test

type check

poetry run mypy .

code check

poetry run black .

unit test

poetry run pytest .

Deploy

Cloud Run

Create Repository(1st Time only.)

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}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published