Giter Club home page Giter Club logo

gopenai's Introduction

OpenAI Binding for Go

This is a super simple wrapper for OpenAI's GPT Completion, GPT Edits, and DALL-E Image generation APIs.

Getting Started

Installing

go get -u github.com/CasualCodersProjects/gopenai

Usage

Initializing the OpenAI object.

openAI := gopenai.NewOpenAI(&gopenai.OpenAIOpts{})

Passing in an API Key.

openAI := gopenai.NewOpenAI(&gopenai.OpenAIOpts{
    APIKey: "your-api-key-here",
})

Creating a Simple Completion.

// if passed an empty string for the model and zero for the tokens, 
// will default to "text-davinci-003" and 256
results, err := openAI.CreateCompletionSimple("Write me a story about a woman named Alice", "", 0)
if err != nil {
    panic(err)
}

Creating a completion with more options.

request := types.NewDefaultCompletionRequest("Your prompt here\n")
request.MaxTokens = 1024
request.Stop = []string{"\n"}
request.N = 3

results, err := openAI.CreateCompletion(request)
if err != nil {
    panic(err)
}

Creating an Edit.

request := types.NewDefaultEditRequest("Misspell this senstence", "Correct the spelling mistakes.")

results, err := openAI.CreateEdit(request)
if err != nil {
    panic(err)
}

Creating an Image.

request := types.NewDefaultImageRequest("A dog in a hat")

results, err := openAI.CreateImage(request)
if err != nil {
    panic(err)
}

FAQ

Will you support other OpenAI APIs?

Not unless we need them! This library is for another Go project of ours, we figured we'd open source it so that others can use it too! It fits our needs, so updates will only be made on an as-needed basis. However, anyone is welcome to submit a Pull Request and add anything else they would also find useful!

Are you affiliated with OpenAI?

No. This is a community project.

gopenai's People

Contributors

chand1012 avatar

Stargazers

Justyn Temme avatar

Watchers

 avatar Kyle Vasulka avatar  avatar Kostas Georgiou 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.