Giter Site home page Giter Site logo

8ff / gpt Goto Github PK

View Code? Open in Web Editor NEW
13.0 3.0 4.0 649 KB

GPT-3.5 Turbo & GPT-4 Chatbot Golang Library

License: GNU Affero General Public License v3.0

Go 99.57% Shell 0.43%
chatgpt chatgpt-api chatgpt-go chatgpt3 golang gpt-3 library openai-api openai-api-chatbot gpt-4

gpt's Introduction

logo

GPT-3.5 Turbo & GPT-4 Chatbot Golang Library

Go Report Card GoDoc License

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.

Library

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.

Prerequisites

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.

Example

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)
	}
}

Installation

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

Usage

This repository also contains two demo applications for using the chatbot: a single request app and a chat app.

Single Request 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.

Chat App

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".

License

This code is released under the GPL3 License. See LICENSE for more information.

gpt's People

Contributors

chiefmarlin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.