@@ -23,6 +23,8 @@ class PostgresCache(Cache):
2323 user_id | text | not null |
2424 conversation_id | text | not null |
2525 created_at | timestamp without time zone | not null |
26+ started_at | text | |
27+ completed_at | text | |
2628 query | text | |
2729 response | text | |
2830 provider | text | |
@@ -38,6 +40,8 @@ class PostgresCache(Cache):
3840 user_id text NOT NULL,
3941 conversation_id text NOT NULL,
4042 created_at timestamp NOT NULL,
43+ started_at text,
44+ completed_at text,
4145 query text,
4246 response text,
4347 provider text,
@@ -62,15 +66,16 @@ class PostgresCache(Cache):
6266 """
6367
6468 SELECT_CONVERSATION_HISTORY_STATEMENT = """
65- SELECT query, response, provider, model
69+ SELECT query, response, provider, model, started_at, completed_at
6670 FROM cache
6771 WHERE user_id=%s AND conversation_id=%s
6872 ORDER BY created_at
6973 """
7074
7175 INSERT_CONVERSATION_HISTORY_STATEMENT = """
72- INSERT INTO cache(user_id, conversation_id, created_at, query, response, provider, model)
73- VALUES (%s, %s, CURRENT_TIMESTAMP, %s, %s, %s, %s)
76+ INSERT INTO cache(user_id, conversation_id, created_at, started_at, completed_at,
77+ query, response, provider, model)
78+ VALUES (%s, %s, CURRENT_TIMESTAMP, %s, %s, %s, %s, %s, %s)
7479 """
7580
7681 QUERY_CACHE_SIZE = """
@@ -211,6 +216,8 @@ def get(
211216 response = conversation_entry [1 ],
212217 provider = conversation_entry [2 ],
213218 model = conversation_entry [3 ],
219+ started_at = conversation_entry [4 ],
220+ completed_at = conversation_entry [5 ],
214221 )
215222 result .append (cache_entry )
216223
@@ -245,6 +252,8 @@ def insert_or_append(
245252 (
246253 user_id ,
247254 conversation_id ,
255+ cache_entry .started_at ,
256+ cache_entry .completed_at ,
248257 cache_entry .query ,
249258 cache_entry .response ,
250259 cache_entry .provider ,
0 commit comments