File size: 1,490 Bytes
6c94128
38b9656
6c94128
 
 
 
38b9656
 
 
 
 
6c94128
38b9656
6c94128
 
 
 
 
 
 
 
38b9656
6c94128
 
 
38b9656
6c94128
38b9656
6c94128
 
 
 
 
 
38b9656
 
6c94128
38b9656
 
 
6c94128
38b9656
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import argparse
import logging
from document_handler import load_documents_from_disk, load_documents_from_sitemap, save_documents_to_disk
from vectorstore_handler import load_or_create_vectorstore, get_embeddings
from query_executor import execute_query

# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', handlers=[
    logging.FileHandler("query_executor.log"),
    logging.StreamHandler()
])

def main(query):
    # Path to save the documents
    sitemap_url = "https://www.originws.it/page-sitemap.xml"
    docs_file_path = 'sitemap_docs.pkl'

    # Try to load documents from disk
    docs = load_documents_from_disk(docs_file_path)

    if docs is None:
        logging.info("Documents not found on disk, loading from sitemap...")
        # Load documents using SitemapLoader
        docs = load_documents_from_sitemap(sitemap_url)
        save_documents_to_disk(docs, docs_file_path)
        logging.info("Documents saved to disk.")
    else:
        logging.info("Documents loaded from disk.")

    # Get embeddings and load/create the vectorstore
    embeddings = get_embeddings()
    vectorstore = load_or_create_vectorstore(docs, embeddings)

    # Now that the vectorstore is ready, let's query it
    question = query
    logging.info(f"Executing query: {question}")
    response = execute_query(question, vectorstore)
    
    # Log the response
    logging.info(f"Query response: {response}")

    return response