openai

package
v1.2.5-sp1 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2023 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Exports = map[string]interface{}{
	"TranslateToChinese": translate,
	"Chat":               chat,
	"apiKey":             WithAPIKey,
	"localAPIKey":        WithAPIKeyFromYakitHome,
	"proxy":              WithProxy,
	"domain":             WithDomain,
	"yakDomain":          WithYakProxy,
	"model":              WithModel,
}

Functions

This section is empty.

Types

type ChatChoice

type ChatChoice struct {
	Index        int        `json:"index"`
	Message      ChatDetail `json:"message"`
	FinishReason string     `json:"finish_reason"`
}

type ChatCompletion

type ChatCompletion struct {
	ID      string       `json:"id"`
	Object  string       `json:"object"`
	Created int64        `json:"created"`
	Choices []ChatChoice `json:"choices"`
	Usage   ChatUsage    `json:"usage"`
}

type ChatDetail

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

type ChatMessage

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

func NewChatMessage

func NewChatMessage(model string, messages ...ChatDetail) *ChatMessage

type ChatUsage

type ChatUsage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

type Client

type Client struct {
	Proxy string

	APIKey       string
	Organization string
	ChatModel    string

	// Role in Org! public model, the role is user
	Role   string
	Domain string
	// contains filtered or unexported fields
}

func NewOpenAIClient

func NewOpenAIClient(opt ...ConfigOption) *Client

func (*Client) Chat

func (c *Client) Chat(data string) (string, error)

func (*Client) TranslateToChinese

func (c *Client) TranslateToChinese(data string) (string, error)

type ConfigOption

type ConfigOption func(client *Client)

func WithAPIKey

func WithAPIKey(i string) ConfigOption

func WithAPIKeyFromYakitHome

func WithAPIKeyFromYakitHome() ConfigOption

func WithDomain

func WithDomain(i string) ConfigOption

func WithModel

func WithModel(i string) ConfigOption

func WithProxy

func WithProxy(i string) ConfigOption

func WithYakProxy

func WithYakProxy() ConfigOption

Jump to

Keyboard shortcuts

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