-
-
Notifications
You must be signed in to change notification settings - Fork 954
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add multi-file type support for Gemini and Claude
- Add file data DTO for structured file handling - Implement file decoder service - Update Claude and Gemini relay channels to handle various file types - Reorganize worker service to cf_worker for clarity - Update token counter and image service for new file types
- Loading branch information
1 parent
d75ecfc
commit 2b38e8e
Showing
11 changed files
with
89 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package dto | ||
|
||
type LocalFileData struct { | ||
MimeType string | ||
Base64Data string | ||
Url string | ||
Size int64 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package service | ||
|
||
import ( | ||
"encoding/base64" | ||
"fmt" | ||
"io" | ||
"one-api/constant" | ||
"one-api/dto" | ||
) | ||
|
||
var maxFileSize = constant.MaxFileDownloadMB * 1024 * 1024 | ||
|
||
func GetFileBase64FromUrl(url string) (*dto.LocalFileData, error) { | ||
resp, err := DoDownloadRequest(url) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
|
||
// Always use LimitReader to prevent oversized downloads | ||
fileBytes, err := io.ReadAll(io.LimitReader(resp.Body, int64(maxFileSize+1))) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Check actual size after reading | ||
if len(fileBytes) > maxFileSize { | ||
return nil, fmt.Errorf("file size exceeds maximum allowed size: %dMB", constant.MaxFileDownloadMB) | ||
} | ||
|
||
// Convert to base64 | ||
base64Data := base64.StdEncoding.EncodeToString(fileBytes) | ||
|
||
return &dto.LocalFileData{ | ||
Base64Data: base64Data, | ||
MimeType: resp.Header.Get("Content-Type"), | ||
Size: int64(len(fileBytes)), | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters