File tree Expand file tree Collapse file tree 1 file changed +17
-12
lines changed Expand file tree Collapse file tree 1 file changed +17
-12
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,14 @@ public function systemPrompt(?string $prompt): AIProviderInterface
6767 public function generateToolsPayload (): array
6868 {
6969 return \array_map (function (ToolInterface $ tool ) {
70+ $ payload = [
71+ 'type ' => 'function ' ,
72+ 'function ' => [
73+ 'name ' => $ tool ->getName (),
74+ 'description ' => $ tool ->getDescription (),
75+ ]
76+ ];
77+
7078 $ properties = \array_reduce ($ tool ->getProperties (), function (array $ carry , ToolProperty $ property ) {
7179 $ carry [$ property ->getName ()] = [
7280 'name ' => $ property ->getName (),
@@ -77,18 +85,15 @@ public function generateToolsPayload(): array
7785 return $ carry ;
7886 }, []);
7987
80- return [
81- 'type ' => 'function ' ,
82- 'function ' => [
83- 'name ' => $ tool ->getName (),
84- 'description ' => $ tool ->getDescription (),
85- 'parameters ' => [
86- 'type ' => 'object ' ,
87- 'properties ' => !empty ($ properties ) ? $ properties : null ,
88- 'required ' => $ tool ->getRequiredProperties (),
89- ]
90- ]
91- ];
88+ if (!empty ($ properties )) {
89+ $ payload ['function ' ]['parameters ' ] = [
90+ 'type ' => 'object ' ,
91+ 'properties ' => $ properties ,
92+ 'required ' => $ tool ->getRequiredProperties (),
93+ ];
94+ }
95+
96+ return $ payload ;
9297 }, $ this ->tools );
9398 }
9499
You can’t perform that action at this time.
0 commit comments