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
6d5abaa4
authored
Mar 14, 2025
by
Calcium-Ion
Committed by
GitHub
Mar 14, 2025
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #867 from Sh1n3zZ/wrong-think-label-fix
fix: wrong thinking labels appear in non-thinking models (#861)
parents
15c5fbd3
75130657
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
3 deletions
+15
-3
relay/channel/openai/adaptor.go
+11
-1
relay/channel/openai/relay-openai.go
+4
-2
No files found.
relay/channel/openai/adaptor.go
View file @
6d5abaa4
...
@@ -5,7 +5,6 @@ import (
...
@@ -5,7 +5,6 @@ import (
"encoding/json"
"encoding/json"
"errors"
"errors"
"fmt"
"fmt"
"github.com/gin-gonic/gin"
"io"
"io"
"mime/multipart"
"mime/multipart"
"net/http"
"net/http"
...
@@ -23,6 +22,8 @@ import (
...
@@ -23,6 +22,8 @@ import (
"one-api/relay/constant"
"one-api/relay/constant"
"one-api/service"
"one-api/service"
"strings"
"strings"
"github.com/gin-gonic/gin"
)
)
type
Adaptor
struct
{
type
Adaptor
struct
{
...
@@ -48,6 +49,15 @@ func (a *Adaptor) ConvertClaudeRequest(c *gin.Context, info *relaycommon.RelayIn
...
@@ -48,6 +49,15 @@ func (a *Adaptor) ConvertClaudeRequest(c *gin.Context, info *relaycommon.RelayIn
func
(
a
*
Adaptor
)
Init
(
info
*
relaycommon
.
RelayInfo
)
{
func
(
a
*
Adaptor
)
Init
(
info
*
relaycommon
.
RelayInfo
)
{
a
.
ChannelType
=
info
.
ChannelType
a
.
ChannelType
=
info
.
ChannelType
// initialize ThinkingContentInfo when thinking_to_content is enabled
if
think2Content
,
ok
:=
info
.
ChannelSetting
[
constant2
.
ChannelSettingThinkingToContent
]
.
(
bool
);
ok
&&
think2Content
{
info
.
ThinkingContentInfo
=
relaycommon
.
ThinkingContentInfo
{
IsFirstThinkingContent
:
true
,
SendLastThinkingContent
:
false
,
HasSentThinkingContent
:
false
,
}
}
}
}
func
(
a
*
Adaptor
)
GetRequestURL
(
info
*
relaycommon
.
RelayInfo
)
(
string
,
error
)
{
func
(
a
*
Adaptor
)
GetRequestURL
(
info
*
relaycommon
.
RelayInfo
)
(
string
,
error
)
{
...
...
relay/channel/openai/relay-openai.go
View file @
6d5abaa4
...
@@ -65,6 +65,7 @@ func sendStreamData(c *gin.Context, info *relaycommon.RelayInfo, data string, fo
...
@@ -65,6 +65,7 @@ func sendStreamData(c *gin.Context, info *relaycommon.RelayInfo, data string, fo
response
.
Choices
[
i
]
.
Delta
.
Reasoning
=
nil
response
.
Choices
[
i
]
.
Delta
.
Reasoning
=
nil
}
}
info
.
ThinkingContentInfo
.
IsFirstThinkingContent
=
false
info
.
ThinkingContentInfo
.
IsFirstThinkingContent
=
false
info
.
ThinkingContentInfo
.
HasSentThinkingContent
=
true
return
helper
.
ObjectData
(
c
,
response
)
return
helper
.
ObjectData
(
c
,
response
)
}
}
}
}
...
@@ -76,7 +77,8 @@ func sendStreamData(c *gin.Context, info *relaycommon.RelayInfo, data string, fo
...
@@ -76,7 +77,8 @@ func sendStreamData(c *gin.Context, info *relaycommon.RelayInfo, data string, fo
// Process each choice
// Process each choice
for
i
,
choice
:=
range
lastStreamResponse
.
Choices
{
for
i
,
choice
:=
range
lastStreamResponse
.
Choices
{
// Handle transition from thinking to content
// Handle transition from thinking to content
if
hasContent
&&
!
info
.
ThinkingContentInfo
.
SendLastThinkingContent
{
// only send `</think>` tag when previous thinking content has been sent
if
hasContent
&&
!
info
.
ThinkingContentInfo
.
SendLastThinkingContent
&&
info
.
ThinkingContentInfo
.
HasSentThinkingContent
{
response
:=
lastStreamResponse
.
Copy
()
response
:=
lastStreamResponse
.
Copy
()
for
j
:=
range
response
.
Choices
{
for
j
:=
range
response
.
Choices
{
response
.
Choices
[
j
]
.
Delta
.
SetContentString
(
"
\n
</think>
\n
"
)
response
.
Choices
[
j
]
.
Delta
.
SetContentString
(
"
\n
</think>
\n
"
)
...
@@ -87,7 +89,7 @@ func sendStreamData(c *gin.Context, info *relaycommon.RelayInfo, data string, fo
...
@@ -87,7 +89,7 @@ func sendStreamData(c *gin.Context, info *relaycommon.RelayInfo, data string, fo
helper
.
ObjectData
(
c
,
response
)
helper
.
ObjectData
(
c
,
response
)
}
}
// Convert reasoning content to regular content
// Convert reasoning content to regular content
if any
if
len
(
choice
.
Delta
.
GetReasoningContent
())
>
0
{
if
len
(
choice
.
Delta
.
GetReasoningContent
())
>
0
{
lastStreamResponse
.
Choices
[
i
]
.
Delta
.
SetContentString
(
choice
.
Delta
.
GetReasoningContent
())
lastStreamResponse
.
Choices
[
i
]
.
Delta
.
SetContentString
(
choice
.
Delta
.
GetReasoningContent
())
lastStreamResponse
.
Choices
[
i
]
.
Delta
.
ReasoningContent
=
nil
lastStreamResponse
.
Choices
[
i
]
.
Delta
.
ReasoningContent
=
nil
...
...
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