Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Python - FastAPI, Postgres, tsvector"""

# Current Version
__version__ = "2.1.8"
__version__ = "2.1.9"
13 changes: 8 additions & 5 deletions app/api/llm/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_llm_records(
if prospect_id is not None:
# No pagination for single prospect_id lookup
select_query = """
SELECT id, prompt, completion, duration, time, data, model, prospect_id
SELECT id, prompt, completion, duration, time, data, model, prospect_id, search_vector
FROM llm
WHERE prospect_id = %s
ORDER BY id DESC
Expand All @@ -38,6 +38,7 @@ def get_llm_records(
"data": row[5],
"model": row[6],
"prospect_id": row[7],
"search_vector": str(row[8]) if row[8] is not None else None,
}
for row in rows
]
Expand All @@ -61,7 +62,7 @@ def get_llm_records(
count_row = cur.fetchone()
total = count_row[0] if count_row and count_row[0] is not None else 0
cur.execute("""
SELECT id, prompt, completion, duration, time, data, model, prospect_id
SELECT id, prompt, completion, duration, time, data, model, prospect_id, search_vector
FROM llm
ORDER BY id DESC
LIMIT %s OFFSET %s;
Expand All @@ -76,6 +77,7 @@ def get_llm_records(
"data": row[5],
"model": row[6],
"prospect_id": row[7],
"search_vector": str(row[8]) if row[8] is not None else None,
}
for row in cur.fetchall()
]
Expand Down Expand Up @@ -146,13 +148,14 @@ def llm_post(payload: dict) -> dict:
data_blob = json.dumps({"version": __version__})
conn = get_db_connection_direct()
cur = conn.cursor()
# Generate tsvector from prompt and completion
cur.execute(
"""
INSERT INTO llm (prompt, completion, duration, data, model, prospect_id)
VALUES (%s, %s, %s, %s, %s, %s)
INSERT INTO llm (prompt, completion, duration, data, model, prospect_id, search_vector)
VALUES (%s, %s, %s, %s, %s, %s, to_tsvector('english', %s || ' ' || %s))
RETURNING id;
""",
(prompt, completion, duration, data_blob, used_model, prospect_id)
(prompt, completion, duration, data_blob, used_model, prospect_id, prompt, completion)
)
record_id_row = cur.fetchone()
record_id = record_id_row[0] if record_id_row else None
Expand Down
5 changes: 5 additions & 0 deletions app/api/llm/sql/alter_add_search_vector.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Migration: Add search_vector tsvector column to llm table
ALTER TABLE llm ADD COLUMN IF NOT EXISTS search_vector tsvector;

-- Optional: Create a GIN index for faster search
CREATE INDEX IF NOT EXISTS idx_llm_search_vector ON llm USING GIN(search_vector);
17 changes: 17 additions & 0 deletions app/api/llm/sql/run_alter_add_search_vector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os
import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../..')))
from app.utils.db import get_db_connection_direct

if __name__ == "__main__":
sql = """
ALTER TABLE llm ADD COLUMN IF NOT EXISTS search_vector tsvector;
CREATE INDEX IF NOT EXISTS idx_llm_search_vector ON llm USING GIN(search_vector);
"""
conn = get_db_connection_direct()
cur = conn.cursor()
cur.execute(sql)
conn.commit()
cur.close()
conn.close()
print("Migration complete: search_vector column and index added to llm table.")
13 changes: 6 additions & 7 deletions app/api/prospects/prospects.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,15 @@ def prospects_read_one(id: int = Path(..., description="ID of the prospect to re
from app.utils.db import get_db_connection_direct
llm_conn = get_db_connection_direct()
llm_cur = llm_conn.cursor()
llm_cur.execute("SELECT id, prompt, completion, duration, time, data, model FROM llm WHERE prospect_id = %s ORDER BY id DESC;", (id,))
llm_cur.execute("SELECT id, duration, time, data, model, search_vector FROM llm WHERE prospect_id = %s ORDER BY id DESC;", (id,))
llm_records = [
{
"id": r[0],
"prompt": r[1],
"completion": r[2],
"duration": r[3],
"time": r[4].isoformat() if r[4] else None,
"data": r[5],
"model": r[6],
"duration": r[1],
"time": r[2].isoformat() if r[2] else None,
"data": r[3],
"model": r[4],
"search_vector": str(r[5]) if r[5] is not None else None,
}
for r in llm_cur.fetchall()
]
Expand Down
2 changes: 2 additions & 0 deletions app/api/prospects/sql/alter_drop_cleaned.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Migration: Remove cleaned column from prospects table
ALTER TABLE prospects DROP COLUMN IF EXISTS cleaned;
2 changes: 2 additions & 0 deletions app/api/prospects/sql/alter_drop_do_not_call.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Migration: Remove do_not_call column from prospects table
ALTER TABLE prospects DROP COLUMN IF EXISTS do_not_call;
2 changes: 2 additions & 0 deletions app/api/prospects/sql/alter_drop_email_confidence.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Migration: Remove email_confidence column from prospects table
ALTER TABLE prospects DROP COLUMN IF EXISTS email_confidence;
2 changes: 2 additions & 0 deletions app/api/prospects/sql/alter_drop_home_phone.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Migration: Remove home_phone column from prospects table
ALTER TABLE prospects DROP COLUMN IF EXISTS home_phone;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Migration: Remove primary_email_catchall_status column from prospects table
ALTER TABLE prospects DROP COLUMN IF EXISTS primary_email_catchall_status;
2 changes: 2 additions & 0 deletions app/api/prospects/sql/alter_drop_primary_intent_score.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Migration: Remove primary_intent_score column from prospects table
ALTER TABLE prospects DROP COLUMN IF EXISTS primary_intent_score;
2 changes: 2 additions & 0 deletions app/api/prospects/sql/alter_drop_primary_intent_topic.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Migration: Remove primary_intent_topic column from prospects table
ALTER TABLE prospects DROP COLUMN IF EXISTS primary_intent_topic;
2 changes: 2 additions & 0 deletions app/api/prospects/sql/alter_drop_qualify_contact.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Migration: Remove qualify_contact column from prospects table
ALTER TABLE prospects DROP COLUMN IF EXISTS qualify_contact;
2 changes: 2 additions & 0 deletions app/api/prospects/sql/alter_drop_secondary_intent_score.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Migration: Remove secondary_intent_score column from prospects table
ALTER TABLE prospects DROP COLUMN IF EXISTS secondary_intent_score;
2 changes: 2 additions & 0 deletions app/api/prospects/sql/alter_drop_secondary_intent_topic.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Migration: Remove secondary_intent_topic column from prospects table
ALTER TABLE prospects DROP COLUMN IF EXISTS secondary_intent_topic;
2 changes: 2 additions & 0 deletions app/api/prospects/sql/alter_drop_tertiary_email.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Migration: Remove tertiary_email column from prospects table
ALTER TABLE prospects DROP COLUMN IF EXISTS tertiary_email;
2 changes: 2 additions & 0 deletions app/api/prospects/sql/alter_drop_tertiary_email_source.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Migration: Remove tertiary_email_source column from prospects table
ALTER TABLE prospects DROP COLUMN IF EXISTS tertiary_email_source;
2 changes: 2 additions & 0 deletions app/api/prospects/sql/alter_drop_tertiary_email_status.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Migration: Remove tertiary_email_status column from prospects table
ALTER TABLE prospects DROP COLUMN IF EXISTS tertiary_email_status;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Migration: Remove tertiary_email_verification_source column from prospects table
ALTER TABLE prospects DROP COLUMN IF EXISTS tertiary_email_verification_source;
2 changes: 2 additions & 0 deletions app/api/prospects/sql/alter_drop_work_direct_phone.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Migration: Remove work_direct_phone column from prospects table
ALTER TABLE prospects DROP COLUMN IF EXISTS work_direct_phone;
14 changes: 14 additions & 0 deletions app/api/prospects/sql/run_alter_drop_cleaned.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../..')))
from app.utils.db import get_db_connection_direct

if __name__ == "__main__":
sql = "ALTER TABLE prospects DROP COLUMN IF EXISTS cleaned;"
conn = get_db_connection_direct()
cur = conn.cursor()
cur.execute(sql)
conn.commit()
cur.close()
conn.close()
print("Migration complete: cleaned column dropped from prospects table.")
14 changes: 14 additions & 0 deletions app/api/prospects/sql/run_alter_drop_do_not_call.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../..')))
from app.utils.db import get_db_connection_direct

if __name__ == "__main__":
sql = "ALTER TABLE prospects DROP COLUMN IF EXISTS do_not_call;"
conn = get_db_connection_direct()
cur = conn.cursor()
cur.execute(sql)
conn.commit()
cur.close()
conn.close()
print("Migration complete: do_not_call column dropped from prospects table.")
14 changes: 14 additions & 0 deletions app/api/prospects/sql/run_alter_drop_email_confidence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../..')))
from app.utils.db import get_db_connection_direct

if __name__ == "__main__":
sql = "ALTER TABLE prospects DROP COLUMN IF EXISTS email_confidence;"
conn = get_db_connection_direct()
cur = conn.cursor()
cur.execute(sql)
conn.commit()
cur.close()
conn.close()
print("Migration complete: email_confidence column dropped from prospects table.")
14 changes: 14 additions & 0 deletions app/api/prospects/sql/run_alter_drop_home_phone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../..')))
from app.utils.db import get_db_connection_direct

if __name__ == "__main__":
sql = "ALTER TABLE prospects DROP COLUMN IF EXISTS home_phone;"
conn = get_db_connection_direct()
cur = conn.cursor()
cur.execute(sql)
conn.commit()
cur.close()
conn.close()
print("Migration complete: home_phone column dropped from prospects table.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../..')))
from app.utils.db import get_db_connection_direct

if __name__ == "__main__":
sql = "ALTER TABLE prospects DROP COLUMN IF EXISTS primary_email_catchall_status;"
conn = get_db_connection_direct()
cur = conn.cursor()
cur.execute(sql)
conn.commit()
cur.close()
conn.close()
print("Migration complete: primary_email_catchall_status column dropped from prospects table.")
14 changes: 14 additions & 0 deletions app/api/prospects/sql/run_alter_drop_primary_intent_score.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../..')))
from app.utils.db import get_db_connection_direct

if __name__ == "__main__":
sql = "ALTER TABLE prospects DROP COLUMN IF EXISTS primary_intent_score;"
conn = get_db_connection_direct()
cur = conn.cursor()
cur.execute(sql)
conn.commit()
cur.close()
conn.close()
print("Migration complete: primary_intent_score column dropped from prospects table.")
14 changes: 14 additions & 0 deletions app/api/prospects/sql/run_alter_drop_primary_intent_topic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../..')))
from app.utils.db import get_db_connection_direct

if __name__ == "__main__":
sql = "ALTER TABLE prospects DROP COLUMN IF EXISTS primary_intent_topic;"
conn = get_db_connection_direct()
cur = conn.cursor()
cur.execute(sql)
conn.commit()
cur.close()
conn.close()
print("Migration complete: primary_intent_topic column dropped from prospects table.")
14 changes: 14 additions & 0 deletions app/api/prospects/sql/run_alter_drop_qualify_contact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../..')))
from app.utils.db import get_db_connection_direct

if __name__ == "__main__":
sql = "ALTER TABLE prospects DROP COLUMN IF EXISTS qualify_contact;"
conn = get_db_connection_direct()
cur = conn.cursor()
cur.execute(sql)
conn.commit()
cur.close()
conn.close()
print("Migration complete: qualify_contact column dropped from prospects table.")
14 changes: 14 additions & 0 deletions app/api/prospects/sql/run_alter_drop_secondary_intent_score.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../..')))
from app.utils.db import get_db_connection_direct

if __name__ == "__main__":
sql = "ALTER TABLE prospects DROP COLUMN IF EXISTS secondary_intent_score;"
conn = get_db_connection_direct()
cur = conn.cursor()
cur.execute(sql)
conn.commit()
cur.close()
conn.close()
print("Migration complete: secondary_intent_score column dropped from prospects table.")
14 changes: 14 additions & 0 deletions app/api/prospects/sql/run_alter_drop_secondary_intent_topic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../..')))
from app.utils.db import get_db_connection_direct

if __name__ == "__main__":
sql = "ALTER TABLE prospects DROP COLUMN IF EXISTS secondary_intent_topic;"
conn = get_db_connection_direct()
cur = conn.cursor()
cur.execute(sql)
conn.commit()
cur.close()
conn.close()
print("Migration complete: secondary_intent_topic column dropped from prospects table.")
14 changes: 14 additions & 0 deletions app/api/prospects/sql/run_alter_drop_tertiary_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../..')))
from app.utils.db import get_db_connection_direct

if __name__ == "__main__":
sql = "ALTER TABLE prospects DROP COLUMN IF EXISTS tertiary_email;"
conn = get_db_connection_direct()
cur = conn.cursor()
cur.execute(sql)
conn.commit()
cur.close()
conn.close()
print("Migration complete: tertiary_email column dropped from prospects table.")
14 changes: 14 additions & 0 deletions app/api/prospects/sql/run_alter_drop_tertiary_email_source.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../..')))
from app.utils.db import get_db_connection_direct

if __name__ == "__main__":
sql = "ALTER TABLE prospects DROP COLUMN IF EXISTS tertiary_email_source;"
conn = get_db_connection_direct()
cur = conn.cursor()
cur.execute(sql)
conn.commit()
cur.close()
conn.close()
print("Migration complete: tertiary_email_source column dropped from prospects table.")
14 changes: 14 additions & 0 deletions app/api/prospects/sql/run_alter_drop_tertiary_email_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../..')))
from app.utils.db import get_db_connection_direct

if __name__ == "__main__":
sql = "ALTER TABLE prospects DROP COLUMN IF EXISTS tertiary_email_status;"
conn = get_db_connection_direct()
cur = conn.cursor()
cur.execute(sql)
conn.commit()
cur.close()
conn.close()
print("Migration complete: tertiary_email_status column dropped from prospects table.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../..')))
from app.utils.db import get_db_connection_direct

if __name__ == "__main__":
sql = "ALTER TABLE prospects DROP COLUMN IF EXISTS tertiary_email_verification_source;"
conn = get_db_connection_direct()
cur = conn.cursor()
cur.execute(sql)
conn.commit()
cur.close()
conn.close()
print("Migration complete: tertiary_email_verification_source column dropped from prospects table.")
14 changes: 14 additions & 0 deletions app/api/prospects/sql/run_alter_drop_work_direct_phone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../..')))
from app.utils.db import get_db_connection_direct

if __name__ == "__main__":
sql = "ALTER TABLE prospects DROP COLUMN IF EXISTS work_direct_phone;"
conn = get_db_connection_direct()
cur = conn.cursor()
cur.execute(sql)
conn.commit()
cur.close()
conn.close()
print("Migration complete: work_direct_phone column dropped from prospects table.")
Loading