This commit is contained in:
Jonas Braus
2024-12-10 23:34:44 +01:00
parent 68e699f38f
commit cda757029e
7 changed files with 31 additions and 128 deletions
+28 -11
View File
@@ -31,10 +31,6 @@ def retrieve_file_contents(path):
return contents
contents = retrieve_file_contents("C:\\Users\\afist\\Downloads\\SoftwareEng")
embedding_list = []
def create_embeddings(pContent):
conn = psycopg2.connect(
@@ -49,35 +45,56 @@ def create_embeddings(pContent):
create_table_query = '''
create table if not exists dbtable (
id SERIAL PRIMARY KEY,
filename TEXT NOT NULL,
embedding VECTOR NOT NULL
)
filepath TEXT NOT NULL,
embedding VECTOR NOT NULL
);
'''
cur.execute('CREATE EXTENSION IF NOT EXISTS vector;')
cur.execute(create_table_query)
cur.execute('CREATE EXTENSION IF NOT EXISTS vector;')
conn.commit()
for content in pContent:
merged_info = "Dateiname: " + content["filename"] + " Dateiinhalt: " + content[
"content"] # Bessere Embeddings mit Dateiname // Information vorne dran?
# print(merged_info)
response = ollama.embeddings(model="mxbai-embed-large", prompt=merged_info)
#embedding_list.append(response["embedding"])
insert_data = f'insert into dbtable (filepath, embedding) Values ({content["filepath"]}, {response["embedding"]});'
cur.execute(insert_data)
insert_data = f"insert into dbtable (filepath, embedding) Values ('{content['path']}', %s);"
cur.execute(insert_data, (response["embedding"],))
conn.commit()
conn.close()
def reload_files():
# path = input("Please provider path to folder: ")
contents = retrieve_file_contents("C:\\SoftwareEng")
create_embeddings(contents)
def add_files():
path = input("Please provider path to folder: ")
pass
def prompt_cycle():
while True:
prompt = input("Please enter prompt: ")
lib.prompt_embedding(prompt)
create_embeddings(contents)
def get_user_action():
user_action = input("Reload Files (r), Add Files (a), Prompt (p): ")
{
"r": lambda: reload_files(),
"a": lambda: add_files(),
"p": lambda: prompt_cycle()
}[user_action]()
get_user_action()
#print(json.dumps(contents, indent="\t"))