mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-04 16:35:27 +08:00
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package toolcall
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func FormatOpenAIToolCalls(calls []ParsedToolCall, toolsRaw any) []map[string]any {
|
|
normalized := NormalizeParsedToolCallsForSchemas(calls, toolsRaw)
|
|
out := make([]map[string]any, 0, len(calls))
|
|
for _, c := range normalized {
|
|
args, _ := json.Marshal(c.Input)
|
|
out = append(out, map[string]any{
|
|
"id": "call_" + strings.ReplaceAll(uuid.NewString(), "-", ""),
|
|
"type": "function",
|
|
"function": map[string]any{
|
|
"name": c.Name,
|
|
"arguments": string(args),
|
|
},
|
|
})
|
|
}
|
|
return out
|
|
}
|
|
|
|
func FormatOpenAIStreamToolCalls(calls []ParsedToolCall, toolsRaw any) []map[string]any {
|
|
normalized := NormalizeParsedToolCallsForSchemas(calls, toolsRaw)
|
|
out := make([]map[string]any, 0, len(calls))
|
|
for i, c := range normalized {
|
|
args, _ := json.Marshal(c.Input)
|
|
out = append(out, map[string]any{
|
|
"index": i,
|
|
"id": "call_" + strings.ReplaceAll(uuid.NewString(), "-", ""),
|
|
"type": "function",
|
|
"function": map[string]any{
|
|
"name": c.Name,
|
|
"arguments": string(args),
|
|
},
|
|
})
|
|
}
|
|
return out
|
|
}
|