ernie

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MulanPSL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TokenPrefix = "baidu:token:"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ErnieFunction

type ErnieFunction struct {
	Name        string                  `json:"name"`
	Description string                  `json:"description"`
	Parameters  any                     `json:"parameters"`
	Responses   any                     `json:"responses"`
	Examples    []*ErnieFunctionExample `json:"examples,omitempty"`
}

type ErnieFunctionCall

type ErnieFunctionCall struct {
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
	Thoughts  string `json:"thoughts"`
}

type ErnieFunctionExample

type ErnieFunctionExample struct {
	Role         string             `json:"role"`
	Content      *string            `json:"content"`
	Name         string             `json:"name,omitempty"`
	FunctionCall *ErnieFunctionCall `json:"function_call,omitempty"`
}

type LLM

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

func NewLLM

func NewLLM(apiKey, apiSecret string, model ModelType, opt *Option) (*LLM, error)

func (*LLM) CheckSupport added in v0.0.2

func (llm *LLM) CheckSupport(v llms.LLMSupportType) bool

func (*LLM) Request

func (llm *LLM) Request(ctx context.Context, input *llms.Input, tb llms.ToolBox) (*llms.Output, error)

type ModelType

type ModelType int
const (
	ModelTypeErnieBot    ModelType = 1 // 对应模型 ERNIE-Bot
	ModelTypeErnieBot8K  ModelType = 2 // 对应模型 ERNIE-Bot-8K
	ModelTypeErnieBotPro ModelType = 3 // 对应模型 ERNIE-Bot 4.0
)

type Option

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

func NewOption

func NewOption() *Option

func (*Option) SetCache

func (p *Option) SetCache(val utils.KeyValueCache) *Option

func (*Option) SetHttpClient

func (p *Option) SetHttpClient(val *http.Client) *Option

func (*Option) SetMsgLimit

func (p *Option) SetMsgLimit(val uint) *Option

func (*Option) SetPenaltyScore

func (p *Option) SetPenaltyScore(val float32) *Option

func (*Option) SetTemperature

func (p *Option) SetTemperature(val float32) *Option

func (*Option) SetTopP

func (p *Option) SetTopP(val float32) *Option

type ReqChatCompMsg

type ReqChatCompMsg struct {
	Role         string             `json:"role"`
	Content      *string            `json:"content"`
	Name         string             `json:"name,omitempty"`
	FunctionCall *ErnieFunctionCall `json:"function_call,omitempty"`
}

type Request

type Request struct {
	Messages        []*ReqChatCompMsg `json:"messages"`
	Temperature     float32           `json:"temperature,omitempty"`
	TopP            float32           `json:"top_p,omitempty"`
	PresencePenalty float32           `json:"presence_penalty,omitempty"`
	Stream          bool              `json:"stream"`
	UserId          string            `json:"user_id,omitempty"`
	PenaltyScore    float32           `json:"penalty_score,omitempty"`
	Functions       []*ErnieFunction  `json:"functions,omitempty"`
	System          string            `json:"system,omitempty"`
	Stop            []string          `json:"stop,omitempty"`
	DisableSearch   bool              `json:"disable_search,omitempty"`
	EnableCitation  bool              `json:"enable_citation,omitempty"`
}

type RespError

type RespError struct {
	ErrorCode int    `json:"error_code"`
	ErrorMsg  string `json:"error_msg"`
}

type RespPluginUsage

type RespPluginUsage struct {
	Name           string `json:"name"`
	ParseTokens    int    `json:"parse_tokens"`
	AbstractTokens int    `json:"abstract_tokens"`
	SearchTokens   int    `json:"search_tokens"`
	TotalTokens    int    `json:"total_tokens"`
}

type RespSearchInfo

type RespSearchInfo struct {
	IsBeset       bool                `json:"is_beset"`
	ReWrite       string              `json:"re_write"`
	SearchResults []*RespSearchResult `json:"search_results,omitempty"`
}

type RespSearchResult

type RespSearchResult struct {
	Index        int    `json:"index"`
	Url          string `json:"url"`
	Title        string `json:"title"`
	DataSourceId string `json:"data_source_id"`
}

type RespUsage

type RespUsage struct {
	PromptTokens     int                `json:"prompt_tokens"`
	CompletionTokens int                `json:"completion_tokens"`
	TotalTokens      int                `json:"total_tokens"`
	Plugins          []*RespPluginUsage `json:"plugins,omitempty"`
}

type Response

type Response struct {
	RespError

	ID               string             `json:"id"`
	Object           string             `json:"object"`
	Created          int                `json:"created"`
	SentenceId       int                `json:"sentence_id"`
	BanRound         int                `json:"ban_round"`
	IsEnd            bool               `json:"is_end"`
	IsTruncated      bool               `json:"is_truncated"`
	NeedClearHistory bool               `json:"need_clear_history"`
	FinishReason     string             `json:"finish_reason"`
	Result           string             `json:"result"`
	Usage            RespUsage          `json:"usage"`
	FunctionCall     *ErnieFunctionCall `json:"function_call,omitempty"`
	SearchInfo       *RespSearchInfo    `json:"search_info,omitempty"`
}

type ResponseAccessToken

type ResponseAccessToken struct {
	RefreshToken     string `json:"refresh_token"`
	ExpiresIn        int    `json:"expires_in"`
	SessionKey       string `json:"session_key"`
	AccessToken      string `json:"access_token"`
	Scope            string `json:"scope"`
	SessionSecret    string `json:"session_secret"`
	Error            string `json:"error"`
	ErrorDescription string `json:"error_description"`
}

Jump to

Keyboard shortcuts

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