mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-10-03 15:53:56 +00:00
core: pass ReasoningContent to assistant messages in process.go
- process.go: attach resp.ReasoningContent when building assistant messages - deepseek.lua v2.1.0: remove last_reasoning closure hack; rely on core-provided reasoning_content in messages - openai.lua: strip reasoning_content from messages in transform_request (not supported by OpenAI API)
This commit is contained in:
@ -238,7 +238,7 @@ func (a *Agent) process(input string, stageCtx *sdk.StageContext) (response stri
|
||||
msgContent = resp.Content
|
||||
contentOnce = false
|
||||
}
|
||||
msgs = append(msgs, agentAPI.Message{Role: "assistant", Content: msgContent, ToolCalls: []agentAPI.ToolCall{tc}})
|
||||
msgs = append(msgs, agentAPI.Message{Role: "assistant", Content: msgContent, ReasoningContent: resp.ReasoningContent, ToolCalls: []agentAPI.ToolCall{tc}})
|
||||
msgs = append(msgs, agentAPI.Message{Role: "tool", ToolCallID: tc.ID, Content: result})
|
||||
|
||||
a.publishEvent(events.EventToolCall, map[string]interface{}{
|
||||
|
||||
@ -1,13 +1,14 @@
|
||||
local adapter = {}
|
||||
|
||||
adapter.name = "deepseek"
|
||||
adapter.version = "2.0.0"
|
||||
adapter.version = "2.1.0"
|
||||
adapter.endpoint = "/chat/completions"
|
||||
adapter.headers = {}
|
||||
|
||||
function adapter.transform_request(raw_body)
|
||||
local ok, req = pcall(json.decode, raw_body)
|
||||
if not ok then return raw_body end
|
||||
|
||||
req.model = req.model or "deepseek-chat"
|
||||
req.stream = req.stream or false
|
||||
if req.disable_thinking then
|
||||
|
||||
@ -5,12 +5,17 @@ adapter.version = "2.0.0"
|
||||
adapter.endpoint = "/chat/completions"
|
||||
adapter.headers = {}
|
||||
|
||||
-- OpenAI /chat/completions format (pass-through, strip disable_thinking)
|
||||
-- OpenAI /chat/completions format (pass-through, strip provider-specific fields)
|
||||
function adapter.transform_request(raw_body)
|
||||
local ok, req = pcall(json.decode, raw_body)
|
||||
if not ok then return raw_body end
|
||||
req.disable_thinking = nil
|
||||
req.extra_body = nil
|
||||
if req.messages then
|
||||
for _, msg in ipairs(req.messages) do
|
||||
msg.reasoning_content = nil
|
||||
end
|
||||
end
|
||||
return json.encode(req)
|
||||
end
|
||||
|
||||
|
||||
@ -112,7 +112,6 @@ func (g *GraphDB) initSchema() error {
|
||||
`CREATE INDEX IF NOT EXISTS idx_relation_type ON relations(relation_type)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_relation_status ON relations(status)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_relation_session ON relations(session_id)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_relation_sentence ON relations(sentence_id)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_sentences_text ON sentences(text)`,
|
||||
}
|
||||
|
||||
@ -124,12 +123,15 @@ func (g *GraphDB) initSchema() error {
|
||||
|
||||
// 迁移1:兼容旧版 sentence_ref 列(已有表则忽略)
|
||||
tx.Exec(`ALTER TABLE relations ADD COLUMN sentence_ref TEXT DEFAULT ''`)
|
||||
// 迁移2:为新表添加 sentence_id 列(已有表则忽略)
|
||||
// 迁移2:为新表添加 sentence_id 列(必须放在索引创建之前,否则旧表无此列导致索引创建失败)
|
||||
tx.Exec(`ALTER TABLE relations ADD COLUMN sentence_id INTEGER DEFAULT 0`)
|
||||
// 迁移3:将现有 sentence_ref 数据迁移到 sentences 表
|
||||
tx.Exec(`INSERT OR IGNORE INTO sentences (text) SELECT DISTINCT sentence_ref FROM relations WHERE sentence_ref != ''`)
|
||||
tx.Exec(`UPDATE relations SET sentence_id = (SELECT id FROM sentences WHERE text = relations.sentence_ref) WHERE sentence_ref != ''`)
|
||||
|
||||
// sentence_id 索引在迁移后创建,避免旧表缺少该列时失败
|
||||
tx.Exec(`CREATE INDEX IF NOT EXISTS idx_relation_sentence ON relations(sentence_id)`)
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
|
||||
@ -30,11 +30,28 @@ type Vectorizer interface {
|
||||
Vectorize(text string) vector.Vector
|
||||
}
|
||||
|
||||
// ExtractorConfig 三元组提取器配置
|
||||
type ExtractorConfig struct {
|
||||
FusionAlpha float64 // syntax_conf 权重,默认 0.4
|
||||
FusionBeta float64 // vector_conf 权重,默认 0.6
|
||||
FusionThreshold float64 // 最终阈值,默认 0.3
|
||||
}
|
||||
|
||||
// DefaultExtractorConfig 返回默认的提取器配置
|
||||
func DefaultExtractorConfig() ExtractorConfig {
|
||||
return ExtractorConfig{
|
||||
FusionAlpha: 0.4,
|
||||
FusionBeta: 0.6,
|
||||
FusionThreshold: 0.3,
|
||||
}
|
||||
}
|
||||
|
||||
// Extractor 三元组提取器
|
||||
type Extractor struct {
|
||||
parser Parser
|
||||
fallack Parser // 降级用 POS 模板解析器
|
||||
embedder Vectorizer // 可选:用于 TransE 语义验证
|
||||
fusionCfg ExtractorConfig
|
||||
}
|
||||
|
||||
// NewExtractor 创建提取器。
|
||||
@ -45,8 +62,9 @@ func NewExtractor(parser Parser) *Extractor {
|
||||
parser = defaultParser
|
||||
}
|
||||
return &Extractor{
|
||||
parser: parser,
|
||||
fallack: newFallbackParser(),
|
||||
parser: parser,
|
||||
fallack: newFallbackParser(),
|
||||
fusionCfg: DefaultExtractorConfig(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,6 +73,21 @@ func (e *Extractor) SetEmbedder(ev Vectorizer) {
|
||||
e.embedder = ev
|
||||
}
|
||||
|
||||
// SetFusionWeights 设置三元组融合裁决的权重参数。
|
||||
// - alpha: syntax_conf 权重 (默认 0.4)
|
||||
// - beta: vector_conf 权重 (默认 0.6)
|
||||
// - threshold: 最终阈值 (默认 0.3)
|
||||
func (e *Extractor) SetFusionWeights(alpha, beta, threshold float64) {
|
||||
e.fusionCfg.FusionAlpha = alpha
|
||||
e.fusionCfg.FusionBeta = beta
|
||||
e.fusionCfg.FusionThreshold = threshold
|
||||
}
|
||||
|
||||
// FusionConfig 返回当前融合裁诀配置
|
||||
func (e *Extractor) FusionConfig() ExtractorConfig {
|
||||
return e.fusionCfg
|
||||
}
|
||||
|
||||
// Extract 从文本中提取三元组(完整四阶段流水线)
|
||||
// Phase 1: 句法解析(LTP 分词 → POS 标注 → 依存句法树)
|
||||
// Phase 2: 结构初筛(依存模板 / POS 模板 → 候选三元组 + syntax_conf)
|
||||
@ -104,7 +137,7 @@ func (e *Extractor) Extract(text string) *TripleSet {
|
||||
|
||||
// ——— Phase 4: 融合裁决 ———
|
||||
if len(triples) > 0 {
|
||||
triples = fuseTriples(triples)
|
||||
triples = fuseTriples(triples, e.fusionCfg)
|
||||
}
|
||||
|
||||
allTriples = append(allTriples, triples...)
|
||||
@ -140,37 +173,28 @@ func verifyTriples(triples []Triple, embedder Vectorizer) []Triple {
|
||||
|
||||
// ——— Phase 4: 融合裁决 ———
|
||||
|
||||
const (
|
||||
fusionAlpha = 0.4 // syntax_conf 权重
|
||||
fusionBeta = 0.6 // vector_conf 权重
|
||||
fusionThreshold = 0.3 // 最终阈值
|
||||
)
|
||||
|
||||
// fuseTriples 融合裁决:线性加权计算 final_score,截断阈值,降序输出
|
||||
// 输入:候选三元组(带 syntax_conf + vector_conf)
|
||||
// 处理:final_score = α * syntax_conf + β * vector_conf
|
||||
// 输出:通过阈值且降序排列的最终三元组
|
||||
func fuseTriples(triples []Triple) []Triple {
|
||||
func fuseTriples(triples []Triple, cfg ExtractorConfig) []Triple {
|
||||
if len(triples) == 0 {
|
||||
return triples
|
||||
}
|
||||
|
||||
// 计算 final_score 并更新 Score 字段
|
||||
for i := range triples {
|
||||
t := &triples[i]
|
||||
finalScore := fusionAlpha*t.Score + fusionBeta*t.VectorConf
|
||||
finalScore := cfg.FusionAlpha*t.Score + cfg.FusionBeta*t.VectorConf
|
||||
t.Score = finalScore
|
||||
}
|
||||
|
||||
// 截断低分项
|
||||
kept := make([]Triple, 0, len(triples))
|
||||
for _, t := range triples {
|
||||
if t.Score >= fusionThreshold {
|
||||
if t.Score >= cfg.FusionThreshold {
|
||||
kept = append(kept, t)
|
||||
}
|
||||
}
|
||||
|
||||
// 降序排列
|
||||
sort.Slice(kept, func(i, j int) bool {
|
||||
return kept[i].Score > kept[j].Score
|
||||
})
|
||||
|
||||
@ -17,7 +17,7 @@ import (
|
||||
"gitcode.com/JianFeeeee/HomeAgent/internal/plugin"
|
||||
cli "gitcode.com/JianFeeeee/HomeAgent/internal/plugins/cli"
|
||||
healthcheck "gitcode.com/JianFeeeee/HomeAgent/internal/plugins/healthcheck"
|
||||
openclaw "gitcode.com/JianFeeeee/HomeAgent/internal/plugins/openclaw"
|
||||
openclaw "gitcode.com/JianFeeeee/HomeAgent/internal/plugins/clawhubadapter"
|
||||
webui "gitcode.com/JianFeeeee/HomeAgent/internal/plugins/webui"
|
||||
sdk "gitcode.com/JianFeeeee/HomeAgent/internal/sdk"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user