Skip to content

Commit e0758b2

Browse files
committed
Add LLM DB schema, seed script & rename tests
Create a new llm table SQL schema (vector(1536), prompt, completion, duration, time, data). Add a small psycopg2 seed script (insert_llm_lorem.py) that loads .env, connects to the DB and inserts 5 dummy records with random 1536-d vectors. Rename tests/test_gemini.py to tests/test_llm.py and update tests to use LLM naming and /llm endpoints, adjust skip/failure messages and assertions accordingly (including updated mocked API handling). These changes introduce the DB schema and local seeding helper and align tests to the LLM endpoint/name changes.
1 parent b2779b8 commit e0758b2

3 files changed

Lines changed: 45 additions & 9 deletions

File tree

app/api/llm/sql/create_table.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
CREATE TABLE IF NOT EXISTS llm (
3+
id SERIAL PRIMARY KEY,
4+
vector vector(1536),
5+
prompt TEXT NOT NULL,
6+
completion TEXT NOT NULL,
7+
duration FLOAT,
8+
time TIMESTAMPTZ DEFAULT NOW(),
9+
data JSONB
10+
);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os
2+
import psycopg2
3+
from dotenv import load_dotenv
4+
import random
5+
6+
load_dotenv()
7+
8+
conn = psycopg2.connect(
9+
host=os.getenv('DB_HOST'),
10+
port=os.getenv('DB_PORT', '5432'),
11+
dbname=os.getenv('DB_NAME'),
12+
user=os.getenv('DB_USER'),
13+
password=os.getenv('DB_PASSWORD'),
14+
)
15+
cur = conn.cursor()
16+
lorem = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'
17+
for i in range(5):
18+
cur.execute(
19+
'INSERT INTO llm (vector, prompt, completion, duration, data) VALUES (%s, %s, %s, %s, %s);',
20+
([random.random() for _ in range(1536)], lorem, lorem, random.uniform(0.1, 2.0), '{}')
21+
)
22+
conn.commit()
23+
print('Inserted 5 records.')
24+
cur.close()
25+
conn.close()
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import os
22
import pytest
3-
def test_gemini_real_api():
3+
def test_llm_real_api():
44
api_key = os.getenv("GEMINI_API_KEY")
55
if not api_key:
6-
pytest.skip("GEMINI_API_KEY not set; skipping real Gemini API test.")
6+
pytest.skip("GEMINI_API_KEY not set; skipping real LLM API test.")
77
from google import genai
88
client = genai.Client(api_key=api_key)
99
try:
@@ -14,7 +14,7 @@ def test_gemini_real_api():
1414
completion = getattr(response, "text", None)
1515
assert completion is not None and "hello" in completion.lower()
1616
except Exception as e:
17-
pytest.fail(f"Gemini real API call failed: {e}")
17+
pytest.fail(f"LLM real API call failed: {e}")
1818
import sys
1919
import os
2020
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../")))
@@ -26,16 +26,17 @@ def test_gemini_real_api():
2626

2727

2828

29-
def test_gemini_get_endpoint():
30-
response = client.get("/gemini")
29+
30+
def test_llm_get_endpoint():
31+
response = client.get("/llm")
3132
assert response.status_code == 200
3233
data = response.json()
3334
assert "meta" in data
3435
assert data["meta"]["severity"] == "success"
35-
assert "Gemini endpoint says hello" in data["meta"]["title"]
36+
assert "LLM endpoint says hello" in data["meta"]["title"]
3637

3738

38-
def test_gemini_post_endpoint(monkeypatch):
39+
def test_llm_post_endpoint(monkeypatch):
3940
# Mock google-genai SDK to avoid real API call
4041
class MockGenAIResponse:
4142
text = "Test completion"
@@ -50,12 +51,12 @@ class MockGenAIClient:
5051
monkeypatch.setattr("google.genai.Client", lambda *args, **kwargs: MockGenAIClient())
5152

5253
payload = {"prompt": "Test prompt"}
53-
response = client.post("/gemini", json=payload)
54+
response = client.post("/llm", json=payload)
5455
assert response.status_code == 200
5556
data = response.json()
5657
assert "meta" in data
5758
assert data["meta"]["severity"] == "success"
58-
assert "Gemini completion received" in data["meta"]["title"]
59+
assert "completion received" in data["meta"]["title"]
5960
assert data["data"]["prompt"] == "Test prompt"
6061
assert data["data"]["completion"] == "Test completion"
6162
assert "data" in data

0 commit comments

Comments
 (0)