Skip to content

Conversation

@JasonTheAdams
Copy link
Member

This adds the contracts (interfaces) for the Providers domain. It omits:

  • Embeddings, since we're deferring this feature
  • HTTP interface(s)
  • Authentication interface(s)

The latter two will be coming in a subsequent PR.

@JasonTheAdams JasonTheAdams self-assigned this Aug 4, 2025
@JasonTheAdams
Copy link
Member Author

I did add some methods to ModelMetadata for comparing against requirements. Perhaps better to move into its own PR... but also happy to just sneak in here. 😁

@JasonTheAdams JasonTheAdams mentioned this pull request Jul 31, 2025
11 tasks
Ref34t pushed a commit to Ref34t/php-ai-client that referenced this pull request Aug 5, 2025
Add core Provider Registry functionality that enables provider discovery
and model selection based on requirements. This is a critical MVP component
that unlocks the main AiClient functionality.

**Key Features:**
- Provider registration and validation
- Provider discovery by ID or class name
- Model metadata discovery with requirements matching
- Provider instance caching for performance
- Comprehensive error handling and validation

**Implementation Details:**
- Full API as specified in architecture documentation
- Follows WordPress coding standards and documentation practices
- Uses existing Provider DTOs (ProviderMetadata, ModelRequirements, etc.)
- Includes method existence validation for duck typing
- Comprehensive test coverage (13 tests, 28 assertions)

**Files Added:**
- src/Providers/AiProviderRegistry.php - Main registry implementation
- tests/unit/Providers/AiProviderRegistryTest.php - Full test suite
- tests/unit/Providers/MockProvider.php - Test provider implementation

**TODOs for Future Enhancement:**
- Integration with ProviderInterface when PR WordPress#35 merges
- Model metadata directory implementation
- Provider availability checking
- Model instantiation functionality

This implementation provides the foundation for provider-agnostic AI access
and enables the next phase of MVP development.
Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JasonTheAdams This looks almost good to go, just a few small points of feedback.

I like the addition of ModelMetadata::meetsRequirements 👍

Comment on lines 10 to 18
/**
* Interface for models that support generative AI operations.
*
* Provides methods to retrieve and manage long-running generative AI
* operations such as text, image, or speech generation.
*
* @since n.e.x.t
*/
interface WithGenerativeAiOperationsInterface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm starting to question whether this approach makes sense: Looking up an existing operation is technically subject to the provider support, not model-specific, so maybe this shouldn't be an interface for models to implement?

Maybe we could instead have a ProviderOperationsHandlerInterface (something like that) with the relevant instance methods (like getOperation), and another ProviderWithOperationsInterface which the actual provider class would implement, with a single static method operationsHandler() which would return the provider-specific instance. That would align well with how the rest works, but keep it optional, as not every provider would need this.

LMKWYT. If this needs more thinking and more discussion, we could leave it out of this PR entirely, as we'll only implement long-running operations later anyway. The key features for the MVP and the big three providers don't need it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know more than I do in this case, but are we confident that looking up operations will always be on a per-provider and not per-model basis? I'd hate to make assumptions that back us into a corner where a provider exists with varying model operational abilities.

I do agree, though, that we shouldn't spend too much time on this right now.

Copy link
Member

@felixarntz felixarntz Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All existing long-running operation implementations in APIs I've seen are model independent - i.e. tied to the entire provider, not specific models. It also makes sense conceptually because the model is only relevant once you trigger/start the operation. At that point you pass all the same information you'd pass to a regular request (model ID, model config etc.), but after that you just get an operation ID back that you can look up provider-wide - no need to remember which model was used at that point.

From that perspective, I'd suggest we go with what I mentioned in the previous comment:

  • ProviderOperationsHandlerInterface with (non-static) method getOperation (just like the current interface)
  • ProviderWithOperationsHandlerInterface with static method operationsHandler(): ProviderOperationsHandlerInterface

Would you be okay replacing this current interface with that? This way we have a starting point in place for operations, which IMO makes sense for a comprehensive picture (similar to #35 (comment)), even if we'll only use it later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha! Appreciate the insight! I resolved this in 5b46445

Comment on lines +30 to +38
/**
* Streams text generation from a prompt.
*
* @since n.e.x.t
*
* @param list<Message> $prompt Array of messages containing the text generation prompt.
* @return Generator<GenerativeAiResult> Generator yielding partial results.
*/
public function streamGenerateTextResult(array $prompt): Generator;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don't likely want to implement streaming for the MVP yet (due to additional complexity), we may want to leave this out for now.

That being said, having this already in place clarifies the intention and leaves the decision to implement it or not at the provider level, so I kind of like keeping it despite the above. Initially we could just have it throw a "Not implemented" exception, until we get to it.

WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with leaving it and throwing an exception. It will be asked about, otherwise. 😆

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JasonTheAdams Looks all good, pending only #35 (comment).

@JasonTheAdams JasonTheAdams added this to the Finish the foundation milestone Aug 6, 2025
Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM!

Ref34t pushed a commit to Ref34t/php-ai-client that referenced this pull request Aug 7, 2025
…ss#35

This commit transforms the Registry from placeholder implementation to fully
functional provider orchestration system:

• Add all Provider interface contracts from PR WordPress#35
• Update Registry to use real interface methods instead of TODOs
• Enhance ModelMetadata with meetsRequirements() method for intelligent selection
• Create complete mock provider ecosystem for comprehensive testing
• Fix all PHPStan type safety and PHPCS style compliance issues
• Achieve 100% test coverage with 548 passing tests

Registry is now production-ready and will work immediately when PR WordPress#35 merges.
This positions the project for MVP phase development with core infrastructure complete.
Ref34t pushed a commit to Ref34t/php-ai-client that referenced this pull request Aug 7, 2025
Add core Provider Registry functionality that enables provider discovery
and model selection based on requirements. This is a critical MVP component
that unlocks the main AiClient functionality.

**Key Features:**
- Provider registration and validation
- Provider discovery by ID or class name
- Model metadata discovery with requirements matching
- Provider instance caching for performance
- Comprehensive error handling and validation

**Implementation Details:**
- Full API as specified in architecture documentation
- Follows WordPress coding standards and documentation practices
- Uses existing Provider DTOs (ProviderMetadata, ModelRequirements, etc.)
- Includes method existence validation for duck typing
- Comprehensive test coverage (13 tests, 28 assertions)

**Files Added:**
- src/Providers/AiProviderRegistry.php - Main registry implementation
- tests/unit/Providers/AiProviderRegistryTest.php - Full test suite
- tests/unit/Providers/MockProvider.php - Test provider implementation

**TODOs for Future Enhancement:**
- Integration with ProviderInterface when PR WordPress#35 merges
- Model metadata directory implementation
- Provider availability checking
- Model instantiation functionality

This implementation provides the foundation for provider-agnostic AI access
and enables the next phase of MVP development.
Ref34t pushed a commit to Ref34t/php-ai-client that referenced this pull request Aug 7, 2025
…ss#35

This commit transforms the Registry from placeholder implementation to fully
functional provider orchestration system:

• Add all Provider interface contracts from PR WordPress#35
• Update Registry to use real interface methods instead of TODOs
• Enhance ModelMetadata with meetsRequirements() method for intelligent selection
• Create complete mock provider ecosystem for comprehensive testing
• Fix all PHPStan type safety and PHPCS style compliance issues
• Achieve 100% test coverage with 548 passing tests

Registry is now production-ready and will work immediately when PR WordPress#35 merges.
This positions the project for MVP phase development with core infrastructure complete.
@JasonTheAdams JasonTheAdams merged commit 258f7c9 into trunk Aug 7, 2025
4 checks passed
@JasonTheAdams JasonTheAdams deleted the provider-contracts branch August 7, 2025 16:19
Ref34t pushed a commit to Ref34t/php-ai-client that referenced this pull request Aug 8, 2025
Add core Provider Registry functionality that enables provider discovery
and model selection based on requirements. This is a critical MVP component
that unlocks the main AiClient functionality.

**Key Features:**
- Provider registration and validation
- Provider discovery by ID or class name
- Model metadata discovery with requirements matching
- Provider instance caching for performance
- Comprehensive error handling and validation

**Implementation Details:**
- Full API as specified in architecture documentation
- Follows WordPress coding standards and documentation practices
- Uses existing Provider DTOs (ProviderMetadata, ModelRequirements, etc.)
- Includes method existence validation for duck typing
- Comprehensive test coverage (13 tests, 28 assertions)

**Files Added:**
- src/Providers/AiProviderRegistry.php - Main registry implementation
- tests/unit/Providers/AiProviderRegistryTest.php - Full test suite
- tests/unit/Providers/MockProvider.php - Test provider implementation

**TODOs for Future Enhancement:**
- Integration with ProviderInterface when PR WordPress#35 merges
- Model metadata directory implementation
- Provider availability checking
- Model instantiation functionality

This implementation provides the foundation for provider-agnostic AI access
and enables the next phase of MVP development.
Ref34t pushed a commit to Ref34t/php-ai-client that referenced this pull request Aug 8, 2025
…ss#35

This commit transforms the Registry from placeholder implementation to fully
functional provider orchestration system:

• Add all Provider interface contracts from PR WordPress#35
• Update Registry to use real interface methods instead of TODOs
• Enhance ModelMetadata with meetsRequirements() method for intelligent selection
• Create complete mock provider ecosystem for comprehensive testing
• Fix all PHPStan type safety and PHPCS style compliance issues
• Achieve 100% test coverage with 548 passing tests

Registry is now production-ready and will work immediately when PR WordPress#35 merges.
This positions the project for MVP phase development with core infrastructure complete.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants