Skip to content

Commit

Permalink
Refactor library (#1)
Browse files Browse the repository at this point in the history
Seeks to re-factor the original repo w/ many breaking changes. Major goals:

- Use more idiomatic go style. (Rename the package, accept and return pointers, shorter variable names, etc.)
- Much better documentation. Add comments to all exported types, fields, methods, packages, etc. (from OpenAI's documentation).
- Make option fields who's go default value is a valid parameter value (and also does not match the API's default) pointers, so omitempty does not strip explicitly set values. (See sashabaranov/go-openai#9 for more).
- Have a consistent style throughout. Most endpoints in the original library were implemented independently (and thus their usages feel inconsistent).
- Implement all endpoints.

Reviewer: neilmadsen
  • Loading branch information
adayNU authored Jan 20, 2023
1 parent 81b5788 commit 106d762
Show file tree
Hide file tree
Showing 34 changed files with 1,734 additions and 778 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.18'
go-version: '1.19'
- name: Run vet
run: |
go vet .
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
# # Run testing on the code
# - name: Run testing
# run: cd test && go test -v
- name: Run testing
run: go test -v
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ linters:
- gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations.
- goprintffuncname # Checks that printf-like functions are named with f at the end
- gosec # Inspects source code for security problems
- lll # Reports long lines
# - lll # Reports long lines
- makezero # Finds slice declarations with non-zero initial length
# - nakedret # Finds naked returns in functions greater than a specified function length
- nestif # Reports deeply nested if statements
Expand All @@ -205,7 +205,7 @@ linters:
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed.
- stylecheck # Stylecheck is a replacement for golint
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
- testpackage # linter that makes you use a separate _test package
# - testpackage # linter that makes you use a separate _test package
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
- unconvert # Remove unnecessary type conversions
- unparam # Reports unused function parameters
Expand Down
31 changes: 15 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# go-gpt3
[![GoDoc](http://img.shields.io/badge/GoDoc-Reference-blue.svg)](https://godoc.org/github.com/sashabaranov/go-gpt3)
[![Go Report Card](https://goreportcard.com/badge/github.com/sashabaranov/go-gpt3)](https://goreportcard.com/report/github.com/sashabaranov/go-gpt3)
# openai
[![GoDoc](http://img.shields.io/badge/GoDoc-Reference-blue.svg)](https://godoc.org/github.com/fabiustech/openai)
[![Go Report Card](https://goreportcard.com/badge/github.com/sashabaranov/go-gpt3)](https://goreportcard.com/report/github.com/fabiustech/openai)


[OpenAI GPT-3](https://beta.openai.com/) API wrapper for Go
Zero dependency Go Client for [OpenAI](https://beta.openai.com/) API endpoints. Built upon the great work done [here](https://github.com/sashabaranov/go-gpt3).

Installation:
```
go get github.com/sashabaranov/go-gpt3
go get github.com/fabiustech/openai
```


Example usage:

```go
Expand All @@ -19,22 +17,23 @@ package main
import (
"context"
"fmt"
gogpt "github.com/sashabaranov/go-gpt3"

"github.com/fabiustech/openai"
"github.com/fabiustech/openai/models"
)

func main() {
c := gogpt.NewClient("your token")
ctx := context.Background()

req := gogpt.CompletionRequest{
Model: gogpt.GPT3Ada,
MaxTokens: 5,
var c = openai.NewClient("your token")

var resp, err = c.CreateCompletion(context.Background(), &openai.CompletionRequest{
Model: models.TextDavinci003,
MaxTokens: 100,
Prompt: "Lorem ipsum",
}
resp, err := c.CreateCompletion(ctx, req)
})
if err != nil {
return
}

fmt.Println(resp.Choices[0].Text)
}
```
51 changes: 0 additions & 51 deletions answers.go

This file was deleted.

85 changes: 0 additions & 85 deletions api.go

This file was deleted.

Loading

0 comments on commit 106d762

Please sign in to comment.