Skip to content

Commit 44e33ea

Browse files
committed
Trim excessive function declarations lists
1 parent 8179987 commit 44e33ea

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/AI/AiClient.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,6 @@ static function () {
9999

100100
$new_contents = $contents;
101101

102-
$tools = new Tools();
103-
if ( ! empty( $this->tools ) ) {
104-
$tools->add_function_declarations_tool( $this->tools );
105-
}
106-
107102
try {
108103
$service = ai_services()->get_available_service(
109104
[
@@ -116,6 +111,20 @@ static function () {
116111
]
117112
);
118113

114+
$all_tools = $this->tools;
115+
116+
$tools = new Tools();
117+
118+
if ( ! empty( $all_tools ) ) {
119+
if ( 'openai' === $service->get_service_slug() ) {
120+
$all_tools = array_slice( $all_tools, 0, 128 );
121+
} elseif ( 'google' === $service->get_service_slug() ) {
122+
$all_tools = array_slice( $all_tools, 0, 512 );
123+
}
124+
125+
$tools->add_function_declarations_tool( $all_tools );
126+
}
127+
119128
/**
120129
* Text generation model.
121130
*

0 commit comments

Comments
 (0)