PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.2.6
ShopBuilder – WooCommerce Builder For Elementor v3.2.6
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / AI / AIServices / OpenAIAdapter.php

OpenAIAdapter.php in ShopBuilder – WooCommerce Builder For Elementor 3.2.6, at app/AI/AIServices/OpenAIAdapter.php

68 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace RadiusTheme\SB\AI\AIServices;
4
5 use RadiusTheme\SB\AI\AIFns;
6 use RadiusTheme\SB\AI\AIServices\Interface\AIServiceInterface;
7
8 /**
9 * Class OpenAIAdapter
10 *
11 * Providing standardized methods for generating AI-based responses.
12 */
13 class OpenAIAdapter implements AIServiceInterface {
14
15 /**
16 * The OpenAI client instance.
17 *
18 * @var object
19 */
20 private $openAIClient;
21
22 /**
23 * Constructor.
24 *
25 * Initializes the adapter with the provided OpenAI client instance.
26 *
27 * @param object $openAIClient An instance of the OpenAI client.
28 */
29 public function __construct( $openAIClient ) {
30 $this->openAIClient = $openAIClient;
31 }
32
33 /**
34 * Generate a general AI response using the OpenAI client.
35 *
36 * @param string $content_type The type of content to generate (title, description, short_description).
37 * @param string $instruction The product information or user instruction.
38 *
39 * @return string The generated AI response.
40 */
41 public function generateResponse( string $content_type, string $instruction ): string {
42 $system_prompt = AIFns::build_prompt( $content_type, $instruction );
43 return $this->openAIClient->ask( $instruction, $system_prompt );
44 }
45
46 /**
47 * Generate keyword suggestions or responses using the OpenAI client.
48 *
49 * @param mixed $data Input data used to generate keyword-based output.
50 *
51 * @return mixed The AI-generated keyword response.
52 */
53 public function generateKeywordResponse( $data ) {
54 return $this->openAIClient->askKeyword( $data );
55 }
56
57 /**
58 * Generate text embeddings using the OpenAI client.
59 *
60 * @param mixed $data Input text or data for which to generate embeddings.
61 *
62 * @return mixed The embedding vector or API response from OpenAI.
63 */
64 public function generateEmbedding( $data ) {
65 return $this->openAIClient->generateEmbedding( $data );
66 }
67 }
68