Giter Club home page Giter Club logo

go-gpt3's Introduction

go-gpt3

An OpenAI GPT-3 API client enabling Go/Golang programs to interact with the gpt3 APIs.

Supports using the completion APIs with or without streaming.

PkgGoDev

Usage

Simple usage to call the main gpt-3 API, completion:

client := gpt3.NewClient(apiKey)
resp, err := client.Completion(ctx, gpt3.CompletionRequest{
    Prompt: []string{"2, 3, 5, 7, 11,"},
})

fmt.Print(resp.Choices[0].Text)
// prints " 13, 17, 19, 23, 29, 31", etc

Documentation

Check out the go docs for more detailed documentation on the types and methods provided: https://pkg.go.dev/github.com/PullRequestInc/go-gpt3

Full Examples

Try out any of these examples with putting the contents in a main.go and running go run main.go. I would recommend using go modules in which case you will also need to run go mod init within your test repo. Alternatively you can clone this repo and run the test script with go run cmd/test/main.go.

You will also need to have a .env file that looks like this to use these examples:

API_KEY=<openAI API Key>
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/PullRequestInc/go-gpt3"
	"github.com/joho/godotenv"
)

func main() {
	godotenv.Load()

	apiKey := os.Getenv("API_KEY")
	if apiKey == "" {
		log.Fatalln("Missing API KEY")
	}

	ctx := context.Background()
	client := gpt3.NewClient(apiKey)

	resp, err := client.Completion(ctx, gpt3.CompletionRequest{
		Prompt:    []string{"The first thing you should know about javascript is"},
		MaxTokens: gpt3.IntPtr(30),
		Stop:      []string{"."},
		Echo:      true,
	})
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Println(resp.Choices[0].Text)
}

Support

  • List Engines API
  • Get Engine API
  • Completion API (this is the main gpt-3 API)
  • Streaming support for the Completion API
  • Document Search API
  • Overriding default url, user-agent, timeout, and other options

Powered by

go-gpt3's People

Contributors

tylermann avatar 3l0w avatar jaderdias avatar wbrown avatar hagemt 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.