Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(develop) (hotfix) Add Gen-AI prompt testing DIG-4280 #3404

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ bos_google_cloud.configForm:
parent: bos_core.admin
route_name: bos_google_cloud.configForm
weight: 3

bos_google_cloud.PromptTesterForm:
title: 'Gen-AI Prompt Tester'
description: 'Prompt Tester for bos_google_cloud'
parent: bos_google_cloud.configForm
route_name: bos_google_cloud.PromptTesterForm
weight: 0
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ bos_google_cloud.configForm:
route_name: bos_google_cloud.configForm
base_route: bos_core.admin
weight: 2

bos_google_cloud.PromptTesterForm:
title: 'Prompt Tester'
route_name: bos_google_cloud.PromptTesterForm
base_route: bos_google_cloud.configForm
weight: 0
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@ bos_google_cloud.configForm:
requirements:
_permission: 'administer google cloud platform'

bos_google_cloud.PromptTesterForm:
path: 'admin/config/system/boston/googlecloud/prompttester'
defaults:
_form: '\Drupal\bos_google_cloud\Form\PromptTesterForm'
_title: 'Prompt Testing'
requirements:
_permission: 'administer google cloud platform'
options:
_admin_route: TRUE

bos_google_cloud.open_PromptTesterForm:
path: 'admin/config/system/boston/googlecloud/prompttester_modal'
defaults:
_controller: '\Drupal\bos_google_cloud\Controller\PromptTesterFormController::openModalForm'
_title: 'Prompt Testing - modal'
requirements:
_permission: 'administer google cloud platform'
options:
_admin_route: TRUE

bos_google_cloud.endpoint:
path: '/rest/bos_google_cloud/v1/{action}'
methods: [POST,GET]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Drupal\bos_google_cloud\Controller;

use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\OpenModalDialogCommand;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Form\FormBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;

/*
class PromptTesterFormController
Creates a modal testing form for bos_google_cloud

david 04 2024
@file docroot/modules/custom/bos_components/modules/bos_google_cloud/src/Form/src/Controller/PromptTesterFormController.php
*/

class PromptTesterFormController extends ControllerBase {

/**
* This Controller class is used to launch a modal instance of the
* PromptTesterForm.
*/

protected $formBuilder;

/**
* The constructor.
*
* @param \Drupal\Core\Form\FormBuilder $formBuilder
* The form builder.
*/
public function __construct(FormBuilder $formBuilder) {
$this->formBuilder = $formBuilder;
}

/**
* {@inheritdoc}
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* The Drupal service container.
*
* @return static
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('form_builder')
);
}

/**
* Callback for opening the modal form.
*/
public function openModalForm() {
$response = new AjaxResponse();

// Get the modal form using the form builder.
$modal_form = $this->formBuilder->getForm('Drupal\bos_google_cloud\Form\PromptTesterForm');

// Add an AJAX command to open a modal dialog with the form as the content.
$response->addCommand(new OpenModalDialogCommand('Prompt Testing/Tuning', $modal_form, ['width' => '80%']));

return $response;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Drupal\bos_google_cloud\Services\GcTranslation;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;

/**
* Creates a config/admin form for bos_google_cloud module.
Expand Down Expand Up @@ -95,6 +96,29 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
'#type' => "fieldset",
'#title' => "Prompt Settings",
"#description" => "The following are prompts which can be defined for the various services.",
'#description_display' => 'before',
'tester' => [
'#type' => "link",
'#title' => "Prompt Tester",
'#weight' => 100,
'#url' => Url::fromRoute('bos_google_cloud.open_PromptTesterForm'),
'#attributes' => [
'class' => ['use-ajax', 'button'],
],
],
],
],
];

// Authentication section.
$authenticator = new GcAuthenticator();
$authenticator->buildForm($form['google_cloud']['authentication_wrapper']);

// Search section
/**
* @var $search \Drupal\bos_google_cloud\Services\GcSearch

],
],

]
Expand Down
Loading