Skip to content

Commit 6d722de

Browse files
authored
Merge pull request #83 from WordPress/adds-message-builder
Adds MessageBuilder class
2 parents 20e9b9d + 6244bf2 commit 6d722de

File tree

4 files changed

+821
-58
lines changed

4 files changed

+821
-58
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ vendor/
1313
*.DS_store
1414
.DS_store?
1515

16+
############
17+
## IDEs
18+
############
19+
20+
.idea/
21+
.vscode/
22+
1623
############
1724
## AI Tools
1825
############

docs/ARCHITECTURE.md

Lines changed: 56 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -296,69 +296,68 @@ direction LR
296296
namespace AiClientNamespace {
297297
class AiClient {
298298
+prompt(string|Message|null $text = null) PromptBuilder$
299-
+message(?string $text) MessageBuilder$
299+
+message($input = null) MessageBuilder$
300300
}
301301
}
302302
303303
namespace AiClientNamespace.Builders {
304304
class PromptBuilder {
305305
+withText(string $text) self
306-
+withInlineImage(string $base64Blob, string $mimeType)
307-
+withRemoteImage(string $uri, string $mimeType)
308-
+withImageFile(File $file) self
309-
+withAudioFile(File $file) self
310-
+withVideoFile(File $file) self
306+
+withFile($file, ?string $mimeType) self
311307
+withFunctionResponse(FunctionResponse $functionResponse) self
312-
+withMessageParts(...MessagePart $part) self
308+
+withMessageParts(...MessagePart $parts) self
313309
+withHistory(...Message $messages) self
314310
+usingModel(ModelInterface $model) self
311+
+usingModelConfig(ModelConfig $config) self
312+
+usingProvider(string $providerIdOrClassName) self
315313
+usingSystemInstruction(string $systemInstruction) self
316314
+usingMaxTokens(int $maxTokens) self
317315
+usingTemperature(float $temperature) self
318316
+usingTopP(float $topP) self
319317
+usingTopK(int $topK) self
320318
+usingStopSequences(...string $stopSequences) self
321319
+usingCandidateCount(int $candidateCount) self
322-
+usingOutputMime(string $mimeType) self
323-
+usingOutputSchema(array< string, mixed > $schema) self
324-
+usingOutputModalities(...ModalityEnum $modalities) self
320+
+usingFunctionDeclarations(...FunctionDeclaration $functionDeclarations) self
321+
+usingPresencePenalty(float $presencePenalty) self
322+
+usingFrequencyPenalty(float $frequencyPenalty) self
323+
+usingWebSearch(WebSearch $webSearch) self
324+
+usingTopLogprobs(?int $topLogprobs) self
325+
+asOutputMimeType(string $mimeType) self
326+
+asOutputSchema(array< string, mixed > $schema) self
327+
+asOutputModalities(...ModalityEnum $modalities) self
328+
+asOutputFileType(FileTypeEnum $fileType) self
325329
+asJsonResponse(?array< string, mixed > $schema) self
326-
+generateResult() GenerativeAiResult
327-
+generateOperation() GenerativeAiOperation
330+
+generateResult(?CapabilityEnum $capability) GenerativeAiResult
328331
+generateTextResult() GenerativeAiResult
329-
+streamGenerateTextResult() Generator< GenerativeAiResult >
330332
+generateImageResult() GenerativeAiResult
331-
+convertTextToSpeechResult() GenerativeAiResult
332333
+generateSpeechResult() GenerativeAiResult
333-
+generateEmbeddingsResult() EmbeddingResult
334-
+generateTextOperation() GenerativeAiOperation
335-
+generateImageOperation() GenerativeAiOperation
336-
+convertTextToSpeechOperation() GenerativeAiOperation
337-
+generateSpeechOperation() GenerativeAiOperation
338-
+generateEmbeddingsOperation() EmbeddingOperation
334+
+convertTextToSpeechResult() GenerativeAiResult
339335
+generateText() string
340336
+generateTexts(?int $candidateCount) string[]
341-
+streamGenerateText() Generator< string >
342337
+generateImage() File
343338
+generateImages(?int $candidateCount) File[]
344339
+convertTextToSpeech() File
345340
+convertTextToSpeeches(?int $candidateCount) File[]
346341
+generateSpeech() File
347342
+generateSpeeches(?int $candidateCount) File[]
348-
+generateEmbeddings() Embedding[]
349-
+getModelRequirements() ModelRequirements
350-
+isSupported() bool
343+
+isSupportedForTextGeneration() bool
344+
+isSupportedForImageGeneration() bool
345+
+isSupportedForTextToSpeechConversion() bool
346+
+isSupportedForVideoGeneration() bool
347+
+isSupportedForSpeechGeneration() bool
348+
+isSupportedForMusicGeneration() bool
349+
+isSupportedForEmbeddingGeneration() bool
351350
}
352351
353352
class MessageBuilder {
354-
+usingRole(MessageRole $role) self
353+
+usingRole(MessageRoleEnum $role) self
354+
+usingUserRole() self
355+
+usingModelRole() self
355356
+withText(string $text) self
356-
+withImageFile(File $file) self
357-
+withAudioFile(File $file) self
358-
+withVideoFile(File $file) self
357+
+withFile($file, ?string $mimeType) self
359358
+withFunctionCall(FunctionCall $functionCall) self
360359
+withFunctionResponse(FunctionResponse $functionResponse) self
361-
+withMessageParts(...MessagePart $part) self
360+
+withMessageParts(...MessagePart $parts) self
362361
+get() Message
363362
}
364363
}
@@ -445,7 +444,7 @@ direction LR
445444
namespace AiClientNamespace {
446445
class AiClient {
447446
+prompt(string|Message|null $text = null) PromptBuilder$
448-
+message(?string $text) MessageBuilder$
447+
+message($input = null) MessageBuilder$
449448
+defaultRegistry() ProviderRegistry$
450449
+isConfigured(ProviderAvailabilityInterface $availability) bool$
451450
+generateResult(string|MessagePart|MessagePart[]|Message|Message[] $prompt, ModelInterface $model) GenerativeAiResult$
@@ -467,62 +466,61 @@ direction LR
467466
namespace AiClientNamespace.Builders {
468467
class PromptBuilder {
469468
+withText(string $text) self
470-
+withInlineImage(string $base64Blob, string $mimeType)
471-
+withRemoteImage(string $uri, string $mimeType)
472-
+withImageFile(File $file) self
473-
+withAudioFile(File $file) self
474-
+withVideoFile(File $file) self
469+
+withFile($file, ?string $mimeType) self
475470
+withFunctionResponse(FunctionResponse $functionResponse) self
476-
+withMessageParts(...MessagePart $part) self
471+
+withMessageParts(...MessagePart $parts) self
477472
+withHistory(...Message $messages) self
478473
+usingModel(ModelInterface $model) self
474+
+usingModelConfig(ModelConfig $config) self
475+
+usingProvider(string $providerIdOrClassName) self
479476
+usingSystemInstruction(string $systemInstruction) self
480477
+usingMaxTokens(int $maxTokens) self
481478
+usingTemperature(float $temperature) self
482479
+usingTopP(float $topP) self
483480
+usingTopK(int $topK) self
484481
+usingStopSequences(...string $stopSequences) self
485482
+usingCandidateCount(int $candidateCount) self
486-
+usingOutputMime(string $mimeType) self
487-
+usingOutputSchema(array< string, mixed > $schema) self
488-
+usingOutputModalities(...ModalityEnum $modalities) self
483+
+usingFunctionDeclarations(...FunctionDeclaration $functionDeclarations) self
484+
+usingPresencePenalty(float $presencePenalty) self
485+
+usingFrequencyPenalty(float $frequencyPenalty) self
486+
+usingWebSearch(WebSearch $webSearch) self
487+
+usingTopLogprobs(?int $topLogprobs) self
488+
+asOutputMimeType(string $mimeType) self
489+
+asOutputSchema(array< string, mixed > $schema) self
490+
+asOutputModalities(...ModalityEnum $modalities) self
491+
+asOutputFileType(FileTypeEnum $fileType) self
489492
+asJsonResponse(?array< string, mixed > $schema) self
490-
+generateResult() GenerativeAiResult
491-
+generateOperation() GenerativeAiOperation
493+
+generateResult(?CapabilityEnum $capability) GenerativeAiResult
492494
+generateTextResult() GenerativeAiResult
493-
+streamGenerateTextResult() Generator< GenerativeAiResult >
494495
+generateImageResult() GenerativeAiResult
495-
+convertTextToSpeechResult() GenerativeAiResult
496496
+generateSpeechResult() GenerativeAiResult
497-
+generateEmbeddingsResult() EmbeddingResult
498-
+generateTextOperation() GenerativeAiOperation
499-
+generateImageOperation() GenerativeAiOperation
500-
+convertTextToSpeechOperation() GenerativeAiOperation
501-
+generateSpeechOperation() GenerativeAiOperation
502-
+generateEmbeddingsOperation() EmbeddingOperation
497+
+convertTextToSpeechResult() GenerativeAiResult
503498
+generateText() string
504499
+generateTexts(?int $candidateCount) string[]
505-
+streamGenerateText() Generator< string >
506500
+generateImage() File
507501
+generateImages(?int $candidateCount) File[]
508502
+convertTextToSpeech() File
509503
+convertTextToSpeeches(?int $candidateCount) File[]
510504
+generateSpeech() File
511505
+generateSpeeches(?int $candidateCount) File[]
512-
+generateEmbeddings() Embedding[]
513-
+getModelRequirements() ModelRequirements
514-
+isSupported() bool
506+
+isSupportedForTextGeneration() bool
507+
+isSupportedForImageGeneration() bool
508+
+isSupportedForTextToSpeechConversion() bool
509+
+isSupportedForVideoGeneration() bool
510+
+isSupportedForSpeechGeneration() bool
511+
+isSupportedForMusicGeneration() bool
512+
+isSupportedForEmbeddingGeneration() bool
515513
}
516514
517515
class MessageBuilder {
518-
+usingRole(MessageRole $role) self
516+
+usingRole(MessageRoleEnum $role) self
517+
+usingUserRole() self
518+
+usingModelRole() self
519519
+withText(string $text) self
520-
+withImageFile(File $file) self
521-
+withAudioFile(File $file) self
522-
+withVideoFile(File $file) self
520+
+withFile($file, ?string $mimeType) self
523521
+withFunctionCall(FunctionCall $functionCall) self
524522
+withFunctionResponse(FunctionResponse $functionResponse) self
525-
+withMessageParts(...MessagePart $part) self
523+
+withMessageParts(...MessagePart $parts) self
526524
+get() Message
527525
}
528526
}

0 commit comments

Comments
 (0)