@@ -51,6 +51,52 @@ func ConvertMessages(openAIMsgs []api.OpenAIMessage) []api.CCMessage {
5151 return ccMsgs
5252}
5353
54+ func ConvertTools (openAITools []any ) []any {
55+ if len (openAITools ) == 0 {
56+ return []any {}
57+ }
58+
59+ tools := make ([]any , 0 , len (openAITools ))
60+ for _ , tool := range openAITools {
61+ toolMap , ok := tool .(map [string ]any )
62+ if ! ok {
63+ continue
64+ }
65+
66+ toolType , _ := toolMap ["type" ].(string )
67+ if toolType != "function" {
68+ tools = append (tools , toolMap )
69+ continue
70+ }
71+
72+ fn , ok := toolMap ["function" ].(map [string ]any )
73+ if ! ok {
74+ continue
75+ }
76+
77+ name , _ := fn ["name" ].(string )
78+ if name == "" {
79+ continue
80+ }
81+
82+ inputSchema , ok := fn ["parameters" ].(map [string ]any )
83+ if ! ok || inputSchema == nil {
84+ inputSchema = map [string ]any {"type" : "object" , "properties" : map [string ]any {}}
85+ }
86+
87+ ccTool := map [string ]any {
88+ "name" : name ,
89+ "input_schema" : inputSchema ,
90+ }
91+ if description , ok := fn ["description" ].(string ); ok && description != "" {
92+ ccTool ["description" ] = description
93+ }
94+ tools = append (tools , ccTool )
95+ }
96+
97+ return tools
98+ }
99+
54100func strPtr (s string ) * string {
55101 if s == "" {
56102 return nil
0 commit comments