daohanlu commited on
Commit
883bdb9
·
verified ·
1 Parent(s): cbf31f6

Update chat_template.jinja to correctly parse types nested in arrays

Browse files

By forcing recursive calls in `render_typescript_type` for "array" types, it now correctly renders any array types that contains items of enum strings or have a "description" field. Before the fix, neither enums nor the "description" field are rendered due to prematurely stopping parsing.
Additionally updated the "any[]" truncation length from 50 to 200, as Enum types typically need longer descriptions.
E.g., these schemas are now correctly rendered:
```
"example_array": {
"items": {
"type": "string",
"description": "An enum string with two types",
"enum": [
"TypeA",
"TypeB"
]
},
"type": "array",
"description": "List of unique enum strings"
}
```

Files changed (1) hide show
  1. chat_template.jinja +4 -14
chat_template.jinja CHANGED
@@ -10,21 +10,11 @@
10
  {%- macro render_typescript_type(param_spec, required_params, is_nullable=false) -%}
11
  {%- if param_spec.type == "array" -%}
12
  {%- if param_spec['items'] -%}
13
- {%- if param_spec['items']['type'] == "string" -%}
14
- {{- "string[]" }}
15
- {%- elif param_spec['items']['type'] == "number" -%}
16
- {{- "number[]" }}
17
- {%- elif param_spec['items']['type'] == "integer" -%}
18
- {{- "number[]" }}
19
- {%- elif param_spec['items']['type'] == "boolean" -%}
20
- {{- "boolean[]" }}
21
  {%- else -%}
22
- {%- set inner_type = render_typescript_type(param_spec['items'], required_params) -%}
23
- {%- if inner_type == "object | object" or inner_type|length > 50 -%}
24
- {{- "any[]" }}
25
- {%- else -%}
26
- {{- inner_type + "[]" }}
27
- {%- endif -%}
28
  {%- endif -%}
29
  {%- if param_spec.nullable -%}
30
  {{- " | null" }}
 
10
  {%- macro render_typescript_type(param_spec, required_params, is_nullable=false) -%}
11
  {%- if param_spec.type == "array" -%}
12
  {%- if param_spec['items'] -%}
13
+ {%- set inner_type = render_typescript_type(param_spec['items'], required_params) -%}
14
+ {%- if inner_type == "object | object" or inner_type|length > 200 -%}
15
+ {{- "any[]" }}
 
 
 
 
 
16
  {%- else -%}
17
+ {{- inner_type + "[]" }}
 
 
 
 
 
18
  {%- endif -%}
19
  {%- if param_spec.nullable -%}
20
  {{- " | null" }}