mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-17 01:06:37 +08:00
Compare commits
8 Commits
6e1f5a8396
...
3d7d87c554
Author | SHA1 | Date | |
---|---|---|---|
|
3d7d87c554 | ||
|
974331a028 | ||
|
a529eab39e | ||
|
2174039fce | ||
|
9ce714ac8d | ||
|
7d2fc27c0f | ||
|
4d3add220e | ||
|
04de01c798 |
14
Dockerfile
14
Dockerfile
@ -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
23
common/file/file.go
Normal 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
|
||||
}
|
@ -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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -17,4 +17,5 @@ var ModelList = []string{
|
||||
|
||||
"deepseek-r1",
|
||||
"deepseek-v3",
|
||||
"deepseek-v3.1",
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -4,4 +4,5 @@ const (
|
||||
ContentTypeText = "text"
|
||||
ContentTypeImageURL = "image_url"
|
||||
ContentTypeInputAudio = "input_audio"
|
||||
ContentTypeInputFile = "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"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user