Skip to content

Commit

Permalink
Merge pull request #3404 from CityOfBoston/DIG-4280
Browse files Browse the repository at this point in the history
(develop) (hotfix) Add Gen-AI prompt testing DIG-4280
  • Loading branch information
davidrkupton committed Apr 10, 2024
2 parents 9bbf25a + 65c1fe8 commit 08914f5
Show file tree
Hide file tree
Showing 11 changed files with 422 additions and 13 deletions.
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

0 comments on commit 08914f5

Please sign in to comment.