Razio05 commited on
Commit
085f1a1
Β·
verified Β·
1 Parent(s): a3275ec

Publish Google GenAI + Pydantic v2 Structured JSON Model Card

Browse files
Files changed (1) hide show
  1. README.md +103 -0
README.md ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - fastapi
5
+ - gemini
6
+ - google-genai
7
+ - pydantic
8
+ - structured-outputs
9
+ - micro-saas
10
+ ---
11
+
12
+ # ⚑ FastAPI + Google Gemini 2026 Structured JSON Blueprint (Python 3.13 Ready)
13
+
14
+ [![CI Passing](https://github.com/RAZIO05/fastapi-gemini-2026-blueprint/actions/workflows/ci.yml/badge.svg)](https://github.com/RAZIO05/fastapi-gemini-2026-blueprint/actions)
15
+ [![Python 3.10-3.13](https://img.shields.io/badge/Python-3.10--3.13-blue.svg)](https://yahiaoui26.gumroad.com/l/fastapi-gemini-blueprint)
16
+ [![FastAPI](https://img.shields.io/badge/FastAPI-Async-009688.svg)](https://yahiaoui26.gumroad.com/l/shipai-pro)
17
+ [![Google Gemini](https://img.shields.io/badge/Google%20Gemini-3.5%20Flash%20JSON-orange.svg)](https://yahiaoui26.gumroad.com/l/shipai-pro)
18
+ [![ShipAI Pro](https://img.shields.io/badge/ShipAI%20v2.0-Commercial%20SaaS%20Engine-brightgreen.svg)](https://yahiaoui26.gumroad.com/l/shipai-pro/LAUNCH20)
19
+
20
+ <p align="center">
21
+ <a href="https://yahiaoui26.gumroad.com/l/shipai-pro/LAUNCH20">
22
+ <img src="https://public-files.gumroad.com/00b6jvp3mssqjd59jm1ax12xa5q9" alt="ShipAI v2.0 β€” FastAPI + Google Gemini Commercial Micro-SaaS Engine" width="100%" />
23
+ </a>
24
+ </p>
25
+
26
+ > **Stop fighting unstructured LLM markdown and Python 3.13 `bcrypt` crashes.**
27
+ > This reference blueprint shows how to wire **FastAPI**, **Pydantic v2**, and the official **`google-genai` SDK** with native `response_mime_type="application/json"` and 3-model automatic failover.
28
+
29
+ ---
30
+
31
+ ## 🎁 Grab the Free 2026 Architecture Cheat Sheet ($0) or Full Commercial Boilerplate
32
+
33
+ * πŸ“˜ **[Download the Free 2026 Architecture Blueprint & Cheat Sheet ($0)](https://yahiaoui26.gumroad.com/l/fastapi-gemini-blueprint)**
34
+ * πŸš€ **[Get ShipAI v2.0 Commercial Engine (20% OFF with code `LAUNCH20`)](https://yahiaoui26.gumroad.com/l/shipai-pro/LAUNCH20)** β€” Includes:
35
+ * πŸ’³ **SaaS Credit Wallet & HTTP 402 Guard** (`app/monetization.py`)
36
+ * πŸ”‘ **Live Gumroad License Key Verification API** (`/api/v1/billing/activate-license`)
37
+ * 🎯 **5 Pre-Built Vertical Micro-SaaS Presets** (AI Startup Validator, Legal Contract Risk Auditor, OWASP Code Security Reviewer, Resume ATS Optimizer, Programmatic SEO Architect)
38
+ * πŸ“Š **Streamlit v2.0 Executive Dashboard** + **Docker Compose Stack**
39
+ * πŸ›‘οΈ **30-Day 100% Risk-Free Money-Back Guarantee**
40
+
41
+ ---
42
+
43
+ ## 1. Enforcing Strict Pydantic v2 JSON with 3-Model Gemini Failover
44
+
45
+ ```python
46
+ import os, json
47
+ from google import genai
48
+ from pydantic import BaseModel
49
+ from typing import List
50
+
51
+ client = genai.Client(api_key=os.getenv("GEMINI_API_KEY"))
52
+
53
+ DEFAULT_MODELS = [
54
+ os.getenv("GEMINI_MODEL", "gemini-3.5-flash"),
55
+ "gemini-flash-lite-latest",
56
+ "gemini-3.8-flash",
57
+ ]
58
+
59
+ class AIStructuredResponse(BaseModel):
60
+ status: str
61
+ summary: str
62
+ key_points: List[str]
63
+ action_items: List[str]
64
+
65
+ def generate_structured_json(prompt: str, system_instruction: str) -> AIStructuredResponse:
66
+ for model_name in DEFAULT_MODELS:
67
+ try:
68
+ res = client.models.generate_content(
69
+ model=model_name,
70
+ contents=prompt,
71
+ config={
72
+ "response_mime_type": "application/json",
73
+ "system_instruction": system_instruction,
74
+ },
75
+ )
76
+ return AIStructuredResponse(**json.loads(res.text))
77
+ except Exception as err:
78
+ if any(code in str(err) for code in ("404", "503", "UNAVAILABLE", "NOT_FOUND")):
79
+ continue
80
+ raise
81
+ ```
82
+
83
+ ## 2. Fixing the Python 3.12 / 3.13 `passlib[bcrypt]` 72-Byte Startup Crash
84
+
85
+ Pin `bcrypt==4.0.1` alongside `passlib[bcrypt]` in `requirements.txt` to avoid the `ValueError: password cannot be longer than 72 bytes` exception during container boot:
86
+
87
+ ```txt
88
+ fastapi
89
+ uvicorn
90
+ google-genai
91
+ pydantic[email]
92
+ passlib[bcrypt]
93
+ bcrypt==4.0.1
94
+ python-jose[cryptography]
95
+ ```
96
+
97
+ ---
98
+
99
+ ## πŸš€ Want the Complete Production Micro-SaaS Repository?
100
+
101
+ Skip 35+ hours of wiring JWT auth, SaaS credit quotas, Gumroad license verification, Streamlit UI, automated tests, and Docker Compose:
102
+
103
+ πŸ‘‰ **[Explore the Live Interactive Demo & Get ShipAI v2.0 on Gumroad](https://yahiaoui26.gumroad.com/l/shipai-pro/LAUNCH20)**