Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
733e3870
authored
Nov 14, 2025
by
wujiacheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 错误解析responses api中的input字段
parent
31384833
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
45 deletions
+65
-45
dto/openai_request.go
+65
-45
No files found.
dto/openai_request.go
View file @
733e3870
...
...
@@ -895,6 +895,12 @@ type Reasoning struct {
Summary
string
`json:"summary,omitempty"`
}
type
Input
struct
{
Type
string
`json:"type,omitempty"`
Role
string
`json:"role,omitempty"`
Content
json
.
RawMessage
`json:"content,omitempty"`
}
type
MediaInput
struct
{
Type
string
`json:"type"`
Text
string
`json:"text,omitempty"`
...
...
@@ -913,7 +919,7 @@ func (r *OpenAIResponsesRequest) ParseInput() []MediaInput {
return
nil
}
var
i
nputs
[]
MediaInput
var
mediaI
nputs
[]
MediaInput
// Try string first
// if str, ok := common.GetJsonType(r.Input); ok {
...
...
@@ -923,60 +929,74 @@ func (r *OpenAIResponsesRequest) ParseInput() []MediaInput {
if
common
.
GetJsonType
(
r
.
Input
)
==
"string"
{
var
str
string
_
=
common
.
Unmarshal
(
r
.
Input
,
&
str
)
inputs
=
append
(
i
nputs
,
MediaInput
{
Type
:
"input_text"
,
Text
:
str
})
return
i
nputs
mediaInputs
=
append
(
mediaI
nputs
,
MediaInput
{
Type
:
"input_text"
,
Text
:
str
})
return
mediaI
nputs
}
// Try array of parts
if
common
.
GetJsonType
(
r
.
Input
)
==
"array"
{
var
array
[]
any
_
=
common
.
Unmarshal
(
r
.
Input
,
&
array
)
for
_
,
itemAny
:=
range
array
{
// Already parsed MediaInput
if
media
,
ok
:=
itemAny
.
(
MediaInput
);
ok
{
inputs
=
append
(
inputs
,
media
)
continue
}
// Generic map
item
,
ok
:=
itemAny
.
(
map
[
string
]
any
)
if
!
ok
{
continue
}
typeVal
,
ok
:=
item
[
"type"
]
.
(
string
)
if
!
ok
{
continue
var
inputs
[]
Input
_
=
common
.
Unmarshal
(
r
.
Input
,
&
inputs
)
for
_
,
input
:=
range
inputs
{
if
common
.
GetJsonType
(
input
.
Content
)
==
"string"
{
var
str
string
_
=
common
.
Unmarshal
(
input
.
Content
,
&
str
)
mediaInputs
=
append
(
mediaInputs
,
MediaInput
{
Type
:
"input_text"
,
Text
:
str
})
}
switch
typeVal
{
case
"input_text"
:
text
,
_
:=
item
[
"text"
]
.
(
string
)
inputs
=
append
(
inputs
,
MediaInput
{
Type
:
"input_text"
,
Text
:
text
})
case
"input_image"
:
// image_url may be string or object with url field
var
imageUrl
string
switch
v
:=
item
[
"image_url"
]
.
(
type
)
{
case
string
:
imageUrl
=
v
case
map
[
string
]
any
:
if
url
,
ok
:=
v
[
"url"
]
.
(
string
);
ok
{
imageUrl
=
url
if
common
.
GetJsonType
(
input
.
Content
)
==
"array"
{
var
array
[]
any
_
=
common
.
Unmarshal
(
input
.
Content
,
&
array
)
for
_
,
itemAny
:=
range
array
{
// Already parsed MediaContent
if
media
,
ok
:=
itemAny
.
(
MediaInput
);
ok
{
mediaInputs
=
append
(
mediaInputs
,
media
)
continue
}
}
inputs
=
append
(
inputs
,
MediaInput
{
Type
:
"input_image"
,
ImageUrl
:
imageUrl
})
case
"input_file"
:
// file_url may be string or object with url field
var
fileUrl
string
switch
v
:=
item
[
"file_url"
]
.
(
type
)
{
case
string
:
fileUrl
=
v
case
map
[
string
]
any
:
if
url
,
ok
:=
v
[
"url"
]
.
(
string
);
ok
{
fileUrl
=
url
// Generic map
item
,
ok
:=
itemAny
.
(
map
[
string
]
any
)
if
!
ok
{
continue
}
typeVal
,
ok
:=
item
[
"type"
]
.
(
string
)
if
!
ok
{
continue
}
switch
typeVal
{
case
"input_text"
:
text
,
_
:=
item
[
"text"
]
.
(
string
)
mediaInputs
=
append
(
mediaInputs
,
MediaInput
{
Type
:
"input_text"
,
Text
:
text
})
case
"input_image"
:
// image_url may be string or object with url field
var
imageUrl
string
switch
v
:=
item
[
"image_url"
]
.
(
type
)
{
case
string
:
imageUrl
=
v
case
map
[
string
]
any
:
if
url
,
ok
:=
v
[
"url"
]
.
(
string
);
ok
{
imageUrl
=
url
}
}
mediaInputs
=
append
(
mediaInputs
,
MediaInput
{
Type
:
"input_image"
,
ImageUrl
:
imageUrl
})
case
"input_file"
:
// file_url may be string or object with url field
var
fileUrl
string
switch
v
:=
item
[
"file_url"
]
.
(
type
)
{
case
string
:
fileUrl
=
v
case
map
[
string
]
any
:
if
url
,
ok
:=
v
[
"url"
]
.
(
string
);
ok
{
fileUrl
=
url
}
}
mediaInputs
=
append
(
mediaInputs
,
MediaInput
{
Type
:
"input_file"
,
FileUrl
:
fileUrl
})
}
}
inputs
=
append
(
inputs
,
MediaInput
{
Type
:
"input_file"
,
FileUrl
:
fileUrl
})
}
}
}
return
i
nputs
return
mediaI
nputs
}
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