Skip to content

Commit d59e12c

Browse files
committed
mcp connector
1 parent 6fc7306 commit d59e12c

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/Providers/OpenAI/OpenAI.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)