Appearance
Artificial Intelligence module
Overview
The Artificial Intelligence module centralises every integration with Large Language Model providers. It exposes a single contract, StructuredPromptClient, that other modules use when they need structured responses from an LLM. The current default implementation (DefaultStructuredPromptClient) relies on the Prism SDK and reads provider/model selection from the prism config file, but consumer modules stay agnostic of that detail.
Responsibilities
- Provide DI-ready clients for issuing structured prompts.
- Own the configuration lookup and provider/model selection logic.
- Offer a clear seam for swapping implementations (e.g. fakes, new providers) without touching dependent modules.
Key classes
App\Modules\ArtificialIntelligence\Contracts\StructuredPromptClientApp\Modules\ArtificialIntelligence\Services\DefaultStructuredPromptClientApp\Modules\ArtificialIntelligence\ArtificialIntelligenceServiceProvider
Usage
- Inject
StructuredPromptClientinto your service or action. - Render your prompt to plain text (e.g. Blade view) and build a
Prism\Prism\Schema\ObjectSchemathat mirrors the expected response. - Call
execute($prompt, $schema)to receive the structured payload as an associative array.
php
use App\Modules\ArtificialIntelligence\Contracts\StructuredPromptClient;
final readonly class GenerateSynopsis
{
public function __construct(private StructuredPromptClient $client) {}
public function handle(string $prompt, \Prism\Prism\Schema\ObjectSchema $schema): array
{
return $this->client->execute($prompt, $schema);
}
}Consumer modules MUST NOT read config('prism.*') directly; the AI module is the single integration point.
Testing
Bind your own stub or fake implementation of StructuredPromptClient in tests when you need to control the structured response.