Compare commits

...

8 Commits

Author SHA1 Message Date
zephyrs988
3d7d87c554
Merge 974331a028 into 8df4a2670b 2025-09-15 09:28:04 +00:00
suziheng
974331a028 feat:gemini file 2025-09-15 17:16:50 +08:00
suziheng
a529eab39e build:dockerfile 2025-09-15 16:18:27 +08:00
suziheng
2174039fce build:dockerfile 2025-09-15 15:58:46 +08:00
suziheng
9ce714ac8d build:dockerfile 2025-09-15 15:33:48 +08:00
suziheng
7d2fc27c0f build:dockerfile 2025-09-15 15:30:56 +08:00
suziheng
4d3add220e build: npm version 2025-09-15 15:17:55 +08:00
suziheng
04de01c798 feat: support openai format enable deepseek v3.1 thinking 2025-09-15 14:43:19 +08:00
9 changed files with 71 additions and 6 deletions

View File

@ -4,13 +4,15 @@ WORKDIR /web
COPY ./VERSION .
COPY ./web .
RUN npm install --prefix /web/default && \
npm install --prefix /web/berry && \
npm install --prefix /web/air
RUN npm install --prefix /web/default & \
npm install --prefix /web/berry & \
npm install --prefix /web/air & \
wait
RUN DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat ./VERSION) npm run build --prefix /web/default && \
DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat ./VERSION) npm run build --prefix /web/berry && \
DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat ./VERSION) npm run build --prefix /web/air
RUN DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat ./VERSION) npm run build --prefix /web/default & \
DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat ./VERSION) npm run build --prefix /web/berry & \
DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat ./VERSION) npm run build --prefix /web/air & \
wait
FROM golang:alpine AS builder2

23
common/file/file.go Normal file
View File

@ -0,0 +1,23 @@
package file
import (
"bytes"
"encoding/base64"
"net/http"
)
func GetFileFromUrl(url string) (mimeType string, data string, err error) {
resp, err := http.Get(url)
if err != nil {
return
}
defer resp.Body.Close()
buffer := bytes.NewBuffer(nil)
_, err = buffer.ReadFrom(resp.Body)
if err != nil {
return
}
mimeType = resp.Header.Get("Content-Type")
data = base64.StdEncoding.EncodeToString(buffer.Bytes())
return
}

View File

@ -36,6 +36,12 @@ func ConvertRequest(request model.GeneralOpenAIRequest) *ChatRequest {
enableSearch = true
aliModel = strings.TrimSuffix(aliModel, EnableSearchModelSuffix)
}
enableThinking := false
if request.ReasoningEffort != nil {
enableThinking = true
}
request.TopP = helper.Float64PtrMax(request.TopP, 0.9999)
return &ChatRequest{
Model: aliModel,
@ -52,6 +58,7 @@ func ConvertRequest(request model.GeneralOpenAIRequest) *ChatRequest {
TopK: request.TopK,
ResultFormat: "message",
Tools: request.Tools,
EnableThinking: enableThinking,
},
}
}

View File

@ -25,6 +25,7 @@ type Parameters struct {
Temperature *float64 `json:"temperature,omitempty"`
ResultFormat string `json:"result_format,omitempty"`
Tools []model.Tool `json:"tools,omitempty"`
EnableThinking bool `json:"enable_thinking,omitempty"`
}
type ChatRequest struct {

View File

@ -17,4 +17,5 @@ var ModelList = []string{
"deepseek-r1",
"deepseek-v3",
"deepseek-v3.1",
}

View File

@ -12,6 +12,7 @@ import (
"github.com/songquanpeng/one-api/common"
"github.com/songquanpeng/one-api/common/config"
"github.com/songquanpeng/one-api/common/file"
"github.com/songquanpeng/one-api/common/helper"
"github.com/songquanpeng/one-api/common/image"
"github.com/songquanpeng/one-api/common/logger"
@ -118,6 +119,14 @@ func ConvertRequest(textRequest model.GeneralOpenAIRequest) *ChatRequest {
parts = append(parts, Part{
Text: part.Text,
})
} else if part.Type == model.ContentTypeInputFile {
mimeType, data, _ := file.GetFileFromUrl(part.File.FileData)
parts = append(parts, Part{
InlineData: &InlineData{
MimeType: mimeType,
Data: data,
},
})
} else if part.Type == model.ContentTypeImageURL {
imageNum += 1
if imageNum > VisionMaxImageNum {

View File

@ -40,6 +40,11 @@ type InlineData struct {
Data string `json:"data"`
}
type FileData struct {
MimeType string `json:"mime_type"`
FileUri string `json:"file_uri"`
}
type FunctionCall struct {
FunctionName string `json:"name"`
Arguments any `json:"args"`
@ -50,6 +55,7 @@ type Part struct {
InlineData *InlineData `json:"inlineData,omitempty"`
FunctionCall *FunctionCall `json:"functionCall,omitempty"`
Thought bool `json:"thought,omitempty"`
FileData *FileData `json:"fileData,omitempty"`
}
type ChatContent struct {

View File

@ -4,4 +4,5 @@ const (
ContentTypeText = "text"
ContentTypeImageURL = "image_url"
ContentTypeInputAudio = "input_audio"
ContentTypeInputFile = "file"
)

View File

@ -121,6 +121,15 @@ func (m Message) ParseContent() []MessageContent {
},
})
}
case ContentTypeInputFile:
if subObj, ok := contentMap["file"].(map[string]any); ok {
contentList = append(contentList, MessageContent{
Type: ContentTypeInputFile,
File: &File{
FileData: subObj["file_data"].(string),
},
})
}
}
}
return contentList
@ -137,4 +146,10 @@ type MessageContent struct {
Type string `json:"type,omitempty"`
Text string `json:"text"`
ImageURL *ImageURL `json:"image_url,omitempty"`
File *File `json:"file,omitempty"`
}
type File struct {
FileData string `json:"file_data,omitempty"`
FileName string `json:"filename,omitempty"`
}