PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.6
JetFormBuilder — Dynamic Blocks Form Builder v3.6.6
3.6.6.1 3.6.6 3.6.5.4 3.6.5.3 3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 134 releases
jetformbuilder / modules / ai / external-api / generate-form-action.php

generate-form-action.php in JetFormBuilder — Dynamic Blocks Form Builder 3.6.6, at modules/ai/external-api/generate-form-action.php

97 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 namespace JFB_Modules\Ai\External_Api;
5
6 // If this file is called directly, abort.
7 if ( ! defined( 'WPINC' ) ) {
8 die;
9 }
10
11 use Jet_Form_Builder\Exceptions\Gateway_Exception;
12 use JFB_Modules\Gateways\Base_Gateway_Action;
13
14 class Generate_Form_Action extends Base_Gateway_Action {
15
16 /**
17 * Maximum allowed length (in characters) of the `prompt` value.
18 *
19 * The prompt is sent as a GET query argument, so it must stay well
20 * under common web server/proxy URL length limits.
21 *
22 * @see https://github.com/Crocoblock/issues-tracker/issues/14825
23 */
24 const MAX_PROMPT_LENGTH = 4000;
25
26 protected $method = \WP_REST_Server::READABLE;
27
28 protected $license = '';
29 protected $prompt = '';
30
31 public function base_url(): string {
32 return 'https://account.crocoblock.com/';
33 }
34
35 public function action_query_args(): array {
36 $this->assert_prompt_length();
37
38 return array(
39 'ai_api' => 'jfb',
40 'license' => $this->get_licence(),
41 'prompt' => $this->prompt,
42 );
43 }
44
45 /**
46 * @throws Gateway_Exception
47 */
48 protected function assert_prompt_length() {
49 if ( mb_strlen( $this->prompt, 'UTF-8' ) <= self::MAX_PROMPT_LENGTH ) {
50 return;
51 }
52
53 throw new Gateway_Exception(
54 esc_html(
55 sprintf(
56 /* translators: %d: maximum allowed prompt length */
57 __( 'Prompt is too long. Maximum length is %d characters.', 'jet-form-builder' ),
58 self::MAX_PROMPT_LENGTH
59 )
60 )
61 );
62 }
63
64 /**
65 * @return string
66 */
67 public function get_licence(): string {
68 if ( defined( 'JFB_AI_LICENSE' ) ) {
69 return JFB_AI_LICENSE;
70 }
71
72 return $this->license;
73 }
74
75 /**
76 * @param string $license
77 */
78 public function set_license( string $license ) {
79 $this->license = $license;
80 }
81
82 /**
83 * @param string $prompt
84 */
85 public function set_prompt( string $prompt ) {
86 $this->prompt = $prompt;
87 }
88
89 /**
90 * @return string
91 */
92 public function get_prompt(): string {
93 return $this->prompt;
94 }
95
96 }
97