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
4bf0d094
authored
May 03, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add video URL support in MediaContent and update token counting logic
parent
f5c2fda2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
2 deletions
+19
-2
dto/openai_request.go
+15
-0
main.go
+2
-2
service/token_counter.go
+2
-0
No files found.
dto/openai_request.go
View file @
4bf0d094
...
@@ -114,6 +114,7 @@ type MediaContent struct {
...
@@ -114,6 +114,7 @@ type MediaContent struct {
ImageUrl
any
`json:"image_url,omitempty"`
ImageUrl
any
`json:"image_url,omitempty"`
InputAudio
any
`json:"input_audio,omitempty"`
InputAudio
any
`json:"input_audio,omitempty"`
File
any
`json:"file,omitempty"`
File
any
`json:"file,omitempty"`
VideoUrl
any
`json:"video_url,omitempty"`
}
}
func
(
m
*
MediaContent
)
GetImageMedia
()
*
MessageImageUrl
{
func
(
m
*
MediaContent
)
GetImageMedia
()
*
MessageImageUrl
{
...
@@ -158,11 +159,16 @@ type MessageFile struct {
...
@@ -158,11 +159,16 @@ type MessageFile struct {
FileId
string
`json:"file_id,omitempty"`
FileId
string
`json:"file_id,omitempty"`
}
}
type
MessageVideoUrl
struct
{
Url
string
`json:"url"`
}
const
(
const
(
ContentTypeText
=
"text"
ContentTypeText
=
"text"
ContentTypeImageURL
=
"image_url"
ContentTypeImageURL
=
"image_url"
ContentTypeInputAudio
=
"input_audio"
ContentTypeInputAudio
=
"input_audio"
ContentTypeFile
=
"file"
ContentTypeFile
=
"file"
ContentTypeVideoUrl
=
"video_url"
// 阿里百炼视频识别
)
)
func
(
m
*
Message
)
GetPrefix
()
bool
{
func
(
m
*
Message
)
GetPrefix
()
bool
{
...
@@ -346,6 +352,15 @@ func (m *Message) ParseContent() []MediaContent {
...
@@ -346,6 +352,15 @@ func (m *Message) ParseContent() []MediaContent {
}
}
}
}
}
}
case
ContentTypeVideoUrl
:
if
videoUrl
,
ok
:=
contentItem
[
"video_url"
]
.
(
string
);
ok
{
contentList
=
append
(
contentList
,
MediaContent
{
Type
:
ContentTypeVideoUrl
,
VideoUrl
:
&
MessageVideoUrl
{
Url
:
videoUrl
,
},
})
}
}
}
}
}
}
}
...
...
main.go
View file @
4bf0d094
...
@@ -80,6 +80,8 @@ func main() {
...
@@ -80,6 +80,8 @@ func main() {
// Initialize options
// Initialize options
model
.
InitOptionMap
()
model
.
InitOptionMap
()
service
.
InitTokenEncoders
()
if
common
.
RedisEnabled
{
if
common
.
RedisEnabled
{
// for compatibility with old versions
// for compatibility with old versions
common
.
MemoryCacheEnabled
=
true
common
.
MemoryCacheEnabled
=
true
...
@@ -133,8 +135,6 @@ func main() {
...
@@ -133,8 +135,6 @@ func main() {
common
.
SysLog
(
"pprof enabled"
)
common
.
SysLog
(
"pprof enabled"
)
}
}
service
.
InitTokenEncoders
()
// Initialize HTTP server
// Initialize HTTP server
server
:=
gin
.
New
()
server
:=
gin
.
New
()
server
.
Use
(
gin
.
CustomRecovery
(
func
(
c
*
gin
.
Context
,
err
any
)
{
server
.
Use
(
gin
.
CustomRecovery
(
func
(
c
*
gin
.
Context
,
err
any
)
{
...
...
service/token_counter.go
View file @
4bf0d094
...
@@ -400,6 +400,8 @@ func CountTokenMessages(info *relaycommon.RelayInfo, messages []dto.Message, mod
...
@@ -400,6 +400,8 @@ func CountTokenMessages(info *relaycommon.RelayInfo, messages []dto.Message, mod
tokenNum
+=
100
tokenNum
+=
100
}
else
if
m
.
Type
==
dto
.
ContentTypeFile
{
}
else
if
m
.
Type
==
dto
.
ContentTypeFile
{
tokenNum
+=
5000
tokenNum
+=
5000
}
else
if
m
.
Type
==
dto
.
ContentTypeVideoUrl
{
tokenNum
+=
5000
}
else
{
}
else
{
tokenNum
+=
getTokenNum
(
tokenEncoder
,
m
.
Text
)
tokenNum
+=
getTokenNum
(
tokenEncoder
,
m
.
Text
)
}
}
...
...
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