Git Product home page Git Product logo

openai's Introduction

OpenAI

Go Reference

OpenAI is a package that wraps around the OpenAI HTTP APIs. To use this package properly you will need to have an OpenAI account (currently in beta), which will give you the API key that you need. You will also be assigned to an organization, which you can optionally add to the API request.

Important to note that each application developed using the OpenAI APIs need to be approved by OpenAI.

Completion

OpenAI models can be used for multiple text related tasks. Given a prompt and some parameters, the model can return one or more predicted completions and other information.

To start using the API, create a client and set the API key and organization.

client := NewClient(apiKey, organization)

Next, we need to create a CompletionRequest, which is a map[string]any with some attached methods. The 2 mandatory fields in the request are model and prompt, which sets the model to use, as well as the prompt to send for completion. You should also send the ID for the end-user even though it is optional, because OpenAI will review your application and this is a stated criteria in the review.

request := make(CompletionRequest)
request.SetUser("test-user")
request.SetModel(TEXT_DAVINCI_002)
request.SetPrompt("Suggest three names for a horse that is a superhero.")

You can also set other parameters, which you can get from the API documentation, by treating the request as a map.

request["temperature"] = 0.75
request["max_tokens"] = 50

To send the completion to OpenAI, use the Complete method in the client, passing it the request.

cr, err := client.Complete(request)
if err != nil {
    // resolve the error
}
fmt.Println(cr.Text())

Once OpenAI responds, it will provide a CompletionResponse which is also a map[string]any that has a few methods. You will most likely just use the Text method to extract the text response, but you can also get the other response data by using the methods or treating it like a map.

openai's People

Contributors

sausheong avatar

Stargazers

Edward Fernandes avatar Tonic avatar Jason McGinnis avatar josephedward avatar Zach avatar Titus Joyson P avatar  avatar  avatar genix avatar Alvin avatar Rui Baltazar avatar Nikita avatar Chee Aun avatar

Watchers

 avatar James Cloos avatar Kostas Georgiou avatar  avatar

openai's Issues

Add API for Edits

Given a prompt and an instruction, the model will return an edited version of the prompt. Add the APIs for for Edits.

Add API for Embeddings

Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.

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.