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
ff6e1286
authored
Jun 08, 2025
by
Calcium-Ion
Committed by
GitHub
Jun 08, 2025
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1175 from RedwindA/fix/mistral-tool-id
馃悰
fix: 閫傚簲Mistral鐨則ool call鏍煎紡瑕佹眰
parents
5ace100f
546d0140
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
0 deletions
+42
-0
relay/channel/mistral/text.go
+42
-0
No files found.
relay/channel/mistral/text.go
View file @
ff6e1286
package
mistral
import
(
"one-api/common"
"one-api/dto"
"regexp"
)
var
mistralToolCallIdRegexp
=
regexp
.
MustCompile
(
"^[a-zA-Z0-9]{9}$"
)
func
requestOpenAI2Mistral
(
request
*
dto
.
GeneralOpenAIRequest
)
*
dto
.
GeneralOpenAIRequest
{
messages
:=
make
([]
dto
.
Message
,
0
,
len
(
request
.
Messages
))
idMap
:=
make
(
map
[
string
]
string
)
for
_
,
message
:=
range
request
.
Messages
{
// 1. tool_calls.id
toolCalls
:=
message
.
ParseToolCalls
()
if
toolCalls
!=
nil
{
for
i
:=
range
toolCalls
{
if
!
mistralToolCallIdRegexp
.
MatchString
(
toolCalls
[
i
]
.
ID
)
{
if
newId
,
ok
:=
idMap
[
toolCalls
[
i
]
.
ID
];
ok
{
toolCalls
[
i
]
.
ID
=
newId
}
else
{
newId
,
err
:=
common
.
GenerateRandomCharsKey
(
9
)
if
err
==
nil
{
idMap
[
toolCalls
[
i
]
.
ID
]
=
newId
toolCalls
[
i
]
.
ID
=
newId
}
}
}
}
message
.
SetToolCalls
(
toolCalls
)
}
// 2. tool_call_id
if
message
.
ToolCallId
!=
""
{
if
newId
,
ok
:=
idMap
[
message
.
ToolCallId
];
ok
{
message
.
ToolCallId
=
newId
}
else
{
if
!
mistralToolCallIdRegexp
.
MatchString
(
message
.
ToolCallId
)
{
newId
,
err
:=
common
.
GenerateRandomCharsKey
(
9
)
if
err
==
nil
{
idMap
[
message
.
ToolCallId
]
=
newId
message
.
ToolCallId
=
newId
}
}
}
}
mediaMessages
:=
message
.
ParseContent
()
if
message
.
Role
==
"assistant"
&&
message
.
ToolCalls
!=
nil
&&
string
(
message
.
Content
)
==
"null"
{
mediaMessages
=
[]
dto
.
MediaContent
{}
}
for
j
,
mediaMessage
:=
range
mediaMessages
{
if
mediaMessage
.
Type
==
dto
.
ContentTypeImageURL
{
imageUrl
:=
mediaMessage
.
GetImageMedia
()
...
...
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