Categorygithub.com/ak9024/go-chatgpt-sdk
modulepackage
0.0.0-20240826023015-edfae3bc827c
Repository: https://github.com/ak9024/go-chatgpt-sdk.git
Documentation: pkg.go.dev

# README

GitHub Actions Workflow Status GitHub top language GitHub License

go-chatgpt-sdk

This Library Provides Unofficial Go Client SDK for OpenAI API

Install

go get -u github.com/ak9024/go-chatgpt-sdk

Model Support

  • Chat
  • Text
  • Image
  • Moderations
  • Audio

Prerequisite

Usage with model chat

to usage with model chat, please usage c.ChatCompletions

package main

import (
	"fmt"

	gochatgptsdk "github.com/ak9024/go-chatgpt-sdk"
)

func main() {
	c := gochatgptsdk.NewConfig(gochatgptsdk.Config{
		OpenAIKey: "",
	})

	resp, _ := c.ChatCompletions(gochatgptsdk.ModelChat{
		Model: "gpt-3.5-turbo",
		Messages: []gochatgptsdk.Message{
			{
				Role:    "system",
				Content: "You are a Software engineer",
			},
			{
				Role:    "user",
				Content: "Please create a simple function to using Go language",
			},
		},
	})

	fmt.Println(resp.Choices)
}

Usage with model text

To usage with model text, please usage c.Completions()

package main

import (
	"fmt"

	gochatgptsdk "github.com/ak9024/go-chatgpt-sdk"
)

func main() {
	c := gochatgptsdk.NewConfig(gochatgptsdk.Config{
		OpenAIKey: "",
	})

	resp, _ := c.Completions(gochatgptsdk.ModelText{
		Model:     "text-davinci-003",
		Prompt:    "What the weather Kota Palu for today?",
		MaxTokens: 100, // max generates of word
	})

	fmt.Println(resp.Choices)
}

Usage with model images

Create images, please use c.ImagesGenerations, but if you want generate base64 image usage c.ImageGenerationsB64JSON

package main

import (
	"fmt"

	gochatgptsdk "github.com/ak9024/go-chatgpt-sdk"
)

func main() {
	c := gochatgptsdk.NewConfig(gochatgptsdk.Config{
		OpenAIKey: "",
	})

	resp, _ := c.ImagesGenerations(gochatgptsdk.ModelImages{
		Prompt: "Sunset sketch art",
		N:      5, // generates 5 images
		Size:   gochatgptsdk.Size512, // with size 512x512
	})

	fmt.Println(resp.Data)
}

Create images variations of a given image, please use c.ImagesVariations() but if you want generate base64 image usage c.ImageVariationsB64JSON

package main

import (
	"fmt"

	gochatgptsdk "github.com/ak9024/go-chatgpt-sdk"
)

func main() {
	c := gochatgptsdk.NewConfig(gochatgptsdk.Config{
		OpenAIKey: "",
	})

	resp, _ := c.ImagesVariations(gochatgptsdk.ModelImagesVariations{
		Image: "./path/to/example-img.png", // please suitable with your path image
		N:     "2",                  // generate 2 images
		Size:  gochatgptsdk.Size256, // with size 256x256
	})

	fmt.Println(resp.Data)
}

For all of response data please read more in file struct_response.go

# Functions

DoRequest(t string) to compose HTTP Request.
No description provided by the author

# Constants

No description provided by the author

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author