8000 Update llama_chat_format.py · brucethemoose/llama-cpp-python@7cdf535 · GitHub
[go: up one dir, main page]

Skip to content < 65F8 span style="width: 0%;" data-view-component="true" class="Progress-item progress-pjax-loader-bar left-0 top-0 color-bg-accent-emphasis">

Commit 7cdf535

Browse files
Update llama_chat_format.py
1 parent 8e44a32 commit 7cdf535

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

llama_cpp/llama_chat_format.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,10 @@ def message_to_str(msg: llama_types.ChatCompletionRequestMessage):
< 10000 /div>
978978
with suppress_stdout_stderr(disable=llama.verbose):
979979
grammar = llama_grammar.LlamaGrammar.from_string(llama_grammar.JSON_GBNF)
980980

981+
if llama.verbose:
982+
print("-------------------------Printing Prompt---------------------------")
983+
print(new_prompt)
984+
print("-------------------------Promp Printed---------------------------")
981985
completion: llama_types.Completion = llama.create_completion(
982986
prompt=new_prompt,
983987
stop=["user:", "</s>"],
@@ -1004,6 +1008,26 @@ def message_to_str(msg: llama_types.ChatCompletionRequestMessage):
10041008
assert isinstance(function_call, str)
10051009
assert stream is False # TODO: support stream mode
10061010

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+
10071031
if llama.verbose:
10081032
print(new_prompt)
10091033
print(completion["choices"][0]["text"])

0 commit comments

Comments
 (0)
0