https://github.com/franciscoescher/goopenai
This is a Go client library for the OpenAI API
https://github.com/franciscoescher/goopenai
chatgpt chatgpt-api go golang gpt-4 llm openai
Last synced: 5 months ago
JSON representation
This is a Go client library for the OpenAI API
- Host: GitHub
- URL: https://github.com/franciscoescher/goopenai
- Owner: franciscoescher
- License: mit
- Created: 2023-03-13T02:09:34.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-23T13:59:46.000Z (about 2 years ago)
- Last Synced: 2025-02-13T09:39:27.015Z (over 1 year ago)
- Topics: chatgpt, chatgpt-api, go, golang, gpt-4, llm, openai
- Language: Go
- Homepage:
- Size: 49.8 KB
- Stars: 45
- Watchers: 2
- Forks: 15
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Go OpenAI
###### DEPRECATION NOTICE
[DEPRECATED] This code is no longer maintained. Please use the official Azure Open AI client: https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/ai/azopenai
###### Introduction
This is a Go client library for the OpenAI API.
It implements the methods described in the docs: https://platform.openai.com/docs/api-reference/introduction
Implemented methods can be found in the Interface.go file.
## Installation
go get github.com/franciscoescher/goopenai/v3
## Usage
First, you need to create a client with the api key and organization id.
```
client := goopenai.NewClient(apiKey, organization)
```
Then, you can use the client to call the api.
Example:
```
package main
import (
"context"
"fmt"
"github.com/franciscoescher/goopenai"
)
func main() {
apiKey := os.Getenv("API_KEY")
organization := os.Getenv("API_ORG")
client := goopenai.NewClient(apiKey, organization)
r := &goopenai.CreateChatCompletionsRequest{
Model: "gpt-3.5-turbo",
Messages: []goopenai.Message{
{
Role: "user",
Content: "Say this is a test!",
},
},
Temperature: 0.7,
}
completions, err := client.CreateChatCompletions(context.Background(), r)
if err != nil {
panic(err)
}
fmt.Println(completions)
}
```
Run this code using:
`API_KEY= API_ORG= go run .`
## Note
This library is not complete and not fully tested.
Feel free to contribute.