Compare commits

2 Commits
Author SHA1 Message Date
Jonas Braus 31ed1aad0b Update main.py 2024-12-18 17:01:12 +01:00
Jonas Braus 98a45dd83c Update main.py 2024-12-18 15:21:28 +01:00
2 changed files with 8 additions and 18 deletions
+1 -1
View File
@@ -107,6 +107,6 @@ def get_data_from_mongo(dataset):
for set in dataset:
json_data = collection.find_one({"doc_id": set[0]})
result_string += "Dateipfad: " + json_data["filepath"] + "; Inhalt: " + json_data["chunk_content"] + "; Erstellungszeitpunkt: " + json_data["ctime"] + "; Letzte Bearbeitung: " + json_data["mtime"]
result_string += "Dateipfad: " + json_data["filepath"] + "; Inhalt: " + json_data["chunk_content"] + "; "
return result_string
+7 -17
View File
@@ -9,7 +9,7 @@ import lib
import json
import psycopg2
import pymongo
from datetime import datetime
import mongo_conn
import pgvec_conn
import redis_conn
@@ -21,8 +21,8 @@ def retrieve_file_contents(path, pPullFromS3):
#Minio Connection
minioClient = Minio(
"localhost:9000",
access_key= "PVFOeJbx87rQyi0WXF1X",
secret_key = "Am8Cd9auYGbEGuEXfJtnWEPsMwJCx9N58NCNHCgs",
access_key="qiictMM9mxPiMpTt4mgC",
secret_key="2LXibJOkrFxNlwrhmfAq0jpLA9flQXLLZCHV4Hdy",
secure=False,
)
@@ -40,24 +40,16 @@ def retrieve_file_contents(path, pPullFromS3):
lib.read_files(path, files := [])
contents = []
ctime = ""
mtime = ""
print("parsing files...")
for file in tqdm(files):
if not pPullFromS3:
ctime = datetime.fromtimestamp(os.path.getctime(file[1])).strftime('%Y-%m-%d %H:%M:%S')
mtime = datetime.fromtimestamp(os.path.getmtime(file[1])).strftime('%Y-%m-%d %H:%M:%S')
print(ctime, mtime)
content = file_extraction_functions[file[0]](file[1])
if not pPullFromS3:
push_files_into_s3(file, content, minioClient)
contents.append({
"type": file[0],
"ctime": ctime if not pPullFromS3 else 'Diese Datei kommt ursprünglich nicht von dir, sondern aus einem S3-Bucket. ',
"mtime": mtime if not pPullFromS3 else 'Diese Datei kommt ursprünglich nicht von dir, sondern aus einem S3-Bucket. ',
"path": file[1] if not pPullFromS3 else 'Diese Datei kommt ursprünglich nicht von dir, sondern aus einem S3-Bucket. ',
"path": file[1] if not pPullFromS3 else "Diese Datei kommt ursprünglich nicht von dir, sondern aus einem S3-Bucket. ",
"filename": file[2],
"content": content
})
@@ -104,18 +96,16 @@ def create_embeddings(pContent):
insert_data = f"insert into dbtable (filepath, embedding) Values ('{content['path']}', %s) Returning id;"
cur.execute(insert_data, (response["embedding"],))
doc_id = cur.fetchone()[0]
insert_data_mongo(doc_id, content['path'], chunk, content['ctime'], content["mtime"])
insert_data_mongo(doc_id, content['path'], chunk)
conn.commit()
conn.close()
def insert_data_mongo(id, filepath,pChunk, pCtime, pMtime):
def insert_data_mongo(id, filepath,pChunk):
client = pymongo.MongoClient('mongodb://python:PasswordPassword123@localhost:27017/')
mongodb = client['document_table']
collection = mongodb['documents']
dokument = {
'doc_id': id,
'ctime' : pCtime,
'mtime' : pMtime,
'filepath': filepath,
'chunk_content': pChunk,
}
@@ -176,7 +166,7 @@ def prompt_cycle():
def get_user_action():
user_action = input("Reload Files (r), Load Files From S3 (l), Add Files (a), Prompt (p): ")
user_action = input("Reload Files (r), Load Files From S3 (l), Prompt (p): ")
{
"r": lambda: reload_files(False),