feat: 初步兼容流模式下openai渠道类型转为claude格式访问 #862

This commit is contained in:
1808837298@qq.com
2025-03-13 19:32:08 +08:00
parent c25d4d8d23
commit 7e46d4217d
37 changed files with 390 additions and 165 deletions

View File

@@ -17,6 +17,16 @@ type ThinkingContentInfo struct {
SendLastThinkingContent bool
}
const (
LastMessageTypeText = "text"
LastMessageTypeTools = "tools"
)
type ClaudeConvertInfo struct {
LastMessagesType string
Index int
}
const (
RelayFormatOpenAI = "openai"
RelayFormatClaude = "claude"
@@ -64,8 +74,9 @@ type RelayInfo struct {
UserEmail string
UserQuota int
RelayFormat string
ResponseTimes int64
SendResponseCount int
ThinkingContentInfo
ClaudeConvertInfo
}
// 定义支持流式选项的通道类型
@@ -93,6 +104,9 @@ func GenRelayInfoClaude(c *gin.Context) *RelayInfo {
info := GenRelayInfo(c)
info.RelayFormat = RelayFormatClaude
info.ShouldIncludeUsage = false
info.ClaudeConvertInfo = ClaudeConvertInfo{
LastMessagesType: LastMessageTypeText,
}
return info
}
@@ -172,7 +186,6 @@ func (info *RelayInfo) SetIsStream(isStream bool) {
}
func (info *RelayInfo) SetFirstResponseTime() {
info.ResponseTimes++
if info.isFirstResponse {
info.FirstResponseTime = time.Now()
info.isFirstResponse = false