11import os
2+ import uuid
23import ujson
34import functools
45from pathlib import Path
6+ from datetime import datetime
57
68try :
79 import warnings
@@ -53,8 +55,14 @@ def __call__(self, prompt=None, messages=None, **kwargs):
5355 entry = dict (prompt = prompt , messages = messages , kwargs = kwargs , response = response )
5456 entry = dict (** entry , outputs = outputs , usage = dict (response ["usage" ]))
5557 entry = dict (** entry , cost = response .get ("_hidden_params" , {}).get ("response_cost" ))
58+ entry = dict (
59+ ** entry ,
60+ timestamp = datetime .now ().isoformat (),
61+ uuid = str (uuid .uuid4 ()),
62+ model = self .model ,
63+ model_type = self .model_type ,
64+ )
5665 self .history .append (entry )
57-
5866 return outputs
5967
6068 def inspect_history (self , n : int = 1 ):
@@ -103,8 +111,11 @@ def _inspect_history(lm, n: int = 1):
103111 for item in lm .history [- n :]:
104112 messages = item ["messages" ] or [{"role" : "user" , "content" : item ['prompt' ]}]
105113 outputs = item ["outputs" ]
114+ timestamp = item .get ("timestamp" , "Unknown time" )
106115
107116 print ("\n \n \n " )
117+ print ("\x1b [34m" + f"[{ timestamp } ]" + "\x1b [0m" + "\n " )
118+
108119 for msg in messages :
109120 print (_red (f"{ msg ['role' ].capitalize ()} message:" ))
110121 print (msg ['content' ].strip ())
@@ -117,4 +128,4 @@ def _inspect_history(lm, n: int = 1):
117128 choices_text = f" \t (and { len (outputs )- 1 } other completions)"
118129 print (_red (choices_text , end = "" ))
119130
120- print ("\n \n \n " )
131+ print ("\n \n \n " )
0 commit comments