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
c0859c05
authored
Oct 11, 2025
by
feitianbubu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add openai sdk for kling
parent
69f497e3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
24 deletions
+67
-24
relay/channel/task/kling/adaptor.go
+49
-8
relay/common/relay_info.go
+18
-16
No files found.
relay/channel/task/kling/adaptor.go
View file @
c0859c05
...
@@ -7,9 +7,11 @@ import (
...
@@ -7,9 +7,11 @@ import (
"io"
"io"
"net/http"
"net/http"
"one-api/model"
"one-api/model"
"strconv"
"strings"
"strings"
"time"
"time"
"github.com/bytedance/gopkg/util/logger"
"github.com/samber/lo"
"github.com/samber/lo"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
...
@@ -303,14 +305,6 @@ func (a *TaskAdaptor) createJWTToken() (string, error) {
...
@@ -303,14 +305,6 @@ func (a *TaskAdaptor) createJWTToken() (string, error) {
return
a
.
createJWTTokenWithKey
(
a
.
apiKey
)
return
a
.
createJWTTokenWithKey
(
a
.
apiKey
)
}
}
//func (a *TaskAdaptor) createJWTTokenWithKey(apiKey string) (string, error) {
// parts := strings.Split(apiKey, "|")
// if len(parts) != 2 {
// return "", fmt.Errorf("invalid API key format, expected 'access_key,secret_key'")
// }
// return a.createJWTTokenWithKey(strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1]))
//}
func
(
a
*
TaskAdaptor
)
createJWTTokenWithKey
(
apiKey
string
)
(
string
,
error
)
{
func
(
a
*
TaskAdaptor
)
createJWTTokenWithKey
(
apiKey
string
)
(
string
,
error
)
{
if
isNewAPIRelay
(
apiKey
)
{
if
isNewAPIRelay
(
apiKey
)
{
return
apiKey
,
nil
// new api relay
return
apiKey
,
nil
// new api relay
...
@@ -369,3 +363,50 @@ func (a *TaskAdaptor) ParseTaskResult(respBody []byte) (*relaycommon.TaskInfo, e
...
@@ -369,3 +363,50 @@ func (a *TaskAdaptor) ParseTaskResult(respBody []byte) (*relaycommon.TaskInfo, e
func
isNewAPIRelay
(
apiKey
string
)
bool
{
func
isNewAPIRelay
(
apiKey
string
)
bool
{
return
strings
.
HasPrefix
(
apiKey
,
"sk-"
)
return
strings
.
HasPrefix
(
apiKey
,
"sk-"
)
}
}
func
(
a
*
TaskAdaptor
)
ConvertToOpenAIVideo
(
originTask
*
model
.
Task
)
(
*
relaycommon
.
OpenAIVideo
,
error
)
{
var
klingResp
responsePayload
if
err
:=
json
.
Unmarshal
(
originTask
.
Data
,
&
klingResp
);
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"unmarshal kling task data failed"
)
}
convertProgress
:=
func
(
progress
string
)
int
{
progress
=
strings
.
TrimSuffix
(
progress
,
"%"
)
p
,
err
:=
strconv
.
Atoi
(
progress
)
if
err
!=
nil
{
logger
.
Warnf
(
"convert progress failed, progress: %s, err: %v"
,
progress
,
err
)
}
return
p
}
openAIVideo
:=
&
relaycommon
.
OpenAIVideo
{
ID
:
klingResp
.
Data
.
TaskId
,
Object
:
"video"
,
//Model: "kling-v1", //todo save model
Status
:
string
(
originTask
.
Status
),
CreatedAt
:
klingResp
.
Data
.
CreatedAt
,
CompletedAt
:
klingResp
.
Data
.
UpdatedAt
,
Metadata
:
make
(
map
[
string
]
any
),
Progress
:
convertProgress
(
originTask
.
Progress
),
}
// 处理视频 URL
if
len
(
klingResp
.
Data
.
TaskResult
.
Videos
)
>
0
{
video
:=
klingResp
.
Data
.
TaskResult
.
Videos
[
0
]
if
video
.
Url
!=
""
{
openAIVideo
.
Metadata
[
"url"
]
=
video
.
Url
}
if
video
.
Duration
!=
""
{
openAIVideo
.
Seconds
=
video
.
Duration
}
}
if
klingResp
.
Code
!=
0
&&
klingResp
.
Message
!=
""
{
openAIVideo
.
Error
=
&
relaycommon
.
OpenAIVideoError
{
Message
:
klingResp
.
Message
,
Code
:
fmt
.
Sprintf
(
"%d"
,
klingResp
.
Code
),
}
}
return
openAIVideo
,
nil
}
relay/common/relay_info.go
View file @
c0859c05
...
@@ -552,20 +552,22 @@ func RemoveDisabledFields(jsonData []byte, channelOtherSettings dto.ChannelOther
...
@@ -552,20 +552,22 @@ func RemoveDisabledFields(jsonData []byte, channelOtherSettings dto.ChannelOther
}
}
type
OpenAIVideo
struct
{
type
OpenAIVideo
struct
{
ID
string
`json:"id"`
ID
string
`json:"id"`
TaskID
string
`json:"task_id,omitempty"`
//兼容旧接口
TaskID
string
`json:"task_id,omitempty"`
//兼容旧接口 待废弃
Object
string
`json:"object"`
Object
string
`json:"object"`
Model
string
`json:"model"`
Model
string
`json:"model"`
Status
string
`json:"status"`
Status
string
`json:"status"`
Progress
int
`json:"progress"`
Progress
int
`json:"progress"`
CreatedAt
int64
`json:"created_at"`
CreatedAt
int64
`json:"created_at"`
CompletedAt
int64
`json:"completed_at,omitempty"`
CompletedAt
int64
`json:"completed_at,omitempty"`
ExpiresAt
int64
`json:"expires_at,omitempty"`
ExpiresAt
int64
`json:"expires_at,omitempty"`
Seconds
string
`json:"seconds,omitempty"`
Seconds
string
`json:"seconds,omitempty"`
Size
string
`json:"size,omitempty"`
Size
string
`json:"size,omitempty"`
RemixedFromVideoID
string
`json:"remixed_from_video_id,omitempty"`
RemixedFromVideoID
string
`json:"remixed_from_video_id,omitempty"`
Error
*
struct
{
Error
*
OpenAIVideoError
`json:"error,omitempty"`
Message
string
`json:"message"`
Metadata
map
[
string
]
any
`json:"metadata,omitempty"`
Code
string
`json:"code"`
}
}
`json:"error,omitempty"`
type
OpenAIVideoError
struct
{
Message
string
`json:"message"`
Code
string
`json:"code"`
}
}
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