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
cf277475
authored
Nov 22, 2025
by
Seefs
Committed by
GitHub
Nov 22, 2025
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2224 from jarvis-u/main
fix: 错误解析responses api中的input字段
parents
c8bbf7be
733e3870
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 @
cf277475
...
@@ -897,6 +897,12 @@ type Reasoning struct {
...
@@ -897,6 +897,12 @@ type Reasoning struct {
Summary
string
`json:"summary,omitempty"`
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
MediaInput
struct
{
Type
string
`json:"type"`
Type
string
`json:"type"`
Text
string
`json:"text,omitempty"`
Text
string
`json:"text,omitempty"`
...
@@ -915,7 +921,7 @@ func (r *OpenAIResponsesRequest) ParseInput() []MediaInput {
...
@@ -915,7 +921,7 @@ func (r *OpenAIResponsesRequest) ParseInput() []MediaInput {
return
nil
return
nil
}
}
var
i
nputs
[]
MediaInput
var
mediaI
nputs
[]
MediaInput
// Try string first
// Try string first
// if str, ok := common.GetJsonType(r.Input); ok {
// if str, ok := common.GetJsonType(r.Input); ok {
...
@@ -925,60 +931,74 @@ func (r *OpenAIResponsesRequest) ParseInput() []MediaInput {
...
@@ -925,60 +931,74 @@ func (r *OpenAIResponsesRequest) ParseInput() []MediaInput {
if
common
.
GetJsonType
(
r
.
Input
)
==
"string"
{
if
common
.
GetJsonType
(
r
.
Input
)
==
"string"
{
var
str
string
var
str
string
_
=
common
.
Unmarshal
(
r
.
Input
,
&
str
)
_
=
common
.
Unmarshal
(
r
.
Input
,
&
str
)
inputs
=
append
(
i
nputs
,
MediaInput
{
Type
:
"input_text"
,
Text
:
str
})
mediaInputs
=
append
(
mediaI
nputs
,
MediaInput
{
Type
:
"input_text"
,
Text
:
str
})
return
i
nputs
return
mediaI
nputs
}
}
// Try array of parts
// Try array of parts
if
common
.
GetJsonType
(
r
.
Input
)
==
"array"
{
if
common
.
GetJsonType
(
r
.
Input
)
==
"array"
{
var
array
[]
any
var
inputs
[]
Input
_
=
common
.
Unmarshal
(
r
.
Input
,
&
array
)
_
=
common
.
Unmarshal
(
r
.
Input
,
&
inputs
)
for
_
,
itemAny
:=
range
array
{
for
_
,
input
:=
range
inputs
{
// Already parsed MediaInput
if
common
.
GetJsonType
(
input
.
Content
)
==
"string"
{
if
media
,
ok
:=
itemAny
.
(
MediaInput
);
ok
{
var
str
string
inputs
=
append
(
inputs
,
media
)
_
=
common
.
Unmarshal
(
input
.
Content
,
&
str
)
continue
mediaInputs
=
append
(
mediaInputs
,
MediaInput
{
Type
:
"input_text"
,
Text
:
str
})
}
// Generic map
item
,
ok
:=
itemAny
.
(
map
[
string
]
any
)
if
!
ok
{
continue
}
typeVal
,
ok
:=
item
[
"type"
]
.
(
string
)
if
!
ok
{
continue
}
}
switch
typeVal
{
case
"input_text"
:
if
common
.
GetJsonType
(
input
.
Content
)
==
"array"
{
text
,
_
:=
item
[
"text"
]
.
(
string
)
var
array
[]
any
inputs
=
append
(
inputs
,
MediaInput
{
Type
:
"input_text"
,
Text
:
text
})
_
=
common
.
Unmarshal
(
input
.
Content
,
&
array
)
case
"input_image"
:
for
_
,
itemAny
:=
range
array
{
// image_url may be string or object with url field
// Already parsed MediaContent
var
imageUrl
string
if
media
,
ok
:=
itemAny
.
(
MediaInput
);
ok
{
switch
v
:=
item
[
"image_url"
]
.
(
type
)
{
mediaInputs
=
append
(
mediaInputs
,
media
)
case
string
:
continue
imageUrl
=
v
case
map
[
string
]
any
:
if
url
,
ok
:=
v
[
"url"
]
.
(
string
);
ok
{
imageUrl
=
url
}
}
}
inputs
=
append
(
inputs
,
MediaInput
{
Type
:
"input_image"
,
ImageUrl
:
imageUrl
})
// Generic map
case
"input_file"
:
item
,
ok
:=
itemAny
.
(
map
[
string
]
any
)
// file_url may be string or object with url field
if
!
ok
{
var
fileUrl
string
continue
switch
v
:=
item
[
"file_url"
]
.
(
type
)
{
}
case
string
:
fileUrl
=
v
typeVal
,
ok
:=
item
[
"type"
]
.
(
string
)
case
map
[
string
]
any
:
if
!
ok
{
if
url
,
ok
:=
v
[
"url"
]
.
(
string
);
ok
{
continue
fileUrl
=
url
}
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