You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#### Generate embeddings using any suitable model from any provider
75
+
#### Generate text using any suitable model from any provider
76
+
77
+
_Note: This does effectively the exact same as [the first code example](#generate-text-using-any-suitable-model-from-any-provider-most-basic-example), but more verbosely. In other words, if you omit the model parameter, the SDK will do this internally._
#### Generate text with an image as additional input using any suitable model from any provider
93
+
94
+
_Note: Since this omits the model parameter, the SDK will automatically determine which models are suitable and use any of them, similar to [the first code example](#generate-text-using-any-suitable-model-from-any-provider-most-basic-example). Since it knows the input includes an image, it can internally infer that the model needs to not only support `AiFeature::TEXT_GENERATION`, but also `AiCapability::INPUT_MODALITIES => ['text', 'image']`._
95
+
96
+
```php
97
+
$text = Ai::generateTextResult(
98
+
[
99
+
[
100
+
'text' => 'Generate alternative text for this image.',
101
+
],
102
+
[
103
+
'mimeType' => 'image/png',
104
+
'base64Data' => '...', // Base64-encoded data blob.
105
+
],
106
+
]
107
+
)->toText();
108
+
```
109
+
110
+
#### Generate text with chat history using any suitable model from any provider
111
+
112
+
_Note: Similarly to the previous example, even without specifying the model here, the SDK will be able to infer required model capabilities because it can detect that multiple chat messages are passed. Therefore it will internally only consider models that support `AiFeature::TEXT_GENERATION` as well as `AiCapability::CHAT_HISTORY`._
113
+
114
+
```php
115
+
$text = Ai::generateTextResult(
116
+
[
117
+
[
118
+
'role' => MessageRole::USER,
119
+
'parts' => ['text' => 'Do you spell it WordPress or Wordpress?'],
120
+
],
121
+
[
122
+
'role' => MessageRole::MODEL,
123
+
'parts' => ['text' => 'The correct spelling is WordPress.'],
124
+
],
125
+
[
126
+
'role' => MessageRole::USER,
127
+
'parts' => ['text' => 'Can you repeat that please?'],
128
+
],
129
+
]
130
+
)->toText();
84
131
```
85
132
86
133
#### Generate text with JSON output using any suitable model from any provider
87
134
135
+
_Note: Unlike the previous two examples, to require JSON output it is necessary to go the verbose route, since it is impossible for the SDK to detect whether you require JSON output purely from the prompt input. Therefore this code example contains the logic to manually search for suitable models and then use one of them for the task._
0 commit comments