Go: fix register user (#16058)

### What problem does this PR solve?

Fix register user

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

---------

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2026-06-16 14:03:53 +08:00
committed by GitHub
parent 5751a22444
commit fad82fd1c0
10 changed files with 75 additions and 35 deletions

View File

@@ -9,6 +9,7 @@ on:
push: push:
tags: tags:
- "v*.*.*" # normal release - "v*.*.*" # normal release
- 'nightly' # mutable tag
permissions: permissions:
contents: write contents: write

View File

@@ -199,6 +199,30 @@ build_cpp() {
echo -e "${GREEN}✓ C++ static library built successfully${NC}" echo -e "${GREEN}✓ C++ static library built successfully${NC}"
} }
# Build C++ test executable
build_cpp_test() {
print_section "Building C++ test executable"
if [ ! -d "$BUILD_DIR" ]; then
echo "Build directory not found, running cmake first..."
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
cmake .. -DCMAKE_BUILD_TYPE=Release
else
cd "$BUILD_DIR"
fi
echo "Building rag_analyzer_c_test..."
make rag_analyzer_c_test -j$(nproc)
if [ ! -f "$BUILD_DIR/rag_analyzer_c_test" ]; then
echo -e "${RED}Error: Failed to build rag_analyzer_c_test${NC}"
exit 1
fi
echo -e "${GREEN}✓ C++ test executable built successfully: $BUILD_DIR/rag_analyzer_c_test${NC}"
}
# Build Go server # Build Go server
build_go() { build_go() {
print_section "Building RAGFlow go" print_section "Building RAGFlow go"
@@ -312,6 +336,7 @@ Build script for RAGFlow Go server with C++ bindings.
OPTIONS: OPTIONS:
--all, -a Build everything (C++ library + Go server) [default] --all, -a Build everything (C++ library + Go server) [default]
--cpp, -c Build only C++ static library --cpp, -c Build only C++ static library
--cpp-test Build C++ test executable (requires --cpp first)
--go, -g Build only Go server (requires C++ library to be built) --go, -g Build only Go server (requires C++ library to be built)
--clean, -C Clean all build artifacts --clean, -C Clean all build artifacts
--run, -r Build and run the server --run, -r Build and run the server
@@ -321,6 +346,7 @@ EXAMPLES:
$0 # Build everything $0 # Build everything
$0 --cpp # Build only C++ library $0 --cpp # Build only C++ library
$0 --go # Build only Go server $0 --go # Build only Go server
$0 --cpp-test # Build C++ test executable
$0 --run # Build and run $0 --run # Build and run
$0 --clean # Clean build artifacts $0 --clean # Clean build artifacts
@@ -343,6 +369,10 @@ main() {
check_cpp_deps check_cpp_deps
build_cpp build_cpp
;; ;;
--cpp-test)
check_cpp_deps
build_cpp_test
;;
--go|-g) --go|-g)
check_go_deps check_go_deps
build_go build_go

View File

@@ -253,7 +253,7 @@ services:
nats: nats:
profiles: profiles:
- ragflow-go - ragflow-go
image: nats:2.14.1 image: nats:2.14.2
ports: ports:
- ${NATS_PORT}:4222 - ${NATS_PORT}:4222
- "8222:8222" - "8222:8222"

View File

@@ -164,7 +164,7 @@ add_executable(rag_analyzer_c_test
rag_analyzer_c_test.cpp rag_analyzer_c_test.cpp
) )
target_link_libraries(rag_analyzer_c_test rag_tokenizer_c_api stdc++ libm.a ${PCRE2_LIB}) target_link_libraries(rag_analyzer_c_test rag_tokenizer_c_api stdc++ m ${PCRE2_LIB})
target_include_directories(rag_analyzer_c_test PUBLIC "${CMAKE_SOURCE_DIR}") target_include_directories(rag_analyzer_c_test PUBLIC "${CMAKE_SOURCE_DIR}")
set_target_properties(rag_analyzer_c_test PROPERTIES set_target_properties(rag_analyzer_c_test PROPERTIES
CXX_STANDARD 20 CXX_STANDARD 20

View File

@@ -684,35 +684,38 @@ RAGAnalyzer::~RAGAnalyzer() {
int32_t RAGAnalyzer::Load() { int32_t RAGAnalyzer::Load() {
fs::path root(dict_path_); fs::path root(dict_path_);
fs::path dict_path(root / DICT_PATH);
fs::path dict_path(root / DICT_PATH);
printf("Validate dict file: %s\n", dict_path.string().c_str());
if (!fs::exists(dict_path)) { if (!fs::exists(dict_path)) {
printf("Invalid analyzer file: %s", dict_path.string().c_str()); printf("Invalid dict file: %s\n", dict_path.string().c_str());
// return Status::InvalidAnalyzerFile(dict_path);
return -1; return -1;
} }
fs::path pos_def_path(root / POS_DEF_PATH); fs::path pos_def_path(root / POS_DEF_PATH);
printf("Validate pos file: %s\n", pos_def_path.string().c_str());
if (!fs::exists(pos_def_path)) { if (!fs::exists(pos_def_path)) {
printf("Invalid post file: %s", pos_def_path.string().c_str()); printf("Invalid pos file: %s\n", pos_def_path.string().c_str());
// return Status::InvalidAnalyzerFile(pos_def_path); return -2;
return -1;
} }
own_dict_ = true; own_dict_ = true;
trie_ = new DartsTrie(); trie_ = new DartsTrie();
pos_table_ = new POSTable(pos_def_path.string()); pos_table_ = new POSTable(pos_def_path.string());
printf("Load pos file: %s\n", pos_def_path.string().c_str());
if (pos_table_->Load() != 0) { if (pos_table_->Load() != 0) {
printf("Fail to load post table: %s", pos_def_path.string().c_str()); printf("Fail to load pos file: %s\n", pos_def_path.string().c_str());
return -1; return -3;
// return Status::InvalidAnalyzerFile("Failed to load RAGAnalyzer POS definition");
} }
fs::path trie_path(root / TRIE_PATH); fs::path trie_path(root / TRIE_PATH);
printf("Validate trie file: %s\n", trie_path.string().c_str());
if (fs::exists(trie_path)) { if (fs::exists(trie_path)) {
printf("Load trie file: %s\n", trie_path.string().c_str());
trie_->Load(trie_path.string()); trie_->Load(trie_path.string());
} else { } else {
// Build trie // Build trie
try { try {
printf("Build trie file: %s\n", dict_path.string().c_str());
std::ifstream from(dict_path.string()); std::ifstream from(dict_path.string());
std::string line; std::string line;
re2::RE2 re_pattern(R"([\r\n]+)"); re2::RE2 re_pattern(R"([\r\n]+)");
@@ -737,36 +740,35 @@ int32_t RAGAnalyzer::Load() {
} }
trie_->Build(); trie_->Build();
} catch (const std::exception &e) { } catch (const std::exception &e) {
return -1; printf("Fail to build trie: %s\n", e.what());
// return Status::InvalidAnalyzerFile("Failed to load RAGAnalyzer analyzer"); return -4;
} }
printf("Save trie file: %s\n", trie_path.string().c_str());
trie_->Save(trie_path.string()); trie_->Save(trie_path.string());
} }
fs::path lemma_path(root / WORDNET_PATH); fs::path lemma_path(root / WORDNET_PATH);
if (!fs::exists(lemma_path)) { if (!fs::exists(lemma_path)) {
printf("Fail to load wordnet: %s", lemma_path.string().c_str()); printf("Fail to load wordnet: %s\n", lemma_path.string().c_str());
return -1; return -5;
// return Status::InvalidAnalyzerFile(lemma_path);
} }
wordnet_lemma_ = new WordNetLemmatizer(lemma_path.string()); wordnet_lemma_ = new WordNetLemmatizer(lemma_path.string());
fs::path opencc_path(root / OPENCC_PATH); fs::path opencc_path(root / OPENCC_PATH);
printf("Validate opencc file: %s\n", opencc_path.string().c_str());
if (!fs::exists(opencc_path)) { if (!fs::exists(opencc_path)) {
printf("Fail to load opencc_path: %s", opencc_path.string().c_str()); printf("opencc_path not exists: %s\n", opencc_path.string().c_str());
return -1; return -6;
// return Status::InvalidAnalyzerFile(opencc_path);
} }
try { try {
printf("Load opencc file: %s\n", opencc_path.string().c_str());
opencc_ = new ::OpenCC(opencc_path.string()); opencc_ = new ::OpenCC(opencc_path.string());
} catch (const std::exception &e) { } catch (const std::exception &e) {
return -1; printf("Fail to open opencc: %s\n", opencc_path.string().c_str());
// return Status::InvalidAnalyzerFile("Failed to load OpenCC"); return -7;
} }
// return Status::OK();
return 0; return 0;
} }

View File

@@ -10,7 +10,7 @@ void test_single_thread() {
std::cout << "Test 1: Single thread, 1000 iterations..." << std::endl; std::cout << "Test 1: Single thread, 1000 iterations..." << std::endl;
// Create analyzer instance // Create analyzer instance
RAGAnalyzerHandle handle = RAGAnalyzer_Create("."); RAGAnalyzerHandle handle = RAGAnalyzer_Create("./resource");
assert(handle != nullptr && "Failed to create RAGAnalyzer"); assert(handle != nullptr && "Failed to create RAGAnalyzer");
// Load the analyzer // Load the analyzer
@@ -110,8 +110,9 @@ void test_multi_thread() {
} }
int main() { int main() {
std::cout << "Please make sure the './resource' directory exists and is accessible." << std::endl;
std::cout << "=== RAGAnalyzer C API Test ===" << std::endl; std::cout << "=== RAGAnalyzer C API Test ===" << std::endl;
test_single_thread(); test_single_thread();
// test_multi_thread(); // test_multi_thread();

View File

@@ -31,10 +31,10 @@ type Tenant struct {
TenantImg2TxtID *int64 `gorm:"column:tenant_img2txt_id;index" json:"tenant_img2txt_id,omitempty"` TenantImg2TxtID *int64 `gorm:"column:tenant_img2txt_id;index" json:"tenant_img2txt_id,omitempty"`
RerankID string `gorm:"column:rerank_id;size:128;not null;index" json:"rerank_id"` RerankID string `gorm:"column:rerank_id;size:128;not null;index" json:"rerank_id"`
TenantRerankID *int64 `gorm:"column:tenant_rerank_id;index" json:"tenant_rerank_id,omitempty"` TenantRerankID *int64 `gorm:"column:tenant_rerank_id;index" json:"tenant_rerank_id,omitempty"`
TTSID *string `gorm:"column:tts_id;size:256;index" json:"tts_id,omitempty"` TTSID string `gorm:"column:tts_id;size:256;index" json:"tts_id,omitempty"`
TenantTTSID *int64 `gorm:"column:tenant_tts_id;index" json:"tenant_tts_id,omitempty"` TenantTTSID *int64 `gorm:"column:tenant_tts_id;index" json:"tenant_tts_id,omitempty"`
ParserIDs string `gorm:"column:parser_ids;size:256;not null;index" json:"parser_ids"` ParserIDs string `gorm:"column:parser_ids;size:256;not null;index" json:"parser_ids"`
OCRID *string `gorm:"column:ocr_id;size:256" json:"ocr_id,omitempty"` OCRID string `gorm:"column:ocr_id;size:256" json:"ocr_id,omitempty"`
TenantOCRID *int64 `gorm:"column:tenant_ocr_id" json:"tenant_ocr_id,omitempty"` TenantOCRID *int64 `gorm:"column:tenant_ocr_id" json:"tenant_ocr_id,omitempty"`
Credit int64 `gorm:"column:credit;default:512;index" json:"credit"` Credit int64 `gorm:"column:credit;default:512;index" json:"credit"`
Status *string `gorm:"column:status;size:1;index" json:"status,omitempty"` Status *string `gorm:"column:status;size:1;index" json:"status,omitempty"`

View File

@@ -88,6 +88,8 @@ type DefaultModelsConfig struct {
RerankModel ModelConfig `mapstructure:"rerank_model"` RerankModel ModelConfig `mapstructure:"rerank_model"`
ASRModel ModelConfig `mapstructure:"asr_model"` ASRModel ModelConfig `mapstructure:"asr_model"`
Image2TextModel ModelConfig `mapstructure:"image2text_model"` Image2TextModel ModelConfig `mapstructure:"image2text_model"`
OCRModel ModelConfig `mapstructure:"ocr_model"`
TTSModel ModelConfig `mapstructure:"tts_model"`
} }
// ModelConfig model configuration // ModelConfig model configuration

View File

@@ -396,15 +396,9 @@ func (s *TenantService) GetDefaultModelName(tenantID string, modelType entity.Mo
case entity.ModelTypeImage2Text: case entity.ModelTypeImage2Text:
modelID = tenant.Img2TxtID modelID = tenant.Img2TxtID
case entity.ModelTypeTTS: case entity.ModelTypeTTS:
if tenant.TTSID == nil { modelID = tenant.TTSID
return "", fmt.Errorf("tenant TTS model not configured")
}
modelID = *tenant.TTSID
case entity.ModelTypeOCR: case entity.ModelTypeOCR:
if tenant.OCRID == nil { modelID = tenant.OCRID
return "", fmt.Errorf("tenant OCR model not configured")
}
modelID = *tenant.OCRID
default: default:
return "", fmt.Errorf("invalid model type: %s", modelType) return "", fmt.Errorf("invalid model type: %s", modelType)
} }

View File

@@ -186,6 +186,14 @@ func (s *UserService) Register(req *RegisterRequest) (*entity.User, common.Error
if rerankID == "" { if rerankID == "" {
rerankID = "" rerankID = ""
} }
ttsID := cfg.UserDefaultLLM.DefaultModels.TTSModel.Name
if ttsID == "" {
ttsID = ""
}
ocrID := cfg.UserDefaultLLM.DefaultModels.OCRModel.Name
if ocrID == "" {
ocrID = ""
}
tenant := &entity.Tenant{ tenant := &entity.Tenant{
ID: userID, ID: userID,
@@ -195,6 +203,8 @@ func (s *UserService) Register(req *RegisterRequest) (*entity.User, common.Error
ASRID: asrID, ASRID: asrID,
Img2TxtID: img2txtID, Img2TxtID: img2txtID,
RerankID: rerankID, RerankID: rerankID,
TTSID: ttsID,
OCRID: ocrID,
ParserIDs: "naive:General,Q&A:Q&A,manual:Manual,table:Table,paper:Research Paper,book:Book,laws:Laws,presentation:Presentation,picture:Picture,one:One,audio:Audio,email:Email,tag:Tag", ParserIDs: "naive:General,Q&A:Q&A,manual:Manual,table:Table,paper:Research Paper,book:Book,laws:Laws,presentation:Presentation,picture:Picture,one:One,audio:Audio,email:Email,tag:Tag",
Status: &status, Status: &status,
} }