Skip to content

Commit

Permalink
remove username when selecting
Browse files Browse the repository at this point in the history
  • Loading branch information
dayesouza committed Apr 5, 2024
1 parent fe4855e commit c80d8ff
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/util/Database.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def __init__(self, cache, db_name) -> None:
def create_table(self, name, attributes = []):
self.connection.execute(f"CREATE TABLE IF NOT EXISTS {name} ({', '.join(attributes)})")

def select_embedding_from_hash(self, hash_text, username = ''):
return self.connection.execute(f"SELECT embedding FROM embeddings WHERE hash_text = '{hash_text}' and username = '{username}'").fetchone()
def select_embedding_from_hash(self, hash_text):
return self.connection.execute(f"SELECT embedding FROM embeddings WHERE hash_text = '{hash_text}'").fetchone()

def insert_into_embeddings(self, hash_text, embedding, username = ''):
self.connection.execute(f"INSERT OR IGNORE INTO embeddings VALUES ('{username}','{hash_text}', {embedding})")
Expand Down
3 changes: 2 additions & 1 deletion app/util/Embedder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from util.Database import Database
import util.session_variables
from util.openai_instance import _OpenAI
import streamlit as st

gen_model = 'gpt-4-turbo-preview'
embed_model = 'text-embedding-3-small'
Expand Down Expand Up @@ -73,7 +74,7 @@ def encode(self, text, auto_save = True):
try:
embedding = openai.client().embeddings.create(input = [text], model=self.model).data[0].embedding
if auto_save:
self.connection.insert_into_embeddings(hsh, embedding)
self.connection.insert_into_embeddings(hsh, embedding, self.username)
return embedding
except:
print(f'Error embedding text: {text}')
Expand Down
3 changes: 2 additions & 1 deletion app/workflows/question_answering/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def chunk_files(sv, files):
all_embeddings_list.append((hash(formatted_chunk), chunk_vec))
file.add_chunk(chunk, np.array(chunk_vec), cx+1)
pb.progress(99, 'Saving embeddings...')
embedder.connection.insert_multiple_into_embeddings(all_embeddings_list)
if len(all_embeddings_list) > 0:
embedder.connection.insert_multiple_into_embeddings(all_embeddings_list)
pb.empty()

def update_question(sv, question_history, new_questions, placeholder, prefix):
Expand Down

0 comments on commit c80d8ff

Please sign in to comment.