File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -978,6 +978,10 @@ def message_to_str(msg: llama_types.ChatCompletionRequestMessage):
<
10000
/div>
978
978
with suppress_stdout_stderr (disable = llama .verbose ):
979
979
grammar = llama_grammar .LlamaGrammar .from_string (llama_grammar .JSON_GBNF )
980
980
981
+ if llama .verbose :
982
+ print ("-------------------------Printing Prompt---------------------------" )
983
+ print (new_prompt )
984
+ print ("-------------------------Promp Printed---------------------------" )
981
985
completion : llama_types .Completion = llama .create_completion (
982
986
prompt = new_prompt ,
983
987
stop = ["user:" , "</s>" ],
@@ -1004,6 +1008,26 @@ def message_to_str(msg: llama_types.ChatCompletionRequestMessage):
1004
1008
assert isinstance (function_call , str )
1005
1009
assert stream is False # TODO: support stream mode
1006
1010
1011
+ #Dump prompt + response pairs to json
1012
+ #https://stackoverflow.com/questions/12994442/how-to-append-data-to-a-json-file
1013
+ a = []
1014
+ fname = "dpotraindata.json"
1015
+ entry = {
1016
+ "prompt" : new_prompt ,
1017
+ "chosen" : ["choices" ][0 ]["text" ]
1018
+ }
1019
+ if not os .path .isfile (fname ):
1020
+ a .append (entry )
1021
+ with open (fname , mode = 'w' ) as f :
1022
+ f .write (json .dumps (a , indent = 2 ))
1023
+ else :
1024
+ with open (fname ) as feedsjson :
1025
+ feeds = json .load (feedsjson )
1026
+
1027
+ feeds .append (entry )
1028
+ with open (fname , mode = 'w' ) as f :
1029
+ f .write (json .dumps (feeds , indent = 2 ))
1030
+
1007
1031
if llama .verbose :
1008
1032
print (new_prompt )
1009
1033
print (completion ["choices" ][0 ]["text" ])
You can’t perform that action at this time.
0 commit comments