Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -534,20 +534,24 @@ def get_footer_message(user_query):
|
|
| 534 |
@st.cache_resource
|
| 535 |
def load_index():
|
| 536 |
"""Load or create the knowledge base index"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 537 |
if os.path.exists("./storage"):
|
| 538 |
storage_context = StorageContext.from_defaults(persist_dir="./storage")
|
| 539 |
return load_index_from_storage(storage_context)
|
| 540 |
-
|
|
|
|
| 541 |
docs = SimpleDirectoryReader(input_files=["time_to_rethink_trust_book (3).md"]).load_data()
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
llm=LlamaOpenAI(model="gpt-4-turbo"),
|
| 545 |
-
embed_model=embed_model
|
| 546 |
-
)
|
| 547 |
-
index = VectorStoreIndex.from_documents(docs, service_context=service_context)
|
| 548 |
index.storage_context.persist(persist_dir="./storage")
|
| 549 |
return index
|
| 550 |
|
|
|
|
| 551 |
# ---------- INITIALIZE SERVICES ----------
|
| 552 |
index = load_index()
|
| 553 |
tavily = TavilyClient(api_key=os.getenv("TAVILY_API_KEY"))
|
|
|
|
| 534 |
@st.cache_resource
|
| 535 |
def load_index():
|
| 536 |
"""Load or create the knowledge base index"""
|
| 537 |
+
|
| 538 |
+
# ✔ NEW GLOBAL SETTINGS (instead of deprecated ServiceContext)
|
| 539 |
+
Settings.llm = LlamaOpenAI(model="gpt-4-turbo")
|
| 540 |
+
Settings.embed_model = OpenAIEmbedding(model="text-embedding-3-small")
|
| 541 |
+
|
| 542 |
+
# Load existing index if storage exists
|
| 543 |
if os.path.exists("./storage"):
|
| 544 |
storage_context = StorageContext.from_defaults(persist_dir="./storage")
|
| 545 |
return load_index_from_storage(storage_context)
|
| 546 |
+
|
| 547 |
+
# Build new index if storage not present
|
| 548 |
docs = SimpleDirectoryReader(input_files=["time_to_rethink_trust_book (3).md"]).load_data()
|
| 549 |
+
index = VectorStoreIndex.from_documents(docs)
|
| 550 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 551 |
index.storage_context.persist(persist_dir="./storage")
|
| 552 |
return index
|
| 553 |
|
| 554 |
+
|
| 555 |
# ---------- INITIALIZE SERVICES ----------
|
| 556 |
index = load_index()
|
| 557 |
tavily = TavilyClient(api_key=os.getenv("TAVILY_API_KEY"))
|