Add Knowledge Hub books FTS and remove training UI (0.16.0).
Index Assistent/books search.jsonl, expose knowledge hops/catalog in chat, and drop QLoRA/HF training stack. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -98,6 +98,11 @@ public partial class SwarmAssistentExtension
|
||||
}
|
||||
AddLayer("skills", skillsBlock.ToString());
|
||||
AddLayer("identity", Config.RenderIdentityBlock(pid));
|
||||
string knowledgeLayer = BuildKnowledgeSystemLayer(pid);
|
||||
if (!string.IsNullOrWhiteSpace(knowledgeLayer))
|
||||
{
|
||||
AddLayer("knowledge", knowledgeLayer);
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(packName))
|
||||
@@ -179,7 +184,7 @@ public partial class SwarmAssistentExtension
|
||||
return (ollamaMessages, layers);
|
||||
}
|
||||
|
||||
async Task<(string reply, JObject raw, JArray civitaiResults, int systemChars, JObject systemLayers)> RunChatWithHops(
|
||||
async Task<(string reply, JObject raw, JArray civitaiResults, JObject knowledge, int systemChars, JObject systemLayers)> RunChatWithHops(
|
||||
Session session,
|
||||
string root,
|
||||
string modelName,
|
||||
@@ -238,6 +243,8 @@ public partial class SwarmAssistentExtension
|
||||
?? 0;
|
||||
string reply = "";
|
||||
JObject lastRaw = null;
|
||||
JArray knowledgeHops = [];
|
||||
JArray knowledgeResults = [];
|
||||
int maxHops = slimUtility ? 1 : CfgInt("max_tool_hops", MaxToolHopsFallback);
|
||||
HashSet<string> hopDone = new(StringComparer.OrdinalIgnoreCase);
|
||||
for (int hop = 0; hop < maxHops; hop++)
|
||||
@@ -267,7 +274,7 @@ public partial class SwarmAssistentExtension
|
||||
follow = null;
|
||||
break;
|
||||
}
|
||||
follow = await RunToolHop(session, pid, patch, tool, hopDone);
|
||||
follow = await RunToolHop(session, pid, patch, tool, hopDone, knowledgeHops, knowledgeResults);
|
||||
if (follow is not null)
|
||||
{
|
||||
break;
|
||||
@@ -285,7 +292,9 @@ public partial class SwarmAssistentExtension
|
||||
messages.Add(new JObject { ["role"] = "assistant", ["content"] = assistantContent });
|
||||
messages.Add(new JObject { ["role"] = "user", ["content"] = follow });
|
||||
}
|
||||
return (reply, lastRaw, [], systemChars, systemLayers);
|
||||
JObject knowledge = BuildKnowledgeResponse(pid, knowledgeHops, knowledgeResults);
|
||||
JArray civitai = CivitaiResultsShim(knowledgeResults);
|
||||
return (reply, lastRaw, civitai, knowledge, systemChars, systemLayers);
|
||||
}
|
||||
|
||||
static string BuildRetrieveQuery(JArray userMessages, string contextJson, string packName = null)
|
||||
@@ -413,7 +422,9 @@ public partial class SwarmAssistentExtension
|
||||
string pid,
|
||||
JObject patch,
|
||||
string tool,
|
||||
HashSet<string> hopDone)
|
||||
HashSet<string> hopDone,
|
||||
JArray knowledgeHops = null,
|
||||
JArray knowledgeResults = null)
|
||||
{
|
||||
if (tool == "ask_settings")
|
||||
{
|
||||
@@ -452,6 +463,35 @@ public partial class SwarmAssistentExtension
|
||||
+ "omit ask:inventory unless you need a different query.\n```json\n"
|
||||
+ rows.ToString(Newtonsoft.Json.Formatting.None) + "\n```";
|
||||
}
|
||||
if (tool == "ask_knowledge")
|
||||
{
|
||||
string q = patch?["knowledge_query"]?.ToString()?.Trim()
|
||||
?? patch?["example_query"]?.ToString()?.Trim()
|
||||
?? patch?["memory_query"]?.ToString()?.Trim()
|
||||
?? "";
|
||||
string rating = patch?["knowledge_rating"]?.ToString()?.Trim()
|
||||
?? patch?["example_rating"]?.ToString()?.Trim();
|
||||
string sig = "ask_knowledge:" + q.ToLowerInvariant() + ":" + (rating ?? "");
|
||||
if (!hopDone.Add(sig))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(q))
|
||||
{
|
||||
return
|
||||
"ask:knowledge needs knowledge_query (tags / scene / style). "
|
||||
+ "Retry with \"ask\":[\"knowledge\"], \"knowledge_query\":\"redhead stockings\".";
|
||||
}
|
||||
int lim = Config.LoadAssistant(pid)["knowledge_hop_limit"]?.Value<int?>()
|
||||
?? Config.LoadAssistant(pid)["examples_hop_limit"]?.Value<int?>() ?? 6;
|
||||
JArray rows = SearchKnowledge(pid, q, lim, rating);
|
||||
knowledgeHops?.Add(new JObject { ["tool"] = "ask_knowledge", ["query"] = q, ["count"] = rows.Count });
|
||||
MergeKnowledgeResults(knowledgeResults, rows);
|
||||
return
|
||||
"ask:knowledge — FTS over attached books (read-only references). "
|
||||
+ "Remix ideas; do not paste long verbatim.\n```json\n"
|
||||
+ rows.ToString(Newtonsoft.Json.Formatting.None) + "\n```";
|
||||
}
|
||||
if (tool == "ask_examples")
|
||||
{
|
||||
string q = patch?["example_query"]?.ToString()?.Trim()
|
||||
@@ -471,6 +511,8 @@ public partial class SwarmAssistentExtension
|
||||
}
|
||||
int lim = Config.LoadAssistant(pid)["examples_hop_limit"]?.Value<int?>() ?? 5;
|
||||
JArray examples = Memory?.LookupExamples(q, lim, rating) ?? [];
|
||||
knowledgeHops?.Add(new JObject { ["tool"] = "ask_examples", ["query"] = q, ["count"] = examples.Count });
|
||||
MergeKnowledgeResults(knowledgeResults, examples, legacyExamples: true);
|
||||
return
|
||||
"ask:examples — Civitai Krea2 prompt references (FTS, no embeddings). "
|
||||
+ "These are EXAMPLES to remix, not copy 1:1. Prefer craft over pasting.\n```json\n"
|
||||
|
||||
Reference in New Issue
Block a user