Example #1
0
def main():
    try:
        opts, args = getopt.getopt(
            sys.argv[1:],
            "t:q:a:ls",
            ["table=", "question=", "answer=", "load", "sentence=", "search"],
        )
    except:
        print("Usage: test.py -t <table>  -l -s")
        sys.exit(2)
    
    table_name = config.DEFAULT_TABLE
    for opt_name, opt_value in opts:
        
        if opt_name in ("-t", "--table"):
            table_name = opt_value
        elif opt_name in ("-q", "--question"):
            question_dir = opt_value
        elif opt_name in ("-a", "--answer"):
            answer_dir = opt_value
        elif opt_name in ("-l", "--load"):
            milvus_bert.import_data(table_name, question_dir, answer_dir)
        elif opt_name in("--sentence"):
            query_sentence = opt_value
            print(query_sentence)
        elif opt_name in ("-s","--search"):
            print("begin search")
            out_put = milvus_bert.search_in_milvus(table_name, query_sentence)
            print(out_put)
Example #2
0
def do_search_api():
    args = reqparse.RequestParser(). \
        add_argument("Table", type=str). \
        add_argument("query_text", type=str). \
        parse_args()

    table_name = args['Table']
    if not table_name:
        table_name = config.DEFAULT_TABLE
    query_sentence = args['query_text']
    if not query_sentence:
        return "no text"
    if query_sentence:
        try:
            output = search_in_milvus(table_name, query_sentence)
            if output:
                return output
            else:
                return "未收录该问题"
        except Exception as e:
            return "Error with {}".format(e)
    return "not found", 400