Skip to content

Commit

Permalink
Ability to specify node name in System Prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
Clay-Ferguson committed Dec 11, 2024
1 parent a37f38b commit 2450e32
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/main/java/quanta/mongo/MongoRead.java
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,6 @@ public TreeNode getSubGraphTree(String rootId, Criteria criteria, HashMap<String

public List<SubNode> getFlatSubGraph(final String rootId, boolean includeComments, SearchDefinition def) {
LinkedList<SubNode> doc = new LinkedList<>();

Criteria typeCriteria = null;
if (!includeComments) {
typeCriteria = Criteria.where(SubNode.TYPE).ne(NodeType.COMMENT);
Expand Down
26 changes: 25 additions & 1 deletion src/main/java/quanta/util/AIUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.core.type.TypeReference;
import quanta.config.ServiceBase;
import quanta.exception.MessageException;
import quanta.exception.NoAgentException;
import quanta.exception.base.RuntimeEx;
import quanta.model.AIResponse;
Expand Down Expand Up @@ -51,7 +52,14 @@ public boolean parseAIConfig(SubNode node, SystemConfig system) {
if (node.hasProp(NodeProp.AI_AGENT.s())) {
system.setService(node.getStr(NodeProp.AI_SERVICE.s()));
system.setAgentNodeId(node.getIdStr());
system.setPrompt(node.getStr(NodeProp.AI_PROMPT.s()));

String prompt = node.getStr(NodeProp.AI_PROMPT.s());
if (prompt != null && prompt.length() < 100) {
String nodeName = TL.getSC().getUserName() + ":" + prompt;
prompt = buildSystemPromptFromNode(nodeName);
}

system.setPrompt(prompt);
system.setFoldersToInclude(node.getStr(NodeProp.AI_FOLDERS_TO_INCLUDE.s()));
system.setFoldersToExclude(node.getStr(NodeProp.AI_FOLDERS_TO_EXCLUDE.s()));
system.setFileExtensions(node.getStr(NodeProp.AI_FILE_EXTENSIONS.s()));
Expand Down Expand Up @@ -85,6 +93,22 @@ public boolean parseAIConfig(SubNode node, SystemConfig system) {
return false;
}

public String buildSystemPromptFromNode(String nodeName) {
StringBuilder sb = new StringBuilder();

// verify ndoe exists first
SubNode node = svc_mongoRead.getNodeByName(nodeName, null);
if (node == null) {
throw new MessageException("Node name not found: [" + nodeName + "]");
}

List<SubNode> nodes = svc_mongoRead.getFlatSubGraph(node.getIdStr(), false, null);
for (SubNode n : nodes) {
sb.append(n.getContent() + "\n\n");
}
return sb.toString();
}

public String removeHtmlComments(String val) {
if (val == null) {
return null;
Expand Down

0 comments on commit 2450e32

Please sign in to comment.