openaitranslator

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: MIT Imports: 7 Imported by: 1

README

openai-translater

go-openai-translater

Documentation

Index

Constants

View Source
const (
	DefaultMaxTokens        = 1000
	DefaultTemperature      = 0.0
	DefaultTopP             = 1.0
	DefaultPresencePenalty  = 1.0
	DefaultFrequencyPenalty = 1.0
	GPT3Dot5Turbo0301       = gpt3.GPT3Dot5Turbo0301
	GPT3Dot5Turbo           = gpt3.GPT3Dot5Turbo
)

Variables

This section is empty.

Functions

func GetLangMap

func GetLangMap() map[string]string

func RegistLanguage

func RegistLanguage(langCode, langName string)

func Translate

func Translate(text, To, Token string, opt ...Option) (string, error)

func TranslateWithConfig

func TranslateWithConfig(text, To, Token string, cfg *TranslationConfig) (string, error)

Types

type Detected

type Detected struct {
	Lang       string  `json:"lang"`       // detected language
	Confidence float64 `json:"confidence"` // the confidence of detection result (0.00 to 1.00)
}

Detected represents language detection result

type Option

type Option func(*TranslationConfig)

func WithCtx

func WithCtx(Ctx context.Context) Option

func WithDebug

func WithDebug() Option

func WithFrequencyPenalty

func WithFrequencyPenalty(FrequencyPenalty float32) Option

func WithFrom

func WithFrom(From string) Option

func WithMaxTokens

func WithMaxTokens(MaxTokens int) Option

func WithModel

func WithModel(Model string) Option

func WithPresencePenalty

func WithPresencePenalty(PresencePenalty float32) Option

func WithTemperature

func WithTemperature(Temperature float32) Option

func WithTopP

func WithTopP(TopP float32) Option

type Translated

type Translated struct {
	// Detected      Detected `json:"detected"`
	Text string `json:"text"` // translated text

}

type TranslationConfig

type TranslationConfig struct {
	Ctx                 context.Context
	Debug               bool
	Model               string // GPT3Dot5Turbo0301,GPT3Dot5Turbo
	MaxTokens           int
	Temperature         float32 // 0-2, 越高越随机
	TopP                float32 // 0-1,0.1表示仅考虑包含最高前10%概率质量的令牌,推荐1.0
	PresencePenalty     float32 // 介于-2.0和2.0之间的数字。正值会根据新标记到目前为止是否出现在文本中来惩罚它们,从而增加模型谈论新主题的可能性。
	FrequencyPenalty    float32 // 介于-2.0和2.0之间的数字。正值会根据新符号在文本中的现有频率来惩罚它们,从而降低模型逐字重复同一行的可能性。
	From, SelectedWords string
}

func DefaultConfig

func DefaultConfig() *TranslationConfig

Jump to

Keyboard shortcuts

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