Files
ds2api/internal/promptcompat/standard_request.go
CJACK c09a4b51a5 feat: 新增 thinking 注入配置支持,扩展设置管理与前端交互
新增 promptcompat 和 OpenAI shared 层的 thinking 注入逻辑,
完善配置系统的编解码与校验,更新设置管理 API 与前端 UI。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-26 13:35:20 +08:00

89 lines
2.1 KiB
Go

package promptcompat
import "ds2api/internal/config"
type StandardRequest struct {
Surface string
RequestedModel string
ResolvedModel string
ResponseModel string
Messages []any
HistoryText string
CurrentInputFileApplied bool
ToolsRaw any
FinalPrompt string
ToolNames []string
ToolChoice ToolChoicePolicy
Stream bool
Thinking bool
Search bool
RefFileIDs []string
PassThrough map[string]any
}
type ToolChoiceMode string
const (
ToolChoiceAuto ToolChoiceMode = "auto"
ToolChoiceNone ToolChoiceMode = "none"
ToolChoiceRequired ToolChoiceMode = "required"
ToolChoiceForced ToolChoiceMode = "forced"
)
type ToolChoicePolicy struct {
Mode ToolChoiceMode
ForcedName string
Allowed map[string]struct{}
}
func DefaultToolChoicePolicy() ToolChoicePolicy {
return ToolChoicePolicy{Mode: ToolChoiceAuto}
}
func (p ToolChoicePolicy) IsNone() bool {
return p.Mode == ToolChoiceNone
}
func (p ToolChoicePolicy) IsRequired() bool {
return p.Mode == ToolChoiceRequired || p.Mode == ToolChoiceForced
}
func (p ToolChoicePolicy) Allows(name string) bool {
if len(p.Allowed) == 0 {
return true
}
_, ok := p.Allowed[name]
return ok
}
func (r StandardRequest) CompletionPayload(sessionID string) map[string]any {
modelID := r.ResolvedModel
if modelID == "" {
modelID = r.RequestedModel
}
modelType := "default"
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": refFileIDs,
"thinking_enabled": r.Thinking,
"search_enabled": r.Search,
}
for k, v := range r.PassThrough {
payload[k] = v
}
return payload
}