Skip to content

Conversation

@Ref34t
Copy link
Contributor

@Ref34t Ref34t commented Aug 19, 2025

This is a draft PR split from #55 to enable separate review of the embeddings functionality.

Mohamed Khaled added 23 commits August 15, 2025 12:38
Add provider availability checking functionality to complete architecture specification.

- Add isConfigured(ProviderAvailabilityInterface $availability): bool method
- Delegate to ProviderAvailabilityInterface::isConfigured() for consistency
Add base generation method that automatically detects model capabilities and delegates to appropriate generation interfaces.

- Add generateResult(prompt, ModelInterface): GenerativeAiResult method
- Smart delegation to generateTextResult() or generateImageResult() based on model interface
- Comprehensive error handling for unsupported model types
- 3 new tests covering text generation, image generation, and error cases
Add streaming text generation using PHP Generator pattern.

- Add streamGenerateTextResult() method with Generator return type
- Delegate to model's streaming method using yield from
- Support model auto-discovery and comprehensive error handling
Add properly typed async operations with model interface validation.

- Add generateTextOperation() with TextGenerationModelInterface validation
- Add generateImageOperation() with ImageGenerationModelInterface validation
- Prefixed operation IDs for better tracking (text_op_, image_op_)
- 4 comprehensive tests covering validation and error cases
- Add convertTextToSpeechResult() method with model auto-discovery
- Add convertTextToSpeechOperation() method for async processing
- Enhance generateResult() to support TextToSpeechConversionModelInterface
- Add findSuitableTextToSpeechModel() helper method
- Update test expectations for extended generation interface support
- Add generateSpeechResult() method with model auto-discovery
- Add generateSpeechOperation() method for async speech processing
- Enhance generateResult() to support SpeechGenerationModelInterface
- Add findSuitableSpeechModel() helper with speechGeneration capability
- Update prompt() method with comprehensive PromptBuilder integration docs
- Add Embedding DTO with vector data representation and dimension tracking
- Add EmbeddingResult class extending ResultInterface for embedding results
- Add EmbeddingOperation class for async embedding operations
- Add EmbeddingGenerationModelInterface for synchronous embedding generation
- Add EmbeddingGenerationOperationModelInterface for async embedding operations
- Implement generateEmbeddingsResult() method with model auto-discovery
- Implement generateEmbeddingsOperation() method for async processing
- Add findSuitableEmbeddingModel() helper with embeddingGeneration capability
- Support both string[] and Message[] input formats for embeddings
- Update PromptBuilder integration documentation to include embeddings
- Create EmbeddingTest.php with 9 test methods covering vector operations and transformations
- Create EmbeddingResultTest.php with 12 test methods covering result validation and serialization
- Create EmbeddingOperationTest.php with 14 test methods covering all operation states
- Create MockEmbeddingGenerationModel.php and MockEmbeddingGenerationOperationModel.php for testing
- Add 5 embedding test methods to AiClientTest.php with proper mock integration
- Fix type errors by ensuring proper list types for embedding interfaces
- Convert Message arrays to proper lists using array_values() for interface compliance
- Add missing newlines at end of files
- Remove trailing whitespace
- Fix alphabetical import sorting in test files
- All PHPCS violations resolved automatically
- Implement message() method with placeholder that throws RuntimeException
- Add comprehensive test coverage for message() method
…ability

- Extract PromptNormalizer utility class for prompt format standardization
- Extract ModelDiscovery utility class for capability-based model discovery
- Fix list type annotations in PromptNormalizer and AiClient
- Ensure all Message arrays are converted to proper lists using array_values()
- Remove 4 redundant tests from AiClientTest that are now covered by utility tests
- Maintain 100% test coverage while eliminating duplicate test logic
- All PHPStan errors resolved, all tests passing
Extract interface validation, operation factory, embedding input normalization,
and generation strategy resolution into dedicated utility classes.
…ation

- Implement template method pattern in AiClient for generation methods
- Add dynamic validation system to InterfaceValidator with configuration mapping
- Consolidate EmbeddingInputNormalizer functionality into PromptNormalizer
- Refactor operation methods with factory pattern approach
- Update all tests to use consolidated normalizer methods
@JasonTheAdams
Copy link
Member

As a note, I'm not sure when we'll add embeddings. It's not a high priority at this time and requires considerable thought downstream as to how it's used, especially in a WordPress context.

@Ref34t
Copy link
Contributor Author

Ref34t commented Aug 19, 2025

@JasonTheAdams I do agree with you. I think I can try to leave it to be a separate package dependent on PHP-AI-SDK
I already have a lot of trials I wanna do with RAG in PHP in the future.

@felixarntz felixarntz closed this pull request by merging all changes into WordPress:trunk in 2c8bfa2 Aug 28, 2025
@Ref34t Ref34t deleted the feature/embeddings-support branch August 29, 2025 07:19
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