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
c5633221
authored
Nov 04, 2024
by
CalciumIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: support gpt-4o-audio-preview
parent
2cf0769b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
11 deletions
+31
-11
common/model-ratio.go
+3
-3
dto/openai_request.go
+24
-7
dto/openai_response.go
+0
-0
service/token_counter.go
+4
-1
web/pnpm-lock.yaml
+0
-0
No files found.
common/model-ratio.go
View file @
c5633221
...
...
@@ -337,15 +337,15 @@ func GetCompletionRatio(name string) float64 {
name
=
"gpt-4o-gizmo-*"
}
if
strings
.
HasPrefix
(
name
,
"gpt-4"
)
&&
!
strings
.
HasSuffix
(
name
,
"-all"
)
&&
!
strings
.
HasSuffix
(
name
,
"-gizmo-*"
)
{
if
strings
.
HasPrefix
(
name
,
"gpt-4-turbo"
)
||
strings
.
HasSuffix
(
name
,
"preview"
)
{
return
3
}
if
strings
.
HasPrefix
(
name
,
"gpt-4o"
)
{
if
name
==
"gpt-4o-2024-05-13"
{
return
3
}
return
4
}
if
strings
.
HasPrefix
(
name
,
"gpt-4-turbo"
)
||
strings
.
HasSuffix
(
name
,
"preview"
)
{
return
3
}
return
2
}
if
strings
.
HasPrefix
(
name
,
"o1-"
)
{
...
...
dto/
text
_request.go
→
dto/
openai
_request.go
View file @
c5633221
...
...
@@ -34,6 +34,8 @@ type GeneralOpenAIRequest struct {
LogProbs
bool
`json:"logprobs,omitempty"`
TopLogProbs
int
`json:"top_logprobs,omitempty"`
Dimensions
int
`json:"dimensions,omitempty"`
Modalities
any
`json:"modalities,omitempty"`
Audio
any
`json:"audio,omitempty"`
}
type
OpenAITools
struct
{
...
...
@@ -83,9 +85,10 @@ type Message struct {
}
type
MediaMessage
struct
{
Type
string
`json:"type"`
Text
string
`json:"text"`
ImageUrl
any
`json:"image_url,omitempty"`
Type
string
`json:"type"`
Text
string
`json:"text"`
ImageUrl
any
`json:"image_url,omitempty"`
InputAudio
any
`json:"input_audio,omitempty"`
}
type
MessageImageUrl
struct
{
...
...
@@ -93,9 +96,15 @@ type MessageImageUrl struct {
Detail
string
`json:"detail"`
}
type
MessageInputAudio
struct
{
Data
string
`json:"data"`
//base64
Format
string
`json:"format"`
}
const
(
ContentTypeText
=
"text"
ContentTypeImageURL
=
"image_url"
ContentTypeText
=
"text"
ContentTypeImageURL
=
"image_url"
ContentTypeInputAudio
=
"input_audio"
)
func
(
m
Message
)
StringContent
()
string
{
...
...
@@ -168,11 +177,19 @@ func (m Message) ParseContent() []MediaMessage {
},
})
}
case
ContentTypeInputAudio
:
if
subObj
,
ok
:=
contentMap
[
"input_audio"
]
.
(
map
[
string
]
any
);
ok
{
contentList
=
append
(
contentList
,
MediaMessage
{
Type
:
ContentTypeInputAudio
,
InputAudio
:
MessageInputAudio
{
Data
:
subObj
[
"data"
]
.
(
string
),
Format
:
subObj
[
"format"
]
.
(
string
),
},
})
}
}
}
return
contentList
}
return
nil
}
dto/
text
_response.go
→
dto/
openai
_response.go
View file @
c5633221
File moved
service/token_counter.go
View file @
c5633221
...
...
@@ -223,7 +223,7 @@ func CountTokenMessages(messages []dto.Message, model string, stream bool) (int,
}
else
{
arrayContent
:=
message
.
ParseContent
()
for
_
,
m
:=
range
arrayContent
{
if
m
.
Type
==
"image_url"
{
if
m
.
Type
==
dto
.
ContentTypeImageURL
{
imageUrl
:=
m
.
ImageUrl
.
(
dto
.
MessageImageUrl
)
imageTokenNum
,
err
:=
getImageToken
(
&
imageUrl
,
model
,
stream
)
if
err
!=
nil
{
...
...
@@ -231,6 +231,9 @@ func CountTokenMessages(messages []dto.Message, model string, stream bool) (int,
}
tokenNum
+=
imageTokenNum
log
.
Printf
(
"image token num: %d"
,
imageTokenNum
)
}
else
if
m
.
Type
==
dto
.
ContentTypeInputAudio
{
// TODO: 音频token数量计算
tokenNum
+=
100
}
else
{
tokenNum
+=
getTokenNum
(
tokenEncoder
,
m
.
Text
)
}
...
...
web/pnpm-lock.yaml
View file @
c5633221
This source diff could not be displayed because it is too large. You can
view the blob
instead.
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