mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-19 01:56:37 +08:00
Compare commits
No commits in common. "cb4ee5e86a70d53e6fd8636ad983a7b73ca44d11" and "4907952fd13dd7640f3e89e260b1446b733f31da" have entirely different histories.
cb4ee5e86a
...
4907952fd1
@ -65,19 +65,13 @@ type ChatTools struct {
|
|||||||
FunctionDeclarations any `json:"function_declarations,omitempty"`
|
FunctionDeclarations any `json:"function_declarations,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ThinkingConfig struct {
|
|
||||||
IncludeThoughts bool `json:"includeThoughts"`
|
|
||||||
ThinkingBudget int `json:"thinkingBudget"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ChatGenerationConfig struct {
|
type ChatGenerationConfig struct {
|
||||||
ResponseMimeType string `json:"responseMimeType,omitempty"`
|
ResponseMimeType string `json:"responseMimeType,omitempty"`
|
||||||
ResponseSchema any `json:"responseSchema,omitempty"`
|
ResponseSchema any `json:"responseSchema,omitempty"`
|
||||||
Temperature *float64 `json:"temperature,omitempty"`
|
Temperature *float64 `json:"temperature,omitempty"`
|
||||||
TopP *float64 `json:"topP,omitempty"`
|
TopP *float64 `json:"topP,omitempty"`
|
||||||
TopK float64 `json:"topK,omitempty"`
|
TopK float64 `json:"topK,omitempty"`
|
||||||
MaxOutputTokens int `json:"maxOutputTokens,omitempty"`
|
MaxOutputTokens int `json:"maxOutputTokens,omitempty"`
|
||||||
CandidateCount int `json:"candidateCount,omitempty"`
|
CandidateCount int `json:"candidateCount,omitempty"`
|
||||||
StopSequences []string `json:"stopSequences,omitempty"`
|
StopSequences []string `json:"stopSequences,omitempty"`
|
||||||
ThinkingConfig *ThinkingConfig `json:"thinkingConfig,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,6 @@ package vertexai
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -30,47 +27,13 @@ var ModelList = []string{
|
|||||||
type Adaptor struct {
|
type Adaptor struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Adaptor) parseGeminiChatGenerationThinking(model string) (string, *gemini.ThinkingConfig) {
|
|
||||||
thinkingConfig := &gemini.ThinkingConfig{
|
|
||||||
IncludeThoughts: false,
|
|
||||||
ThinkingBudget: 0,
|
|
||||||
}
|
|
||||||
modelName := model
|
|
||||||
if strings.Contains(model, "?") {
|
|
||||||
parts := strings.Split(model, "?")
|
|
||||||
_modelName := parts[0]
|
|
||||||
if len(parts) >= 2 {
|
|
||||||
modelOptions, err := url.ParseQuery(parts[1])
|
|
||||||
if err == nil && modelOptions != nil {
|
|
||||||
modelName = _modelName
|
|
||||||
hasThinkingFlag := modelOptions.Has("thinking")
|
|
||||||
if hasThinkingFlag {
|
|
||||||
thinkingConfig.IncludeThoughts = modelOptions.Get("thinking") == "1"
|
|
||||||
}
|
|
||||||
thinkingBudget := modelOptions.Get("thinking_budget")
|
|
||||||
if thinkingBudget != "" {
|
|
||||||
thinkingBudgetInt, err := strconv.Atoi(thinkingBudget)
|
|
||||||
if err == nil {
|
|
||||||
thinkingConfig.ThinkingBudget = thinkingBudgetInt
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return modelName, thinkingConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *Adaptor) ConvertRequest(c *gin.Context, relayMode int, request *model.GeneralOpenAIRequest) (any, error) {
|
func (a *Adaptor) ConvertRequest(c *gin.Context, relayMode int, request *model.GeneralOpenAIRequest) (any, error) {
|
||||||
if request == nil {
|
if request == nil {
|
||||||
return nil, errors.New("request is nil")
|
return nil, errors.New("request is nil")
|
||||||
}
|
}
|
||||||
modelName, thinkingConfig := a.parseGeminiChatGenerationThinking(request.Model)
|
|
||||||
request.Model = modelName
|
|
||||||
geminiRequest := gemini.ConvertRequest(*request)
|
geminiRequest := gemini.ConvertRequest(*request)
|
||||||
if thinkingConfig != nil {
|
c.Set(ctxkey.RequestModel, request.Model)
|
||||||
geminiRequest.GenerationConfig.ThinkingConfig = thinkingConfig
|
|
||||||
}
|
|
||||||
c.Set(ctxkey.RequestModel, modelName)
|
|
||||||
c.Set(ctxkey.ConvertedRequest, geminiRequest)
|
c.Set(ctxkey.ConvertedRequest, geminiRequest)
|
||||||
return geminiRequest, nil
|
return geminiRequest, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user