llms

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: 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(name, content string, FnList []*FunctionCall) *AssistantMessage

type BaseMessage

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

func (*BaseMessage) MsgContent

func (im *BaseMessage) MsgContent() string

func (*BaseMessage) MsgRoleName

func (im *BaseMessage) MsgRoleName() string

func (*BaseMessage) MsgType

func (im *BaseMessage) MsgType() MessageType

type ConvertMessage

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

func ConvertOutput2Message

func ConvertOutput2Message(o *Output) ConvertMessage

func ConvertPrompt2Message

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

func ConvertString2Message

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

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 struct {
	// contains filtered or unexported fields
}

func (*Input) CurrValues

func (i *Input) CurrValues() []Message

func (*Input) GetSysMsg

func (i *Input) GetSysMsg() *SystemMessage

func (*Input) LastMsg

func (i *Input) LastMsg() Message

func (*Input) Next

func (i *Input) Next() *Input

func (*Input) Push

func (i *Input) Push(fn ConvertMessage) error

func (*Input) SetSysMsg

func (i *Input) SetSysMsg(name, content string)

func (*Input) TotalValues

func (i *Input) TotalValues() []Message

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 {
	MsgType() MessageType
	MsgContent() string
}

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 {
	Name    string
	Content string
}

func NewSystemMessage

func NewSystemMessage(name, content string) *SystemMessage

func (*SystemMessage) MsgContent

func (im *SystemMessage) MsgContent() string

func (*SystemMessage) MsgType

func (im *SystemMessage) MsgType() MessageType

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(name, content string) *UserMessage

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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