Documentation
¶
Overview ¶
Package parser 提供模型响应解析与结构化提取功能
该包从模型输出中解析代码块、JSON 等结构化内容
Index ¶
Constants ¶
View Source
const ( ModeOutside int16 = iota // 0-标签外 ModeEnterTag // 1-进入标签起始 ModeInTag // 2-标签内容 ModePossibleEnd // 3-可能的结束标签起始 ModeEndTagName // 4-结束标签名解析 )
状态机主模式常量
View Source
const ( KeyModeNormal int16 = iota // 0-普通文本 KeyModeThink // 1-思考(think) KeyModeTools // 2-工具调用(tools) )
KeyMode 逻辑区域常量
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AIToolsResponse ¶
type AIToolsResponse struct {
Name string `json:"name"`
ID string `json:"id"`
Parameters map[string]*any `json:"parameters"`
}
AIToolsResponse 工具返回接口
type Parser ¶
type Parser struct {
Session *structs.Chats
Tools []*ToolsDefine
TokenCache string // 缓存正在解析中的标签名(如 "think" 或 "tools")
Mode int16 // 状态机主模式
KeyMode int16 // 当前所处的逻辑区域
Stop bool // 发生错误时停止解析
ToolResponse map[string]string
CalledTools bool // 标记当前请求是否触发了工具调用
ToolsSolved []AIToolsResponse
ToolOriginString strings.Builder
// contains filtered or unexported fields
}
Parser 流式解析器,负责从 AI 响应流中提取 <think> 和 <tools> 标签内容。 它使用状态机处理可能被切分的 token,确保在流式传输中准确识别标签边界。
func NewParser ¶
func NewParser(session *structs.Chats, tools []*ToolsDefine) *Parser
NewParser 创建解析器
type ToolParameters ¶
ToolParameters 工具参数
Click to show internal directories.
Click to hide internal directories.