MCPcopy Create free account
hub / github.com/OpenBMB/AgentCPM-GUI / _prepare_messages

Function _prepare_messages

rft/trainer/utils/process.py:5–46  ·  view source on GitHub ↗
(
    prompts,
    processing_class,
    max_prompt_length
)

Source from the content-addressed store, hash-verified

3from PIL import Image
4
5def _prepare_messages(
6 prompts,
7 processing_class,
8 max_prompt_length
9):
10 prompts_lists = []
11 input_images_lists = []
12
13 for msgs in prompts:
14 copy_msgs = copy.deepcopy(msgs)
15
16 images = []
17 for i, msg in enumerate(copy_msgs):
18 role, content = msg["role"], msg["content"]
19
20 if isinstance(content,str):
21 content = [content]
22 cur_msgs = []
23 for c in content:
24 if isinstance(c, Image.Image):
25 images.append(c)
26 cur_msgs.append("(<image>./</image>)")
27 elif isinstance(c, str):
28 cur_msgs.append(c)
29 msg['content'] = "\n".join(cur_msgs)
30
31 prompts_lists.append(
32 processing_class.tokenizer.apply_chat_template(copy_msgs, tokenize=False, add_generation_prompt=True)
33 )
34 input_images_lists.append(images)
35
36 ret = processing_class(
37 prompts_lists,
38 input_images_lists,
39 return_tensors="pt",
40 max_length=max_prompt_length
41 )
42
43
44 return {
45 **ret
46 }
47
48def _create_inputs(
49 processing_class,

Callers 2

data_collatorMethod · 0.85
_process_inputsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected