PHP code example of websystems / web-prompt-creator-bundle

1. Go to this page and download the library: Download websystems/web-prompt-creator-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

websystems / web-prompt-creator-bundle example snippets


namespace App\Service;

use Websystems\WebPromptCreatorBundle\PromptInputOptions\PromptInputOptions;

class PromptInputOptionsService extends PromptInputOptions
{
    public function configureOptions(): array
    {
        $options = [
            'input_content' => '',
            'other_input_data' => '',
        ];

        return $options;
    }
}

    public function __construct(
        ...
        private PromptInputOptionsService $promptInputOptionsService,
    )
    {
    }
    ...
    public function configureFields(string $pageName): iterable
    {
        return [
            PromptField::new('prompt')
                ->setCustomOption("input", $this->promptInputOptionsService->getInputOptions())->hideOnIndex(),        

    public function configureCrud(Crud $crud): Crud
    {
        return $crud
            ->setFormThemes(['admin/web_prompt_creator.html.twig', '@EasyAdmin/crud/form_theme.html.twig'])
        ;
    }   

    ...
    use Websystems\WebPromptCreatorBundle\Asset\AssetPackage;
    ...
    public function __construct(
        ...
        protected RequestStack $requestStack,
    )
    {
    }
    ...
    public function configureAssets(Assets $assets): Assets
    {
        $assetPackage = new AssetPackage($this->requestStack);

        return $assets
            ->addJsFile($assetPackage->getUrl('437.js'))
            ->addJsFile($assetPackage->getUrl('runtime.js'))
            ->addJsFile($assetPackage->getUrl('builder.js'))
            ->addCssFile($assetPackage->getUrl('437.css'))
            ->addCssFile($assetPackage->getUrl('builder.css'))
        ;
    }   

...
use Websystems\WebPromptCreatorBundle\AiInterface;

class OpenAi implements AiInterface
{
    public function supports($type): bool
    {
        return is_a($this, $type, true);
    }   

    public function send(array $messages): ?array
    {
        ...
        
        return [
            'content' => $response['choices'][0]['message']['content'],
            'data' => $response,
        ];        
    }

    ...
    public function __construct(
        private OpenAi $openAi,
        private WebPromptCreator $webPromptCreator,
        private PromptInputOptionsService $promptInputOptionsService,
    )
    {
    }

        $json = $someRepository->find(...)
        $contentToProcess = "Some content to process";

        $this->webPromptCreator->setPromptData(json_decode($json, true));
        $this->webPromptCreator->setAiService($this->openAi);
        $this->promptInputOptionsService->updateOptionByKey('input_content', $contentToProcess);
        ...
        $this->webPromptCreator->setInputData($this->promptInputOptionsService);
        $this->webPromptCreator->createRequests();

$this->webPromptCreator->getFinalResponse();

getResponseOfRequestByUid($uid)

getResponseDataOfRequestByUid($uid)

getRequestCollection()
getPromptRequestCollectionAsArrayConversation(bool $withAnswers = false)

showDummyCoversation(string $responseText = "This is a dummy response")