Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ MACA currently uses Gemini for medium and above tasks. For secure setup details,
```bash
export GEMINI_API_KEY="your-gemini-api-key"
```

You can optionally customize the Gemini model and request timeout (in seconds):
```bash
export GEMINI_MODEL="gemini-3.5-flash"
export GEMINI_TIMEOUT_SECONDS="45"
```
* **Recommended macOS Keychain + .zshenv Setup**:
```bash
security add-generic-password -a "$USER" -s "MACA_GEMINI_API_KEY" -w "your-gemini-key"
Expand Down
6 changes: 6 additions & 0 deletions src/maca/maca_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ def get_gemini_api_key():
OLLAMA_API_URL = os.environ.get("OLLAMA_API_URL", "http://localhost:11434")
OLLAMA_MODEL = os.environ.get("OLLAMA_MODEL", "gemma2:2b")

GEMINI_MODEL = os.environ.get("GEMINI_MODEL", "gemini-3.5-flash")
try:
GEMINI_TIMEOUT_SECONDS = float(os.environ.get("GEMINI_TIMEOUT_SECONDS", "45"))
except ValueError:
GEMINI_TIMEOUT_SECONDS = 45.0

# If set to True, will mock Gemma/Gemini calls if unavailable/unconfigured
MOCK_GEMMA_FALLBACK = os.environ.get("MOCK_GEMMA_FALLBACK", "True").lower() == "true"

Expand Down
5 changes: 3 additions & 2 deletions src/maca/models/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
class GeminiClient:
def __init__(self):
self.api_key = config.get_gemini_api_key()
self.model = "gemini-3.5-flash"
self.model = config.GEMINI_MODEL
self.timeout = config.GEMINI_TIMEOUT_SECONDS

def generate(self, prompt, system_instruction=""):
if not self.api_key:
Expand Down Expand Up @@ -42,7 +43,7 @@ def generate(self, prompt, system_instruction=""):
headers={"Content-Type": "application/json"},
method="POST"
)
with urllib.request.urlopen(req, timeout=45, context=ssl_context) as response:
with urllib.request.urlopen(req, timeout=self.timeout, context=ssl_context) as response:
res = json.loads(response.read().decode("utf-8"))
# Extract response text
candidates = res.get("candidates", [])
Expand Down
13 changes: 13 additions & 0 deletions tests/test_behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ def test_local_gemma_client_falls_back_to_cli(self):
self.assertEqual(result, "CLI response")
run_mock.assert_called_once()

def test_gemini_config_uses_maca_config(self):
old_model = config.GEMINI_MODEL
old_timeout = config.GEMINI_TIMEOUT_SECONDS
try:
config.GEMINI_MODEL = "gemini-test-model"
config.GEMINI_TIMEOUT_SECONDS = 12.5
client = GeminiClient()
self.assertEqual(client.model, "gemini-test-model")
self.assertEqual(client.timeout, 12.5)
finally:
config.GEMINI_MODEL = old_model
config.GEMINI_TIMEOUT_SECONDS = old_timeout


if __name__ == "__main__":
unittest.main()
Loading