llms

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 License: MulanPSL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssistantMessage

type AssistantMessage struct {
	BaseMessage
	FnList []*FunctionCall
}

func NewAssistantMessage

func NewAssistantMessage(role, content string, FnList []*FunctionCall) *AssistantMessage

type BaseMessage

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

func (*BaseMessage) Content

func (im *BaseMessage) Content() string

func (*BaseMessage) Role added in v0.0.9

func (im *BaseMessage) Role() string

func (*BaseMessage) Type added in v0.0.9

func (im *BaseMessage) Type() MessageType

type ConvertMessage

type ConvertMessage func() ([]Message, error)

type FunctionCall

type FunctionCall struct {
	ID,
	Name,
	Arguments,
	Result string
}

type FunctionTool

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

func NewFuncTool

func NewFuncTool(name, desc string, fn interface{}, example ...ToolFunctionExample) (*FunctionTool, error)

func (*FunctionTool) Desc

func (t *FunctionTool) Desc() string

func (*FunctionTool) Examples

func (t *FunctionTool) Examples() []ToolFunctionExample

func (*FunctionTool) Name

func (t *FunctionTool) Name() string

func (*FunctionTool) ParamJsonScheme

func (t *FunctionTool) ParamJsonScheme() (string, error)

func (*FunctionTool) Run

func (t *FunctionTool) Run(param string) (string, error)

func (*FunctionTool) Type

func (t *FunctionTool) Type() ToolType

type Input

type Input interface {
	SetSysMsg(name, content string)
	GetSysMsg() *SystemMessage
	Append(...Message)
	GetAll() []Message
	GetLastOne() Message
	Next() Input
}

type LLM

type LLM interface {
	CheckSupport(LLMSupportType) bool
	Request(ctx context.Context, msg Input, tb ToolBox) (*Output, error)
}

type LLMSupportType added in v0.0.2

type LLMSupportType int
const (
	LLMSupportTypeTool LLMSupportType = 1 // 消息为系统类型
)

type Message

type Message interface {
	Type() MessageType
	Content() string
	Role() string
}

func ConvertOutput2Message

func ConvertOutput2Message(o *Output) []Message

func ConvertPrompt2Message

func ConvertPrompt2Message(msgType MessageType, roleName string, pm utils.ParamsManager, pt prompt.Prompt) (Message, error)

func ConvertPromptArray2Message added in v0.0.9

func ConvertPromptArray2Message(msgType MessageType, roleName string, pm utils.ParamsManager, pts ...prompt.Prompt) ([]Message, error)

func ConvertString2Message

func ConvertString2Message(msgType MessageType, roleName string, msg string) Message

func ConvertStringArray2Message added in v0.0.9

func ConvertStringArray2Message(msgType MessageType, roleName string, msgs ...string) []Message

type MessageType

type MessageType int
const (
	MessageTypeInvalid   MessageType = 0
	MessageTypeSystem    MessageType = 1 // 消息为系统类型
	MessageTypeUser      MessageType = 2 // 消息为用户类型
	MessageTypeAssistant MessageType = 3 // 消息为对话助手类型

	MessageLimit = 100
)

type Output

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

func NewOutput

func NewOutput(usage TokenUsage, content []*OutputMsg) *Output

func (*Output) GetCurrUsage

func (o *Output) GetCurrUsage() TokenUsage

func (*Output) GetTotalUsage

func (o *Output) GetTotalUsage() TokenUsage

func (*Output) LastMsg

func (o *Output) LastMsg() *OutputMsg

func (*Output) MergeMessage

func (o *Output) MergeMessage(oList ...*Output)

func (*Output) SetChild

func (o *Output) SetChild(children ...*Output)

type OutputFinishType

type OutputFinishType int
const (
	OutputFinishInvalid       OutputFinishType = 0
	OutputFinishNormal        OutputFinishType = 1 // 输出内容完全由大模型生成,未触发截断、替换
	OutputFinishStop          OutputFinishType = 2 // 输出结果命中入参 stop 中指定的字段后被截断
	OutputFinishLength        OutputFinishType = 3 // 达到了最大的 token 数
	OutputFinishContentFilter OutputFinishType = 4 // 输出内容被截断、兜底、替换为**等
	OutputFinishToolCalls     OutputFinishType = 5 // 调用了 tool call 功能
)

type OutputMsg

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

func NewOutputMsg

func NewOutputMsg(msgType MessageType, name, content string, finishReason OutputFinishType, fnList ...*FunctionCall) *OutputMsg

func (*OutputMsg) Content

func (om *OutputMsg) Content() string

func (*OutputMsg) FinishReason

func (om *OutputMsg) FinishReason() OutputFinishType

func (*OutputMsg) FunctionCallList

func (om *OutputMsg) FunctionCallList() []FunctionCall

func (*OutputMsg) MsgType

func (om *OutputMsg) MsgType() MessageType

type SystemMessage

type SystemMessage struct {
	BaseMessage
}

func NewSystemMessage

func NewSystemMessage(role, content string) *SystemMessage

type TokenUsage

type TokenUsage struct {
	Prompt,
	Completion,
	Total int64
}

type Tool

type Tool interface {
	Type() ToolType
	Name() string
	Desc() string
	Run(param string) (string, error)
}

type ToolBox

type ToolBox map[string]Tool

func (ToolBox) Add

func (tm ToolBox) Add(t Tool)

func (ToolBox) Get

func (tm ToolBox) Get(k string) (Tool, bool)

func (ToolBox) Remove

func (tm ToolBox) Remove(k string)

func (ToolBox) Tools

func (tm ToolBox) Tools() []Tool

type ToolFunctionExample

type ToolFunctionExample struct {
	Input          string // 用户问题
	FunctionParams string // Json 格式的函数参数示例
	IsCall         bool   // 是否会触发调用函数
}

type ToolType

type ToolType int
const (
	ToolTypeInvalid  ToolType = 0
	ToolTypeFunction ToolType = 1 // 工具类型为:函数
)

type UserMessage

type UserMessage struct {
	BaseMessage
}

func NewUserMessage

func NewUserMessage(role, content string) *UserMessage

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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