mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-21 00:17:44 +08:00
Merge pull request #374 from shern-point/feat/full-context-file-token-accounting
Feat/full context file token accounting
This commit is contained in:
@@ -39,11 +39,12 @@ func (e *inlineFileUploadError) Error() string {
|
||||
}
|
||||
|
||||
type inlineUploadState struct {
|
||||
ctx context.Context
|
||||
handler *Handler
|
||||
auth *auth.RequestAuth
|
||||
uploadedByID map[string]string
|
||||
uploadCount int
|
||||
ctx context.Context
|
||||
handler *Handler
|
||||
auth *auth.RequestAuth
|
||||
uploadedByID map[string]string
|
||||
uploadCount int
|
||||
inlineFileBytes int
|
||||
}
|
||||
|
||||
type inlineDecodedFile struct {
|
||||
@@ -75,6 +76,9 @@ func (h *Handler) PreprocessInlineFileInputs(ctx context.Context, a *auth.Reques
|
||||
if refIDs := promptcompat.CollectOpenAIRefFileIDs(req); len(refIDs) > 0 {
|
||||
req["ref_file_ids"] = stringsToAnySlice(refIDs)
|
||||
}
|
||||
if state.inlineFileBytes > 0 {
|
||||
req["_inline_file_bytes"] = state.inlineFileBytes
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -143,6 +147,7 @@ func (s *inlineUploadState) tryUploadBlock(block map[string]any) (map[string]any
|
||||
return nil, true, &inlineFileUploadError{status: http.StatusInternalServerError, message: "Failed to upload inline file.", err: err}
|
||||
}
|
||||
s.uploadCount++
|
||||
s.inlineFileBytes += len(decoded.Data)
|
||||
replacement := map[string]any{
|
||||
"type": decoded.ReplacementType,
|
||||
"file_id": fileID,
|
||||
|
||||
Reference in New Issue
Block a user