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
zhougaofeng
internlm2-math-7B
Commits
570935de
Commit
570935de
authored
Jun 11, 2024
by
zhougaofeng
Browse files
Upload New File
parent
c6d7e5ee
Pipeline
#1121
canceled with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
0 deletions
+20
-0
src/llmfactory/api/common.py
src/llmfactory/api/common.py
+20
-0
No files found.
src/llmfactory/api/common.py
0 → 100644
View file @
570935de
import
json
from
typing
import
TYPE_CHECKING
,
Any
,
Dict
if
TYPE_CHECKING
:
from
pydantic
import
BaseModel
def
dictify
(
data
:
"BaseModel"
)
->
Dict
[
str
,
Any
]:
try
:
# pydantic v2
return
data
.
model_dump
(
exclude_unset
=
True
)
except
AttributeError
:
# pydantic v1
return
data
.
dict
(
exclude_unset
=
True
)
def
jsonify
(
data
:
"BaseModel"
)
->
str
:
try
:
# pydantic v2
return
json
.
dumps
(
data
.
model_dump
(
exclude_unset
=
True
),
ensure_ascii
=
False
)
except
AttributeError
:
# pydantic v1
return
data
.
json
(
exclude_unset
=
True
,
ensure_ascii
=
False
)
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