Add Data From External Sources To Instructions

 

This is the same idea as Add Data From External Sources To Instructions for the chatbot.

This also applies to AI Forms, as the query will pass through the same filter. However, as it expects input fields with the syntax {INPUT}, you have the flexibility to alter the { } to another symbol, perhaps [ ]. Nonetheless, it's crucial to adjust the code accordingly.

It's important to highlight that AI Forms do not utilize "Context." The formatted prompt is transmitted directly as a user message, eliminating the need for setContext and instead we’ll be using replace.

add_filter( 'mwai_ai_query', function ( $query ) {

    // Check if the $query object is an instance of Meow_MWAI_Query_Text
    if ( $query instanceof Meow_MWAI_Query_Text ) {
      // Replace the [NAME] placeholder in an AI Form prompt
      $name = get_user_meta( get_current_user_id(), 'name', true );
      $query->replace( '[NAME]', $name );

    }
  
    return $query;
  }, 10, 2 );
Did this answer your question?
😞
😐
🤩