Coder Social home page Coder Social logo

openai's Introduction

OpenAi (community-maintained) Go Reference

Package openai provides a Go SDK for the OpenAI API.this package supports several models, including GPT-4, GPT-3.5, GPT-3, DALL-E, and audio models. You can specify the desired model using the Model field in the request object.

Feature

  • ChatGPT (GPT-3, GPT-3.5, GPT-4)
  • DALL·E 2
  • Embedding
  • Audio
  • Fine-Tune
  • File
  • Moderations
  • Completion Patterns
  • Multiple API keys support

Install Go Version

$ go get -u github.com/GoFarsi/openai

Example Completion

package main

import (
	"context"
	"github.com/GoFarsi/openai"
	"github.com/GoFarsi/openai/client"
	"github.com/GoFarsi/openai/entity"
	"github.com/GoFarsi/openai/models"
	"log"
	"os"
)

func main() {
	apiKey := os.Getenv("OPENAI_API_KEY")
	cli, err := client.New([]string{apiKey})
	if err != nil {
		log.Fatalln(err)
	}

	c := openai.NewCompletion(cli)
	resp, err := c.CreateCompletion(context.Background(), entity.CompletionRequest{
		Model:  models.TEXT_DAVINCI_002,
		Prompt: "can you explain bubble sort algorithm?",
	})

	if err != nil {
		log.Fatalln(err)
	}

	log.Println(resp)
}

Example Completion Patterns

package main

import (
	"context"
	"github.com/GoFarsi/openai"
	"github.com/GoFarsi/openai/client"
	"github.com/GoFarsi/openai/patterns/completion"
	"github.com/GoFarsi/openai/types/programming"
	"log"
	"os"
)

var code string = `
func add(a, b int) int {
	return a + b
}
`

func main() {
	apiKey := os.Getenv("OPENAI_API_KEY")
	cli, err := client.New([]string{apiKey})
	if err != nil {
		log.Fatalln(err)
	}

	c := openai.NewCompletion(cli)
	resp, err := c.CreateCompletionFromPattern(context.Background(), completion.ProgrammingLanguageTranslator(
		code,
		programming.Go,
		programming.Python,
		0,
	))

	if err != nil {
		log.Fatalln(err)
	}

	log.Println(resp.Choices[0].Text)
}

See more details in documentation.

TODO

  • Stream Support
  • Moderation API
  • Example API
  • Fine-Tune API
  • File API
  • Engine API
  • Azure API Support
  • Client, API Unit test

Contributing

  1. fork project in your GitHub account.
  2. create new branch for new changes.
  3. after change code, send Pull Request.

openai's People

Contributors

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