ernie

package
v0.1.2-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: MIT Imports: 9 Imported by: 4

Documentation

Overview

Package ernie wrapper around the Baidu Large Language Model Platform APIs. ERNIE-Bot is a Baidu-developed large language model. Additional information can be found at: https://cloud.baidu.com/doc/WENXINWORKSHOP/index.html .

Index

Constants

View Source
const (
	ModelNameERNIEBot       = "ERNIE-Bot"
	ModelNameERNIEBot8K     = "ERNIE-Bot-8K"
	ModelNameERNIEBotTurbo  = "ERNIE-Bot-turbo"
	ModelNameERNIEBotPro    = "ERNIE-Bot-pro"
	ModelNameBloomz7B       = "BLOOMZ-7B"
	ModelNameLlama2_7BChat  = "Llama-2-7b-chat"
	ModelNameLlama2_13BChat = "Llama-2-13b-chat"
	ModelNameLlama2_70BChat = "Llama-2-70b-chat"
)

Variables

View Source
var (
	ErrEmptyResponse = errors.New("no response")
	ErrCodeResponse  = errors.New("has error code")
)

Functions

This section is empty.

Types

type Chat

type Chat struct {
	CallbacksHandler callbacks.Handler
	// contains filtered or unexported fields
}

func NewChat

func NewChat(opts ...Option) (*Chat, error)

func (*Chat) Call

func (o *Chat) Call(ctx context.Context, messages []schema.ChatMessage, options ...llms.CallOption) (*schema.AIChatMessage, error)

Call requests a chat response for the given messages.

func (*Chat) Generate

func (o *Chat) Generate(ctx context.Context, messageSets [][]schema.ChatMessage, options ...llms.CallOption) ([]*llms.Generation, error)

func (*Chat) GeneratePrompt

func (o *Chat) GeneratePrompt(ctx context.Context, promptValues []schema.PromptValue, options ...llms.CallOption) (llms.LLMResult, error)

func (*Chat) GetNumTokens

func (o *Chat) GetNumTokens(text string) int

type ChatMessage

type ChatMessage = ernieclient.ChatMessage

type FunctionCalled

type FunctionCalled interface {
	GetFunctionCall() *schema.FunctionCall
}

FunctionCalled is an interface for objects that have a function call info.

type LLM

type LLM struct {
	CallbacksHandler callbacks.Handler
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) (*LLM, error)

New returns a new Anthropic LLM.

func (*LLM) Call

func (o *LLM) Call(ctx context.Context, prompt string, options ...llms.CallOption) (string, error)

Call implements llms.LLM.

func (*LLM) CreateEmbedding

func (o *LLM) CreateEmbedding(ctx context.Context, texts []string) ([][]float32, error)

CreateEmbedding use ernie Embedding-V1. 1. texts counts less than 16 2. text runes counts less than 384 doc: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/alj562vvu

func (*LLM) Generate

func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.CallOption) ([]*llms.Generation, error)

Generate implements llms.LLM.

func (*LLM) GeneratePrompt

func (o *LLM) GeneratePrompt(ctx context.Context, promptValues []schema.PromptValue,
	options ...llms.CallOption,
) (llms.LLMResult, error)

GeneratePrompt implements llms.LanguageModel.

func (*LLM) GetNumTokens

func (o *LLM) GetNumTokens(_ string) int

GetNumTokens implements llms.LanguageModel.

type ModelName

type ModelName string

type Option

type Option func(*options)

func WithAKSK

func WithAKSK(apiKey, secretKey string) Option

WithAKSK passes the ERNIE API Key and Secret Key to the client. If not set, the keys are read from the ERNIE_API_KEY and ERNIE_SECRET_KEY environment variable. eg:

export ERNIE_API_KEY={Api Key}
export ERNIE_SECRET_KEY={Serect Key}

Api Key,Serect Key from https://console.bce.baidu.com/qianfan/ais/console/applicationConsole/application More information available: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/flfmc9do2

func WithAccessToken

func WithAccessToken(accessToken string) Option

WithAccessToken usually used for dev, Prod env recommend use WithAKSK.

func WithCallbackHandler added in v0.1.3

func WithCallbackHandler(callbacksHandler callbacks.Handler) Option

WithCallbackHandler passes the callback Handler to the client.

func WithModelName

func WithModelName(modelName ModelName) Option

WithModelName passes the Model Name to the client. If not set, use default ERNIE-Bot.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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