{"id":18575129,"date":"2025-07-29T00:08:17","date_gmt":"2025-07-29T00:08:17","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/function-calling-issues\/"},"modified":"2025-07-29T00:08:17","modified_gmt":"2025-07-29T00:08:17","slug":"function-calling-issues","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/function-calling-issues\/","title":{"rendered":"Function calling issues"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hello.<br \/><br \/>AI Engine 2.9.5<br \/>Code Engine 0.3.5<br \/>WordPress 6.8.2<br \/>AI Engine Settings\/General\/Streaming is Enabled, Settings\/General\/Event Logs is Enabled.<br \/>mwai log in the \/uploads\/ folder is empty.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I&#8217;m having a few issues with function calling.<br \/>1. I tried to use Code Engine plugin to set a Callable PHP function. Function test went fine, but the function does not appear in the Chatbot interface of AI Engine plugin.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. Using Method 1 and Method 2 as per documentation here (<a href=\"https:\/\/ai.thehiddendocs.com\/use-function-calling\/\">https:\/\/ai.thehiddendocs.com\/use-function-calling\/<\/a>) doesn&#8217;t work for me.<br \/>A few weeks ago combining Method 2 of Part 1 and Method 1 of Part 2 allowed to set a mail sending function with PHP. Now that code doesn&#8217;t work.<br \/>What works now is combining Method 1 of Part 1 and Method 2 of Part 2. With a caveat: I cannot detect the call and have to change the chatbot feedback globally.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">mwai_ai_feedback filter pretty much doesn&#8217;t work. $reply-&gt;needFeedbacks array doesn&#8217;t exist.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the code that currently works:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>add_filter('mwai_functions_list', function ($functions) {<br \/><br \/>error_log('test mwai_functions_list');<br \/><br \/>$functions&#091;] = Meow_MWAI_Query_Function::fromJson(&#091;<br \/><br \/>'id' =&gt; 'userInfo',<br \/><br \/>'type' =&gt; 'manual',<br \/><br \/>'name' =&gt; 'getCurrentUserInfo',<br \/><br \/>'desc' =&gt; 'Get the current user information.',<br \/><br \/>]);<br \/><br \/>return $functions;<br \/><br \/>}, 10, 1);<br \/><br \/>function getCurrentUserInfo()<br \/><br \/>{<br \/><br \/>return \"Color of the day is grey with the shade of red\";<br \/><br \/>}<br \/><br \/>add_filter('mwai_ai_feedback', function ($result, $function, $args) {<br \/><br \/>error_log('MWAI_AI_FEEDBACK Result: ' . json_encode($result));<br \/><br \/>error_log('MWAI_AI_FEEDBACK Function: ' . json_encode($function));<br \/><br \/>error_log('MWAI_AI_FEEDBACK Args: ' . json_encode($args));<br \/><br \/>return getCurrentUserInfo();<br \/><br \/>}, 10, 3);<br \/><br \/>add_filter('mwai_ai_reply', function ($reply, $query) {<br \/><br \/>error_log('MWAI_AI_REPLY Value: ' . json_encode($reply));<br \/><br \/>error_log('MWAI_AI_REPLY Query: ' . json_encode($query));<br \/><br \/>$reply-&gt;result = getCurrentUserInfo();<br \/><br \/>return $reply;<br \/><br \/>}, 10, 2);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In WordPress debug log it returns the following:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>[28-Jul-2025 23:51:49 UTC] MWAI_AI_REPLY Value: {\"result\":\"The color of the day is blue.\",\"results\":[\"The color of the day is blue.\"],\"usage\":{\"prompt_tokens\":8,\"completion_tokens\":7,\"total_tokens\":15,\"price\":null,\"queries\":1},\"system\":{\"class\":\"Meow_MWAI_Reply\"}}<br \/>[28-Jul-2025 23:51:49 UTC] MWAI_AI_REPLY Query: {\"message\":\"test\",\"instructions\":\"On input \\\"test\\\" use function getCurrentUserInfo. Tell me, what the color of the day is.\",\"ai\":{\"model\":\"gpt-4.1-nano\",\"feature\":\"completion\",\"maxTokens\":16384,\"temperature\":0.8000000000000000444089209850062616169452667236328125},\"system\":{\"class\":\"Meow_MWAI_Query_Text\",\"envId\":\"xxx\",\"scope\":\"chatbot\",\"session\":\"xxx\",\"maxMessages\":15}}<\/code><\/p>\n","protected":false},"template":"","class_list":["post-18575129","topic","type-topic","status-publish","hentry","topic-tag-function"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18575129","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18575129\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=18575129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}