File tree Expand file tree Collapse file tree 4 files changed +32
-1
lines changed Expand file tree Collapse file tree 4 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ _This library is not developed or endorsed by Google._
25
25
- [ Text Generation using Image File] ( #text-generation-using-image-file )
26
26
- [ Text Generation using Image Data] ( #text-generation-using-image-data )
27
27
- [ Chat Session (Multi-Turn Conversations)] ( #chat-session-multi-turn-conversations )
28
+ - [ Text Embeddings] ( #text-embeddings )
28
29
- [ Tokens counting] ( #tokens-counting )
29
30
- [ Listing models] ( #listing-models )
30
31
- [ Credits] ( #credits )
@@ -150,6 +151,19 @@ print $chat->sendMessage('in Go');
150
151
// This code will print "Hello World!" to the standard output.
151
152
```
152
153
154
+ ### Text Embeddings
155
+
156
+ ``` php
157
+ use GeminiAPI\Laravel\Facades\Gemini;
158
+
159
+ print_r(Gemini::embedText('PHP in less than 100 chars'));
160
+ // [
161
+ // [0] => 0.041395925
162
+ // [1] => -0.017692696
163
+ // ...
164
+ // ]
165
+ ```
166
+
153
167
### Tokens counting
154
168
155
169
``` php
Original file line number Diff line number Diff line change 22
22
],
23
23
"require" : {
24
24
"php" : " ^8.1" ,
25
- "gemini-api-php/client" : " ^1.2 " ,
25
+ "gemini-api-php/client" : " ^1.3.1 " ,
26
26
"illuminate/support" : " ^9.0 || ^10.0 || ^11.0" ,
27
27
"psr/container" : " ^1.0 || ^2.0" ,
28
28
"psr/http-client" : " ^1.0"
Original file line number Diff line number Diff line change 10
10
11
11
/**
12
12
* @method static int countTokens(string $prompt)
13
+ * @method static float[] embedText(string $prompt)
13
14
* @method static string generateText(string $prompt)
14
15
* @method static string generateTextUsingImage(string $imageType, string $image, string $prompt = '')
15
16
* @method static string generateTextUsingImageFile(string $imageType, string $imagePath, string $prompt = '')
Original file line number Diff line number Diff line change @@ -34,6 +34,22 @@ public function __construct(
34
34
) {
35
35
}
36
36
37
+ /**
38
+ * @return float[]
39
+ *
40
+ * @throws ClientExceptionInterface
41
+ */
42
+ public function embedText (string $ prompt , ?string $ title = null ): array
43
+ {
44
+ $ model = $ this ->client ->embeddingModel (ModelName::Embedding);
45
+
46
+ $ response = $ title
47
+ ? $ model ->embedContentWithTitle ($ title , new TextPart ($ prompt ))
48
+ : $ model ->embedContent (new TextPart ($ prompt ));
49
+
50
+ return $ response ->embedding ->values ;
51
+ }
52
+
37
53
/**
38
54
* @throws ClientExceptionInterface
39
55
*/
You can’t perform that action at this time.
0 commit comments