This program uses the OpenAI API to create a chatbot that can converse with the user. The program prompts the user to enter input, sends that input to the OpenAI API, and displays the response.
This program depends on the following packages:
- "bufio": Package for reading input from the user. Created by The Go Authors. Repository
- "context": Package for managing contexts for Go programs. Created by The Go Authors. Repository
- "fmt": Package for formatting input and output in Go programs. Created by The Go Authors. Repository
- "os": Package for accessing operating system functionality in Go programs. Created by The Go Authors. Repository
- "github.com/joho/godotenv": Package for loading environment variables from a .env file. Created by John Barton. Repository
- "github.com/sashabaranov/go-openai": Package for accessing the OpenAI API. Created by Sasha Baranov. Repository
To run the program, execute the following command in the terminal:
go run main.go
The program will prompt the user to enter input, and then display the response generated by the OpenAI API. This process will repeat ten times.
This program uses an API key to access the OpenAI API. The API key is stored in a .env file
, which should be located in the same directory as the program. The contents of the .env
file should be as follows:
api_key=<your_api_key_here>
Replace <your_api_key_here> with your actual API key. To get an API key, head to the openai website and sign up.
This program only allows the user to enter text input. It does not currently support other types of input, such as voice input.
Special thanks to the creators and contributors of these packages for their hard work and dedication to the Go community.