CISCai commited on
Commit
0d5ccb3
1 Parent(s): 841ba68

reindent json to make code editor happier

Browse files
Files changed (1) hide show
  1. app.py +236 -236
app.py CHANGED
@@ -32,287 +32,287 @@ example_values = [
32
  [
33
  "{}",
34
  """[
35
- {
36
- "role": "user",
37
- "content": "What is the capital of Norway?"
38
- }
39
  ]""",
40
  ],
41
  [
42
  "{}",
43
  """[
44
- {
45
- "role": "system",
46
- "content": "You are a somewhat helpful AI."
47
- },
48
- {
49
- "role": "user",
50
- "content": "What is the capital of Norway?"
51
- }
52
  ]""",
53
  ],
54
  [
55
  "{}",
56
  """[
57
- {
58
- "role": "user",
59
- "content": "What is the capital of Norway?"
60
- },
61
- {
62
- "role": "assistant",
63
- "content": "Oslo is the capital of Norway."
64
- },
65
- {
66
- "role": "user",
67
- "content": "What is the world famous sculpture park there called?"
68
- },
69
- {
70
- "role": "assistant",
71
- "content": "The world famous sculpture park in Oslo is called Vigelandsparken."
72
- },
73
- {
74
- "role": "user",
75
- "content": "What is the most famous sculpture in the park?"
76
- }
77
  ]""",
78
  ],
79
  [
80
  """{
81
- "tools": [
82
- {
83
- "type": "function",
84
- "function": {
85
- "name": "get_current_weather",
86
- "description": "Get the current weather in a given location",
87
- "parameters": {
88
- "type": "object",
89
- "properties": {
90
- "location": {
91
- "type": "string",
92
- "description": "The city and state, e.g. San Francisco, CA"
93
- },
94
- "unit": {
95
- "type": "string",
96
- "enum": [ "celsius", "fahrenheit" ]
97
- }
98
- },
99
- "required": [ "location" ]
100
- }
101
  }
 
 
102
  }
103
- ]
 
 
104
  }""",
105
  """[
106
- {
107
- "role": "user",
108
- "content": "What's the weather like in Oslo?"
109
- }
110
  ]""",
111
  ],
112
  [
113
  """{
114
- "tools": [
115
- {
116
- "type": "function",
117
- "function": {
118
- "name": "get_current_weather",
119
- "description": "Get the current weather in a given location",
120
- "parameters": {
121
- "type": "object",
122
- "properties": {
123
- "location": {
124
- "type": "string",
125
- "description": "The city and state, e.g. San Francisco, CA"
126
- },
127
- "unit": {
128
- "type": "string",
129
- "enum": [ "celsius", "fahrenheit" ]
130
- }
131
- },
132
- "required": [ "location" ]
133
- }
134
  }
 
 
135
  }
136
- ]
 
 
137
  }""",
138
  """[
139
- {
140
- "role": "user",
141
- "content": "What's the weather like in Oslo?"
142
- },
143
- {
144
- "role": "assistant",
145
- "content": null,
146
- "tool_calls": [
147
- {
148
- "id": "toolcall1",
149
- "type": "function",
150
- "function": {
151
- "name": "get_current_weather",
152
- "arguments": {
153
- "location": "Oslo, Norway",
154
- "unit": "celsius"
155
- }
156
- }
157
- }
158
- ]
159
- },
160
- {
161
- "role": "tool",
162
- "content": "20",
163
- "tool_call_id": "toolcall1"
164
- }
165
  ]""",
166
  ],
167
  [
168
  """{
169
- "tools": [
170
- {
171
- "type": "function",
172
- "function": {
173
- "name": "get_current_weather",
174
- "description": "Get the current weather in a given location",
175
- "parameters": {
176
- "type": "object",
177
- "properties": {
178
- "location": {
179
- "type": "string",
180
- "description": "The city and state, e.g. San Francisco, CA"
181
- },
182
- "unit": {
183
- "type": "string",
184
- "enum": [ "celsius", "fahrenheit" ]
185
- }
186
- },
187
- "required": [ "location" ]
188
- }
189
- }
190
- }
191
- ]
192
- }""",
193
- """[
194
- {
195
- "role": "user",
196
- "content": "What's the weather like in Oslo and Stockholm?"
197
- },
198
  {
199
- "role": "assistant",
200
- "content": null,
201
- "tool_calls": [
202
- {
203
- "id": "toolcall1",
204
- "type": "function",
205
- "function": {
206
- "name": "get_current_weather",
207
- "arguments": {
208
- "location": "Oslo, Norway",
209
- "unit": "celsius"
210
- }
211
- }
212
  },
213
- {
214
- "id": "toolcall2",
215
- "type": "function",
216
- "function": {
217
- "name": "get_current_weather",
218
- "arguments": {
219
- "location": "Stockholm, Sweden",
220
- "unit": "celsius"
221
- }
222
- }
223
  }
224
- ]
225
- },
226
- {
227
- "role": "tool",
228
- "content": "20",
229
- "tool_call_id": "toolcall1"
230
- },
231
- {
232
- "role": "tool",
233
- "content": "22",
234
- "tool_call_id": "toolcall2"
235
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
  ]""",
237
  ],
238
  [
239
  """{
240
- "tools": [
241
- {
242
- "type": "function",
243
- "function": {
244
- "name": "create_user",
245
- "description": "creates a user",
246
- "parameters": {
247
- "type": "object",
248
- "properties": {
249
- "user": {
250
- "title": "User",
251
- "type": "object",
252
- "properties": {
253
- "user_id": {
254
- "title": "User Id",
255
- "description": "The unique identifier for a user",
256
- "default": 0,
257
- "type": "integer"
258
- },
259
- "name": {
260
- "title": "Name",
261
- "description": "The name of the user",
262
- "type": "string"
263
- },
264
- "birthday": {
265
- "type": "string",
266
- "description": "The birthday of the user, e.g. 2022-01-01",
267
- "pattern": "^([1-9] |1[0-9]| 2[0-9]|3[0-1])(.|-)([1-9] |1[0-2])(.|-|)20[0-9][0-9]$"
268
- },
269
- "email": {
270
- "title": "Email",
271
- "description": "The email address of the user",
272
- "type": "string"
273
- },
274
- "friends": {
275
- "title": "Friends",
276
- "description": "List of friends of the user",
277
- "type": "array",
278
- "items": {"type": "string"}
279
- }
280
- },
281
- "required": ["name", "email"]
282
- }
283
- },
284
- "required": ["user"],
285
- "definitions": {}
286
  }
 
 
287
  }
 
 
 
288
  }
289
- ]
 
 
290
  }""",
291
  """[
292
- {
293
- "role": "user",
294
- "content": "Create a user for Test User ([email protected]), born January 1st 2000, with some random friends."
295
- }
296
  ]""",
297
  ],
298
  [
299
  """{
300
- "documents": [
301
- {
302
- "title": "Much ado about nothing",
303
- "content": "Dolor sit amet..."
304
- },
305
- {
306
- "title": "Less ado about something",
307
- "content": "Lorem ipsum..."
308
- }
309
- ]
310
- }""",
311
- """[
312
  {
313
- "role": "user",
314
- "content": "Write a brief summary of the following documents."
 
 
 
 
315
  }
 
 
 
 
 
 
 
316
  ]""",
317
  ],
318
  ]
@@ -963,7 +963,7 @@ You can freely edit and test GGUF chat template(s) (and are encouraged to do so)
963
  if info.widget_data:
964
  for data in info.widget_data:
965
  if "messages" in data:
966
- template_messages = json.dumps(data["messages"], ensure_ascii = False, indent = 4)
967
  break
968
 
969
  if isinstance(templates, list):
@@ -972,7 +972,7 @@ You can freely edit and test GGUF chat template(s) (and are encouraged to do so)
972
  template_rag = templates.get("rag")
973
  templates = templates.get("default")
974
 
975
- return model_info, json.dumps(template_kwargs, ensure_ascii = False, indent = 4), template_messages, templates, template_tool_use, template_rag, template_inverse
976
 
977
 
978
  def template_data_from_model_files(
@@ -1139,7 +1139,7 @@ You can freely edit and test GGUF chat template(s) (and are encouraged to do so)
1139
  x = example.copy()
1140
  x0 = json.loads(x[0])
1141
  x0.update(settings)
1142
- x[0] = json.dumps(x0, ensure_ascii = False, indent = 4)
1143
  examples.append(x)
1144
 
1145
  return gr.Dataset(
@@ -1303,7 +1303,7 @@ You can freely edit and test GGUF chat template(s) (and are encouraged to do so)
1303
  title = "Inverse Template Error",
1304
  )
1305
 
1306
- return chat_output, chat_tool_use_output, chat_rag_output, json.dumps(inverse_output, ensure_ascii = False, indent = 4) if inverse_output is not None else None
1307
 
1308
 
1309
  if __name__ == "__main__":
 
32
  [
33
  "{}",
34
  """[
35
+ {
36
+ "role": "user",
37
+ "content": "What is the capital of Norway?"
38
+ }
39
  ]""",
40
  ],
41
  [
42
  "{}",
43
  """[
44
+ {
45
+ "role": "system",
46
+ "content": "You are a somewhat helpful AI."
47
+ },
48
+ {
49
+ "role": "user",
50
+ "content": "What is the capital of Norway?"
51
+ }
52
  ]""",
53
  ],
54
  [
55
  "{}",
56
  """[
57
+ {
58
+ "role": "user",
59
+ "content": "What is the capital of Norway?"
60
+ },
61
+ {
62
+ "role": "assistant",
63
+ "content": "Oslo is the capital of Norway."
64
+ },
65
+ {
66
+ "role": "user",
67
+ "content": "What is the world famous sculpture park there called?"
68
+ },
69
+ {
70
+ "role": "assistant",
71
+ "content": "The world famous sculpture park in Oslo is called Vigelandsparken."
72
+ },
73
+ {
74
+ "role": "user",
75
+ "content": "What is the most famous sculpture in the park?"
76
+ }
77
  ]""",
78
  ],
79
  [
80
  """{
81
+ "tools": [
82
+ {
83
+ "type": "function",
84
+ "function": {
85
+ "name": "get_current_weather",
86
+ "description": "Get the current weather in a given location",
87
+ "parameters": {
88
+ "type": "object",
89
+ "properties": {
90
+ "location": {
91
+ "type": "string",
92
+ "description": "The city and state, e.g. San Francisco, CA"
93
+ },
94
+ "unit": {
95
+ "type": "string",
96
+ "enum": [ "celsius", "fahrenheit" ]
 
 
 
 
97
  }
98
+ },
99
+ "required": [ "location" ]
100
  }
101
+ }
102
+ }
103
+ ]
104
  }""",
105
  """[
106
+ {
107
+ "role": "user",
108
+ "content": "What's the weather like in Oslo?"
109
+ }
110
  ]""",
111
  ],
112
  [
113
  """{
114
+ "tools": [
115
+ {
116
+ "type": "function",
117
+ "function": {
118
+ "name": "get_current_weather",
119
+ "description": "Get the current weather in a given location",
120
+ "parameters": {
121
+ "type": "object",
122
+ "properties": {
123
+ "location": {
124
+ "type": "string",
125
+ "description": "The city and state, e.g. San Francisco, CA"
126
+ },
127
+ "unit": {
128
+ "type": "string",
129
+ "enum": [ "celsius", "fahrenheit" ]
 
 
 
 
130
  }
131
+ },
132
+ "required": [ "location" ]
133
  }
134
+ }
135
+ }
136
+ ]
137
  }""",
138
  """[
139
+ {
140
+ "role": "user",
141
+ "content": "What's the weather like in Oslo?"
142
+ },
143
+ {
144
+ "role": "assistant",
145
+ "content": null,
146
+ "tool_calls": [
147
+ {
148
+ "id": "toolcall1",
149
+ "type": "function",
150
+ "function": {
151
+ "name": "get_current_weather",
152
+ "arguments": {
153
+ "location": "Oslo, Norway",
154
+ "unit": "celsius"
155
+ }
156
+ }
157
+ }
158
+ ]
159
+ },
160
+ {
161
+ "role": "tool",
162
+ "content": "20",
163
+ "tool_call_id": "toolcall1"
164
+ }
165
  ]""",
166
  ],
167
  [
168
  """{
169
+ "tools": [
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  {
171
+ "type": "function",
172
+ "function": {
173
+ "name": "get_current_weather",
174
+ "description": "Get the current weather in a given location",
175
+ "parameters": {
176
+ "type": "object",
177
+ "properties": {
178
+ "location": {
179
+ "type": "string",
180
+ "description": "The city and state, e.g. San Francisco, CA"
 
 
 
181
  },
182
+ "unit": {
183
+ "type": "string",
184
+ "enum": [ "celsius", "fahrenheit" ]
 
 
 
 
 
 
 
185
  }
186
+ },
187
+ "required": [ "location" ]
188
+ }
189
+ }
 
 
 
 
 
 
 
190
  }
191
+ ]
192
+ }""",
193
+ """[
194
+ {
195
+ "role": "user",
196
+ "content": "What's the weather like in Oslo and Stockholm?"
197
+ },
198
+ {
199
+ "role": "assistant",
200
+ "content": null,
201
+ "tool_calls": [
202
+ {
203
+ "id": "toolcall1",
204
+ "type": "function",
205
+ "function": {
206
+ "name": "get_current_weather",
207
+ "arguments": {
208
+ "location": "Oslo, Norway",
209
+ "unit": "celsius"
210
+ }
211
+ }
212
+ },
213
+ {
214
+ "id": "toolcall2",
215
+ "type": "function",
216
+ "function": {
217
+ "name": "get_current_weather",
218
+ "arguments": {
219
+ "location": "Stockholm, Sweden",
220
+ "unit": "celsius"
221
+ }
222
+ }
223
+ }
224
+ ]
225
+ },
226
+ {
227
+ "role": "tool",
228
+ "content": "20",
229
+ "tool_call_id": "toolcall1"
230
+ },
231
+ {
232
+ "role": "tool",
233
+ "content": "22",
234
+ "tool_call_id": "toolcall2"
235
+ }
236
  ]""",
237
  ],
238
  [
239
  """{
240
+ "tools": [
241
+ {
242
+ "type": "function",
243
+ "function": {
244
+ "name": "create_user",
245
+ "description": "creates a user",
246
+ "parameters": {
247
+ "type": "object",
248
+ "properties": {
249
+ "user": {
250
+ "title": "User",
251
+ "type": "object",
252
+ "properties": {
253
+ "user_id": {
254
+ "title": "User Id",
255
+ "description": "The unique identifier for a user",
256
+ "default": 0,
257
+ "type": "integer"
258
+ },
259
+ "name": {
260
+ "title": "Name",
261
+ "description": "The name of the user",
262
+ "type": "string"
263
+ },
264
+ "birthday": {
265
+ "type": "string",
266
+ "description": "The birthday of the user, e.g. 2022-01-01",
267
+ "pattern": "^([1-9] |1[0-9]| 2[0-9]|3[0-1])(.|-)([1-9] |1[0-2])(.|-|)20[0-9][0-9]$"
268
+ },
269
+ "email": {
270
+ "title": "Email",
271
+ "description": "The email address of the user",
272
+ "type": "string"
273
+ },
274
+ "friends": {
275
+ "title": "Friends",
276
+ "description": "List of friends of the user",
277
+ "type": "array",
278
+ "items": {"type": "string"}
 
 
 
 
 
 
 
279
  }
280
+ },
281
+ "required": ["name", "email"]
282
  }
283
+ },
284
+ "required": ["user"],
285
+ "definitions": {}
286
  }
287
+ }
288
+ }
289
+ ]
290
  }""",
291
  """[
292
+ {
293
+ "role": "user",
294
+ "content": "Create a user for Test User ([email protected]), born January 1st 2000, with some random friends."
295
+ }
296
  ]""",
297
  ],
298
  [
299
  """{
300
+ "documents": [
 
 
 
 
 
 
 
 
 
 
 
301
  {
302
+ "title": "Much ado about nothing",
303
+ "content": "Dolor sit amet..."
304
+ },
305
+ {
306
+ "title": "Less ado about something",
307
+ "content": "Lorem ipsum..."
308
  }
309
+ ]
310
+ }""",
311
+ """[
312
+ {
313
+ "role": "user",
314
+ "content": "Write a brief summary of the following documents."
315
+ }
316
  ]""",
317
  ],
318
  ]
 
963
  if info.widget_data:
964
  for data in info.widget_data:
965
  if "messages" in data:
966
+ template_messages = json.dumps(data["messages"], ensure_ascii = False, indent = 2)
967
  break
968
 
969
  if isinstance(templates, list):
 
972
  template_rag = templates.get("rag")
973
  templates = templates.get("default")
974
 
975
+ return model_info, json.dumps(template_kwargs, ensure_ascii = False, indent = 2), template_messages, templates, template_tool_use, template_rag, template_inverse
976
 
977
 
978
  def template_data_from_model_files(
 
1139
  x = example.copy()
1140
  x0 = json.loads(x[0])
1141
  x0.update(settings)
1142
+ x[0] = json.dumps(x0, ensure_ascii = False, indent = 2)
1143
  examples.append(x)
1144
 
1145
  return gr.Dataset(
 
1303
  title = "Inverse Template Error",
1304
  )
1305
 
1306
+ return chat_output, chat_tool_use_output, chat_rag_output, json.dumps(inverse_output, ensure_ascii = False, indent = 2) if inverse_output is not None else None
1307
 
1308
 
1309
  if __name__ == "__main__":