Categorygithub.com/PullRequestInc/go-gpt3
modulepackage
1.2.0
Repository: https://github.com/pullrequestinc/go-gpt3.git
Documentation: pkg.go.dev

# README

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

# Packages

No description provided by the author
Code generated by counterfeiter.

# Functions

Float32Ptr converts a float32 to a *float32 as a convenience.
IntPtr converts an integer to an *int as a convenience.
NewClient returns a new OpenAI GPT-3 API client.
NewRateLimitHeadersFromResponse does a best effort to parse the rate limit information included in response headers.
WithBaseURL is a client option that allows you to override the default base url of the client.
WithDefaultEngine is a client option that allows you to override the default engine of the client.
WithHTTPClient allows you to override the internal http.Client used.
WithOrg is a client option that allows you to override the organization ID.
WithTimeout is a client option that allows you to override the default timeout duration of requests for the client.
WithUserAgent is a client option that allows you to override the default user agent of the client.

# Constants

Engine Types.
Engine Types.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Engine Types.
Engine Types.
Engine Types.
No description provided by the author
No description provided by the author
No description provided by the author
Engine Types.
Engine Types.
Engine Types.
Engine Types.
Engine Types.
Engine Types.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

APIError represents an error that occured on an API.
APIErrorResponse is the full error respnose that has been returned by an API.
ChatCompletionFunctionParameters captures the metadata of the function parameter.
ChatCompletionFunctions represents the functions the model may generate JSON inputs for.
ChatCompletionRequest is a request for the chat completion API.
ChatCompletionRequestMessage is a message to use as the context for the chat completion API.
ChatCompletionResponse is the full response from a request to the Chat Completions API.
ChatCompletionResponseChoice is one of the choices returned in the response to the Chat Completions API.
ChatCompletionResponseMessage is a message returned in the response to the Chat Completions API.
ChatCompletionsResponseUsage is the object that returns how many tokens the completion's request used.
No description provided by the author
ChatCompletionResponseChoice is one of the choices returned in the response to the Chat Completions API.
CompletionRequest is a request for the completions API.
CompletionResponse is the full response from a request to the completions API.
CompletionResponseChoice is one of the choices returned in the response to the Completions API.
CompletionResponseUsage is the object that returns how many tokens the completion's request used.
EditsRequest is a request for the edits API.
EditsResponse is the full response from a request to the edits API.
EditsResponseChoice is one of the choices returned in the response to the Edits API.
EditsResponseUsage is a structure used in the response from a request to the edits API.
EmbeddingsRequest is a request for the Embeddings API.
EmbeddingsResponse is the response from a create embeddings request.
The inner result of a create embeddings request, containing the embeddings for a single input.
The usage stats for an embeddings response.
EngineObject contained in an engine reponse.
EnginesResponse is returned from the Engines API.
Function represents a function with a name and arguments.
FunctionParameterPropertyMetadata represents the metadata of the function parameter property.
LogprobResult represents logprob result of Choice.
ModerationCategoryResult shows the categories that the moderation classifier flagged the input text for.
ModerationCategoryScores shows the classifier scores for each moderation category.
ModerationRequest is a request for the moderation API.
ModerationResponse is the full response from a request to the moderation API.
ModerationResult represents a single moderation classification result returned by the moderation API.
RateLimitHeaders contain the HTTP response headers indicating rate limiting status.
SearchData is a single search result from the document search API.
SearchRequest is a request for the document search API.
SearchResponse is the full response from a request to the document search API.

# Interfaces

A Client is an API client to communicate with the OpenAI gpt-3 APIs.

# Type aliases

ClientOption are options that can be passed when creating a new client.
No description provided by the author