gemconnect 1.2.0__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.
@@ -0,0 +1,9 @@
1
+ from .connector import ask_gemini
2
+ __version__ = "1.0.0"
3
+
4
+ def list_models(client):
5
+ print("The available Gemini Models are:")
6
+ for model in client.models.list():
7
+ print(model.name)
8
+
9
+
@@ -0,0 +1,39 @@
1
+ # connector.py
2
+
3
+ from .errors import error_simplify # imports your errors file
4
+ def ask_gemini(prompt, client, model):
5
+
6
+ # Check 1 — empty prompt
7
+
8
+ if prompt is None:
9
+ return "Your prompt is None. Please pass a text string like ask_gemini('hello', client, model)."
10
+
11
+ if prompt.strip() == "":
12
+ return "Your prompt is empty. Please type something before sending."
13
+
14
+ # Check 2 — non-string prompt
15
+ if not isinstance(prompt, str):
16
+ return "Your prompt must be plain text. You passed a " + type(prompt).__name__ + " instead of a string."
17
+
18
+ # Check 3 — client looks wrong
19
+
20
+ if isinstance(client, str):
21
+ return "You passed a string as the client. You need to create a proper Gemini client first using genai.Client(api_key=...)."
22
+
23
+ if client is None:
24
+ return "Your Gemini client is None. Make sure you created it using genai.Client(api_key=...) before calling ask_gemini()."
25
+ if model is None:
26
+ return "You forgot to pass a model name. Try ask_gemini(prompt, client, 'gemini-2.0-flash')."
27
+
28
+ if not isinstance(model, str):
29
+ return "Your model name must be a string like 'gemini-2.0-flash'. You passed a " + type(model).__name__ + " instead."
30
+
31
+ if model.strip() == "":
32
+ return "Your model name is empty. Try ask_gemini(prompt, client, 'gemini-2.0-flash')."
33
+
34
+ # rest of your existing code...
35
+ try:
36
+ response = client.models.generate_content(model=model, contents=prompt)
37
+ return response.text
38
+ except Exception as e:
39
+ return error_simplify(str(e))
@@ -0,0 +1,188 @@
1
+ '''
2
+ scary errors=> string
3
+
4
+ if you find anyof the key from the dict in the string.
5
+ then return the values.
6
+
7
+ we use dictory to store the key and value pair.
8
+ '''
9
+ keyword = {
10
+
11
+ ### Package setup
12
+ 'FutureWarning':
13
+ "Your Gemini package is old. Open your terminal and run: pip install --upgrade google-generativeai",
14
+
15
+ ### Flask setup
16
+ 'ERR_CONNECTION_REFUSED':
17
+ "Your Flask server is not running. Go to your terminal and run your app.py file first, then try again.",
18
+
19
+ 'TemplateNotFound':
20
+ "Flask cannot find your HTML file. Make sure your HTML file is inside a folder named exactly 'templates' (no capital letters, no spaces).",
21
+
22
+ 'jinja2':
23
+ "There is a mistake inside your HTML file. Open index.html and look for any {{ }} or {% %} blocks — one of them has a typo.",
24
+
25
+ ### API Key
26
+ 'invalid api key':
27
+ "Your API key is wrong. Go to aistudio.google.com/apikey, copy your key again and paste it carefully — even one wrong character breaks it.",
28
+
29
+ 'API key not found':
30
+ "You forgot to add your API key. Go to aistudio.google.com/apikey, copy your key and paste it where the client is set up in your code.",
31
+
32
+ '401 Unauthorized':
33
+ "Gemini does not recognize you. Your API key is either wrong, expired, or missing. Go to aistudio.google.com/apikey and get a fresh one.",
34
+
35
+ ### Quota and model
36
+ 'limit: 0':
37
+ "This Gemini model has no free quota left. Run list_models() to see other models or go to ai.dev/rate-limit to find one with free quota.",
38
+
39
+ 'RESOURCE_EXHAUSTED':
40
+ "You have used up all your free Gemini quota. Go to aistudio.google.com/apikey, create a brand new project and generate a new API key from there.",
41
+
42
+ '429 Too Many Requests':
43
+ "You sent too many requests too fast. Wait 30-60 seconds and try again.",
44
+
45
+ '403 Forbidden':
46
+ "Your account does not have permission to use this model. Try a different model like 'gemini-2.0-flash' which is free for everyone.",
47
+
48
+ '404 models':
49
+ "The model name you typed does not exist. Run list_models() to see the exact names and copy-paste one of those.",
50
+
51
+ ### Gemini server errors
52
+ 'InternalServerError':
53
+ "Something crashed on Gemini's side — this is not your fault. Wait a minute and try the exact same request again.",
54
+
55
+ '502':
56
+ "Gemini's servers are not communicating right now. Wait 2-3 minutes and try again.",
57
+
58
+ '503 UNAVAILABLE':
59
+ "Too many people are using Gemini right now. Wait a few minutes and try again.",
60
+
61
+ '504 Timeout':
62
+ "Gemini took too long to reply. Wait a moment and try again.",
63
+
64
+ ### Request errors
65
+ 'PayloadTooLarge':
66
+ "Your prompt is too long. Try splitting it into smaller pieces and sending one part at a time.",
67
+
68
+ 'DeadlineExceeded':
69
+ "Your request took too long. Check your internet connection and try again.",
70
+
71
+ 'UnprocessableEntity':
72
+ "Gemini did not understand how your request was structured. Make sure you are passing the prompt as a plain string and not inside a list or dict.",
73
+
74
+ ### Safety
75
+ 'safety filters':
76
+ "Gemini blocked your prompt because it triggered its safety rules. Try rewriting your question in a more neutral way.",
77
+
78
+ ### Frontend
79
+ 'blocked by CORS policy':
80
+ "Your browser is blocking the request because your frontend and backend are on different ports. Install flask-cors and add CORS(app) to your Flask file.",
81
+
82
+ 'SyntaxError: Unexpected token':
83
+ "Your Flask server crashed and sent back an error page instead of data. Check your terminal — the real error is printed there.",
84
+
85
+ '400 Bad Request':
86
+ "The data you sent does not match what Flask expected. Make sure the key name in your JavaScript fetch matches exactly what you use in request.json in Flask.",
87
+
88
+ 'invalid api key':
89
+ "Your API key is wrong. Go to aistudio.google.com/apikey, copy your key again and paste it carefully — even one wrong character breaks it.",
90
+
91
+ ### Install errors
92
+ 'ModuleNotFoundError':
93
+ "A required package is not installed. Open your terminal and run: pip install google-generativeai",
94
+
95
+ 'No module named':
96
+ "A required package is not installed. Open your terminal and run: pip install google-generativeai",
97
+
98
+ ### Network errors
99
+ 'ConnectionError':
100
+ "Could not reach Gemini. Check your internet connection and try again.",
101
+
102
+ 'SSLError':
103
+ "A secure connection to Gemini failed. Check your internet or try a different network.",
104
+
105
+ 'NewConnectionError':
106
+ "No internet connection found. Make sure you are connected to the internet and try again.",
107
+ }
108
+
109
+
110
+ synonyms = {
111
+ # Quota
112
+ 'quota': 'RESOURCE_EXHAUSTED',
113
+ 'exhausted': 'RESOURCE_EXHAUSTED',
114
+ 'resource exhausted': 'RESOURCE_EXHAUSTED',
115
+
116
+ # Rate limit
117
+ 'rate limit': '429 Too Many Requests',
118
+ 'too many': '429 Too Many Requests',
119
+
120
+ # Permission
121
+ 'permission denied': '403 Forbidden',
122
+ 'PERMISSIO DENIED': '403 Forbidden',
123
+ 'access denied': '403 Forbidden',
124
+ 'forbidden': '403 Forbidden',
125
+
126
+ # Model
127
+ 'model not found': '404 models',
128
+ 'not_found': '404 models',
129
+
130
+ # Timeout
131
+ 'timeout': '504 Timeout',
132
+ 'timed out': '504 Timeout',
133
+ 'deadline': 'DeadlineExceeded',
134
+
135
+ # Payload
136
+ 'payload too large': 'PayloadTooLarge',
137
+ 'prompt too long': 'PayloadTooLarge',
138
+
139
+ # Frontend
140
+ 'cors': 'blocked by CORS policy',
141
+ 'cross-origin': 'blocked by CORS policy',
142
+
143
+ # Template
144
+ 'template': 'TemplateNotFound',
145
+
146
+ # Safety
147
+ 'safety': 'safety filters',
148
+ 'blocked': 'safety filters',
149
+
150
+ # Auth
151
+ 'invalid key': 'invalid api key',
152
+ 'API_KEY_INVALID': 'invalid api key',
153
+ 'API key not valid': 'invalid api key',
154
+ 'unauthorized': '401 Unauthorized',
155
+
156
+ # Request
157
+ 'bad request': '400 Bad Request',
158
+
159
+ # Server
160
+ 'server error': 'InternalServerError',
161
+ 'internal error': 'InternalServerError',
162
+ 'bad gateway': '502',
163
+ 'service unavailable': '503 UNAVAILABLE',
164
+
165
+ # Connection
166
+ 'connection refused': 'ERR_CONNECTION_REFUSED',
167
+
168
+ # Package
169
+ 'deprecated': 'FutureWarning',
170
+ 'outdated': 'FutureWarning',
171
+ }
172
+
173
+
174
+ def error_simplify(s):
175
+ s_lower = s.lower()
176
+
177
+ # Layer 1 — direct keyword match
178
+ for k in keyword:
179
+ if k.lower() in s_lower:
180
+ return f"**{keyword[k]}**\n\nRaw technical error:\n{s}"
181
+
182
+ # Layer 2 — synonym match
183
+ for alias in synonyms:
184
+ if alias.lower() in s_lower: # ← add .lower() here
185
+ mapped_key = synonyms[alias]
186
+ return f"**{keyword[mapped_key]}**\n\nRaw technical error:\n{s}"
187
+ # Nothing matched
188
+ return f"**GemConnect could not simplify this error.**\n\nHere is the raw error for you to search online:\n{s}"
@@ -0,0 +1,306 @@
1
+ Metadata-Version: 2.4
2
+ Name: gemconnect
3
+ Version: 1.2.0
4
+ Summary: gemconnect sits between Flask and Gemini, calls the API safely, and if anything goes wrong translates the scary technical error into a simple message the beginner can understand and fix.
5
+ Author-email: Divya P <divyaprofessional416@email.com>
6
+ Project-URL: Homepage, https://github.com/DIVICODER/gemconnect-lib-
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Dynamic: license-file
11
+
12
+ # GemConnect
13
+
14
+ **GemConnect sits between Flask and Gemini, calls the API safely, and if anything goes wrong, translates the scary technical error into a simple message the beginner can understand and fix.**
15
+
16
+ ---
17
+
18
+ ## The Problem
19
+
20
+ As an engineer, it felt fascinating to connect upcoming trends like AI into a website and see it work. Getting Gemini to respond in the terminal felt exciting. But when I tried to connect it with the frontend, it once again felt like zero.
21
+
22
+ Errors kept coming when interconnecting the frontend with Flask. Initially I tried to debug on my own, but it reached a threshold where I shifted from being curious and excited to a mood of just finishing what I had started. I kept copy-pasting the error to an AI bot to debug. Sometimes it worked, sometimes it didn't. But whether it worked or not, I hadn't been able to debug the error myself.
23
+
24
+ The errors were in technical terms like "404" — like these types of numbers. And in some cases it would show a scary list of errors and say "JSON error" like that, making it difficult to understand what went wrong and where.
25
+
26
+ What I needed was an error document to understand each error. That problem led to the creation of this library.
27
+
28
+ ---
29
+
30
+ ## What GemConnect Does
31
+
32
+ GemConnect gets the scary error and converts it into a human-understandable message for easy debugging.
33
+
34
+ ```
35
+ WITHOUT GemConnect:
36
+ Flask → Gemini → 😵 Scary JSON error dump → Beginner gives up
37
+
38
+ WITH GemConnect:
39
+ Flask → GemConnect → Gemini → ❌ Error?
40
+
41
+ "Hey! Your API key looks wrong.
42
+ Go to aistudio.google.com/apikey and get a fresh one."
43
+ ```
44
+
45
+ ---
46
+
47
+ ## Who Is This For
48
+
49
+ Beginners who are really interested in frontend connectivity with AI services but get scared seeing those errors and not knowing how to solve them.
50
+
51
+ ---
52
+
53
+ ## Requirements
54
+
55
+ Before using GemConnect, install the Gemini package:
56
+
57
+ ```
58
+ pip install google-genai
59
+ ```
60
+
61
+ GemConnect itself has zero dependencies. You are responsible for creating and passing the Gemini client.
62
+
63
+ ---
64
+
65
+ ## Installation
66
+
67
+ ```
68
+ pip install gemconnect
69
+ ```
70
+
71
+ ---
72
+
73
+ ## How To Use
74
+
75
+ ```python
76
+ from google import genai
77
+ from gemconnect import ask_gemini
78
+
79
+ # you bring your own client
80
+ client = genai.Client(api_key="YOUR_API_KEY")
81
+
82
+ # one line to call Gemini safely
83
+ result = ask_gemini("What is Python?", client, "gemini-2.5-flash")
84
+ print(result)
85
+ ```
86
+
87
+ ---
88
+
89
+ ## Input Validation
90
+
91
+ GemConnect checks your inputs before even calling Gemini. If something is wrong it tells you immediately in plain English:
92
+
93
+ ```python
94
+ ask_gemini(None, client, model)
95
+ # → "Your prompt is None. Please pass a text string like ask_gemini('hello', client, model)."
96
+
97
+ ask_gemini("", client, model)
98
+ # → "Your prompt is empty. Please type something before sending."
99
+
100
+ ask_gemini(["hello"], client, model)
101
+ # → "Your prompt must be plain text. You passed a list instead of a string."
102
+
103
+ ask_gemini(prompt, None, model)
104
+ # → "Your Gemini client is None. Make sure you created it using genai.Client(api_key=...)."
105
+
106
+ ask_gemini(prompt, client, None)
107
+ # → "You forgot to pass a model name. Try ask_gemini(prompt, client, 'gemini-2.0-flash')."
108
+
109
+ ask_gemini(prompt, client, "")
110
+ # → "Your model name is empty. Try ask_gemini(prompt, client, 'gemini-2.0-flash')."
111
+ ```
112
+
113
+ ---
114
+
115
+ ## How It Works Inside
116
+
117
+ ```
118
+ User writes ask_gemini()
119
+
120
+ connector.py runs input checks
121
+
122
+ ┌─────────────────────────┐
123
+ │ │
124
+ checks pass checks fail
125
+ │ │
126
+ ↓ ↓
127
+ calls Gemini API friendly message
128
+ │ returned to user
129
+
130
+ ┌─────────────┐
131
+ │ │
132
+ SUCCESS ERROR
133
+ │ │
134
+ ↓ ↓
135
+ response.text errors.py
136
+ │ │
137
+ ↓ ↓ Layer 1 — keyword match
138
+ returned errors.py
139
+ to user │
140
+ ↓ Layer 2 — synonym match
141
+
142
+
143
+ simple message
144
+ returned to user
145
+ ```
146
+
147
+ ---
148
+
149
+ ## Real Project Example — Chatbot
150
+
151
+ ```python
152
+ # BEFORE GemConnect — scary errors possible
153
+ response = client.models.generate_content(
154
+ model="gemini-2.5-flash",
155
+ contents=conversation
156
+ )
157
+ ai_reply = response.text
158
+
159
+
160
+ # AFTER GemConnect — one line, errors handled
161
+ from gemconnect import ask_gemini
162
+
163
+ ai_reply = ask_gemini(conversation, client, "gemini-2.5-flash")
164
+ ```
165
+
166
+ ---
167
+
168
+ ## What Errors GemConnect Covers
169
+
170
+ Every error message inside GemConnect was collected from real beginner projects. Two layers of matching make sure as many errors as possible are caught.
171
+
172
+ ### Setup Errors
173
+ ```
174
+ ❌ jinja2.exceptions.TemplateNotFound
175
+ ✅ Flask cannot find your HTML file. Make sure your HTML file is inside
176
+ a folder named exactly 'templates' (no capital letters, no spaces).
177
+
178
+ ❌ ERR_CONNECTION_REFUSED
179
+ ✅ Your Flask server is not running. Go to your terminal and run your
180
+ app.py file first, then try again.
181
+
182
+ ❌ FutureWarning: google.generativeai has ended
183
+ ✅ Your Gemini package is old. Open your terminal and run:
184
+ pip install --upgrade google-generativeai
185
+ ```
186
+
187
+ ### Install Errors
188
+ ```
189
+ ❌ ModuleNotFoundError: No module named 'google.generativeai'
190
+ ✅ A required package is not installed. Open your terminal and run:
191
+ pip install google-generativeai
192
+ ```
193
+
194
+ ### API Key Errors
195
+ ```
196
+ ❌ 401 Unauthorized
197
+ ✅ Gemini does not recognize you. Your API key is either wrong, expired,
198
+ or missing. Go to aistudio.google.com/apikey and get a fresh one.
199
+
200
+ ❌ API key not valid. Please pass a valid API key.
201
+ ✅ Your API key is wrong. Go to aistudio.google.com/apikey, copy your
202
+ key again and paste it carefully — even one wrong character breaks it.
203
+ ```
204
+
205
+ ### Quota Errors
206
+ ```
207
+ ❌ RESOURCE_EXHAUSTED
208
+ ✅ You have used up all your free Gemini quota. Go to
209
+ aistudio.google.com/apikey, create a brand new project and generate
210
+ a new API key from there.
211
+
212
+ ❌ 429 Too Many Requests
213
+ ✅ You sent too many requests too fast. Wait 30-60 seconds and try again.
214
+ ```
215
+
216
+ ### Model Errors
217
+ ```
218
+ ❌ 404 models/gemini-1.5-flash is not found
219
+ ✅ The model name you typed does not exist. Run list_models() to see the
220
+ exact names and copy-paste one of those.
221
+ ```
222
+
223
+ ### Gemini Server Errors
224
+ ```
225
+ ❌ InternalServerError
226
+ ✅ Something crashed on Gemini's side — this is not your fault.
227
+ Wait a minute and try the exact same request again.
228
+
229
+ ❌ 503 UNAVAILABLE
230
+ ✅ Too many people are using Gemini right now. Wait a few minutes and try again.
231
+
232
+ ❌ 504 Timeout
233
+ ✅ Gemini took too long to reply. Wait a moment and try again.
234
+ ```
235
+
236
+ ### Network Errors
237
+ ```
238
+ ❌ ConnectionError
239
+ ✅ Could not reach Gemini. Check your internet connection and try again.
240
+
241
+ ❌ SSLError
242
+ ✅ A secure connection to Gemini failed. Check your internet or try a
243
+ different network.
244
+ ```
245
+
246
+ ### Frontend Errors
247
+ ```
248
+ ❌ blocked by CORS policy
249
+ ✅ Your browser is blocking the request because your frontend and backend
250
+ are on different ports. Install flask-cors and add CORS(app) to your Flask file.
251
+
252
+ ❌ SyntaxError: Unexpected token
253
+ ✅ Your Flask server crashed and sent back an error page instead of data.
254
+ Check your terminal — the real error is printed there.
255
+ ```
256
+
257
+ ---
258
+
259
+ ## Check Available Models
260
+
261
+ Not sure which model to use? Run this:
262
+
263
+ ```python
264
+ from google import genai
265
+ from gemconnect import list_models
266
+
267
+ client = genai.Client(api_key="YOUR_API_KEY")
268
+ list_models(client)
269
+ ```
270
+
271
+ This prints all models your API key can access.
272
+
273
+ ---
274
+
275
+ ## What GemConnect Supports — v1.0
276
+
277
+ ```
278
+ Works with:
279
+ ✅ PDF Summarizer (extract text first, pass as string)
280
+ ✅ Chatbot (conversation as plain string)
281
+ ✅ Text Summarizer (plain text input)
282
+ ✅ CSV Analyzer (convert to string with df.to_string())
283
+ ✅ Any project where input to Gemini is plain text
284
+
285
+ Coming in v2.0:
286
+ 🔜 Image support
287
+ 🔜 Audio support
288
+ 🔜 Video support
289
+ ```
290
+
291
+ ---
292
+
293
+ ## Check Version
294
+
295
+ ```python
296
+ import gemconnect
297
+ print(gemconnect.__version__)
298
+ ```
299
+
300
+ ---
301
+
302
+ ## Built From Real Mistakes
303
+
304
+ This library was not built from assumptions. Every error message inside GemConnect was collected from real beginner projects — PDF summarizer, chatbot, image describer, audio transcriber. Each scary error was faced, documented, and translated into a simple message.
305
+
306
+ **GemConnect v1.0 — Built from real beginner mistakes, for real beginners.**
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ GemConnect/gemconnect/__init__.py
5
+ GemConnect/gemconnect/connector.py
6
+ GemConnect/gemconnect/errors.py
7
+ GemConnect/gemconnect.egg-info/PKG-INFO
8
+ GemConnect/gemconnect.egg-info/SOURCES.txt
9
+ GemConnect/gemconnect.egg-info/dependency_links.txt
10
+ GemConnect/gemconnect.egg-info/top_level.txt
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DIVYA
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,306 @@
1
+ Metadata-Version: 2.4
2
+ Name: gemconnect
3
+ Version: 1.2.0
4
+ Summary: gemconnect sits between Flask and Gemini, calls the API safely, and if anything goes wrong translates the scary technical error into a simple message the beginner can understand and fix.
5
+ Author-email: Divya P <divyaprofessional416@email.com>
6
+ Project-URL: Homepage, https://github.com/DIVICODER/gemconnect-lib-
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Dynamic: license-file
11
+
12
+ # GemConnect
13
+
14
+ **GemConnect sits between Flask and Gemini, calls the API safely, and if anything goes wrong, translates the scary technical error into a simple message the beginner can understand and fix.**
15
+
16
+ ---
17
+
18
+ ## The Problem
19
+
20
+ As an engineer, it felt fascinating to connect upcoming trends like AI into a website and see it work. Getting Gemini to respond in the terminal felt exciting. But when I tried to connect it with the frontend, it once again felt like zero.
21
+
22
+ Errors kept coming when interconnecting the frontend with Flask. Initially I tried to debug on my own, but it reached a threshold where I shifted from being curious and excited to a mood of just finishing what I had started. I kept copy-pasting the error to an AI bot to debug. Sometimes it worked, sometimes it didn't. But whether it worked or not, I hadn't been able to debug the error myself.
23
+
24
+ The errors were in technical terms like "404" — like these types of numbers. And in some cases it would show a scary list of errors and say "JSON error" like that, making it difficult to understand what went wrong and where.
25
+
26
+ What I needed was an error document to understand each error. That problem led to the creation of this library.
27
+
28
+ ---
29
+
30
+ ## What GemConnect Does
31
+
32
+ GemConnect gets the scary error and converts it into a human-understandable message for easy debugging.
33
+
34
+ ```
35
+ WITHOUT GemConnect:
36
+ Flask → Gemini → 😵 Scary JSON error dump → Beginner gives up
37
+
38
+ WITH GemConnect:
39
+ Flask → GemConnect → Gemini → ❌ Error?
40
+
41
+ "Hey! Your API key looks wrong.
42
+ Go to aistudio.google.com/apikey and get a fresh one."
43
+ ```
44
+
45
+ ---
46
+
47
+ ## Who Is This For
48
+
49
+ Beginners who are really interested in frontend connectivity with AI services but get scared seeing those errors and not knowing how to solve them.
50
+
51
+ ---
52
+
53
+ ## Requirements
54
+
55
+ Before using GemConnect, install the Gemini package:
56
+
57
+ ```
58
+ pip install google-genai
59
+ ```
60
+
61
+ GemConnect itself has zero dependencies. You are responsible for creating and passing the Gemini client.
62
+
63
+ ---
64
+
65
+ ## Installation
66
+
67
+ ```
68
+ pip install gemconnect
69
+ ```
70
+
71
+ ---
72
+
73
+ ## How To Use
74
+
75
+ ```python
76
+ from google import genai
77
+ from gemconnect import ask_gemini
78
+
79
+ # you bring your own client
80
+ client = genai.Client(api_key="YOUR_API_KEY")
81
+
82
+ # one line to call Gemini safely
83
+ result = ask_gemini("What is Python?", client, "gemini-2.5-flash")
84
+ print(result)
85
+ ```
86
+
87
+ ---
88
+
89
+ ## Input Validation
90
+
91
+ GemConnect checks your inputs before even calling Gemini. If something is wrong it tells you immediately in plain English:
92
+
93
+ ```python
94
+ ask_gemini(None, client, model)
95
+ # → "Your prompt is None. Please pass a text string like ask_gemini('hello', client, model)."
96
+
97
+ ask_gemini("", client, model)
98
+ # → "Your prompt is empty. Please type something before sending."
99
+
100
+ ask_gemini(["hello"], client, model)
101
+ # → "Your prompt must be plain text. You passed a list instead of a string."
102
+
103
+ ask_gemini(prompt, None, model)
104
+ # → "Your Gemini client is None. Make sure you created it using genai.Client(api_key=...)."
105
+
106
+ ask_gemini(prompt, client, None)
107
+ # → "You forgot to pass a model name. Try ask_gemini(prompt, client, 'gemini-2.0-flash')."
108
+
109
+ ask_gemini(prompt, client, "")
110
+ # → "Your model name is empty. Try ask_gemini(prompt, client, 'gemini-2.0-flash')."
111
+ ```
112
+
113
+ ---
114
+
115
+ ## How It Works Inside
116
+
117
+ ```
118
+ User writes ask_gemini()
119
+
120
+ connector.py runs input checks
121
+
122
+ ┌─────────────────────────┐
123
+ │ │
124
+ checks pass checks fail
125
+ │ │
126
+ ↓ ↓
127
+ calls Gemini API friendly message
128
+ │ returned to user
129
+
130
+ ┌─────────────┐
131
+ │ │
132
+ SUCCESS ERROR
133
+ │ │
134
+ ↓ ↓
135
+ response.text errors.py
136
+ │ │
137
+ ↓ ↓ Layer 1 — keyword match
138
+ returned errors.py
139
+ to user │
140
+ ↓ Layer 2 — synonym match
141
+
142
+
143
+ simple message
144
+ returned to user
145
+ ```
146
+
147
+ ---
148
+
149
+ ## Real Project Example — Chatbot
150
+
151
+ ```python
152
+ # BEFORE GemConnect — scary errors possible
153
+ response = client.models.generate_content(
154
+ model="gemini-2.5-flash",
155
+ contents=conversation
156
+ )
157
+ ai_reply = response.text
158
+
159
+
160
+ # AFTER GemConnect — one line, errors handled
161
+ from gemconnect import ask_gemini
162
+
163
+ ai_reply = ask_gemini(conversation, client, "gemini-2.5-flash")
164
+ ```
165
+
166
+ ---
167
+
168
+ ## What Errors GemConnect Covers
169
+
170
+ Every error message inside GemConnect was collected from real beginner projects. Two layers of matching make sure as many errors as possible are caught.
171
+
172
+ ### Setup Errors
173
+ ```
174
+ ❌ jinja2.exceptions.TemplateNotFound
175
+ ✅ Flask cannot find your HTML file. Make sure your HTML file is inside
176
+ a folder named exactly 'templates' (no capital letters, no spaces).
177
+
178
+ ❌ ERR_CONNECTION_REFUSED
179
+ ✅ Your Flask server is not running. Go to your terminal and run your
180
+ app.py file first, then try again.
181
+
182
+ ❌ FutureWarning: google.generativeai has ended
183
+ ✅ Your Gemini package is old. Open your terminal and run:
184
+ pip install --upgrade google-generativeai
185
+ ```
186
+
187
+ ### Install Errors
188
+ ```
189
+ ❌ ModuleNotFoundError: No module named 'google.generativeai'
190
+ ✅ A required package is not installed. Open your terminal and run:
191
+ pip install google-generativeai
192
+ ```
193
+
194
+ ### API Key Errors
195
+ ```
196
+ ❌ 401 Unauthorized
197
+ ✅ Gemini does not recognize you. Your API key is either wrong, expired,
198
+ or missing. Go to aistudio.google.com/apikey and get a fresh one.
199
+
200
+ ❌ API key not valid. Please pass a valid API key.
201
+ ✅ Your API key is wrong. Go to aistudio.google.com/apikey, copy your
202
+ key again and paste it carefully — even one wrong character breaks it.
203
+ ```
204
+
205
+ ### Quota Errors
206
+ ```
207
+ ❌ RESOURCE_EXHAUSTED
208
+ ✅ You have used up all your free Gemini quota. Go to
209
+ aistudio.google.com/apikey, create a brand new project and generate
210
+ a new API key from there.
211
+
212
+ ❌ 429 Too Many Requests
213
+ ✅ You sent too many requests too fast. Wait 30-60 seconds and try again.
214
+ ```
215
+
216
+ ### Model Errors
217
+ ```
218
+ ❌ 404 models/gemini-1.5-flash is not found
219
+ ✅ The model name you typed does not exist. Run list_models() to see the
220
+ exact names and copy-paste one of those.
221
+ ```
222
+
223
+ ### Gemini Server Errors
224
+ ```
225
+ ❌ InternalServerError
226
+ ✅ Something crashed on Gemini's side — this is not your fault.
227
+ Wait a minute and try the exact same request again.
228
+
229
+ ❌ 503 UNAVAILABLE
230
+ ✅ Too many people are using Gemini right now. Wait a few minutes and try again.
231
+
232
+ ❌ 504 Timeout
233
+ ✅ Gemini took too long to reply. Wait a moment and try again.
234
+ ```
235
+
236
+ ### Network Errors
237
+ ```
238
+ ❌ ConnectionError
239
+ ✅ Could not reach Gemini. Check your internet connection and try again.
240
+
241
+ ❌ SSLError
242
+ ✅ A secure connection to Gemini failed. Check your internet or try a
243
+ different network.
244
+ ```
245
+
246
+ ### Frontend Errors
247
+ ```
248
+ ❌ blocked by CORS policy
249
+ ✅ Your browser is blocking the request because your frontend and backend
250
+ are on different ports. Install flask-cors and add CORS(app) to your Flask file.
251
+
252
+ ❌ SyntaxError: Unexpected token
253
+ ✅ Your Flask server crashed and sent back an error page instead of data.
254
+ Check your terminal — the real error is printed there.
255
+ ```
256
+
257
+ ---
258
+
259
+ ## Check Available Models
260
+
261
+ Not sure which model to use? Run this:
262
+
263
+ ```python
264
+ from google import genai
265
+ from gemconnect import list_models
266
+
267
+ client = genai.Client(api_key="YOUR_API_KEY")
268
+ list_models(client)
269
+ ```
270
+
271
+ This prints all models your API key can access.
272
+
273
+ ---
274
+
275
+ ## What GemConnect Supports — v1.0
276
+
277
+ ```
278
+ Works with:
279
+ ✅ PDF Summarizer (extract text first, pass as string)
280
+ ✅ Chatbot (conversation as plain string)
281
+ ✅ Text Summarizer (plain text input)
282
+ ✅ CSV Analyzer (convert to string with df.to_string())
283
+ ✅ Any project where input to Gemini is plain text
284
+
285
+ Coming in v2.0:
286
+ 🔜 Image support
287
+ 🔜 Audio support
288
+ 🔜 Video support
289
+ ```
290
+
291
+ ---
292
+
293
+ ## Check Version
294
+
295
+ ```python
296
+ import gemconnect
297
+ print(gemconnect.__version__)
298
+ ```
299
+
300
+ ---
301
+
302
+ ## Built From Real Mistakes
303
+
304
+ This library was not built from assumptions. Every error message inside GemConnect was collected from real beginner projects — PDF summarizer, chatbot, image describer, audio transcriber. Each scary error was faced, documented, and translated into a simple message.
305
+
306
+ **GemConnect v1.0 — Built from real beginner mistakes, for real beginners.**
@@ -0,0 +1,295 @@
1
+ # GemConnect
2
+
3
+ **GemConnect sits between Flask and Gemini, calls the API safely, and if anything goes wrong, translates the scary technical error into a simple message the beginner can understand and fix.**
4
+
5
+ ---
6
+
7
+ ## The Problem
8
+
9
+ As an engineer, it felt fascinating to connect upcoming trends like AI into a website and see it work. Getting Gemini to respond in the terminal felt exciting. But when I tried to connect it with the frontend, it once again felt like zero.
10
+
11
+ Errors kept coming when interconnecting the frontend with Flask. Initially I tried to debug on my own, but it reached a threshold where I shifted from being curious and excited to a mood of just finishing what I had started. I kept copy-pasting the error to an AI bot to debug. Sometimes it worked, sometimes it didn't. But whether it worked or not, I hadn't been able to debug the error myself.
12
+
13
+ The errors were in technical terms like "404" — like these types of numbers. And in some cases it would show a scary list of errors and say "JSON error" like that, making it difficult to understand what went wrong and where.
14
+
15
+ What I needed was an error document to understand each error. That problem led to the creation of this library.
16
+
17
+ ---
18
+
19
+ ## What GemConnect Does
20
+
21
+ GemConnect gets the scary error and converts it into a human-understandable message for easy debugging.
22
+
23
+ ```
24
+ WITHOUT GemConnect:
25
+ Flask → Gemini → 😵 Scary JSON error dump → Beginner gives up
26
+
27
+ WITH GemConnect:
28
+ Flask → GemConnect → Gemini → ❌ Error?
29
+
30
+ "Hey! Your API key looks wrong.
31
+ Go to aistudio.google.com/apikey and get a fresh one."
32
+ ```
33
+
34
+ ---
35
+
36
+ ## Who Is This For
37
+
38
+ Beginners who are really interested in frontend connectivity with AI services but get scared seeing those errors and not knowing how to solve them.
39
+
40
+ ---
41
+
42
+ ## Requirements
43
+
44
+ Before using GemConnect, install the Gemini package:
45
+
46
+ ```
47
+ pip install google-genai
48
+ ```
49
+
50
+ GemConnect itself has zero dependencies. You are responsible for creating and passing the Gemini client.
51
+
52
+ ---
53
+
54
+ ## Installation
55
+
56
+ ```
57
+ pip install gemconnect
58
+ ```
59
+
60
+ ---
61
+
62
+ ## How To Use
63
+
64
+ ```python
65
+ from google import genai
66
+ from gemconnect import ask_gemini
67
+
68
+ # you bring your own client
69
+ client = genai.Client(api_key="YOUR_API_KEY")
70
+
71
+ # one line to call Gemini safely
72
+ result = ask_gemini("What is Python?", client, "gemini-2.5-flash")
73
+ print(result)
74
+ ```
75
+
76
+ ---
77
+
78
+ ## Input Validation
79
+
80
+ GemConnect checks your inputs before even calling Gemini. If something is wrong it tells you immediately in plain English:
81
+
82
+ ```python
83
+ ask_gemini(None, client, model)
84
+ # → "Your prompt is None. Please pass a text string like ask_gemini('hello', client, model)."
85
+
86
+ ask_gemini("", client, model)
87
+ # → "Your prompt is empty. Please type something before sending."
88
+
89
+ ask_gemini(["hello"], client, model)
90
+ # → "Your prompt must be plain text. You passed a list instead of a string."
91
+
92
+ ask_gemini(prompt, None, model)
93
+ # → "Your Gemini client is None. Make sure you created it using genai.Client(api_key=...)."
94
+
95
+ ask_gemini(prompt, client, None)
96
+ # → "You forgot to pass a model name. Try ask_gemini(prompt, client, 'gemini-2.0-flash')."
97
+
98
+ ask_gemini(prompt, client, "")
99
+ # → "Your model name is empty. Try ask_gemini(prompt, client, 'gemini-2.0-flash')."
100
+ ```
101
+
102
+ ---
103
+
104
+ ## How It Works Inside
105
+
106
+ ```
107
+ User writes ask_gemini()
108
+
109
+ connector.py runs input checks
110
+
111
+ ┌─────────────────────────┐
112
+ │ │
113
+ checks pass checks fail
114
+ │ │
115
+ ↓ ↓
116
+ calls Gemini API friendly message
117
+ │ returned to user
118
+
119
+ ┌─────────────┐
120
+ │ │
121
+ SUCCESS ERROR
122
+ │ │
123
+ ↓ ↓
124
+ response.text errors.py
125
+ │ │
126
+ ↓ ↓ Layer 1 — keyword match
127
+ returned errors.py
128
+ to user │
129
+ ↓ Layer 2 — synonym match
130
+
131
+
132
+ simple message
133
+ returned to user
134
+ ```
135
+
136
+ ---
137
+
138
+ ## Real Project Example — Chatbot
139
+
140
+ ```python
141
+ # BEFORE GemConnect — scary errors possible
142
+ response = client.models.generate_content(
143
+ model="gemini-2.5-flash",
144
+ contents=conversation
145
+ )
146
+ ai_reply = response.text
147
+
148
+
149
+ # AFTER GemConnect — one line, errors handled
150
+ from gemconnect import ask_gemini
151
+
152
+ ai_reply = ask_gemini(conversation, client, "gemini-2.5-flash")
153
+ ```
154
+
155
+ ---
156
+
157
+ ## What Errors GemConnect Covers
158
+
159
+ Every error message inside GemConnect was collected from real beginner projects. Two layers of matching make sure as many errors as possible are caught.
160
+
161
+ ### Setup Errors
162
+ ```
163
+ ❌ jinja2.exceptions.TemplateNotFound
164
+ ✅ Flask cannot find your HTML file. Make sure your HTML file is inside
165
+ a folder named exactly 'templates' (no capital letters, no spaces).
166
+
167
+ ❌ ERR_CONNECTION_REFUSED
168
+ ✅ Your Flask server is not running. Go to your terminal and run your
169
+ app.py file first, then try again.
170
+
171
+ ❌ FutureWarning: google.generativeai has ended
172
+ ✅ Your Gemini package is old. Open your terminal and run:
173
+ pip install --upgrade google-generativeai
174
+ ```
175
+
176
+ ### Install Errors
177
+ ```
178
+ ❌ ModuleNotFoundError: No module named 'google.generativeai'
179
+ ✅ A required package is not installed. Open your terminal and run:
180
+ pip install google-generativeai
181
+ ```
182
+
183
+ ### API Key Errors
184
+ ```
185
+ ❌ 401 Unauthorized
186
+ ✅ Gemini does not recognize you. Your API key is either wrong, expired,
187
+ or missing. Go to aistudio.google.com/apikey and get a fresh one.
188
+
189
+ ❌ API key not valid. Please pass a valid API key.
190
+ ✅ Your API key is wrong. Go to aistudio.google.com/apikey, copy your
191
+ key again and paste it carefully — even one wrong character breaks it.
192
+ ```
193
+
194
+ ### Quota Errors
195
+ ```
196
+ ❌ RESOURCE_EXHAUSTED
197
+ ✅ You have used up all your free Gemini quota. Go to
198
+ aistudio.google.com/apikey, create a brand new project and generate
199
+ a new API key from there.
200
+
201
+ ❌ 429 Too Many Requests
202
+ ✅ You sent too many requests too fast. Wait 30-60 seconds and try again.
203
+ ```
204
+
205
+ ### Model Errors
206
+ ```
207
+ ❌ 404 models/gemini-1.5-flash is not found
208
+ ✅ The model name you typed does not exist. Run list_models() to see the
209
+ exact names and copy-paste one of those.
210
+ ```
211
+
212
+ ### Gemini Server Errors
213
+ ```
214
+ ❌ InternalServerError
215
+ ✅ Something crashed on Gemini's side — this is not your fault.
216
+ Wait a minute and try the exact same request again.
217
+
218
+ ❌ 503 UNAVAILABLE
219
+ ✅ Too many people are using Gemini right now. Wait a few minutes and try again.
220
+
221
+ ❌ 504 Timeout
222
+ ✅ Gemini took too long to reply. Wait a moment and try again.
223
+ ```
224
+
225
+ ### Network Errors
226
+ ```
227
+ ❌ ConnectionError
228
+ ✅ Could not reach Gemini. Check your internet connection and try again.
229
+
230
+ ❌ SSLError
231
+ ✅ A secure connection to Gemini failed. Check your internet or try a
232
+ different network.
233
+ ```
234
+
235
+ ### Frontend Errors
236
+ ```
237
+ ❌ blocked by CORS policy
238
+ ✅ Your browser is blocking the request because your frontend and backend
239
+ are on different ports. Install flask-cors and add CORS(app) to your Flask file.
240
+
241
+ ❌ SyntaxError: Unexpected token
242
+ ✅ Your Flask server crashed and sent back an error page instead of data.
243
+ Check your terminal — the real error is printed there.
244
+ ```
245
+
246
+ ---
247
+
248
+ ## Check Available Models
249
+
250
+ Not sure which model to use? Run this:
251
+
252
+ ```python
253
+ from google import genai
254
+ from gemconnect import list_models
255
+
256
+ client = genai.Client(api_key="YOUR_API_KEY")
257
+ list_models(client)
258
+ ```
259
+
260
+ This prints all models your API key can access.
261
+
262
+ ---
263
+
264
+ ## What GemConnect Supports — v1.0
265
+
266
+ ```
267
+ Works with:
268
+ ✅ PDF Summarizer (extract text first, pass as string)
269
+ ✅ Chatbot (conversation as plain string)
270
+ ✅ Text Summarizer (plain text input)
271
+ ✅ CSV Analyzer (convert to string with df.to_string())
272
+ ✅ Any project where input to Gemini is plain text
273
+
274
+ Coming in v2.0:
275
+ 🔜 Image support
276
+ 🔜 Audio support
277
+ 🔜 Video support
278
+ ```
279
+
280
+ ---
281
+
282
+ ## Check Version
283
+
284
+ ```python
285
+ import gemconnect
286
+ print(gemconnect.__version__)
287
+ ```
288
+
289
+ ---
290
+
291
+ ## Built From Real Mistakes
292
+
293
+ This library was not built from assumptions. Every error message inside GemConnect was collected from real beginner projects — PDF summarizer, chatbot, image describer, audio transcriber. Each scary error was faced, documented, and translated into a simple message.
294
+
295
+ **GemConnect v1.0 — Built from real beginner mistakes, for real beginners.**
@@ -0,0 +1,23 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+
6
+
7
+ [project]
8
+ name = "gemconnect"
9
+ version = "1.2.0"
10
+ description = "gemconnect sits between Flask and Gemini, calls the API safely, and if anything goes wrong translates the scary technical error into a simple message the beginner can understand and fix."
11
+ readme = "README.md"
12
+ requires-python = ">=3.8"
13
+ dependencies = []
14
+ authors = [
15
+ {name = "Divya P", email = "divyaprofessional416@email.com"}
16
+ ]
17
+
18
+ [project.urls]
19
+ Homepage = "https://github.com/DIVICODER/gemconnect-lib-"
20
+
21
+ [tool.setuptools]
22
+ package-dir = {"" = "GemConnect"}
23
+ packages = ["gemconnect"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+