This repository contains a Golang implementation of a chatbot using the OpenAI GPT-3.5 Turbo as well as the new GPT-4 API. The chatbot is able to generate human-like responses to user queries.
The core of this chatbot implementation are the gpt_3_5_turbo and gpt_4 packages, which are Golang libraries for interacting with the OpenAI GPT-3.5 Turbo and GPT-4 API. These libraries provide a simple API for sending text queries to the GPT-3.5 and GPT-4 models and receiving human-like responses in return. They include support for features like setting the API token, configuring the request, and managing message history. With these libraries, developers can easily incorporate the power of the GPT-3.5 & GPT-4 models into their Golang applications and build intelligent chatbots or other NLP-driven tools.
To use this chatbot, you need to have an API token for the OpenAI GPT-3.5 Turbo or GPT-4 API. You can obtain one by following the instructions on the OpenAI website.
package main
import (
"fmt"
"os"
gpt "github.com/8ff/gpt/pkg/gpt_3_5_turbo"
// gpt "github.com/8ff/gpt/pkg/gpt_4"
)
func main() {
// Read API_TOKEN from env
token := os.Getenv("API_TOKEN")
api, err := gpt.Init(gpt.Params{
API_TOKEN: token,
StripNewline: true,
Request: gpt.ChatRequest{
Model: "gpt-3.5-turbo",
// Model: "gpt-4-0613",
},
})
if err != nil {
panic(err)
}
choices, err := api.Query("What are you ?")
if err != nil {
panic(err)
}
for _, choice := range choices {
fmt.Printf("Response: %s\n", choice.Message.Content)
}
}
To install this chatbot, you need to have Go installed on your machine. Once you have Go installed, you can use the following command to download and install the chatbot:
git clone github.com/8ff/gpt
This repository also contains two demo applications for using the chatbot: a single request app and a chat app.
The single request app is located in cmd/singleRequest
. To use the single request app, set the API_TOKEN
environment variable to your OpenAI API token, and run the following command:
go run main.go
The app will prompt you for a message, and generate a response based on your input.
The chat app is located in cmd/chat
. To use the chat app, set the API_TOKEN
environment variable to your OpenAI API token, and run the following command:
go run main.go
The app will prompt you for a message, and generate a response based on your input. You can continue chatting with the bot until you type "exit".
This code is released under the GPL3 License. See LICENSE
for more information.