Skip to content

Commit e3cd44d

Browse files
committed
updated examples with gemini 2.5_pro
1 parent e621e03 commit e3cd44d

3 files changed

Lines changed: 17 additions & 20 deletions

File tree

examples/example_4_gemini_memory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
Usage:
88
export GEMINI_API_KEY=your_api_key
9-
python examples/example_5_gemini_memory.py
9+
python examples/example_4_gemini_memory.py
1010
"""
1111

1212
import asyncio
@@ -53,7 +53,7 @@ async def main():
5353
3. Extracts memory categories from conversations
5454
4. Outputs the categories to files
5555
"""
56-
print("Example 5: Conversation Memory Processing (Google Gemini)")
56+
print("Example 4: Conversation Memory Processing (Google Gemini)")
5757
print("-" * 55)
5858

5959
api_key = os.getenv("GEMINI_API_KEY")
@@ -69,7 +69,7 @@ async def main():
6969
"client_backend": "httpx",
7070
"base_url": "https://generativelanguage.googleapis.com/v1beta",
7171
"api_key": api_key,
72-
"chat_model": "gemini-2.5-flash", # Fast and capable model
72+
"chat_model": "gemini-2.5-pro", # Fast and capable model
7373
"embed_model": "text-embedding-004", # Gemini's embedding model
7474
},
7575
},

src/memu/llm/backends/gemini.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class GeminiLLMBackend(LLMBackend):
99
"""Backend for Google Gemini LLM API.
10-
10+
1111
Gemini uses a different API format than OpenAI-compatible APIs:
1212
- Endpoint: /models/{model}:generateContent
1313
- Auth: x-goog-api-key header
@@ -22,36 +22,33 @@ def build_summary_payload(
2222
) -> dict[str, Any]:
2323
"""Build payload for Gemini generateContent API."""
2424
contents: list[dict[str, Any]] = []
25-
25+
2626
# Add user message
2727
contents.append({
2828
"role": "user",
2929
"parts": [{"text": text}]
3030
})
31-
31+
3232
payload: dict[str, Any] = {
3333
"contents": contents,
3434
}
35-
35+
3636
# Add system instruction if provided
37+
# Note: When system_prompt is None, we don't set a default to allow the user prompt
38+
# to fully control the output format (e.g., for JSON responses)
3739
if system_prompt:
3840
payload["system_instruction"] = {
3941
"parts": [{"text": system_prompt}]
4042
}
41-
else:
42-
# Default system prompt for summarization
43-
payload["system_instruction"] = {
44-
"parts": [{"text": "Summarize the text in one short paragraph."}]
45-
}
46-
43+
4744
# Add generation config
4845
generation_config: dict[str, Any] = {
4946
"temperature": 1.0, # Gemini recommends keeping at 1.0
5047
}
5148
if max_tokens is not None:
5249
generation_config["maxOutputTokens"] = max_tokens
5350
payload["generationConfig"] = generation_config
54-
51+
5552
return payload
5653

5754
def parse_summary_response(self, data: dict[str, Any]) -> str:
@@ -83,30 +80,30 @@ def build_vision_payload(
8380
}
8481
},
8582
]
86-
83+
8784
contents: list[dict[str, Any]] = [
8885
{
8986
"role": "user",
9087
"parts": user_parts,
9188
}
9289
]
93-
90+
9491
payload: dict[str, Any] = {
9592
"contents": contents,
9693
}
97-
94+
9895
# Add system instruction if provided
9996
if system_prompt:
10097
payload["system_instruction"] = {
10198
"parts": [{"text": system_prompt}]
10299
}
103-
100+
104101
# Add generation config
105102
generation_config: dict[str, Any] = {
106103
"temperature": 1.0,
107104
}
108105
if max_tokens is not None:
109106
generation_config["maxOutputTokens"] = max_tokens
110107
payload["generationConfig"] = generation_config
111-
108+
112109
return payload

src/memu/llm/http_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def parse_embedding_response(self, data: dict[str, Any]) -> list[list[float]]:
4949

5050
class _GeminiEmbeddingBackend(_EmbeddingBackend):
5151
"""Gemini embedding API backend.
52-
52+
5353
Gemini uses a different format:
5454
- Endpoint: /models/{model}:embedContent
5555
- Single text per request (batch supported via batchEmbedContents)

0 commit comments

Comments
 (0)