Skip to content

Commit 05d976d

Browse files
Merge pull request #60 from goldlabelapps/staging
Return inserted llm record ID in response
2 parents 8f20cc0 + 53b1c49 commit 05d976d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

app/api/llm/llm.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def llm_post(payload: dict) -> dict:
9696
error_details = " | ".join([f"{k}: {v}" for k, v in errors.items()])
9797
raise Exception(f"No available Gemini model succeeded for generate_content with your API key. Details: {error_details}")
9898
# Insert record into llm table
99+
record_id = None
99100
try:
100101
import json
101102
from app import __version__
@@ -105,18 +106,21 @@ def llm_post(payload: dict) -> dict:
105106
cur.execute(
106107
"""
107108
INSERT INTO llm (prompt, completion, duration, data, model)
108-
VALUES (%s, %s, %s, %s, %s);
109+
VALUES (%s, %s, %s, %s, %s)
110+
RETURNING id;
109111
""",
110112
(prompt, completion, duration, data_blob, used_model)
111113
)
114+
record_id_row = cur.fetchone()
115+
record_id = record_id_row[0] if record_id_row else None
112116
conn.commit()
113117
cur.close()
114118
conn.close()
115119
except Exception as db_exc:
116120
# Log DB error but do not fail the API response
117121
logging.error(f"Failed to insert llm record: {db_exc}")
118122
meta = make_meta("success", f"Gemini completion received from {used_model}")
119-
return {"meta": meta, "data": {"prompt": prompt, "completion": completion}}
123+
return {"meta": meta, "data": {"id": record_id, "prompt": prompt, "completion": completion}}
120124
except Exception as e:
121125
meta = make_meta("error", f"Gemini API error: {str(e)}")
122126
return {"meta": meta, "data": {}}

0 commit comments

Comments
 (0)