Spaces:
Sleeping
Sleeping
Commit ·
cbbc2a2
1
Parent(s): 31013be
tweak logging
Browse files- modules/llama_func.py +10 -11
modules/llama_func.py
CHANGED
|
@@ -98,18 +98,17 @@ def construct_index(
|
|
| 98 |
documents = get_documents(file_src)
|
| 99 |
logging.info("构建索引中……")
|
| 100 |
service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, prompt_helper=prompt_helper)
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
except Exception as e:
|
| 111 |
-
logging.error("索引构建失败!", e)
|
| 112 |
except Exception as e:
|
|
|
|
| 113 |
print(e)
|
| 114 |
return None
|
| 115 |
|
|
|
|
| 98 |
documents = get_documents(file_src)
|
| 99 |
logging.info("构建索引中……")
|
| 100 |
service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, prompt_helper=prompt_helper)
|
| 101 |
+
index = GPTSimpleVectorIndex.from_documents(
|
| 102 |
+
documents, service_context=service_context
|
| 103 |
+
)
|
| 104 |
+
logging.debug("索引构建完成!")
|
| 105 |
+
os.makedirs("./index", exist_ok=True)
|
| 106 |
+
index.save_to_disk(f"./index/{index_name}.json")
|
| 107 |
+
logging.debug("索引已保存至本地!")
|
| 108 |
+
return index
|
| 109 |
+
|
|
|
|
|
|
|
| 110 |
except Exception as e:
|
| 111 |
+
logging.error("索引构建失败!", e)
|
| 112 |
print(e)
|
| 113 |
return None
|
| 114 |
|