MCPcopy Index your code
hub / github.com/GeniusAI-Platform/openai

github.com/GeniusAI-Platform/openai @v0.8.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.8.0 ↗ · + Follow
207 symbols 496 edges 46 files 47 documented · 23%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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/GeniusAI-Platform/openai

Example Completion

package main

import (
    "context"
    "github.com/GeniusAI-Platform/openai"
    "github.com/GeniusAI-Platform/openai/client"
    "github.com/GeniusAI-Platform/openai/entity"
    "github.com/GeniusAI-Platform/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/GeniusAI-Platform/openai"
    "github.com/GeniusAI-Platform/openai/client"
    "github.com/GeniusAI-Platform/openai/patterns/completion"
    "github.com/GeniusAI-Platform/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
  • [x] Moderation API
  • [x] Example API
  • [x] Fine-Tune API
  • [x] 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.

Extension points exported contracts — how you extend this code

Transporter (Interface)
(no doc) [1 implementers]
client/client.go
FormBuilder (Interface)
(no doc) [1 implementers]
utils/formbuilder.go
Option (FuncType)
(no doc)
client/options.go
CompletionPattern (FuncType)
(no doc)
patterns/completion/completion.go

Core symbols most depended-on inside this repo

New
called by 23
errors/errors.go
Error
called by 17
entity/error.go
WriteField
called by 16
utils/formbuilder.go
New
called by 13
client/client.go
GetValidator
called by 11
client/client.go
Post
called by 7
client/client.go
String
called by 7
models/chat.go
NewCompletion
called by 6
completion.go

Shape

Method 91
Struct 56
Function 41
TypeAlias 14
Interface 3
FuncType 2

Languages

Go100%

Modules by API surface

client/client.go27 symbols
utils/formbuilder.go11 symbols
fine_tune.go8 symbols
example_test.go8 symbols
entity/image.partial.go8 symbols
client/options.go8 symbols
patterns/completion/completion.go7 symbols
entity/fine_tune.go7 symbols
patterns/completion/example_test.go5 symbols
image.go5 symbols
file.go5 symbols
entity/moderation.go5 symbols

For agents

$ claude mcp add openai \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact