loadAvailableOptions(); parent::__construct(); $this->buildJsonSchema(); } /** * Load available industries and types from the Template model */ protected function loadAvailableOptions(): void { $this->availableIndustries = Template::getAllIndustries()->pluck('slug')->toArray(); $this->availableTypes = Template::getAllTypes()->pluck('slug')->toArray(); } /** * Dynamically build the JSON schema with enums for industries and types */ protected function buildJsonSchema(): void { $this->jsonSchema = [ 'type' => 'object', 'properties' => [ 'short_description' => [ 'type' => 'string', 'description' => 'A concise single-sentence description of the form template' ], 'detailed_description' => [ 'type' => 'string', 'description' => 'Detailed HTML content describing the form template' ], 'title' => [ 'type' => 'string', 'description' => 'The title of the form template' ], 'industries' => [ 'type' => 'array', 'description' => 'List of industry slugs for the template', 'items' => [ 'type' => 'string', 'enum' => $this->availableIndustries ] ], 'types' => [ 'type' => 'array', 'description' => 'List of type slugs for the template', 'items' => [ 'type' => 'string', 'enum' => $this->availableTypes ] ], 'image_search_query' => [ 'type' => 'string', 'description' => 'Search query for Unsplash to find a relevant image' ], 'qa_content' => [ 'type' => 'array', 'description' => 'Q&A content for the template', 'items' => [ 'type' => 'object', 'properties' => [ 'question' => [ 'type' => 'string', 'description' => 'The question about the form template' ], 'answer' => [ 'type' => 'string', 'description' => 'The answer to the question' ] ], 'required' => ['question', 'answer'], 'additionalProperties' => false ] ] ], 'required' => [ 'short_description', 'detailed_description', 'title', 'industries', 'types', 'image_search_query', 'qa_content' ], 'additionalProperties' => false ]; } protected function getSystemMessage(): ?string { return 'You are an assistant helping to generate comprehensive metadata for form templates. Create well-structured, informative content that explains the purpose, benefits, and target audience of the form template.'; } protected function getPromptTemplate(): string { return self::PROMPT_TEMPLATE; } protected function buildPrompt(): string { $template = $this->getPromptTemplate(); $industriesString = implode(', ', $this->availableIndustries); $typesString = implode(', ', $this->availableTypes); return Str::of($template) ->replace('{templatePrompt}', $this->templatePrompt) ->replace('{availableIndustries}', $industriesString) ->replace('{availableTypes}', $typesString) ->toString(); } /** * Override the initialize method to ensure the options are loaded */ protected function initialize(): void { if (empty($this->availableIndustries) || empty($this->availableTypes)) { throw new \InvalidArgumentException('Failed to load available industries and types from the database'); } parent::initialize(); } }