Skip to content

genai-musings/chatting-with-ChatGPT

Repository files navigation

chatting-with-ChatGPT

License: MPL 2.0 Bandit Safety Check Super-Linter [CodeQL Markdown Links Check Spell-Checker Unit-Tests Code-Coverage Docker-Build-Push Docker-Push-README

Repository for chatting with ChatGPT.

This repository contains Python code, and associated unit tests, for an application which uses the OpenAI API to perform language generation. The application uses GitHub workflows for continuous integration and continuous deployment.

The application a simple command line program takes the input from the user and generates a response using the "gpt-4" model.

To run application

You will need an OpenAI API Key.

To get an Open AI Key you need to follow these steps:

  1. Create an OpenAI Account via the OpenAI website

  2. Login to your account and browse to OpenAI API Keys

  3. Select "Create new secret key".

Once you have created an OpenAI API key, you need to pass it to the application via an environment variable

export OPENAI_API_KEY="Your OpenAI API Key"
python main.py

To run unit tests

pytest

To build and run an instance of a Docker image locally.

The username and password for Docker Hub are stored as secrets this GitHub repository.

Note: To set up the secrets in your GitHub repository, go to the repository page, navigate to the "Settings" tab, and then select "Secrets" from the left menu. Add a repository secret named DOCKERHUB_USERNAME with the Docker Hub username to be used, a repository secret named DOCKERHUB_PASSWORD with the Docker Hub password to be used and a repository secret named OPENAI_API_KEY with your OpenAI API Key.

Build

Build the Docker image.

docker build -t chatting-with-chatgpt .

Run

Run the Docker image as a container.

export OPENAI_API_KEY="Your OpenAI API Key"
docker run -it -e OPENAI_API_KEY=$OPENAI_API_KEY chatting-with-chatgpt

To pull and run an instance of the Docker image from Docker Hub

Pull

docker pull <dockerhub-username>/chatting-with-chatgpt:<tag>

Replace with your Docker Hub username and with the specific tag of the Docker image you want to pull.

Run

export OPENAI_API_KEY="Your OpenAI API Key"
docker run -it -e OPENAI_API_KEY=$OPENAI_API_KEY <dockerhub-username>/chatting-with-chatgpt:<tag>

OpenAI API Reference

For more information on the API available from OpenAI see the OpenAI API Reference Documentation.