Skip to content

Commit

Permalink
feat: support gemini-2.0-flash-thinking #639 #637
Browse files Browse the repository at this point in the history
  • Loading branch information
Calcium-Ion committed Dec 20, 2024
1 parent 2d865eb commit 9a54b34
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions controller/channel-test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ func buildTestRequest(model string) *dto.GeneralOpenAIRequest {
}
if strings.HasPrefix(model, "o1-") {
testRequest.MaxCompletionTokens = 1
} else if strings.HasPrefix(model, "gemini-2.0-flash-thinking") {
testRequest.MaxTokens = 2
} else {
testRequest.MaxTokens = 1
}
Expand Down
3 changes: 2 additions & 1 deletion relay/channel/gemini/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ const (
var ModelList = []string{
"gemini-1.5-pro-latest", "gemini-1.5-flash-latest",
"gemini-1.5-pro-exp-0827", "gemini-1.5-flash-exp-0827",
"gemini-exp-1114", "gemini-exp-1206",
"gemini-exp-1114", "gemini-exp-1121", "gemini-exp-1206",
"gemini-2.0-flash-exp",
"gemini-2.0-flash-thinking-exp-1219",
}

var ChannelName = "google gemini"
13 changes: 11 additions & 2 deletions relay/channel/gemini/relay-gemini.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"io"
"net/http"
"one-api/common"
Expand All @@ -13,6 +12,8 @@ import (
relaycommon "one-api/relay/common"
"one-api/service"
"strings"

"github.com/gin-gonic/gin"
)

// Setting safety to the lowest possible values since Gemini is already powerless enough
Expand All @@ -36,6 +37,10 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) *GeminiChatReques
Category: "HARM_CATEGORY_DANGEROUS_CONTENT",
Threshold: common.GeminiSafetySetting,
},
{
Category: "HARM_CATEGORY_CIVIC_INTEGRITY",
Threshold: common.GeminiSafetySetting,
},
},
GenerationConfig: GeminiChatGenerationConfig{
Temperature: textRequest.Temperature,
Expand Down Expand Up @@ -215,7 +220,11 @@ func responseGeminiChat2OpenAI(response *GeminiChatResponse) *dto.OpenAITextResp
choice.FinishReason = constant.FinishReasonToolCalls
choice.Message.ToolCalls = getToolCalls(&candidate)
} else {
choice.Message.SetStringContent(candidate.Content.Parts[0].Text)
var texts []string
for _, part := range candidate.Content.Parts {
texts = append(texts, part.Text)
}
choice.Message.SetStringContent(strings.Join(texts, "\n"))
}
}
fullTextResponse.Choices = append(fullTextResponse.Choices, choice)
Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/Redemption/EditRedemption.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const EditRedemption = (props) => {
let name = inputs.name;
if (!isEdit && inputs.name === '') {
// set default name
name = t('新建兑换码') + ' ' + renderQuota(quota);
name = renderQuota(quota);
}
setLoading(true);
let localInputs = inputs;
Expand Down

0 comments on commit 9a54b34

Please sign in to comment.