Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
cd0935dd
Unverified
Commit
cd0935dd
authored
Jul 02, 2024
by
Matt
Committed by
GitHub
Jul 02, 2024
Browse files
Make tool JSON schemas consistent (#31756)
Make the order of array items consistent using sorted()
parent
82486e59
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
4 deletions
+4
-4
src/transformers/utils/chat_template_utils.py
src/transformers/utils/chat_template_utils.py
+1
-1
tests/utils/test_chat_template_utils.py
tests/utils/test_chat_template_utils.py
+3
-3
No files found.
src/transformers/utils/chat_template_utils.py
View file @
cd0935dd
...
@@ -80,7 +80,7 @@ def _parse_type_hint(hint: str) -> Dict:
...
@@ -80,7 +80,7 @@ def _parse_type_hint(hint: str) -> Dict:
return_dict
=
subtypes
[
0
]
return_dict
=
subtypes
[
0
]
elif
all
(
isinstance
(
subtype
[
"type"
],
str
)
for
subtype
in
subtypes
):
elif
all
(
isinstance
(
subtype
[
"type"
],
str
)
for
subtype
in
subtypes
):
# A union of basic types can be expressed as a list in the schema
# A union of basic types can be expressed as a list in the schema
return_dict
=
{
"type"
:
[
subtype
[
"type"
]
for
subtype
in
subtypes
]}
return_dict
=
{
"type"
:
sorted
(
[
subtype
[
"type"
]
for
subtype
in
subtypes
]
)
}
else
:
else
:
# A union of more complex types requires "anyOf"
# A union of more complex types requires "anyOf"
return_dict
=
{
"anyOf"
:
subtypes
}
return_dict
=
{
"anyOf"
:
subtypes
}
...
...
tests/utils/test_chat_template_utils.py
View file @
cd0935dd
...
@@ -137,7 +137,7 @@ class JsonSchemaGeneratorTest(unittest.TestCase):
...
@@ -137,7 +137,7 @@ class JsonSchemaGeneratorTest(unittest.TestCase):
"properties"
:
{
"properties"
:
{
"x"
:
{
"x"
:
{
"type"
:
"array"
,
"type"
:
"array"
,
"items"
:
{
"type"
:
"array"
,
"items"
:
{
"type"
:
[
"
string"
,
"integer
"
]}},
"items"
:
{
"type"
:
"array"
,
"items"
:
{
"type"
:
[
"
integer"
,
"string
"
]}},
"description"
:
"The input"
,
"description"
:
"The input"
,
}
}
},
},
...
@@ -455,13 +455,13 @@ class JsonSchemaGeneratorTest(unittest.TestCase):
...
@@ -455,13 +455,13 @@ class JsonSchemaGeneratorTest(unittest.TestCase):
},
},
"y"
:
{
"y"
:
{
"type"
:
"array"
,
"type"
:
"array"
,
"items"
:
{
"type"
:
[
"
string"
,
"integer
"
]},
"items"
:
{
"type"
:
[
"
integer"
,
"string
"
]},
"nullable"
:
True
,
"nullable"
:
True
,
"description"
:
"The second input. It's a big list with a single-line description."
,
"description"
:
"The second input. It's a big list with a single-line description."
,
},
},
"z"
:
{
"z"
:
{
"type"
:
"array"
,
"type"
:
"array"
,
"prefixItems"
:
[{
"type"
:
[
"
string"
,
"integer
"
]},
{
"type"
:
"string"
}],
"prefixItems"
:
[{
"type"
:
[
"
integer"
,
"string
"
]},
{
"type"
:
"string"
}],
"description"
:
"The third input. It's some kind of tuple with a default arg."
,
"description"
:
"The third input. It's some kind of tuple with a default arg."
,
},
},
},
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment