chatgpt

package
v0.0.0-...-e2cee1a Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2024 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	English = "English"
	Chinese = "Chinese"
)

Variables

This section is empty.

Functions

func TransDecorate

func TransDecorate(content, language string) (string, error)

func Version

func Version() string

Types

type ChatCompChoice

type ChatCompChoice struct {
	Message      ChatCompMsg `json:"message,omitempty"`
	FinishReason string      `json:"finish_reason,omitempty"`
	Index        uint        `json:"index,omitempty"`
}

type ChatCompMsg

type ChatCompMsg struct {
	// enum: user, system, assistant
	Role    string `json:"role"`
	Content string `json:"content"`
}

type ChatCompReq

type ChatCompReq struct {
	Model       string        `json:"model"`
	Temperature float32       `json:"temperature"`
	Messages    []ChatCompMsg `json:"messages"`
}

func (*ChatCompReq) Validate

func (req *ChatCompReq) Validate() (err error)

type ChatCompRes

type ChatCompRes struct {
	Id      string `json:"id,omitempty"`
	Object  string `json:"object,omitempty"`
	Created int64  `json:"created,omitempty"`
	Model   string `json:"model,omitempty"`
	Usage   struct {
		PromptTokens     uint32 `json:"prompt_tokens,omitempty"`
		CompletionTokens uint32 `json:"completion_tokens,omitempty"`
		TotalTokens      uint32 `json:"total_tokens,omitempty"`
	} `json:"usage,omitempty"`
	Choices []ChatCompChoice `json:"choices,omitempty"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(fp, key string) (client *Client, err error)

func (*Client) Ask

func (client *Client) Ask(ctx context.Context, content string) (ans string, err error)

func (*Client) ChatCompletions

func (client *Client) ChatCompletions(ctx context.Context, req *ChatCompReq) (res *ChatCompRes, err error)

func (*Client) ImgGen

func (client *Client) ImgGen(ctx context.Context, req *ImgGenReq) (res *ImgGenRes, err error)

func (*Client) Models

func (client *Client) Models(ctx context.Context) (res *ModelsRes, err error)

func (*Client) Trans2Cn

func (client *Client) Trans2Cn(ctx context.Context, content string) (ans string, err error)

func (*Client) Trans2En

func (client *Client) Trans2En(ctx context.Context, content string) (ans string, err error)

type Config

type Config struct {
	Url     string `mapstructure:"url"`
	API_Key string `mapstructure:"api_key"`
	ORG_ID  string `mapstructure:"org_id"`

	Proxy         string `mapstructure:"proxy"`
	TlsSkipVerify bool   `mapstructure:"tls_skip_verify"`
}

func NewConfg

func NewConfg(fp, key string) (config *Config, err error)

type ImgGenReq

type ImgGenReq struct {
	Prompt string `json:"prompt"`
	N      uint32 `json:"n,omitempty"`
	Size   string `json:"size,omitempty"`
}

func (*ImgGenReq) Validate

func (req *ImgGenReq) Validate() (err error)

type ImgGenRes

type ImgGenRes struct {
	Created int64 `json:"created"`
	Data    []struct {
		Url string `json:"url"`
	} `json:"data,omitempty"`
}

func (*ImgGenRes) List

func (res *ImgGenRes) List() []string

func (*ImgGenRes) Save

func (res *ImgGenRes) Save(dir string, id *uuid.UUID) (prefix string, err error)

type Model

type Model struct {
	Id         string       `json:"id,omitempty"`
	Object     string       `json:"object,omitempty"`
	Created    int64        `json:"created,omitempty"`
	OwnedBy    string       `json:"owned_by,omitempty"`
	Root       string       `json:"root,omitempty"`
	Permission []Permission `json:"permission,omitempty"`
}

type ModelsRes

type ModelsRes struct {
	Oobject string  `json:"object,omitempty"`
	Data    []Model `json:"data,omitempty"`
}

type Permission

type Permission struct {
	Id                  string `json:"id,omitempty"`
	Object              string `json:"object,omitempty"`
	Created             int64  `json:"created,omitempty"`
	Organization        string `json:"organization,omitempty"`
	AllowCreateEngine   bool   `json:"allow_create_engine,omitempty"`
	AllowSampling       bool   `json:"allow_sampling,omitempty"`
	AllowLogprobs       bool   `json:"allow_logprobs,omitempty"`
	AllowSearch_indices bool   `json:"allow_search_indices,omitempty"`
	AllowView           bool   `json:"allow_view,omitempty"`
	AllowFineTuning     bool   `json:"allow_fine_tuning,omitempty"`
	IsBlocking          bool   `json:"is_blocking,omitempty"`
}

Jump to

Keyboard shortcuts

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