mirror of
https://github.com/SakanaAI/doc-to-lora.git
synced 2026-07-23 17:01:04 +02:00
chat_to_str for chat-history related dataset
This commit is contained in:
parent
7ac74e6d58
commit
1193d10fb4
1 changed files with 12 additions and 1 deletions
|
|
@ -14,6 +14,17 @@ def closed_qa_prompting(prompt: str):
|
|||
return template.format(input=prompt)
|
||||
|
||||
|
||||
def chat_to_str(messages: list[dict[str, str]]):
|
||||
return "\n\n".join(
|
||||
[
|
||||
"Message from: {role}\n{content}".format(
|
||||
**{**m, "role": m["role"].capitalize()}
|
||||
)
|
||||
for m in messages
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def get_preprocessing_fn(
|
||||
ds_name: str,
|
||||
is_eval: bool,
|
||||
|
|
@ -266,7 +277,7 @@ def get_preprocessing_fn(
|
|||
# ctx → all history up to the last turn
|
||||
# q → last user input
|
||||
def f(sample):
|
||||
chat_history = sample["messages"][:-2]
|
||||
chat_history = chat_to_str(sample["messages"][:-2])
|
||||
q = sample["messages"][-2]["content"]
|
||||
response = sample["messages"][-1]["content"]
|
||||
return {"context": chat_history, "prompt": q, "response": response}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue