llm-gemini 0.13.1__py3-none-any.whl → 0.14__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: llm-gemini
3
- Version: 0.13.1
3
+ Version: 0.14
4
4
  Summary: LLM plugin to access Google's Gemini family of models
5
5
  Author: Simon Willison
6
6
  License: Apache-2.0
@@ -17,6 +17,7 @@ Requires-Dist: ijson
17
17
  Provides-Extra: test
18
18
  Requires-Dist: pytest; extra == "test"
19
19
  Requires-Dist: pytest-recording; extra == "test"
20
+ Requires-Dist: pytest-asyncio; extra == "test"
20
21
  Requires-Dist: nest-asyncio; extra == "test"
21
22
 
22
23
  # llm-gemini
@@ -145,7 +146,7 @@ llm chat -m gemini-1.5-pro-latest
145
146
 
146
147
  ## Embeddings
147
148
 
148
- The plugin also adds support for the `text-embedding-004` embedding model.
149
+ The plugin also adds support for the `gemini-embedding-exp-03-07` and `text-embedding-004` embedding models.
149
150
 
150
151
  Run that against a single string like this:
151
152
  ```bash
@@ -153,10 +154,20 @@ llm embed -m text-embedding-004 -c 'hello world'
153
154
  ```
154
155
  This returns a JSON array of 768 numbers.
155
156
 
157
+ The `gemini-embedding-exp-03-07` model is larger, returning 3072 numbers. You can also use variants of it that are truncated down to smaller sizes:
158
+
159
+ - `gemini-embedding-exp-03-07` - 3072 numbers
160
+ - `gemini-embedding-exp-03-07-2048` - 2048 numbers
161
+ - `gemini-embedding-exp-03-07-1024` - 1024 numbers
162
+ - `gemini-embedding-exp-03-07-512` - 512 numbers
163
+ - `gemini-embedding-exp-03-07-256` - 256 numbers
164
+ - `gemini-embedding-exp-03-07-128` - 128 numbers
165
+
156
166
  This command will embed every `README.md` file in child directories of the current directory and store the results in a SQLite database called `embed.db` in a collection called `readmes`:
157
167
 
158
168
  ```bash
159
- llm embed-multi readmes --files . '*/README.md' -d embed.db -m text-embedding-004
169
+ llm embed-multi readmes -d embed.db -m gemini-embedding-exp-03-07-128 \
170
+ --files . '*/README.md'
160
171
  ```
161
172
  You can then run similarity searches against that collection like this:
162
173
  ```bash
@@ -0,0 +1,7 @@
1
+ llm_gemini.py,sha256=KgiKMPY6q-GkAMzH0gfQWp0cjBBKizNhlnZ3nX5pXWY,14917
2
+ llm_gemini-0.14.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
3
+ llm_gemini-0.14.dist-info/METADATA,sha256=J8oA7hZmNrFsRyH3_s4oesSjWNEaK8pWcT2p-_quPTA,7556
4
+ llm_gemini-0.14.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
5
+ llm_gemini-0.14.dist-info/entry_points.txt,sha256=n544bpgUPIBc5l_cnwsTxPc3gMGJHPtAyqBNp-CkMWk,26
6
+ llm_gemini-0.14.dist-info/top_level.txt,sha256=WUQmG6_2QKbT_8W4HH93qyKl_0SUteL4Ra6_PhyNGKU,11
7
+ llm_gemini-0.14.dist-info/RECORD,,
llm_gemini.py CHANGED
@@ -378,9 +378,19 @@ class AsyncGeminiPro(_SharedGemini, llm.AsyncKeyModel):
378
378
 
379
379
  @llm.hookimpl
380
380
  def register_embedding_models(register):
381
+ register(GeminiEmbeddingModel("text-embedding-004", "text-embedding-004"))
382
+ # gemini-embedding-exp-03-07 in different truncation sizes
381
383
  register(
382
- GeminiEmbeddingModel("text-embedding-004", "text-embedding-004"),
384
+ GeminiEmbeddingModel(
385
+ "gemini-embedding-exp-03-07", "gemini-embedding-exp-03-07"
386
+ ),
383
387
  )
388
+ for i in (128, 256, 512, 1024, 2048):
389
+ register(
390
+ GeminiEmbeddingModel(
391
+ f"gemini-embedding-exp-03-07-{i}", f"gemini-embedding-exp-03-07", i
392
+ ),
393
+ )
384
394
 
385
395
 
386
396
  class GeminiEmbeddingModel(llm.EmbeddingModel):
@@ -388,9 +398,10 @@ class GeminiEmbeddingModel(llm.EmbeddingModel):
388
398
  key_env_var = "LLM_GEMINI_KEY"
389
399
  batch_size = 20
390
400
 
391
- def __init__(self, model_id, gemini_model_id):
401
+ def __init__(self, model_id, gemini_model_id, truncate=None):
392
402
  self.model_id = model_id
393
403
  self.gemini_model_id = gemini_model_id
404
+ self.truncate = truncate
394
405
 
395
406
  def embed_batch(self, items):
396
407
  headers = {
@@ -416,4 +427,7 @@ class GeminiEmbeddingModel(llm.EmbeddingModel):
416
427
  )
417
428
 
418
429
  response.raise_for_status()
419
- return [item["values"] for item in response.json()["embeddings"]]
430
+ values = [item["values"] for item in response.json()["embeddings"]]
431
+ if self.truncate:
432
+ values = [value[: self.truncate] for value in values]
433
+ return values
@@ -1,7 +0,0 @@
1
- llm_gemini.py,sha256=JWaRtT8vJzdxrRbCAgoNrKqes2df_T4gqqeDmiw0oRI,14370
2
- llm_gemini-0.13.1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
3
- llm_gemini-0.13.1.dist-info/METADATA,sha256=S87OFYnm9K0EVvJIRrJoZT-J0gxhPA4BrnIGkVD8q8c,7016
4
- llm_gemini-0.13.1.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
5
- llm_gemini-0.13.1.dist-info/entry_points.txt,sha256=n544bpgUPIBc5l_cnwsTxPc3gMGJHPtAyqBNp-CkMWk,26
6
- llm_gemini-0.13.1.dist-info/top_level.txt,sha256=WUQmG6_2QKbT_8W4HH93qyKl_0SUteL4Ra6_PhyNGKU,11
7
- llm_gemini-0.13.1.dist-info/RECORD,,