mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-23 01:17:44 +08:00
feat: Improve OpenAI tool call handling by passing unknown tool calls as content and filtering streamed tool calls by schema.
This commit is contained in:
@@ -8,12 +8,48 @@ type StandardRequest struct {
|
||||
Messages []any
|
||||
FinalPrompt string
|
||||
ToolNames []string
|
||||
ToolChoice ToolChoicePolicy
|
||||
Stream bool
|
||||
Thinking bool
|
||||
Search bool
|
||||
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 {
|
||||
payload := map[string]any{
|
||||
"chat_session_id": sessionID,
|
||||
|
||||
Reference in New Issue
Block a user