@@ -22,31 +22,31 @@ def insert_or_select_cmd(self, name:str) -> int:
2222
2323 def setup_db (self ):
2424 # create tables
25- self .cursor .execute ("CREATE TABLE IF NOT EXISTS runs (id INTEGER PRIMARY KEY, model text, context_size INTEGER, state TEXT, tag TEXT)" )
25+ self .cursor .execute ("CREATE TABLE IF NOT EXISTS runs (id INTEGER PRIMARY KEY, model text, context_size INTEGER, state TEXT, tag TEXT, started_at text, stopped_at text, rounds INTEGER )" )
2626 self .cursor .execute ("CREATE TABLE IF NOT EXISTS commands (id INTEGER PRIMARY KEY, name string unique)" )
27- self .cursor .execute ("CREATE TABLE IF NOT EXISTS queries (run_id INTEGER, round INTEGER, cmd_id INTEGER, query TEXT, response TEXT, duration REAL, tokens_query INTEGER, tokens_response INTEGER)" )
27+ self .cursor .execute ("CREATE TABLE IF NOT EXISTS queries (run_id INTEGER, round INTEGER, cmd_id INTEGER, query TEXT, response TEXT, duration REAL, tokens_query INTEGER, tokens_response INTEGER, prompt TEXT, answer TEXT )" )
2828
2929 # insert commands
3030 self .query_cmd_id = self .insert_or_select_cmd ('query_cmd' )
3131 self .analyze_response_id = self .insert_or_select_cmd ('analyze_response' )
3232 self .state_update_id = self .insert_or_select_cmd ('update_state' )
3333
3434 def create_new_run (self , model , context_size , tag = '' ):
35- self .cursor .execute ("INSERT INTO runs (model, context_size, state, tag) VALUES (?, ?, ?, ?)" , (model , context_size , "in progress" , tag ))
35+ self .cursor .execute ("INSERT INTO runs (model, context_size, state, tag, started_at ) VALUES (?, ?, ?, ?, datetime('now') )" , (model , context_size , "in progress" , tag ))
3636 return self .cursor .lastrowid
3737
3838 def add_log_query (self , run_id , round , cmd , result , answer ):
39- self .cursor .execute ("INSERT INTO queries (run_id, round, cmd_id, query, response, duration, tokens_query, tokens_response) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" , (run_id , round , self .query_cmd_id , cmd , result , answer .duration , answer .tokens_query , answer .tokens_response ))
39+ self .cursor .execute ("INSERT INTO queries (run_id, round, cmd_id, query, response, duration, tokens_query, tokens_response, prompt, answer ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ? )" , (run_id , round , self .query_cmd_id , cmd , result , answer .duration , answer .tokens_query , answer .tokens_response , answer . prompt , answer . answer ))
4040
4141 def add_log_analyze_response (self , run_id , round , cmd , result , answer ):
42- self .cursor .execute ("INSERT INTO queries (run_id, round, cmd_id, query, response, duration, tokens_query, tokens_response) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" , (run_id , round , self .analyze_response_id , cmd , result , answer .duration , answer .tokens_query , answer .tokens_response ))
42+ self .cursor .execute ("INSERT INTO queries (run_id, round, cmd_id, query, response, duration, tokens_query, tokens_response, prompt, answer ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ? )" , (run_id , round , self .analyze_response_id , cmd , result , answer .duration , answer .tokens_query , answer .tokens_response , answer . prompt , answer . answer ))
4343
4444 def add_log_update_state (self , run_id , round , cmd , result , answer ):
4545
4646 if answer != None :
47- self .cursor .execute ("INSERT INTO queries (run_id, round, cmd_id, query, response, duration, tokens_query, tokens_response) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" , (run_id , round , self .state_update_id , cmd , result , answer .duration , answer .tokens_query , answer .tokens_response ))
47+ self .cursor .execute ("INSERT INTO queries (run_id, round, cmd_id, query, response, duration, tokens_query, tokens_response, prompt, answer ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ? )" , (run_id , round , self .state_update_id , cmd , result , answer .duration , answer .tokens_query , answer .tokens_response , answer . prompt , answer . answer ))
4848 else :
49- self .cursor .execute ("INSERT INTO queries (run_id, round, cmd_id, query, response, duration, tokens_query, tokens_response) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" , (run_id , round , self .state_update_id , cmd , result , 0 , 0 , 0 ))
49+ self .cursor .execute ("INSERT INTO queries (run_id, round, cmd_id, query, response, duration, tokens_query, tokens_response, prompt, answer ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ? )" , (run_id , round , self .state_update_id , cmd , result , 0 , 0 , 0 , '' , '' ))
5050
5151 def get_round_data (self , run_id , round ):
5252 rows = self .cursor .execute ("select cmd_id, query, response, duration, tokens_query, tokens_response from queries where run_id = ? and round = ?" , (run_id , round )).fetchall ()
@@ -61,8 +61,11 @@ def get_round_data(self, run_id, round):
6161 reason = row [2 ]
6262 analyze_time = f"{ row [3 ]:.4f} "
6363 analyze_token = f"{ row [4 ]} /{ row [5 ]} "
64+ if row [0 ] == self .state_update_id :
65+ state_time = f"{ row [3 ]:.4f} "
66+ state_token = f"{ row [4 ]} /{ row [5 ]} "
6467
65- result = [duration , tokens , cmd , size_resp , analyze_time , analyze_token , reason ]
68+ result = [duration , tokens , cmd , size_resp , analyze_time , analyze_token , reason , state_time , state_token ]
6669 return result
6770
6871 def get_cmd_history (self , run_id ):
@@ -75,12 +78,12 @@ def get_cmd_history(self, run_id):
7578
7679 return result
7780
78- def run_was_success (self , run_id ):
79- self .cursor .execute ("update runs set state=? where id = ?" , ("got root" , run_id ))
81+ def run_was_success (self , run_id , round ):
82+ self .cursor .execute ("update runs set state=?,stopped_at=datetime('now'), rounds=? where id = ?" , ("got root" , round , run_id ))
8083 self .db .commit ()
8184
82- def run_was_failure (self , run_id ):
83- self .cursor .execute ("update runs set state=? where id = ?" , ("reached max runs" , run_id ))
85+ def run_was_failure (self , run_id , round ):
86+ self .cursor .execute ("update runs set state=?, stopped_at=datetime('now'), rounds=? where id = ?" , ("reached max runs" , round , run_id ))
8487 self .db .commit ()
8588
8689 def commit (self ):
0 commit comments