Skip to content

Commit 6cdfde0

Browse files
committed
feat: adds provider interfaces
1 parent e964a1d commit 6cdfde0

14 files changed

+500
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WordPress\AiClient\Providers\Contracts;
6+
7+
use InvalidArgumentException;
8+
use WordPress\AiClient\Providers\Models\DTO\ModelMetadata;
9+
10+
/**
11+
* Interface for accessing model metadata within a provider.
12+
*
13+
* Provides methods to list, check, and retrieve model metadata
14+
* for all models supported by a provider.
15+
*
16+
* @since n.e.x.t
17+
*/
18+
interface ModelMetadataDirectoryInterface
19+
{
20+
/**
21+
* Lists all available model metadata.
22+
*
23+
* @since n.e.x.t
24+
*
25+
* @return list<ModelMetadata> Array of model metadata.
26+
*/
27+
public function listModelMetadata(): array;
28+
29+
/**
30+
* Checks if metadata exists for a specific model.
31+
*
32+
* @since n.e.x.t
33+
*
34+
* @param string $modelId Model identifier.
35+
* @return bool True if metadata exists, false otherwise.
36+
*/
37+
public function hasModelMetadata(string $modelId): bool;
38+
39+
/**
40+
* Gets metadata for a specific model.
41+
*
42+
* @since n.e.x.t
43+
*
44+
* @param string $modelId Model identifier.
45+
* @return ModelMetadata Model metadata.
46+
* @throws InvalidArgumentException If model metadata not found.
47+
*/
48+
public function getModelMetadata(string $modelId): ModelMetadata;
49+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WordPress\AiClient\Providers\Contracts;
6+
7+
/**
8+
* Interface for checking provider availability.
9+
*
10+
* Determines whether a provider is configured and available
11+
* for use based on API keys, credentials, or other requirements.
12+
*
13+
* @since n.e.x.t
14+
*/
15+
interface ProviderAvailabilityInterface
16+
{
17+
/**
18+
* Checks if the provider is configured.
19+
*
20+
* @since n.e.x.t
21+
*
22+
* @return bool True if the provider is configured and available, false otherwise.
23+
*/
24+
public function isConfigured(): bool;
25+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WordPress\AiClient\Providers\Contracts;
6+
7+
use InvalidArgumentException;
8+
use WordPress\AiClient\Providers\DTO\ProviderMetadata;
9+
use WordPress\AiClient\Providers\Models\Contracts\ModelInterface;
10+
use WordPress\AiClient\Providers\Models\DTO\ModelConfig;
11+
12+
/**
13+
* Interface for AI providers.
14+
*
15+
* Providers represent AI services (Google, OpenAI, Anthropic, etc.)
16+
* and provide access to models, metadata, and availability information.
17+
*
18+
* @since n.e.x.t
19+
*/
20+
interface ProviderInterface
21+
{
22+
/**
23+
* Gets provider metadata.
24+
*
25+
* @since n.e.x.t
26+
*
27+
* @return ProviderMetadata Provider metadata.
28+
*/
29+
public static function metadata(): ProviderMetadata;
30+
31+
/**
32+
* Creates a model instance.
33+
*
34+
* @since n.e.x.t
35+
*
36+
* @param string $modelId Model identifier.
37+
* @param ModelConfig|array<string,mixed> $modelConfig Model configuration.
38+
* @return ModelInterface Model instance.
39+
* @throws InvalidArgumentException If model not found or configuration invalid.
40+
*/
41+
public static function model(string $modelId, $modelConfig = []): ModelInterface;
42+
43+
/**
44+
* Gets provider availability checker.
45+
*
46+
* @since n.e.x.t
47+
*
48+
* @return ProviderAvailabilityInterface Provider availability checker.
49+
*/
50+
public static function availability(): ProviderAvailabilityInterface;
51+
52+
/**
53+
* Gets model metadata directory.
54+
*
55+
* @since n.e.x.t
56+
*
57+
* @return ModelMetadataDirectoryInterface Model metadata directory.
58+
*/
59+
public static function modelMetadataDirectory(): ModelMetadataDirectoryInterface;
60+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WordPress\AiClient\Providers\Models\Contracts;
6+
7+
use WordPress\AiClient\Providers\Models\DTO\ModelConfig;
8+
use WordPress\AiClient\Providers\Models\DTO\ModelMetadata;
9+
10+
/**
11+
* Interface for AI models.
12+
*
13+
* Models represent specific AI models from providers and define
14+
* their capabilities, configuration, and execution methods.
15+
*
16+
* @since n.e.x.t
17+
*/
18+
interface ModelInterface
19+
{
20+
/**
21+
* Gets model metadata.
22+
*
23+
* @since n.e.x.t
24+
*
25+
* @return ModelMetadata Model metadata.
26+
*/
27+
public function metadata(): ModelMetadata;
28+
29+
/**
30+
* Sets model configuration.
31+
*
32+
* @since n.e.x.t
33+
*
34+
* @param ModelConfig $config Model configuration.
35+
* @return void
36+
*/
37+
public function setConfig(ModelConfig $config): void;
38+
39+
/**
40+
* Gets model configuration.
41+
*
42+
* @since n.e.x.t
43+
*
44+
* @return ModelConfig Current model configuration.
45+
*/
46+
public function getConfig(): ModelConfig;
47+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WordPress\AiClient\Providers\Models\Contracts;
6+
7+
use InvalidArgumentException;
8+
use WordPress\AiClient\Operations\DTO\GenerativeAiOperation;
9+
10+
/**
11+
* Interface for models that support generative AI operations.
12+
*
13+
* Provides methods to retrieve and manage long-running generative AI
14+
* operations such as text, image, or speech generation.
15+
*
16+
* @since n.e.x.t
17+
*/
18+
interface WithGenerativeAiOperationsInterface
19+
{
20+
/**
21+
* Gets a generative AI operation by ID.
22+
*
23+
* @since n.e.x.t
24+
*
25+
* @param string $operationId Operation identifier.
26+
* @return GenerativeAiOperation The generative AI operation.
27+
* @throws InvalidArgumentException If operation not found.
28+
*/
29+
public function getOperation(string $operationId): GenerativeAiOperation;
30+
}

src/Providers/Models/DTO/ModelMetadata.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,60 @@ public function toArray(): array
189189
];
190190
}
191191

192+
/**
193+
* Checks whether this model meets the specified requirements.
194+
*
195+
* @since n.e.x.t
196+
*
197+
* @param ModelRequirements $requirements The requirements to check against.
198+
* @return bool True if the model meets all requirements, false otherwise.
199+
*/
200+
public function meetsRequirements(ModelRequirements $requirements): bool
201+
{
202+
// Check if all required capabilities are supported
203+
foreach ($requirements->getRequiredCapabilities() as $requiredCapability) {
204+
if (!in_array($requiredCapability, $this->supportedCapabilities, true)) {
205+
return false;
206+
}
207+
}
208+
209+
// Check if all required options are supported with the specified values
210+
foreach ($requirements->getRequiredOptions() as $requiredOption) {
211+
$supportedOption = $this->findSupportedOption($requiredOption->getName());
212+
213+
// If the option is not supported at all, fail
214+
if ($supportedOption === null) {
215+
return false;
216+
}
217+
218+
// Check if the required value is supported by this option
219+
if (!$supportedOption->isSupportedValue($requiredOption->getValue())) {
220+
return false;
221+
}
222+
}
223+
224+
return true;
225+
}
226+
227+
/**
228+
* Finds a supported option by name.
229+
*
230+
* @since n.e.x.t
231+
*
232+
* @param string $name The option name to find.
233+
* @return SupportedOption|null The supported option, or null if not found.
234+
*/
235+
private function findSupportedOption(string $name): ?SupportedOption
236+
{
237+
foreach ($this->supportedOptions as $supportedOption) {
238+
if ($supportedOption->getName() === $name) {
239+
return $supportedOption;
240+
}
241+
}
242+
243+
return null;
244+
}
245+
192246
/**
193247
* {@inheritDoc}
194248
*
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WordPress\AiClient\Providers\Models\ImageGeneration\Contracts;
6+
7+
use WordPress\AiClient\Messages\DTO\Message;
8+
use WordPress\AiClient\Results\DTO\GenerativeAiResult;
9+
10+
/**
11+
* Interface for models that support image generation.
12+
*
13+
* Provides synchronous methods for generating images from text prompts.
14+
*
15+
* @since n.e.x.t
16+
*/
17+
interface ImageGenerationModelInterface
18+
{
19+
/**
20+
* Generates images from a prompt.
21+
*
22+
* @since n.e.x.t
23+
*
24+
* @param list<Message> $prompt Array of messages containing the image generation prompt.
25+
* @return GenerativeAiResult Result containing generated images.
26+
*/
27+
public function generateImageResult(array $prompt): GenerativeAiResult;
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WordPress\AiClient\Providers\Models\ImageGeneration\Contracts;
6+
7+
use WordPress\AiClient\Messages\DTO\Message;
8+
use WordPress\AiClient\Operations\DTO\GenerativeAiOperation;
9+
10+
/**
11+
* Interface for models that support asynchronous image generation operations.
12+
*
13+
* Provides methods for initiating long-running image generation tasks.
14+
*
15+
* @since n.e.x.t
16+
*/
17+
interface ImageGenerationOperationModelInterface
18+
{
19+
/**
20+
* Creates an image generation operation.
21+
*
22+
* @since n.e.x.t
23+
*
24+
* @param list<Message> $prompt Array of messages containing the image generation prompt.
25+
* @return GenerativeAiOperation The initiated image generation operation.
26+
*/
27+
public function generateImageOperation(array $prompt): GenerativeAiOperation;
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WordPress\AiClient\Providers\Models\SpeechGeneration\Contracts;
6+
7+
use WordPress\AiClient\Messages\DTO\Message;
8+
use WordPress\AiClient\Results\DTO\GenerativeAiResult;
9+
10+
/**
11+
* Interface for models that support speech generation.
12+
*
13+
* Provides synchronous methods for generating speech from prompts.
14+
*
15+
* @since n.e.x.t
16+
*/
17+
interface SpeechGenerationModelInterface
18+
{
19+
/**
20+
* Generates speech from a prompt.
21+
*
22+
* @since n.e.x.t
23+
*
24+
* @param list<Message> $prompt Array of messages containing the speech generation prompt.
25+
* @return GenerativeAiResult Result containing generated speech audio.
26+
*/
27+
public function generateSpeechResult(array $prompt): GenerativeAiResult;
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WordPress\AiClient\Providers\Models\SpeechGeneration\Contracts;
6+
7+
use WordPress\AiClient\Messages\DTO\Message;
8+
use WordPress\AiClient\Operations\DTO\GenerativeAiOperation;
9+
10+
/**
11+
* Interface for models that support asynchronous speech generation operations.
12+
*
13+
* Provides methods for initiating long-running speech generation tasks.
14+
*
15+
* @since n.e.x.t
16+
*/
17+
interface SpeechGenerationOperationModelInterface
18+
{
19+
/**
20+
* Creates a speech generation operation.
21+
*
22+
* @since n.e.x.t
23+
*
24+
* @param list<Message> $prompt Array of messages containing the speech generation prompt.
25+
* @return GenerativeAiOperation The initiated speech generation operation.
26+
*/
27+
public function generateSpeechOperation(array $prompt): GenerativeAiOperation;
28+
}

0 commit comments

Comments
 (0)