• I am using the Free version of AI Engine. What a great plugin! Love it!
    I am trying to use the Function Calling option.
    I have made sure that Rest API is fully functioning on my website.
    I have created a mwai_allow_public_api snippet
    I have also created a get_game_data snippet that is set up as a (dynamic) Callable Function
    I have created a chatbot that begins with calling the get_game_data function, and when the user enters a number (for example paas3) the functions looks through either a CSV-file or Excel-file (using SimpleXLSX.php) on my server and should return data from specific columns in the file.
    But for some reason the chatbot does not recognize it as a callable function. Instead it writes out the entire command (try it on spillegudsrige.dk/paaskespillet – try for example to write ‘paas3’)
    I have tried to add the function to my WordPress theme’s functions.php
    Nothing helps.
    Why doesn’t the chatbot recognize the callable function get_game_data that I have created using Code Engine (I have of course tried ‘Test’)?
    Are there limitations because I am using the Free version?

    Here is the Instruction I have given to the chatbot:

    The user enters a number of the event they want to read about.
    You now call the get_game_data function with the following parameters:

    • "lookup_value": "{user_input}"
    • "column_name": "easterevents_number"
    • "requested_columns": ["easterevents_number", "easterevents_day", "easterevents_day_time", "easterevents_day_city", "easterevents_day_city_location", "easterevents_day_description", "easterevents_imageurl", "locations_props_numbers", "locations_props", "locations_props_imageurl", "jerusalem_locations_number", "jerusalem_locations", "jerusalem_locations_props", "jerusalem_locations_imageurl", "nazareth_locations_number", "nazareth_locations", "nazareth_locations_props", "nazareth_locations_imageurl", "bethlehem_locations_number", "bethlehem_locations", "bethlehem_locations_props", "bethlehem_locations_imageurl", "capernaum_locations_number", "capernaum_locations", "capernaum_locations_props", "capernaum_locations_imageurl", "betania_locations_number", "betania_locations", "betania_locations_props", "betania_locations_imageurl", "persongallery_number", "persongallery", "persongallery_imageurl", "persongallery_characteristics", "persongallery_locations_easterdays_and_mysteries", "persongallery_mysteryparticipation", "mystery1_props_number", "mystery1_props", "mystery1_props_location_or_person", "mystery1_props_imageurl", "mystery2_props_number", "mystery2_props", "mystery2_props_location_or_person", "mystery2_props_imageurl", "mystery3_props_number", "mystery3_props", "mystery3_props_location_or_person", "mystery3_props_imageurl"]

    Replace {user_input} with the actual number the user entered.

    After retrieving the information from get_game_data, you show the user the following:

    • Image of the event (easterevents_imageurl).
    • Easter day and time (easterevents_day, easterevents_day_time).
    • Description of the event (easterevents_day_description).
    • List of people present (peoplegallery).
    • List of available props (locations_props).

    Use the data you get back from get_game_data and format it into an easy-to-read and vividly narrated message for the user.

    Example output:
    "[Image]<br>It's {Easter_events_day} {Easter_events_day_time}. What's happening: {Easter_events_day_description}.<br>People present: {people_gallery}.<br>Props at the location/people: {locations_props}"


    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Carsten Riis Jensen

    (@crjensen)

    Addition:
    1: I can see in my errorlog that get_game_data is correctly registered in AI Engine. But there is no connection.
    2: A json test (/wp-json/mwai/v1/call-function) gives an error ({“code”:”rest_no_route”,”message”:”Ingen rute blev fundet der matchede URL og anmodningen.”,”data”:{“status”:404}})
    3: And this is what I have added to my WordPress theme’s functions.php:

    add_filter(‘mwai_allow_public_api’, function ($allow, $feature, $extra) {
    if ($feature === ‘call-function’ && isset($extra[‘function’]) && $extra[‘function’] === ‘get_game_data’) {
    return true;
    }
    return $allow;
    }, 10, 3);

    add_filter(‘mwai_functions_list’, function ($functions) {
    $functions[] = Meow_MWAI_Query_Function::fromJson([
    ‘id’ => ‘get_game_data’,
    ‘type’ => ‘manual’,
    ‘name’ => ‘get_game_data’,
    ‘desc’ => ‘Henter data fra CSV eller Excel baseret p? en specifik kolonne og v?rdi.’,
    ‘args’ => [
    [‘name’ => ‘lookup_value’, ‘type’ => ‘string’, ‘required’ => true, ‘desc’ => ‘V?rdien at sl? op.’],
    [‘name’ => ‘column_name’, ‘type’ => ‘string’, ‘required’ => true, ‘desc’ => ‘Kolonnenavn at s?ge i.’],
    [‘name’ => ‘requested_columns’, ‘type’ => ‘array’, ‘required’ => false, ‘desc’ => ‘Liste over ?nskede kolonner.’]
    ]
    ]);
    return $functions;
    }, 10, 1);

    add_filter(‘mwai_ai_function’, function ($value, $funcName, $funcArgs) {
    if ($funcName === ‘get_game_data’) {
    // Kald din get_game_data-funktion med de givne argumenter
    return get_game_data($funcArgs);
    }
    return $value;
    }, 10, 3);

    add_filter(‘mwai_ai_feedback’, function ($value, $needFeedback) {
    $function = $needFeedback[‘function’];
    if ($function->id === ‘get_game_data’) {
    $args = $needFeedback[‘arguments’];
    return get_game_data($args);
    }
    return $value;
    }, 10, 2);

    add_filter(‘mwai_ai_reply’, function ($reply, $query) {
    foreach ($reply->needFeedbacks as $index => $needFeedback) {
    $function = $needFeedback[‘function’];
    if ($function->id === ‘get_game_data’) {
    $value = get_game_data($needFeedback[‘arguments’]);
    if (!empty($value)) {
    $reply->result = “Her er dine data: ” . json_encode($value);
    unset($reply->needFeedbacks[$index]);
    return $reply;
    }
    }
    }
    return $reply;
    }, 10, 2);

    error_log(“AI Engine Functions: ” . json_encode(apply_filters(‘mwai_functions_list’, [])));

    add_filter(‘mwai_ai_function’, function ($value, $funcName, $funcArgs) {
    error_log(“?? AI Engine kaldte funktion: ” . $funcName . ” med parametre: ” . json_encode($funcArgs));

    if ($funcName === 'get_game_data') {
        error_log("? AI Engine fors?ger nu at eksekvere get_game_data...");
        $result = get_game_data($funcArgs);
        error_log("?? get_game_data RETURNEREDE: " . json_encode($result));
        return $result;
    }
    
    return $value;

    }, 10, 3);


    Plugin Support Val Meow

    (@valwa)

    Hey @crjensen! ??

    If you are already using Code Engine, there’s no need to rely on filters, as the plugins will automatically handle function declarations. When troubleshooting function calling, start with a simplified version of your function and work incrementally. Avoid using arrays as arguments, as the generated parameters might not align with your expectations. Instead, use string values, which can be parsed into JSON within your function. Be sure to provide relevant descriptions for each argument individually in this case.

    Begin by creating a function without any parameters to verify that it is being called correctly with placeholder values. Then, add arguments step by step to identify where the issue occurs. Thanks!

    Thread Starter Carsten Riis Jensen

    (@crjensen)

    This looks way too difficult for me. I bought the Pro version yesterday, as you may have noticed (I sent a help request through your website). Do you know of people who can help me build a function from scratch? – so I can concentrate on using AI Engine for my purpose (as part of a board game where the players interact with persons that AI Engine looks up in an Excel-datafile I have uploaded). Where can I get help to build a function from scratch?

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.