llm-gemini 0.1a0__py3-none-any.whl → 0.1a2__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.1
2
2
  Name: llm-gemini
3
- Version: 0.1a0
3
+ Version: 0.1a2
4
4
  Summary: LLM plugin to access Google's Gemini family of models
5
5
  Author: Simon Willison
6
6
  License: Apache-2.0
@@ -34,7 +34,7 @@ llm install llm-gemini
34
34
  ```
35
35
  ## Usage
36
36
 
37
- Configure the model by setting a key called "gemini" to your API key:
37
+ Configure the model by setting a key called "gemini" to your [API key](https://ai.google.dev/):
38
38
 
39
39
  ```bash
40
40
  llm keys set gemini
@@ -59,6 +59,8 @@ To chat interactively with the model, run `llm chat`:
59
59
  llm chat -m gemini-pro
60
60
  ```
61
61
 
62
+ If you have access to the Gemini 1.5 Pro preview you can use `-m gemini-1.5-pro-latest` to work with that model.
63
+
62
64
  ## Development
63
65
 
64
66
  To set up this plugin locally, first checkout the code. Then create a new virtual environment:
@@ -0,0 +1,7 @@
1
+ llm_gemini.py,sha256=D5EeLRGOTiIiDnChXVaJQcOL1AQNZNpvBYDGXjulMFA,2745
2
+ llm_gemini-0.1a2.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
3
+ llm_gemini-0.1a2.dist-info/METADATA,sha256=ptgaTC5N3g0z1NDbzNJypnfy4V44W-jteo9bcQJsjeU,2262
4
+ llm_gemini-0.1a2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
5
+ llm_gemini-0.1a2.dist-info/entry_points.txt,sha256=n544bpgUPIBc5l_cnwsTxPc3gMGJHPtAyqBNp-CkMWk,26
6
+ llm_gemini-0.1a2.dist-info/top_level.txt,sha256=WUQmG6_2QKbT_8W4HH93qyKl_0SUteL4Ra6_PhyNGKU,11
7
+ llm_gemini-0.1a2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.42.0)
2
+ Generator: bdist_wheel (0.43.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
llm_gemini.py CHANGED
@@ -26,38 +26,47 @@ SAFETY_SETTINGS = [
26
26
 
27
27
  @llm.hookimpl
28
28
  def register_models(register):
29
- register(GeminiPro())
29
+ register(GeminiPro("gemini-pro"))
30
+ register(GeminiPro("gemini-1.5-pro-latest"))
30
31
 
31
32
 
32
33
  class GeminiPro(llm.Model):
33
- model_id = "gemini-pro"
34
34
  can_stream = True
35
35
 
36
+ def __init__(self, model_id):
37
+ self.model_id = model_id
38
+
36
39
  def build_messages(self, prompt, conversation):
37
40
  if not conversation:
38
41
  return [{"role": "user", "parts": [{"text": prompt.prompt}]}]
39
42
  messages = []
40
43
  for response in conversation.responses:
41
- messages.append({"role": "user", "parts": [{"text": response.prompt.prompt}]})
44
+ messages.append(
45
+ {"role": "user", "parts": [{"text": response.prompt.prompt}]}
46
+ )
42
47
  messages.append({"role": "model", "parts": [{"text": response.text()}]})
43
48
  messages.append({"role": "user", "parts": [{"text": prompt.prompt}]})
44
49
  return messages
45
50
 
46
51
  def execute(self, prompt, stream, response, conversation):
47
52
  key = llm.get_key("", "gemini", "LLM_GEMINI_KEY")
48
- url = (
49
- "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:streamGenerateContent?"
50
- + urllib.parse.urlencode({"key": key})
53
+ url = "https://generativelanguage.googleapis.com/v1beta/models/{}:streamGenerateContent?".format(
54
+ self.model_id
55
+ ) + urllib.parse.urlencode(
56
+ {"key": key}
51
57
  )
52
58
  gathered = []
59
+ body = {
60
+ "contents": self.build_messages(prompt, conversation),
61
+ "safetySettings": SAFETY_SETTINGS,
62
+ }
63
+ if prompt.system:
64
+ body["systemInstruction"] = {"parts": [{"text": prompt.system}]}
53
65
  with httpx.stream(
54
66
  "POST",
55
67
  url,
56
68
  timeout=None,
57
- json={
58
- "contents": self.build_messages(prompt, conversation),
59
- "safetySettings": SAFETY_SETTINGS,
60
- },
69
+ json=body,
61
70
  ) as http_response:
62
71
  events = ijson.sendable_list()
63
72
  coro = ijson.items_coro(events, "item")
@@ -1,7 +0,0 @@
1
- llm_gemini.py,sha256=n-lPcdPFa3SptnQix4bPNpIGl9RnhL2pDd12NCswdyw,2481
2
- llm_gemini-0.1a0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
3
- llm_gemini-0.1a0.dist-info/METADATA,sha256=jjlN-1dNdsKYtRGC87sPp61mOCJZiwkwVtNJVZHGliw,2122
4
- llm_gemini-0.1a0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
5
- llm_gemini-0.1a0.dist-info/entry_points.txt,sha256=n544bpgUPIBc5l_cnwsTxPc3gMGJHPtAyqBNp-CkMWk,26
6
- llm_gemini-0.1a0.dist-info/top_level.txt,sha256=WUQmG6_2QKbT_8W4HH93qyKl_0SUteL4Ra6_PhyNGKU,11
7
- llm_gemini-0.1a0.dist-info/RECORD,,