Skip to content

Commit ff8877b

Browse files
committed
refactor: integrate new gaia-nexus
Signed-off-by: Xin Liu <sam@secondstate.io>
1 parent 90a4076 commit ff8877b

File tree

2 files changed

+94
-132
lines changed

2 files changed

+94
-132
lines changed

config.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
"llamaedge_chat_port": "9068",
66
"llamaedge_embedding_port": "9069",
77
"llamaedge_port": "8080",
8-
"chat": "https://huggingface.co/second-state/Llama-3.2-3B-Instruct-GGUF/resolve/main/Llama-3.2-3B-Instruct-Q5_K_M.gguf",
9-
"chat_name": "Llama-3.2-3B-Instruct",
8+
"chat": "https://huggingface.co/second-state/Qwen3-4B-GGUF/resolve/main/Qwen3-4B-Q5_K_M.gguf",
9+
"chat_name": "Qwen3-4B",
1010
"chat_ctx_size": "16384",
1111
"chat_batch_size": "128",
1212
"chat_ubatch_size": "128",
13-
"prompt_template": "llama-3-chat",
13+
"prompt_template": "qwen3-no-think",
1414
"reverse_prompt": "",
1515
"system_prompt": "You are a helpful AI assistant. Please answer questions as clearly and concisely as possible.",
16-
"context_window": "1",
1716
"embedding": "https://huggingface.co/gaianet/Nomic-embed-text-v1.5-Embedding-GGUF/resolve/main/nomic-embed-text-v1.5.f16.gguf",
1817
"embedding_name": "Nomic-embed-text-v1.5",
1918
"embedding_ctx_size": "8192",
@@ -22,7 +21,5 @@
2221
"snapshot": "",
2322
"embedding_collection_name": "default",
2423
"qdrant_limit": "1",
25-
"qdrant_score_threshold": "0.5",
26-
"rag_policy": "system-message",
27-
"rag_prompt": "Use the following information to answer the question.\n----------------\n"
24+
"qdrant_score_threshold": "0.5"
2825
}

gaianet

Lines changed: 90 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,6 @@ check_config_options() {
155155
exit 1
156156
fi
157157

158-
# check if the `rag_prompt` field exists or not
159-
if ! grep -q '"rag_prompt":' $gaianet_base_dir/config.json; then
160-
error "❌ Not found the 'rag_prompt' field in $gaianet_base_dir/config.json\n"
161-
exit 1
162-
fi
163-
164-
# check if the `rag_policy` field exists or not
165-
if ! grep -q '"rag_policy":' $gaianet_base_dir/config.json; then
166-
error "❌ Not found the 'rag_policy' field in $gaianet_base_dir/config.json\n"
167-
exit 1
168-
fi
169-
170158
# check if the `domain` field exists or not
171159
if ! grep -q '"domain":' $gaianet_base_dir/config.json; then
172160
error "❌ Not found the 'domain' field in $gaianet_base_dir/config.json\n"
@@ -770,6 +758,41 @@ start_qdrant_instance() {
770758

771759
}
772760

761+
start_cardea_agentic_search_mcp_server() {
762+
# check if cardea-agentic-search-mcp-server exists
763+
cardea_agentic_search_mcp_server="$gaianet_base_dir/bin/cardea-agentic-search-mcp-server"
764+
if [ ! -f "$cardea_agentic_search_mcp_server" ]; then
765+
error "❌ Not found cardea-agentic-search-mcp-server binary at $gaianet_base_dir/bin"
766+
gaianet stop
767+
exit 1
768+
fi
769+
770+
# parse qdrant collection name
771+
qdrant_collection_name=$(awk -F'"' '/"embedding_collection_name":/ {print $4}' $gaianet_base_dir/config.json)
772+
if [[ -z "$qdrant_collection_name" ]]; then
773+
qdrant_collection_name="default"
774+
fi
775+
776+
# parse qdrant score threshold
777+
qdrant_score_threshold=$(awk -F'"' '/"qdrant_score_threshold":/ {print $4}' $gaianet_base_dir/config.json)
778+
779+
# parse qdrant limit
780+
qdrant_limit=$(awk -F'"' '/"qdrant_limit":/ {print $4}' $gaianet_base_dir/config.json)
781+
782+
nohup $gaianet_base_dir/bin/cardea-agentic-search-mcp-server \
783+
qdrant \
784+
--qdrant-collection $qdrant_collection_name \
785+
--score-threshold $qdrant_score_threshold \
786+
--limit $qdrant_limit \
787+
--qdrant-payload-field "source" \
788+
--embedding-service http://localhost:$llamaedge_embedding_port/v1 > /dev/null 2>&1 &
789+
790+
sleep 2
791+
cardea_agentic_search_mcp_server_pid=$!
792+
echo $cardea_agentic_search_mcp_server_pid > $gaianet_base_dir/cardea_agentic_search_mcp.pid
793+
info "\n 👍 Done! Cardea Agentic Search MCP server started with pid: $cardea_agentic_search_mcp_server_pid"
794+
}
795+
773796
check_nexus_with_retry() {
774797
local url=$1
775798
local max_retries=6
@@ -832,24 +855,6 @@ start_gaia_nexus() {
832855
# parse qdrant limit
833856
qdrant_limit=$(awk -F'"' '/"qdrant_limit":/ {print $4}' $gaianet_base_dir/config.json)
834857

835-
# parse system prompt for chat model
836-
rag_prompt=$(awk -F'"' '/"rag_prompt":/ {print $4}' $gaianet_base_dir/config.json)
837-
838-
# parse context window
839-
# check if context window is present in config.json
840-
if grep -q '"context_window":' $gaianet_base_dir/config.json; then
841-
context_window=$(awk -F'"' '/"context_window":/ {print $4}' $gaianet_base_dir/config.json)
842-
else
843-
context_window=1
844-
fi
845-
846-
# parse rag policy
847-
if grep -q '"rag_policy":' $gaianet_base_dir/config.json; then
848-
rag_policy=$(awk -F'"' '/"rag_policy":/ {print $4}' $gaianet_base_dir/config.json)
849-
else
850-
rag_policy="system-message"
851-
fi
852-
853858
# parse port for LlamaEdge API Server
854859
llamaedge_port=$(awk -F'"' '/"llamaedge_port":/ {print $4}' $gaianet_base_dir/config.json)
855860

@@ -863,49 +868,58 @@ start_gaia_nexus() {
863868
exit 1
864869
fi
865870

866-
# start gaia-nexus
867871
cd $gaianet_base_dir
872+
873+
# enable mcp server if rag_mode is true
874+
MCP_CONFIG_FILE=$gaianet_base_dir/mcp_config.toml
868875
if [ "$rag_mode" = true ]; then
869-
# check if cardea-qdrant-mcp-server exists
870-
cardea_qdrant_mcp_server="$gaianet_base_dir/bin/cardea-qdrant-mcp-server"
871-
if [ ! -f "$cardea_qdrant_mcp_server" ]; then
872-
error "❌ Not found cardea-qdrant-mcp-server binary at $gaianet_base_dir/bin"
876+
if [ "$(uname)" == "Darwin" ]; then
877+
# macOS
878+
sed -i '.bak' '/name.*=.*"cardea-agentic-search"/,/fallback_message.*=/ {
879+
/enable.*=.*false/ s/enable.*=.*false/enable = true/
880+
}' "$MCP_CONFIG_FILE"
881+
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
882+
# Linux
883+
sed -i.bak '/name.*=.*"cardea-agentic-search"/,/fallback_message.*=/ {
884+
/enable.*=.*false/ s/enable.*=.*false/enable = true/
885+
}' "$MCP_CONFIG_FILE"
886+
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
887+
error " ❌ For Windows users, please run this script in WSL."
888+
exit 1
889+
else
890+
error " ❌ Only support Linux, MacOS and Windows."
873891
exit 1
874892
fi
875-
876-
# start cardea-qdrant-mcp-server
877-
nohup $gaianet_base_dir/bin/cardea-qdrant-mcp-server \
878-
--collection $qdrant_collection_name \
879-
--limit $qdrant_limit \
880-
--score-threshold $qdrant_score_threshold \
881-
--transport stream-http \
882-
--socket-addr 127.0.0.1:8003 > $log_dir/qdrant-mcp-server.log 2>&1 &
883-
884-
# start gaia-nexus
885-
nohup $gaianet_base_dir/bin/gaia-nexus \
886-
--gaianet-dir $gaianet_base_dir \
887-
--rag \
888-
--rag-prompt "'$rag_prompt'" \
889-
--rag-context-window $context_window \
890-
--rag-policy $rag_policy \
891-
--check-health \
892-
--check-health-interval 60 \
893-
--web-ui $gaianet_base_dir/dashboard \
894-
--log-destination file \
895-
--log-file $log_dir/gaia-nexus.log \
896-
--port $llamaedge_port > $log_dir/start-gaia-nexus.log 2>&1 &
897-
898893
else
899-
# start gaia-nexus
900-
nohup $gaianet_base_dir/bin/gaia-nexus \
901-
--gaianet-dir $gaianet_base_dir \
902-
--check-health \
903-
--check-health-interval 60 \
904-
--web-ui $gaianet_base_dir/dashboard \
905-
--log-destination file \
906-
--log-file $log_dir/gaia-nexus.log \
907-
--port $llamaedge_port > $log_dir/start-gaia-nexus.log 2>&1 &
894+
if [ "$(uname)" == "Darwin" ]; then
895+
# macOS
896+
sed -i '.bak' '/name.*=.*"cardea-agentic-search"/,/fallback_message.*=/ {
897+
/enable.*=.*true/ s/enable.*=.*true/enable = false/
898+
}' "$MCP_CONFIG_FILE"
899+
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
900+
# Linux
901+
sed -i.bak '/name.*=.*"cardea-agentic-search"/,/fallback_message.*=/ {
902+
/enable.*=.*true/ s/enable.*=.*true/enable = false/
903+
}' "$MCP_CONFIG_FILE"
904+
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
905+
error " ❌ For Windows users, please run this script in WSL."
906+
exit 1
907+
else
908+
error " ❌ Only support Linux, MacOS and Windows."
909+
exit 1
910+
fi
908911
fi
912+
913+
# start gaia-nexus
914+
nohup $gaianet_base_dir/bin/gaia-nexus \
915+
--gaianet-dir $gaianet_base_dir \
916+
--check-health \
917+
--check-health-interval 60 \
918+
--web-ui $gaianet_base_dir/dashboard \
919+
--log-destination file \
920+
--log-file $log_dir/gaia-nexus.log \
921+
--port $llamaedge_port > $log_dir/start-gaia-nexus.log 2>&1 &
922+
909923
llama_nexus_pid=$!
910924

911925
# Check if the command started successfully
@@ -1072,6 +1086,9 @@ start() {
10721086
if [ "$rag_mode" = true ]; then
10731087
printf " * Starting Qdrant instance ...⏳\n"
10741088
start_qdrant_instance
1089+
1090+
printf " * Starting Cardea Agentic Search MCP server ...⏳\n"
1091+
start_cardea_agentic_search_mcp_server
10751092
fi
10761093

10771094
# 3. start gaia-frp
@@ -1101,7 +1118,6 @@ start() {
11011118
printf " * Register embedding server ...⏳\n\n"
11021119
register_embedding_server
11031120

1104-
11051121
if [ "$local_only" -eq 0 ]; then
11061122
# Extract the subdomain from frpc.toml
11071123
subdomain=$(grep "subdomain" $gaianet_base_dir/gaia-frp/frpc.toml | cut -d'=' -f2 | tr -d ' "')
@@ -1127,6 +1143,7 @@ stop_force() {
11271143

11281144
pkill -9 qdrant || true
11291145
pkill -9 gaia-nexus || true
1146+
pkill -9 cardea-agentic-search-mcp-server || true
11301147
pkill -9 wasmedge || true
11311148
pkill -9 frpc || true
11321149

@@ -1150,6 +1167,11 @@ stop_force() {
11501167
rm $llama_nexus_pid
11511168
fi
11521169

1170+
cardea_agentic_search_mcp_pid=$gaianet_base_dir/cardea_agentic_search_mcp.pid
1171+
if [ -f $cardea_agentic_search_mcp_pid ]; then
1172+
rm $cardea_agentic_search_mcp_pid
1173+
fi
1174+
11531175
gaia_frp_pid=$gaianet_base_dir/gaia-frp.pid
11541176
if [ -f $gaia_frp_pid ]; then
11551177
rm $gaia_frp_pid
@@ -1292,14 +1314,11 @@ case $subcommand in
12921314
llamaedge_chat_port=""
12931315
llamaedge_embedding_port=""
12941316
system_prompt=""
1295-
rag_prompt=""
1296-
rag_policy=""
12971317
reverse_prompt=""
12981318
domain=""
12991319
snapshot="placeholder"
13001320
qdrant_limit=""
13011321
qdrant_score_threshold=""
1302-
context_window=""
13031322

13041323
while (( "$#" )); do
13051324
case "$1" in
@@ -1381,18 +1400,6 @@ case $subcommand in
13811400
shift 2
13821401
fi
13831402
;;
1384-
--rag-prompt)
1385-
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
1386-
rag_prompt=$2
1387-
shift 2
1388-
fi
1389-
;;
1390-
--rag-policy)
1391-
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
1392-
rag_policy=$2
1393-
shift 2
1394-
fi
1395-
;;
13961403
--reverse-prompt)
13971404
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
13981405
reverse_prompt=$2
@@ -1428,12 +1435,6 @@ case $subcommand in
14281435
shift 2
14291436
fi
14301437
;;
1431-
--context-window)
1432-
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
1433-
context_window=$2
1434-
shift 2
1435-
fi
1436-
;;
14371438
--base)
14381439
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
14391440
gaianet_base_dir=$2
@@ -1595,32 +1596,6 @@ case $subcommand in
15951596
sed_in_place "s|\"system_prompt\": \".*\"|\"system_prompt\": \"$new_value_escaped\"|" $gaianet_base_dir/config.json
15961597
fi
15971598

1598-
# update rag prompt
1599-
if [ -n "$rag_prompt" ]; then
1600-
printf "[+] Updating the rag prompt of chat model ...\n"
1601-
printf " * Old port: $(awk -F'"' '/"rag_prompt":/ {print $4}' $gaianet_base_dir/config.json)\n"
1602-
info " * New rag prompt: $rag_prompt"
1603-
1604-
# The new value for rag_prompt
1605-
new_value="$rag_prompt"
1606-
1607-
# Escape ampersands and backslashes in the new value
1608-
new_value_escaped=$(echo "$new_value" | sed 's/[&\\/]/\\&/g')
1609-
1610-
# Update the value of rag_prompt in config.json
1611-
sed_in_place "s|\"rag_prompt\": \".*\"|\"rag_prompt\": \"$new_value_escaped\"|" $gaianet_base_dir/config.json
1612-
fi
1613-
1614-
# update rag policy
1615-
if [ -n "$rag_policy" ]; then
1616-
printf "[+] Updating the rag policy of GaiaNet node ...\n"
1617-
printf " * Old rag policy: $(awk -F'"' '/"rag_policy":/ {print $4}' $gaianet_base_dir/config.json)\n"
1618-
info " * New rag policy: $rag_policy"
1619-
1620-
# update
1621-
update_config rag_policy $rag_policy
1622-
fi
1623-
16241599
# update domain
16251600
if [ -n "$domain" ]; then
16261601
printf "[+] Updating the domain of GaiaNet node ...\n"
@@ -1661,16 +1636,6 @@ case $subcommand in
16611636
update_config qdrant_score_threshold $qdrant_score_threshold
16621637
fi
16631638

1664-
# update context window
1665-
if [ -n "$context_window" ]; then
1666-
printf "[+] Updating the context window ...\n"
1667-
printf " * Old window: $(awk -F'"' '/"context_window":/ {print $4}' $gaianet_base_dir/config.json)\n"
1668-
info " * New window: $context_window"
1669-
1670-
# update
1671-
update_config context_window $context_window
1672-
fi
1673-
16741639
printf "✅ COMPLETED! The config.json is updated successfully.\n\n"
16751640

16761641
exit 0

0 commit comments

Comments
 (0)