oacg

package module
v1.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2023 License: MIT Imports: 11 Imported by: 0

README

OpenAI Go SDK

Release Go Report Card Go Reference License

Applications written in Go can easily access OpenAI API.

Usage Example

Read usage instructions here.

Contribute

Feel free to contribute. Open a Pull Request (aka PR).

License

This project is licensed under the MIT License.

(c) 2023 Finbarrs Oketunji.

Cheers to technological advancement and moving the human race forward. 🙏🏽

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Authentication

func Authentication(apiKey string, orgID string) error

func CancelFineTune added in v1.0.8

func CancelFineTune(apiKey string, fineTuneID string) error

func CreateFineTune added in v1.0.8

func CreateFineTune(apiKey string, trainingFileID string) (string, error)

func DeleteFile added in v1.0.8

func DeleteFile(apiKey string, fileId string) error

func DeleteFineTune added in v1.0.8

func DeleteFineTune(apiKey string, fineTuneID string) error

func GetChatCompletion added in v1.0.5

func GetChatCompletion(apiKey string, model string, messages []ChatMessage) (string, error)

func GetCompletion

func GetCompletion(apiKey string, model string, prompt string, maxTokens int, temperature float32) (string, error)

func GetEdit added in v1.0.6

func GetEdit(apiKey string, model string, input string, instruction string) (string, error)

func GetEmbeddings added in v1.0.7

func GetEmbeddings(apiKey string, model string, input string) ([]float32, error)

func GetFileContent added in v1.0.8

func GetFileContent(apiKey string, fileId string) ([]byte, error)

func GetModeration added in v1.0.7

func GetModeration(apiKey string, input string) (float32, error)

Types

type AudioTranscriptionResponse added in v1.0.9

type AudioTranscriptionResponse struct {
	ID      string `json:"id"`
	Object  string `json:"object"`
	Text    string `json:"text"`
	Status  string `json:"status"`
	JobID   string `json:"job_id"`
	JobType string `json:"job_type"`
}

func TranscribeAudio added in v1.0.9

func TranscribeAudio(apiKey string, audioFilePath string, model string) (*AudioTranscriptionResponse, error)

type AudioTranslationResponse added in v1.0.9

type AudioTranslationResponse struct {
	ID      string `json:"id"`
	Object  string `json:"object"`
	Text    string `json:"text"`
	Status  string `json:"status"`
	JobID   string `json:"job_id"`
	JobType string `json:"job_type"`
}

func TranslateAudio added in v1.0.9

func TranslateAudio(apiKey string, audioFilePath string, model string) (*AudioTranslationResponse, error)

type ChatMessage added in v1.0.5

type ChatMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type ChatRequest added in v1.0.5

type ChatRequest struct {
	Model    string        `json:"model"`
	Messages []ChatMessage `json:"messages"`
}

type ChatResponse added in v1.0.5

type ChatResponse struct {
	Choices []struct {
		Text          string    `json:"text"`
		Index         int       `json:"index"`
		Logprobs      []Logprob `json:"logprobs"`
		FinishReason  string    `json:"finish_reason"`
		SelectedToken int       `json:"selected_token"`
	} `json:"choices"`
}

type CompletionRequest

type CompletionRequest struct {
	Model            string                 `json:"model"`
	Prompt           string                 `json:"prompt"`
	MaxTokens        int                    `json:"max_tokens,omitempty"`
	Temperature      float32                `json:"temperature,omitempty"`
	TopP             float32                `json:"top_p,omitempty"`
	N                int                    `json:"n,omitempty"`
	Stream           bool                   `json:"stream,omitempty"`
	Logprobs         int                    `json:"logprobs,omitempty"`
	Echo             bool                   `json:"echo,omitempty"`
	Stop             []string               `json:"stop,omitempty"`
	PresencePenalty  float32                `json:"presence_penalty,omitempty"`
	FrequencyPenalty float32                `json:"frequency_penalty,omitempty"`
	BestOf           int                    `json:"best_of,omitempty"`
	LogitBias        map[string]interface{} `json:"logit_bias,omitempty"`
}

type CompletionResponse

type CompletionResponse struct {
	Choices []struct {
		Text         string    `json:"text"`
		Index        int       `json:"index"`
		Logprobs     []Logprob `json:"logprobs"`
		FinishReason string    `json:"finish_reason"`
	} `json:"choices"`
}

type EditRequest added in v1.0.6

type EditRequest struct {
	Model       string `json:"model"`
	Input       string `json:"input"`
	Instruction string `json:"instruction"`
}

type EditResponse added in v1.0.6

type EditResponse struct {
	Data struct {
		Object string `json:"object"`
		ID     string `json:"id"`
		Model  string `json:"model"`
		Result string `json:"result"`
	} `json:"data"`
}

type EmbeddingsRequest added in v1.0.7

type EmbeddingsRequest struct {
	Model string `json:"model"`
	Input string `json:"input"`
}

type EmbeddingsResponse added in v1.0.7

type EmbeddingsResponse struct {
	Data []float32 `json:"data"`
}

type FileResponse added in v1.0.8

type FileResponse struct {
	Object    string `json:"object"`
	ID        string `json:"id"`
	Purpose   string `json:"purpose"`
	Bytes     int64  `json:"bytes"`
	CreatedAt string `json:"created_at"`
	URL       string `json:"url"`
}

func GetFile added in v1.0.8

func GetFile(apiKey string, fileId string) (*FileResponse, error)

func ListFiles added in v1.0.8

func ListFiles(apiKey string) ([]FileResponse, error)

type FileUploadResponse added in v1.0.8

type FileUploadResponse struct {
	Object    string `json:"object"`
	ID        string `json:"id"`
	Purpose   string `json:"purpose"`
	Bytes     int64  `json:"bytes"`
	CreatedAt string `json:"created_at"`
}

func UploadFile added in v1.0.8

func UploadFile(apiKey string, purpose string, filePath string) (*FileUploadResponse, error)

type FineTune added in v1.0.8

type FineTune struct {
	ID          string `json:"id"`
	ModelID     string `json:"model"`
	Status      string `json:"status"`
	TrainingLog string `json:"training_log"`
}

func GetFineTune added in v1.0.8

func GetFineTune(apiKey string, fineTuneID string) (*FineTune, error)

func ListFineTunes added in v1.0.8

func ListFineTunes(apiKey string) ([]FineTune, error)

type FineTuneEvents added in v1.0.8

type FineTuneEvents struct {
	Data []struct {
		Event      string `json:"event"`
		CreatedAt  int64  `json:"created_at"`
		Status     string `json:"status"`
		Percentage int    `json:"percentage"`
	} `json:"data"`
}

func GetFineTuneEvents added in v1.0.8

func GetFineTuneEvents(apiKey string, fineTuneID string) (*FineTuneEvents, error)

type FineTuneList added in v1.0.8

type FineTuneList struct {
	Data []FineTune `json:"data"`
}

type FineTuneResponse added in v1.0.8

type FineTuneResponse struct {
	Data FineTune `json:"data"`
}

type ImageEditRequest added in v1.0.11

type ImageEditRequest struct {
	Image  *os.File
	Mask   *os.File
	Prompt string
	N      int
	Size   string
}

type ImageEditResponse added in v1.0.11

type ImageEditResponse struct {
	Data []struct {
		URL string `json:"url"`
	} `json:"data"`
}

func EditImages added in v1.0.11

func EditImages(apiKey string, request *ImageEditRequest) (*ImageEditResponse, error)

type ImageGenerationRequest added in v1.0.10

type ImageGenerationRequest struct {
	Prompt string `json:"prompt"`
	N      int    `json:"n,omitempty"`
	Size   string `json:"size,omitempty"`
	Model  string `json:"model,omitempty"`
}

type ImageGenerationResponse added in v1.0.10

type ImageGenerationResponse struct {
	ID         string `json:"id"`
	Object     string `json:"object"`
	CreatedAt  int64  `json:"created_at"`
	Model      string `json:"model"`
	Iterations int    `json:"iterations"`
	Url        string `json:"url"`
}

func GenerateImages added in v1.0.10

func GenerateImages(apiKey string, prompt string, n int, size string) (*ImageGenerationResponse, error)

type ImageVariationResponse added in v1.0.10

type ImageVariationResponse struct {
	ID         string `json:"id"`
	Object     string `json:"object"`
	CreatedAt  int64  `json:"created_at"`
	Model      string `json:"model"`
	Iterations int    `json:"iterations"`
	Url        string `json:"url"`
}

func VariationsImages added in v1.0.10

func VariationsImages(apiKey string, imagePath string, n int, size string) (*ImageVariationResponse, error)

type Logprob added in v1.0.4

type Logprob struct {
	Text  string  `json:"text"`
	Value float32 `json:"value"`
}

type Model added in v1.0.2

type Model struct {
	ID          string `json:"id"`
	Object      string `json:"object"`
	CreatedAt   int64  `json:"created"`
	ModelType   string `json:"model_type"`
	Description string `json:"description"`
}

func GetModel added in v1.0.2

func GetModel(apiKey string, modelID string) (*Model, error)

func ListModels

func ListModels(apiKey string) ([]Model, error)

type ModelListResponse added in v1.0.3

type ModelListResponse struct {
	Data []Model `json:"data"`
}

type ModerationRequest added in v1.0.7

type ModerationRequest struct {
	Input string `json:"input"`
}

type ModerationResponse added in v1.0.7

type ModerationResponse struct {
	Data struct {
		Object string  `json:"object"`
		ID     string  `json:"id"`
		Model  string  `json:"model"`
		Score  float32 `json:"score"`
	} `json:"data"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL