mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-11 19:57:41 +08:00
feat: implement OpenAI-compatible file upload and reference handling for DeepSeek API
This commit is contained in:
@@ -14,6 +14,7 @@ type StandardRequest struct {
|
||||
Stream bool
|
||||
Thinking bool
|
||||
Search bool
|
||||
RefFileIDs []string
|
||||
PassThrough map[string]any
|
||||
}
|
||||
|
||||
@@ -61,12 +62,19 @@ func (r StandardRequest) CompletionPayload(sessionID string) map[string]any {
|
||||
if resolvedType, ok := config.GetModelType(modelID); ok {
|
||||
modelType = resolvedType
|
||||
}
|
||||
refFileIDs := make([]any, 0, len(r.RefFileIDs))
|
||||
for _, fileID := range r.RefFileIDs {
|
||||
if fileID == "" {
|
||||
continue
|
||||
}
|
||||
refFileIDs = append(refFileIDs, fileID)
|
||||
}
|
||||
payload := map[string]any{
|
||||
"chat_session_id": sessionID,
|
||||
"model_type": modelType,
|
||||
"parent_message_id": nil,
|
||||
"prompt": r.FinalPrompt,
|
||||
"ref_file_ids": []any{},
|
||||
"ref_file_ids": refFileIDs,
|
||||
"thinking_enabled": r.Thinking,
|
||||
"search_enabled": r.Search,
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ func TestStandardRequestCompletionPayloadSetsModelTypeFromResolvedModel(t *testi
|
||||
FinalPrompt: "hello",
|
||||
Thinking: tc.thinking,
|
||||
Search: tc.search,
|
||||
RefFileIDs: []string{"file-a", "file-b"},
|
||||
PassThrough: map[string]any{
|
||||
"temperature": 0.3,
|
||||
},
|
||||
@@ -44,6 +45,13 @@ func TestStandardRequestCompletionPayloadSetsModelTypeFromResolvedModel(t *testi
|
||||
if got := payload["temperature"]; got != 0.3 {
|
||||
t.Fatalf("expected passthrough temperature, got %#v", got)
|
||||
}
|
||||
refFileIDs, ok := payload["ref_file_ids"].([]any)
|
||||
if !ok {
|
||||
t.Fatalf("expected ref_file_ids slice, got %#v", payload["ref_file_ids"])
|
||||
}
|
||||
if len(refFileIDs) != 2 || refFileIDs[0] != "file-a" || refFileIDs[1] != "file-b" {
|
||||
t.Fatalf("unexpected ref_file_ids: %#v", refFileIDs)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user