7zon-cli 0.2.6__tar.gz → 0.2.7__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.
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/PKG-INFO +1 -1
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/pyproject.toml +1 -1
- 7zon_cli-0.2.7/src/zon7/__init__.py +1 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/src/zon7/providers/gemini.py +50 -24
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/tests/test_gemini.py +34 -2
- 7zon_cli-0.2.6/src/zon7/__init__.py +0 -1
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/.github/workflows/ci.yml +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/.github/workflows/publish.yml +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/.gitignore +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/LICENSE +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/README.md +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/install-termux.sh +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/src/zon7/__main__.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/src/zon7/ai.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/src/zon7/banner.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/src/zon7/cli.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/src/zon7/common.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/src/zon7/config.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/src/zon7/context.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/src/zon7/instagram.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/src/zon7/memory.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/src/zon7/menu.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/src/zon7/prompts.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/src/zon7/providers/__init__.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/src/zon7/providers/claude.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/src/zon7/safety.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/src/zon7/secrets.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/src/zon7/shell.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/src/zon7/tools.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/tests/test_cli.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/tests/test_config.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/tests/test_context.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/tests/test_instagram.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/tests/test_memory.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/tests/test_menu.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/tests/test_powershell_real.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/tests/test_safety.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/tests/test_secrets.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/tests/test_shell.py +0 -0
- {7zon_cli-0.2.6 → 7zon_cli-0.2.7}/tests/test_tools.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: 7zon-cli
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.7
|
|
4
4
|
Summary: 7ZON — terminalda ishlaydigan AI yordamchi: buyruq yozadi, xatolarni tuzatadi, tushuntiradi.
|
|
5
5
|
Project-URL: Homepage, https://github.com/7zon-uz/7ZON-CLI
|
|
6
6
|
Project-URL: Issues, https://github.com/7zon-uz/7ZON-CLI/issues
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.7"
|
|
@@ -10,6 +10,7 @@ from __future__ import annotations
|
|
|
10
10
|
import base64
|
|
11
11
|
import json
|
|
12
12
|
import os
|
|
13
|
+
import re
|
|
13
14
|
import time
|
|
14
15
|
import urllib.error
|
|
15
16
|
import urllib.request
|
|
@@ -390,39 +391,64 @@ class Agent:
|
|
|
390
391
|
# --------------------------------------------------------------------------- rasm yaratish
|
|
391
392
|
|
|
392
393
|
IMAGE_MODELS = ("gemini-3-pro-image", "gemini-3.1-flash-image", "gemini-2.5-flash-image")
|
|
393
|
-
|
|
394
|
-
"
|
|
395
|
-
"
|
|
394
|
+
FREE_TIER_HINT = (
|
|
395
|
+
"Bu API kalit Google'da BEPUL tarifda ishlayapti (Google javobida \"Free Tier\" deb yozilgan), "
|
|
396
|
+
"bepul tarifda esa rasm modellari yopiq. Diqqat: Google AI Pro / Ultra obunasi faqat Gemini ilovasi uchun, "
|
|
397
|
+
"API kalitni pullik qilmaydi. API uchun billing alohida yoqiladi: https://aistudio.google.com/apikey → "
|
|
398
|
+
"kalitingiz turgan loyiha → \"Set up billing\". Pullik loyihadagi boshqa kalitingiz bo'lsa, chatda /key "
|
|
399
|
+
"deb yozib o'shani kiriting."
|
|
396
400
|
)
|
|
401
|
+
RATE_LIMIT_HINT = "Rasm modellari hozir limitga yetdi (pullik tarif, daqiqalik limit). Bir daqiqadan keyin qayta urinib ko'ring."
|
|
402
|
+
MAX_RETRY_WAIT = 60
|
|
403
|
+
_sleep = time.sleep # testlarda almashtiriladi
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
def _retry_delay(message: str) -> float | None:
|
|
407
|
+
m = re.search(r'"retryDelay":\s*"(\d+(?:\.\d+)?)s"', message)
|
|
408
|
+
return float(m.group(1)) if m else None
|
|
397
409
|
|
|
398
410
|
|
|
399
411
|
def generate_image(cfg: dict[str, Any], prompt: str, aspect_ratio: str = "1:1") -> tuple[bytes, str, str]:
|
|
400
|
-
"""Gemini rasm modeli bilan rasm yaratadi: (baytlar, mime, model). Eng sifatli modeldan boshlanadi.
|
|
412
|
+
"""Gemini rasm modeli bilan rasm yaratadi: (baytlar, mime, model). Eng sifatli modeldan boshlanadi.
|
|
413
|
+
|
|
414
|
+
429 ikki xil bo'ladi: kalit bepul tarifda (javobda "FreeTier") yoki pullik kalitning daqiqalik limiti.
|
|
415
|
+
Ikkinchisida Google aytgan vaqtcha kutib, yana bir marta urinamiz.
|
|
416
|
+
"""
|
|
401
417
|
key = _api_key(cfg)
|
|
402
418
|
body = {
|
|
403
419
|
"contents": [{"role": "user", "parts": [{"text": prompt}]}],
|
|
404
420
|
"generationConfig": {"responseModalities": ["IMAGE", "TEXT"], "imageConfig": {"aspectRatio": aspect_ratio}},
|
|
405
421
|
}
|
|
406
|
-
|
|
422
|
+
free_tier = rate_limited = False
|
|
407
423
|
last: GeminiError | None = None
|
|
408
424
|
for model in IMAGE_MODELS:
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
425
|
+
for attempt in range(2):
|
|
426
|
+
try:
|
|
427
|
+
data = _http_post(f"{API_BASE}/{model}:generateContent", key, body)
|
|
428
|
+
except GeminiError as e:
|
|
429
|
+
last = e
|
|
430
|
+
if e.code == 429:
|
|
431
|
+
if "FreeTier" in e.message or "free_tier" in e.message:
|
|
432
|
+
free_tier = True
|
|
433
|
+
break
|
|
434
|
+
rate_limited = True
|
|
435
|
+
delay = _retry_delay(e.message)
|
|
436
|
+
if attempt == 0 and delay is not None and delay <= MAX_RETRY_WAIT:
|
|
437
|
+
_sleep(delay + 1)
|
|
438
|
+
continue
|
|
439
|
+
break
|
|
440
|
+
if e.code in (404, 500, 502, 503, 504):
|
|
441
|
+
break
|
|
442
|
+
raise
|
|
443
|
+
for cand in data.get("candidates", []):
|
|
444
|
+
for part in (cand.get("content") or {}).get("parts", []):
|
|
445
|
+
inline = part.get("inlineData")
|
|
446
|
+
if inline and inline.get("data"):
|
|
447
|
+
return base64.b64decode(inline["data"]), inline.get("mimeType", "image/png"), model
|
|
448
|
+
reason = (data.get("candidates") or [{}])[0].get("finishReason", "") or "sabab noma'lum"
|
|
449
|
+
raise AIError(f"Model rasm qaytarmadi ({reason}). So'rovni boshqacha yozib ko'ring.")
|
|
450
|
+
if rate_limited:
|
|
451
|
+
raise AIError(RATE_LIMIT_HINT)
|
|
452
|
+
if free_tier:
|
|
453
|
+
raise AIError(FREE_TIER_HINT)
|
|
428
454
|
raise AIError(f"Rasm yaratib bo'lmadi: {last}")
|
|
@@ -229,10 +229,11 @@ def test_generate_image_falls_back_and_reports_billing(monkeypatch):
|
|
|
229
229
|
|
|
230
230
|
def fake_post(url, key, body, stream=False):
|
|
231
231
|
tried.append(url.rsplit("/", 1)[1])
|
|
232
|
-
raise gemini.GeminiError(429, "RESOURCE_EXHAUSTED",
|
|
232
|
+
raise gemini.GeminiError(429, "RESOURCE_EXHAUSTED",
|
|
233
|
+
'quota [{"quotaId": "GenerateRequestsPerDayPerProjectPerModel-FreeTier"}]')
|
|
233
234
|
|
|
234
235
|
monkeypatch.setattr(gemini, "_http_post", fake_post)
|
|
235
|
-
with pytest.raises(AIError, match="
|
|
236
|
+
with pytest.raises(AIError, match="BEPUL tarifda"):
|
|
236
237
|
gemini.generate_image({"gemini_api_key": "k" * 30}, "logo")
|
|
237
238
|
assert len(tried) == len(gemini.IMAGE_MODELS)
|
|
238
239
|
|
|
@@ -250,3 +251,34 @@ def test_generate_image_returns_bytes(monkeypatch):
|
|
|
250
251
|
monkeypatch.setattr(gemini, "_http_post", fake_post)
|
|
251
252
|
assert gemini.generate_image({"gemini_api_key": "k" * 30}, "logo", "16:9") == (b"IMG", "image/png",
|
|
252
253
|
gemini.IMAGE_MODELS[0])
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def test_generate_image_paid_rate_limit_waits_and_retries(monkeypatch):
|
|
257
|
+
import base64
|
|
258
|
+
|
|
259
|
+
from zon7.providers import gemini
|
|
260
|
+
|
|
261
|
+
calls, slept = [], []
|
|
262
|
+
|
|
263
|
+
def fake_post(url, key, body, stream=False):
|
|
264
|
+
calls.append(url)
|
|
265
|
+
if len(calls) == 1:
|
|
266
|
+
raise gemini.GeminiError(429, "RESOURCE_EXHAUSTED",
|
|
267
|
+
'rate [{"@type": "RetryInfo", "retryDelay": "7s"}]')
|
|
268
|
+
return {"candidates": [{"content": {"parts": [{"inlineData": {
|
|
269
|
+
"mimeType": "image/png", "data": base64.b64encode(b"IMG").decode()}}]}}]}
|
|
270
|
+
|
|
271
|
+
monkeypatch.setattr(gemini, "_http_post", fake_post)
|
|
272
|
+
monkeypatch.setattr(gemini, "_sleep", slept.append)
|
|
273
|
+
assert gemini.generate_image({"gemini_api_key": "k" * 30}, "logo")[0] == b"IMG"
|
|
274
|
+
assert slept == [8.0] and len(calls) == 2
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def test_generate_image_paid_rate_limit_message(monkeypatch):
|
|
278
|
+
from zon7.common import AIError
|
|
279
|
+
from zon7.providers import gemini
|
|
280
|
+
|
|
281
|
+
monkeypatch.setattr(gemini, "_http_post", lambda *a, **k: (_ for _ in ()).throw(
|
|
282
|
+
gemini.GeminiError(429, "RESOURCE_EXHAUSTED", "rate limit")))
|
|
283
|
+
with pytest.raises(AIError, match="pullik tarif"):
|
|
284
|
+
gemini.generate_image({"gemini_api_key": "k" * 30}, "logo")
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.2.6"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|