Skip to content

Commit 144ed4f

Browse files
authored
Merge pull request #85 from vitalops/batch_prefix_fix
Batch prefix fix
2 parents 3252871 + bbce1a4 commit 144ed4f

3 files changed

Lines changed: 12 additions & 16 deletions

File tree

‎datatune/core/filter.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ def llm_batch_inference(
6363
prompt = f"FILTERING CRITERIA:{os.linesep}{prompt}{os.linesep}{os.linesep}"
6464
suffix = (
6565
f"{os.linesep}{os.linesep}"
66-
f"DECISION:Your response MUST be a valid Python dictionary in the format: {{key1: value1, key2: value2, ...}} with added key called '__filter__' with value either True to KEEP the record or False to REMOVE it."
66+
f"DECISION:Your response MUST be the entire input record as Python dictionary in the format: index=<row_index>|{{key1: value1, key2: value2, ...}}<endofrow> with added key called '__filter__' with value either True to KEEP the record or False to REMOVE it."
6767
f"No explanations or additional text."
68+
f"ALWAYS STICK TO THE FORMAT index=<row_index>|{{key1: value1, key2: value2, ...}}<endofrow> with added key called '__filter__' with value either True to KEEP the record or False to REMOVE it."
6869
)
6970
df[llm_output_column] = llm(df[serialized_input_column], prefix, prompt, suffix, optimized=True)
7071
return df

‎datatune/core/map.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def llm_batch_inference(
7070
f"""Your response MUST be the entire input record as a valid Python dictionary in the format
7171
'index=<row_index>|{{key1: value1, key2: value2, ...}}' with added keys of expected new fields if any.
7272
ALWAYS START YOUR RESPONSE WITH 'index=<row_index>|' WHERE <row_index> IS THE INDEX OF THE ROW.
73+
ALWAYS END YOUR RESPONSE WITH '<endofrow>'.
7374
"""
7475
)
7576

‎datatune/llm/llm.py‎

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,16 @@ def _create_batched_prompts(
7474
7575
"""
7676
batch_prefix = (
77-
"You will be given multiple data rows to process. Each request will:\n"
78-
"- have the format 'index=<row_index>|{<row_data>}' where <row_index> is the zero-based index of the row in the original input list.\n"
79-
"- End with '<endofrow>'\n\n"
80-
"You MUST respond to each row in order. Each answer:\n"
81-
"MUST BE OF THE FORMAT 'index=<row_index>|{response}<endofrow>' where <row_index> is the zero-based index of the row in the original input list.\n" \
82-
"{response} must be enclosed in curly braces and strings should be enclosed in quotes.\n"
83-
"- End with '<endofrow>'\n" \
84-
"Always begin your response with 'index=<row_index>|' to indicate which row you are responding to without exception.\n"
85-
"- Do NOT skip or omit any rows\n"
86-
"Your entire response MUST include one answer per row. Respond strictly in the format described WITHOUT ANY OTHER TEXT, EXPLANATIONS OR BACKSTICKS\n" \
87-
"IF DATA ROWS ARE NOT GIVEN IN DICTIONARY FORMAT RETURN THE ANSWER ONLY STARTING WITH index=<row_index>|"
88-
"ALL RESPONSES MUST START WITH 'index='\n"
89-
"ALL RESPONSES MUST END WITH '<endofrow>'\n"
90-
f"Instructions:\n{batch_prefix or ''}"
77+
"You will be given requests in the format 'index=<index>|{prompt}'. Each request ends with '<endofrow>'.\n"
78+
"Respond to each prompt in order.\n"
79+
"Each answer must be formatted exactly as 'index=<index>|{answer}<endofrow>'.\n"
80+
"{answer} MUST BE ENCLOSED IN CURLY BRACES with strings in quotes.\n"
81+
"DO NOT skip or omit any rows. DO NOT add explanations, backticks, or extra text.\n"
82+
"Always start with 'index=<index>|' and end with '<endofrow>'.\n"
83+
f"Instructions:\n{batch_prefix or ''}"
9184
)
9285

86+
9387
max_tokens = self.get_max_tokens()
9488
model_name = self._base_model_name
9589

@@ -99,7 +93,7 @@ def _create_batched_prompts(
9993
nrows_per_api_call = []
10094
count = 0
10195
message = lambda x: [
102-
{"role": "user", "content": f"{batch_prefix or ''}{x}{batch_suffix or ''}"}
96+
{"role": "user", "content": f"{batch_prefix}{x}{batch_suffix or ''}"}
10397
]
10498
prefix_suffix_tokens = token_counter(model_name, messages=message(""))
10599
total_ntokens = prefix_suffix_tokens

0 commit comments

Comments
 (0)