wangzhengtao commited on
Commit
8847e1c
·
1 Parent(s): 85874df

fix: check content type

Browse files
Files changed (1) hide show
  1. chat_template.jinja +23 -14
chat_template.jinja CHANGED
@@ -1,3 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  {%- if tools -%}
2
  <|im_system|>tool_declare<|im_middle|>{{ tools | tojson(separators=(',', ':')) }}<|im_end|>
3
  {%- endif -%}
@@ -16,26 +32,19 @@
16
  {%- endif -%}
17
 
18
  {%- if message['role'] == 'assistant' and message.get('tool_calls') -%}
19
- {%- if message['content'] -%}{{ message['content'] }}{%- endif -%}
20
- <|tool_calls_section_begin|>
21
  {%- for tool_call in message['tool_calls'] -%}
22
- {%- set formatted_id = tool_call['id'] -%}
 
23
  <|tool_call_begin|>{{ formatted_id }}<|tool_call_argument_begin|>{% if tool_call['function']['arguments'] is string %}{{ tool_call['function']['arguments'] }}{% else %}{{ tool_call['function']['arguments'] | tojson }}{% endif %}<|tool_call_end|>
24
  {%- endfor -%}
25
  <|tool_calls_section_end|>
26
  {%- elif message['role'] == 'tool' -%}
27
- ## Return of {{ message.tool_call_id }}
28
- {{ message['content'] }}
29
- {%- elif message['content'] is string -%}
30
- {{ message['content'] }}
31
  {%- elif message['content'] is not none -%}
32
- {% for content in message['content'] -%}
33
- {% if content['type'] == 'image' or 'image' in content or 'image_url' in content -%}
34
- <|media_start|>image<|media_content|><|media_pad|><|media_end|>
35
- {% else -%}
36
- {{ content['text'] }}
37
- {%- endif -%}
38
- {%- endfor -%}
39
  {%- endif -%}
40
  <|im_end|>
41
  {%- endfor -%}
 
1
+ {% macro render_content(msg) -%}
2
+ {%- set c = msg.get('content') -%}
3
+ {%- if c is string -%}
4
+ {{ c }}
5
+ {%- elif c is not none -%}
6
+ {% for content in c -%}
7
+ {% if content['type'] == 'image' or 'image' in content or 'image_url' in content -%}
8
+ <|media_start|>image<|media_content|><|media_pad|><|media_end|>
9
+ {% else -%}
10
+ {{ content['text'] }}
11
+ {%- endif -%}
12
+ {%- endfor -%}
13
+ {%- endif -%}
14
+ {%- endmacro %}
15
+
16
+
17
  {%- if tools -%}
18
  <|im_system|>tool_declare<|im_middle|>{{ tools | tojson(separators=(',', ':')) }}<|im_end|>
19
  {%- endif -%}
 
32
  {%- endif -%}
33
 
34
  {%- if message['role'] == 'assistant' and message.get('tool_calls') -%}
35
+ {{render_content(message)}}<|tool_calls_section_begin|>
 
36
  {%- for tool_call in message['tool_calls'] -%}
37
+ {%- set raw_id = tool_call['id'] -%}
38
+ {%- set formatted_id = raw_id if raw_id.startswith('functions.') else 'functions.' + raw_id -%}
39
  <|tool_call_begin|>{{ formatted_id }}<|tool_call_argument_begin|>{% if tool_call['function']['arguments'] is string %}{{ tool_call['function']['arguments'] }}{% else %}{{ tool_call['function']['arguments'] | tojson }}{% endif %}<|tool_call_end|>
40
  {%- endfor -%}
41
  <|tool_calls_section_end|>
42
  {%- elif message['role'] == 'tool' -%}
43
+ {%- set tool_call_id = message.tool_call_id if message.tool_call_id.startswith('functions.') else 'functions.' + message.tool_call_id -%}
44
+ ## Return of {{ tool_call_id }}
45
+ {{render_content(message)}}
 
46
  {%- elif message['content'] is not none -%}
47
+ {{render_content(message)}}
 
 
 
 
 
 
48
  {%- endif -%}
49
  <|im_end|>
50
  {%- endfor -%}