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
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
10 deletions
+30
-10
dto/openai_request.go
+30
-10
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,25 +931,37 @@ func (r *OpenAIResponsesRequest) ParseInput() []MediaInput {
...
@@ -925,25 +931,37 @@ 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
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
})
}
if
common
.
GetJsonType
(
input
.
Content
)
==
"array"
{
var
array
[]
any
var
array
[]
any
_
=
common
.
Unmarshal
(
r
.
Inpu
t
,
&
array
)
_
=
common
.
Unmarshal
(
input
.
Conten
t
,
&
array
)
for
_
,
itemAny
:=
range
array
{
for
_
,
itemAny
:=
range
array
{
// Already parsed MediaInpu
t
// Already parsed MediaConten
t
if
media
,
ok
:=
itemAny
.
(
MediaInput
);
ok
{
if
media
,
ok
:=
itemAny
.
(
MediaInput
);
ok
{
inputs
=
append
(
i
nputs
,
media
)
mediaInputs
=
append
(
mediaI
nputs
,
media
)
continue
continue
}
}
// Generic map
// Generic map
item
,
ok
:=
itemAny
.
(
map
[
string
]
any
)
item
,
ok
:=
itemAny
.
(
map
[
string
]
any
)
if
!
ok
{
if
!
ok
{
continue
continue
}
}
typeVal
,
ok
:=
item
[
"type"
]
.
(
string
)
typeVal
,
ok
:=
item
[
"type"
]
.
(
string
)
if
!
ok
{
if
!
ok
{
continue
continue
...
@@ -951,7 +969,7 @@ func (r *OpenAIResponsesRequest) ParseInput() []MediaInput {
...
@@ -951,7 +969,7 @@ func (r *OpenAIResponsesRequest) ParseInput() []MediaInput {
switch
typeVal
{
switch
typeVal
{
case
"input_text"
:
case
"input_text"
:
text
,
_
:=
item
[
"text"
]
.
(
string
)
text
,
_
:=
item
[
"text"
]
.
(
string
)
inputs
=
append
(
i
nputs
,
MediaInput
{
Type
:
"input_text"
,
Text
:
text
})
mediaInputs
=
append
(
mediaI
nputs
,
MediaInput
{
Type
:
"input_text"
,
Text
:
text
})
case
"input_image"
:
case
"input_image"
:
// image_url may be string or object with url field
// image_url may be string or object with url field
var
imageUrl
string
var
imageUrl
string
...
@@ -963,7 +981,7 @@ func (r *OpenAIResponsesRequest) ParseInput() []MediaInput {
...
@@ -963,7 +981,7 @@ func (r *OpenAIResponsesRequest) ParseInput() []MediaInput {
imageUrl
=
url
imageUrl
=
url
}
}
}
}
inputs
=
append
(
i
nputs
,
MediaInput
{
Type
:
"input_image"
,
ImageUrl
:
imageUrl
})
mediaInputs
=
append
(
mediaI
nputs
,
MediaInput
{
Type
:
"input_image"
,
ImageUrl
:
imageUrl
})
case
"input_file"
:
case
"input_file"
:
// file_url may be string or object with url field
// file_url may be string or object with url field
var
fileUrl
string
var
fileUrl
string
...
@@ -975,10 +993,12 @@ func (r *OpenAIResponsesRequest) ParseInput() []MediaInput {
...
@@ -975,10 +993,12 @@ func (r *OpenAIResponsesRequest) ParseInput() []MediaInput {
fileUrl
=
url
fileUrl
=
url
}
}
}
}
inputs
=
append
(
inputs
,
MediaInput
{
Type
:
"input_file"
,
FileUrl
:
fileUrl
})
mediaInputs
=
append
(
mediaInputs
,
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