llm-gemini 0.10__tar.gz → 0.12__tar.gz

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.10
3
+ Version: 0.12
4
4
  Summary: LLM plugin to access Google's Gemini family of models
5
5
  Author: Simon Willison
6
6
  License: Apache-2.0
@@ -11,12 +11,13 @@ Project-URL: CI, https://github.com/simonw/llm-gemini/actions
11
11
  Classifier: License :: OSI Approved :: Apache Software License
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
- Requires-Dist: llm>=0.19
14
+ Requires-Dist: llm>=0.22
15
15
  Requires-Dist: httpx
16
16
  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: nest-asyncio; extra == "test"
20
21
 
21
22
  # llm-gemini
22
23
 
@@ -68,7 +69,7 @@ Other models are:
68
69
  - `gemini-2.0-flash-thinking-exp-1219` - experimental "thinking" model from December 2024
69
70
  - `gemini-2.0-flash-thinking-exp-01-21` - experimental "thinking" model from January 2025
70
71
  - `gemini-2.0-flash` - Gemini 2.0 Flash
71
- - `gemini-2.0-flash-lite-preview-02-05` - Gemini 2.0 Flash-Lite
72
+ - `gemini-2.0-flash-lite` - Gemini 2.0 Flash-Lite
72
73
  - `gemini-2.0-pro-exp-02-05` - experimental release of Gemini 2.0 Pro
73
74
 
74
75
  ### Images, audio and video
@@ -48,7 +48,7 @@ Other models are:
48
48
  - `gemini-2.0-flash-thinking-exp-1219` - experimental "thinking" model from December 2024
49
49
  - `gemini-2.0-flash-thinking-exp-01-21` - experimental "thinking" model from January 2025
50
50
  - `gemini-2.0-flash` - Gemini 2.0 Flash
51
- - `gemini-2.0-flash-lite-preview-02-05` - Gemini 2.0 Flash-Lite
51
+ - `gemini-2.0-flash-lite` - Gemini 2.0 Flash-Lite
52
52
  - `gemini-2.0-pro-exp-02-05` - experimental release of Gemini 2.0 Pro
53
53
 
54
54
  ### Images, audio and video
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: llm-gemini
3
- Version: 0.10
3
+ Version: 0.12
4
4
  Summary: LLM plugin to access Google's Gemini family of models
5
5
  Author: Simon Willison
6
6
  License: Apache-2.0
@@ -11,12 +11,13 @@ Project-URL: CI, https://github.com/simonw/llm-gemini/actions
11
11
  Classifier: License :: OSI Approved :: Apache Software License
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
- Requires-Dist: llm>=0.19
14
+ Requires-Dist: llm>=0.22
15
15
  Requires-Dist: httpx
16
16
  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: nest-asyncio; extra == "test"
20
21
 
21
22
  # llm-gemini
22
23
 
@@ -68,7 +69,7 @@ Other models are:
68
69
  - `gemini-2.0-flash-thinking-exp-1219` - experimental "thinking" model from December 2024
69
70
  - `gemini-2.0-flash-thinking-exp-01-21` - experimental "thinking" model from January 2025
70
71
  - `gemini-2.0-flash` - Gemini 2.0 Flash
71
- - `gemini-2.0-flash-lite-preview-02-05` - Gemini 2.0 Flash-Lite
72
+ - `gemini-2.0-flash-lite` - Gemini 2.0 Flash-Lite
72
73
  - `gemini-2.0-pro-exp-02-05` - experimental release of Gemini 2.0 Pro
73
74
 
74
75
  ### Images, audio and video
@@ -1,7 +1,8 @@
1
- llm>=0.19
1
+ llm>=0.22
2
2
  httpx
3
3
  ijson
4
4
 
5
5
  [test]
6
6
  pytest
7
7
  pytest-recording
8
+ nest-asyncio
@@ -32,6 +32,7 @@ GOOGLE_SEARCH_MODELS = {
32
32
  "gemini-1.5-pro-002",
33
33
  "gemini-1.5-flash-002",
34
34
  "gemini-2.0-flash-exp",
35
+ "gemini-2.0-flash",
35
36
  }
36
37
 
37
38
 
@@ -57,8 +58,9 @@ def register_models(register):
57
58
  "gemini-2.0-flash-thinking-exp-01-21",
58
59
  # Released 5th Feb 2025:
59
60
  "gemini-2.0-flash",
60
- "gemini-2.0-flash-lite-preview-02-05",
61
61
  "gemini-2.0-pro-exp-02-05",
62
+ # Released 25th Feb 2025:
63
+ "gemini-2.0-flash-lite",
62
64
  ]:
63
65
  can_google_search = model_id in GOOGLE_SEARCH_MODELS
64
66
  register(
@@ -220,7 +222,7 @@ class _SharedGemini:
220
222
  if prompt.options and prompt.options.code_execution:
221
223
  body["tools"] = [{"codeExecution": {}}]
222
224
  if prompt.options and self.can_google_search and prompt.options.google_search:
223
- body["tools"] = [{"google_search_retrieval": {}}]
225
+ body["tools"] = [{"google_search": {}}]
224
226
  if prompt.system:
225
227
  body["systemInstruction"] = {"parts": [{"text": prompt.system}]}
226
228
 
@@ -268,9 +270,8 @@ class _SharedGemini:
268
270
  pass
269
271
 
270
272
 
271
- class GeminiPro(_SharedGemini, llm.Model):
272
- def execute(self, prompt, stream, response, conversation):
273
- key = self.get_key()
273
+ class GeminiPro(_SharedGemini, llm.KeyModel):
274
+ def execute(self, prompt, stream, response, conversation, key):
274
275
  url = f"https://generativelanguage.googleapis.com/v1beta/models/{self.model_id}:streamGenerateContent"
275
276
  gathered = []
276
277
  body = self.build_request_body(prompt, conversation)
@@ -279,7 +280,7 @@ class GeminiPro(_SharedGemini, llm.Model):
279
280
  "POST",
280
281
  url,
281
282
  timeout=None,
282
- headers={"x-goog-api-key": key},
283
+ headers={"x-goog-api-key": self.get_key(key)},
283
284
  json=body,
284
285
  ) as http_response:
285
286
  events = ijson.sendable_list()
@@ -301,9 +302,8 @@ class GeminiPro(_SharedGemini, llm.Model):
301
302
  self.set_usage(response)
302
303
 
303
304
 
304
- class AsyncGeminiPro(_SharedGemini, llm.AsyncModel):
305
- async def execute(self, prompt, stream, response, conversation):
306
- key = self.get_key()
305
+ class AsyncGeminiPro(_SharedGemini, llm.AsyncKeyModel):
306
+ async def execute(self, prompt, stream, response, conversation, key):
307
307
  url = f"https://generativelanguage.googleapis.com/v1beta/models/{self.model_id}:streamGenerateContent"
308
308
  gathered = []
309
309
  body = self.build_request_body(prompt, conversation)
@@ -313,7 +313,7 @@ class AsyncGeminiPro(_SharedGemini, llm.AsyncModel):
313
313
  "POST",
314
314
  url,
315
315
  timeout=None,
316
- headers={"x-goog-api-key": key},
316
+ headers={"x-goog-api-key": self.get_key(key)},
317
317
  json=body,
318
318
  ) as http_response:
319
319
  events = ijson.sendable_list()
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "llm-gemini"
3
- version = "0.10"
3
+ version = "0.12"
4
4
  description = "LLM plugin to access Google's Gemini family of models"
5
5
  readme = "README.md"
6
6
  authors = [{name = "Simon Willison"}]
@@ -9,7 +9,7 @@ classifiers = [
9
9
  "License :: OSI Approved :: Apache Software License"
10
10
  ]
11
11
  dependencies = [
12
- "llm>=0.19",
12
+ "llm>=0.22",
13
13
  "httpx",
14
14
  "ijson"
15
15
  ]
@@ -24,4 +24,4 @@ CI = "https://github.com/simonw/llm-gemini/actions"
24
24
  gemini = "llm_gemini"
25
25
 
26
26
  [project.optional-dependencies]
27
- test = ["pytest", "pytest-recording"]
27
+ test = ["pytest", "pytest-recording", "nest-asyncio"]
@@ -1,7 +1,10 @@
1
1
  import llm
2
+ import nest_asyncio
2
3
  import os
3
4
  import pytest
4
5
 
6
+ nest_asyncio.apply()
7
+
5
8
  GEMINI_API_KEY = os.environ.get("PYTEST_GEMINI_API_KEY", None) or "gm-..."
6
9
 
7
10
 
@@ -9,15 +12,14 @@ GEMINI_API_KEY = os.environ.get("PYTEST_GEMINI_API_KEY", None) or "gm-..."
9
12
  @pytest.mark.asyncio
10
13
  async def test_prompt():
11
14
  model = llm.get_model("gemini-1.5-flash-latest")
12
- model.key = model.key or GEMINI_API_KEY
13
- response = model.prompt("Name for a pet pelican, just the name")
15
+ response = model.prompt("Name for a pet pelican, just the name", key=GEMINI_API_KEY)
14
16
  assert str(response) == "Percy"
15
17
  assert response.response_json == [
16
18
  {
17
19
  "candidates": [
18
20
  {"content": {"parts": [{"text": "Percy"}], "role": "model"}}
19
21
  ],
20
- "modelVersion": "gemini-1.5-flash-002",
22
+ "modelVersion": "gemini-1.5-flash-latest",
21
23
  }
22
24
  ]
23
25
  assert response.token_details is None
@@ -28,7 +30,8 @@ async def test_prompt():
28
30
 
29
31
  # And try it async too
30
32
  async_model = llm.get_async_model("gemini-1.5-flash-latest")
31
- async_model.key = async_model.key or GEMINI_API_KEY
32
- response = await async_model.prompt("Name for a pet pelican, just the name")
33
+ response = await async_model.prompt(
34
+ "Name for a pet pelican, just the name", key=GEMINI_API_KEY
35
+ )
33
36
  text = await response.text()
34
37
  assert text == "Percy"
File without changes
File without changes