Skip to content

Commit 47f4f85

Browse files
committed
refactor: simplify scripts
Signed-off-by: Xin Liu <sam@secondstate.io>
1 parent d6bc891 commit 47f4f85

File tree

2 files changed

+260
-242
lines changed

2 files changed

+260
-242
lines changed

gaianet

Lines changed: 144 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -354,41 +354,41 @@ init() {
354354
exit 1
355355
fi
356356

357-
# download GGUF embedding model file to $gaianet_base_dir
358-
url_embedding_model=$(awk -F'"' '/"embedding":/ {print $4}' $gaianet_base_dir/config.json)
359-
embedding_model=$(basename $url_embedding_model)
360-
if [[ $url_embedding_model =~ ^http[s]?://.* ]]; then
361-
printf "[+] Downloading $embedding_model ...\n"
362-
if [ -f "$gaianet_base_dir/$embedding_model" ]; then
363-
warning " ❗ Using the cached $embedding_model in $gaianet_base_dir"
364-
else
365-
check_curl $url_embedding_model $gaianet_base_dir/$embedding_model
366-
info " 👍 Done! $embedding_model is downloaded in $gaianet_base_dir"
367-
fi
368-
elif [[ $url_embedding_model =~ .*\.gguf$ ]]; then
369-
printf "[+] Using local $embedding_model ...\n"
370-
if [ -f "$gaianet_base_dir/$embedding_model" ]; then
371-
warning " ❗ Found $embedding_model in $gaianet_base_dir"
372-
else
373-
error " ❌ Not found $embedding_model in $gaianet_base_dir. Exit ..."
374-
exit 1
375-
fi
376-
else
377-
error "❌ The 'embedding' field in $gaianet_base_dir/config.json should be a url or a gguf model file. Exit ..."
378-
exit 1
379-
fi
380-
381-
snapshot=$(awk -F'"' '/"snapshot":/ {print $4}' $gaianet_base_dir/config.json)
382-
embedding_collection_name=$(awk -F'"' '/"embedding_collection_name":/ {print $4}' $gaianet_base_dir/config.json)
383-
if [[ -z "$embedding_collection_name" ]]; then
384-
embedding_collection_name="default"
385-
fi
386-
387-
if [ -n "$snapshot" ]; then
388-
# create or recover a qdrant collection
389-
printf "[+] Creating '%s' collection in the Qdrant instance ...\n" "$embedding_collection_name"
390-
create_collection
391-
fi
357+
# # download GGUF embedding model file to $gaianet_base_dir
358+
# url_embedding_model=$(awk -F'"' '/"embedding":/ {print $4}' $gaianet_base_dir/config.json)
359+
# embedding_model=$(basename $url_embedding_model)
360+
# if [[ $url_embedding_model =~ ^http[s]?://.* ]]; then
361+
# printf "[+] Downloading $embedding_model ...\n"
362+
# if [ -f "$gaianet_base_dir/$embedding_model" ]; then
363+
# warning " ❗ Using the cached $embedding_model in $gaianet_base_dir"
364+
# else
365+
# check_curl $url_embedding_model $gaianet_base_dir/$embedding_model
366+
# info " 👍 Done! $embedding_model is downloaded in $gaianet_base_dir"
367+
# fi
368+
# elif [[ $url_embedding_model =~ .*\.gguf$ ]]; then
369+
# printf "[+] Using local $embedding_model ...\n"
370+
# if [ -f "$gaianet_base_dir/$embedding_model" ]; then
371+
# warning " ❗ Found $embedding_model in $gaianet_base_dir"
372+
# else
373+
# error " ❌ Not found $embedding_model in $gaianet_base_dir. Exit ..."
374+
# exit 1
375+
# fi
376+
# else
377+
# error "❌ The 'embedding' field in $gaianet_base_dir/config.json should be a url or a gguf model file. Exit ..."
378+
# exit 1
379+
# fi
380+
381+
# snapshot=$(awk -F'"' '/"snapshot":/ {print $4}' $gaianet_base_dir/config.json)
382+
# embedding_collection_name=$(awk -F'"' '/"embedding_collection_name":/ {print $4}' $gaianet_base_dir/config.json)
383+
# if [[ -z "$embedding_collection_name" ]]; then
384+
# embedding_collection_name="default"
385+
# fi
386+
387+
# if [ -n "$snapshot" ]; then
388+
# # create or recover a qdrant collection
389+
# printf "[+] Creating '%s' collection in the Qdrant instance ...\n" "$embedding_collection_name"
390+
# create_collection
391+
# fi
392392

393393
# Copy config to dashboard
394394
if [ ! -f "$gaianet_base_dir/registry.wasm" ] ; then
@@ -878,45 +878,45 @@ start_gaia_nexus() {
878878

879879
cd $gaianet_base_dir
880880

881-
# enable mcp server if rag_mode is true
882-
MCP_CONFIG_FILE=$gaianet_base_dir/mcp_config.toml
883-
if [ "$rag_mode" = true ]; then
884-
if [ "$(uname)" == "Darwin" ]; then
885-
# macOS
886-
sed -i '.bak' '/name.*=.*"cardea-agentic-search"/,/fallback_message.*=/ {
887-
/enable.*=.*false/ s/enable.*=.*false/enable = true/
888-
}' "$MCP_CONFIG_FILE"
889-
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
890-
# Linux
891-
sed -i.bak '/name.*=.*"cardea-agentic-search"/,/fallback_message.*=/ {
892-
/enable.*=.*false/ s/enable.*=.*false/enable = true/
893-
}' "$MCP_CONFIG_FILE"
894-
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
895-
error " ❌ For Windows users, please run this script in WSL."
896-
exit 1
897-
else
898-
error " ❌ Only support Linux, MacOS and Windows."
899-
exit 1
900-
fi
901-
else
902-
if [ "$(uname)" == "Darwin" ]; then
903-
# macOS
904-
sed -i '.bak' '/name.*=.*"cardea-agentic-search"/,/fallback_message.*=/ {
905-
/enable.*=.*true/ s/enable.*=.*true/enable = false/
906-
}' "$MCP_CONFIG_FILE"
907-
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
908-
# Linux
909-
sed -i.bak '/name.*=.*"cardea-agentic-search"/,/fallback_message.*=/ {
910-
/enable.*=.*true/ s/enable.*=.*true/enable = false/
911-
}' "$MCP_CONFIG_FILE"
912-
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
913-
error " ❌ For Windows users, please run this script in WSL."
914-
exit 1
915-
else
916-
error " ❌ Only support Linux, MacOS and Windows."
917-
exit 1
918-
fi
919-
fi
881+
# # enable mcp server if rag_mode is true
882+
# MCP_CONFIG_FILE=$gaianet_base_dir/mcp_config.toml
883+
# if [ "$rag_mode" = true ]; then
884+
# if [ "$(uname)" == "Darwin" ]; then
885+
# # macOS
886+
# sed -i '.bak' '/name.*=.*"cardea-agentic-search"/,/fallback_message.*=/ {
887+
# /enable.*=.*false/ s/enable.*=.*false/enable = true/
888+
# }' "$MCP_CONFIG_FILE"
889+
# elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
890+
# # Linux
891+
# sed -i.bak '/name.*=.*"cardea-agentic-search"/,/fallback_message.*=/ {
892+
# /enable.*=.*false/ s/enable.*=.*false/enable = true/
893+
# }' "$MCP_CONFIG_FILE"
894+
# elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
895+
# error " ❌ For Windows users, please run this script in WSL."
896+
# exit 1
897+
# else
898+
# error " ❌ Only support Linux, MacOS and Windows."
899+
# exit 1
900+
# fi
901+
# else
902+
# if [ "$(uname)" == "Darwin" ]; then
903+
# # macOS
904+
# sed -i '.bak' '/name.*=.*"cardea-agentic-search"/,/fallback_message.*=/ {
905+
# /enable.*=.*true/ s/enable.*=.*true/enable = false/
906+
# }' "$MCP_CONFIG_FILE"
907+
# elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
908+
# # Linux
909+
# sed -i.bak '/name.*=.*"cardea-agentic-search"/,/fallback_message.*=/ {
910+
# /enable.*=.*true/ s/enable.*=.*true/enable = false/
911+
# }' "$MCP_CONFIG_FILE"
912+
# elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
913+
# error " ❌ For Windows users, please run this script in WSL."
914+
# exit 1
915+
# else
916+
# error " ❌ Only support Linux, MacOS and Windows."
917+
# exit 1
918+
# fi
919+
# fi
920920

921921
# start gaia-nexus
922922
nohup $gaianet_base_dir/bin/gaia-nexus \
@@ -1097,24 +1097,40 @@ register_chat_server_for_demo() {
10971097

10981098
# start rag-api-server and a qdrant instance
10991099
start() {
1100+
# check if DEFAULT_CHAT_SERVICE, DEFAULT_CHAT_SERVICE_API_KEY, and DEMO_CHAT_MODEL are set or not
1101+
if [ -z "$DEFAULT_CHAT_SERVICE" ] || [ -z "$DEFAULT_CHAT_SERVICE_API_KEY" ] || [ -z "$DEMO_CHAT_MODEL" ]; then
1102+
error "Environment variable configuration error:"
1103+
if [ -z "$DEFAULT_CHAT_SERVICE" ]; then
1104+
error " DEFAULT_CHAT_SERVICE is not set or empty"
1105+
fi
1106+
if [ -z "$DEFAULT_CHAT_SERVICE_API_KEY" ]; then
1107+
error " DEFAULT_CHAT_SERVICE_API_KEY is not set or empty"
1108+
fi
1109+
if [ -z "$DEMO_CHAT_MODEL" ]; then
1110+
error " DEMO_CHAT_MODEL is not set or empty"
1111+
fi
1112+
error "All three environment variables must be set together"
1113+
exit 1
1114+
fi
1115+
11001116
local_only=$1
11011117
force_rag=$2
11021118
log_dir=$gaianet_base_dir/log
11031119
if ! [ -d "$log_dir" ]; then
11041120
mkdir -p -m777 $log_dir
11051121
fi
11061122

1107-
snapshot=$(awk -F'"' '/"snapshot":/ {print $4}' $gaianet_base_dir/config.json)
1108-
embedding_collection_name=$(awk -F'"' '/"embedding_collection_name":/ {print $4}' $gaianet_base_dir/config.json)
1109-
if [[ -z "$embedding_collection_name" ]]; then
1110-
embedding_collection_name="default"
1111-
fi
1123+
# snapshot=$(awk -F'"' '/"snapshot":/ {print $4}' $gaianet_base_dir/config.json)
1124+
# embedding_collection_name=$(awk -F'"' '/"embedding_collection_name":/ {print $4}' $gaianet_base_dir/config.json)
1125+
# if [[ -z "$embedding_collection_name" ]]; then
1126+
# embedding_collection_name="default"
1127+
# fi
11121128

1113-
if [ -n "$snapshot" ] || [ "$force_rag" = true ]; then
1114-
rag_mode=true
1115-
else
1116-
rag_mode=false
1117-
fi
1129+
# if [ -n "$snapshot" ] || [ "$force_rag" = true ]; then
1130+
# rag_mode=true
1131+
# else
1132+
# rag_mode=false
1133+
# fi
11181134

11191135
# 1. check if config.json exists or not
11201136
printf "[1/4] Checking the config.json file ...\n"
@@ -1138,14 +1154,14 @@ start() {
11381154
start_embedding_server
11391155
fi
11401156

1141-
# start Qdrant instance if rag mode is true
1142-
if [ "$rag_mode" = true ]; then
1143-
printf " * Starting Qdrant instance ...⏳\n"
1144-
start_qdrant_instance
1157+
# # start Qdrant instance if rag mode is true
1158+
# if [ "$rag_mode" = true ]; then
1159+
# printf " * Starting Qdrant instance ...⏳\n"
1160+
# start_qdrant_instance
11451161

1146-
printf " * Starting Cardea Agentic Search MCP server ...⏳\n"
1147-
start_cardea_agentic_search_mcp_server
1148-
fi
1162+
# printf " * Starting Cardea Agentic Search MCP server ...⏳\n"
1163+
# start_cardea_agentic_search_mcp_server
1164+
# fi
11491165

11501166
# 3. start gaia-frp
11511167
if [ "$local_only" -eq 0 ]; then
@@ -1169,41 +1185,43 @@ start() {
11691185

11701186
# register downstream servers
11711187
printf " * Registering chat server ...⏳\n\n"
1172-
if [ -n "$DEFAULT_CHAT_SERVICE" ] && [ -n "$DEFAULT_CHAT_SERVICE_API_KEY" ]; then
1173-
# Both environment variables are set and non-empty, use demo mode
1174-
register_chat_server_for_demo
1175-
elif [ -z "$DEFAULT_CHAT_SERVICE" ] && [ -z "$DEFAULT_CHAT_SERVICE_API_KEY" ]; then
1176-
# Both environment variables are unset or empty, use normal mode
1177-
register_chat_server
1178-
else
1179-
# One is set but the other is not, show error message
1180-
error "Environment variable configuration error:"
1181-
if [ -z "$DEFAULT_CHAT_SERVICE" ]; then
1182-
error " DEFAULT_CHAT_SERVICE is not set or empty"
1183-
fi
1184-
if [ -z "$DEFAULT_CHAT_SERVICE_API_KEY" ]; then
1185-
error " DEFAULT_CHAT_SERVICE_API_KEY is not set or empty"
1186-
fi
1187-
error "Both DEFAULT_CHAT_SERVICE and DEFAULT_CHAT_SERVICE_API_KEY must be set together, or both left unset"
1188-
exit 1
1189-
fi
1190-
1191-
printf " * Register embedding server ...⏳\n\n"
1192-
if [ -z "$DEFAULT_CHAT_SERVICE" ] && [ -z "$DEFAULT_CHAT_SERVICE_API_KEY" ]; then
1193-
# Both environment variables are unset or empty, use normal mode
1194-
register_embedding_server
1195-
elif [ -z "$DEFAULT_CHAT_SERVICE" ] || [ -z "$DEFAULT_CHAT_SERVICE_API_KEY" ]; then
1196-
# One is set but the other is not, show error message
1197-
error "Environment variable configuration error:"
1198-
if [ -z "$DEFAULT_CHAT_SERVICE" ]; then
1199-
error " DEFAULT_CHAT_SERVICE is not set or empty"
1200-
fi
1201-
if [ -z "$DEFAULT_CHAT_SERVICE_API_KEY" ]; then
1202-
error " DEFAULT_CHAT_SERVICE_API_KEY is not set or empty"
1203-
fi
1204-
error "Both DEFAULT_CHAT_SERVICE and DEFAULT_CHAT_SERVICE_API_KEY must be set together, or both left unset"
1205-
exit 1
1206-
fi
1188+
register_chat_server_for_demo
1189+
1190+
# if [ -n "$DEFAULT_CHAT_SERVICE" ] && [ -n "$DEFAULT_CHAT_SERVICE_API_KEY" ]; then
1191+
# # Both environment variables are set and non-empty, use demo mode
1192+
# register_chat_server_for_demo
1193+
# elif [ -z "$DEFAULT_CHAT_SERVICE" ] && [ -z "$DEFAULT_CHAT_SERVICE_API_KEY" ]; then
1194+
# # Both environment variables are unset or empty, use normal mode
1195+
# register_chat_server
1196+
# else
1197+
# # One is set but the other is not, show error message
1198+
# error "Environment variable configuration error:"
1199+
# if [ -z "$DEFAULT_CHAT_SERVICE" ]; then
1200+
# error " DEFAULT_CHAT_SERVICE is not set or empty"
1201+
# fi
1202+
# if [ -z "$DEFAULT_CHAT_SERVICE_API_KEY" ]; then
1203+
# error " DEFAULT_CHAT_SERVICE_API_KEY is not set or empty"
1204+
# fi
1205+
# error "Both DEFAULT_CHAT_SERVICE and DEFAULT_CHAT_SERVICE_API_KEY must be set together, or both left unset"
1206+
# exit 1
1207+
# fi
1208+
1209+
# printf " * Register embedding server ...⏳\n\n"
1210+
# if [ -z "$DEFAULT_CHAT_SERVICE" ] && [ -z "$DEFAULT_CHAT_SERVICE_API_KEY" ]; then
1211+
# # Both environment variables are unset or empty, use normal mode
1212+
# register_embedding_server
1213+
# elif [ -z "$DEFAULT_CHAT_SERVICE" ] || [ -z "$DEFAULT_CHAT_SERVICE_API_KEY" ]; then
1214+
# # One is set but the other is not, show error message
1215+
# error "Environment variable configuration error:"
1216+
# if [ -z "$DEFAULT_CHAT_SERVICE" ]; then
1217+
# error " DEFAULT_CHAT_SERVICE is not set or empty"
1218+
# fi
1219+
# if [ -z "$DEFAULT_CHAT_SERVICE_API_KEY" ]; then
1220+
# error " DEFAULT_CHAT_SERVICE_API_KEY is not set or empty"
1221+
# fi
1222+
# error "Both DEFAULT_CHAT_SERVICE and DEFAULT_CHAT_SERVICE_API_KEY must be set together, or both left unset"
1223+
# exit 1
1224+
# fi
12071225

12081226
if [ "$local_only" -eq 0 ]; then
12091227
# Extract the subdomain from frpc.toml

0 commit comments

Comments
 (0)