askai-python 0.3.3__tar.gz → 0.4.1__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.
Files changed (45) hide show
  1. askai_python-0.4.1/PKG-INFO +229 -0
  2. {askai_python-0.3.3 → askai_python-0.4.1}/README.md +113 -8
  3. askai_python-0.4.1/ask_ai/__init__.py +51 -0
  4. askai_python-0.4.1/ask_ai/base.py +444 -0
  5. askai_python-0.4.1/ask_ai/cli.py +107 -0
  6. askai_python-0.4.1/ask_ai/config.py +81 -0
  7. {askai_python-0.3.3 → askai_python-0.4.1}/ask_ai/exceptions.py +13 -1
  8. askai_python-0.4.1/ask_ai/media.py +90 -0
  9. {askai_python-0.3.3 → askai_python-0.4.1}/ask_ai/providers/__init__.py +1 -4
  10. askai_python-0.4.1/ask_ai/providers/anthropic_provider.py +128 -0
  11. askai_python-0.4.1/ask_ai/providers/azure_provider.py +67 -0
  12. askai_python-0.4.1/ask_ai/providers/google_provider.py +150 -0
  13. askai_python-0.4.1/ask_ai/providers/groq_provider.py +114 -0
  14. askai_python-0.4.1/ask_ai/providers/openai_provider.py +257 -0
  15. askai_python-0.4.1/ask_ai/providers/openrouter_provider.py +123 -0
  16. askai_python-0.4.1/ask_ai/utils.py +68 -0
  17. askai_python-0.4.1/askai_python.egg-info/PKG-INFO +229 -0
  18. {askai_python-0.3.3 → askai_python-0.4.1}/askai_python.egg-info/SOURCES.txt +1 -0
  19. askai_python-0.4.1/askai_python.egg-info/entry_points.txt +2 -0
  20. askai_python-0.4.1/askai_python.egg-info/requires.txt +26 -0
  21. askai_python-0.3.3/PKG-INFO → askai_python-0.4.1/docs/PYPI_README.md +68 -31
  22. askai_python-0.4.1/pyproject.toml +83 -0
  23. {askai_python-0.3.3 → askai_python-0.4.1}/tests/test_core.py +10 -6
  24. askai_python-0.3.3/ask_ai/__init__.py +0 -26
  25. askai_python-0.3.3/ask_ai/base.py +0 -226
  26. askai_python-0.3.3/ask_ai/cli.py +0 -77
  27. askai_python-0.3.3/ask_ai/config.py +0 -56
  28. askai_python-0.3.3/ask_ai/media.py +0 -63
  29. askai_python-0.3.3/ask_ai/providers/anthropic_provider.py +0 -87
  30. askai_python-0.3.3/ask_ai/providers/azure_provider.py +0 -46
  31. askai_python-0.3.3/ask_ai/providers/google_provider.py +0 -87
  32. askai_python-0.3.3/ask_ai/providers/groq_provider.py +0 -75
  33. askai_python-0.3.3/ask_ai/providers/openai_provider.py +0 -122
  34. askai_python-0.3.3/ask_ai/providers/openrouter_provider.py +0 -44
  35. askai_python-0.3.3/ask_ai/utils.py +0 -43
  36. askai_python-0.3.3/askai_python.egg-info/PKG-INFO +0 -145
  37. askai_python-0.3.3/askai_python.egg-info/requires.txt +0 -6
  38. askai_python-0.3.3/docs/PYPI_README.md +0 -126
  39. askai_python-0.3.3/pyproject.toml +0 -33
  40. {askai_python-0.3.3 → askai_python-0.4.1}/LICENSE +0 -0
  41. {askai_python-0.3.3 → askai_python-0.4.1}/ask_ai/__main__.py +0 -0
  42. {askai_python-0.3.3 → askai_python-0.4.1}/ask_ai/requirements.txt +0 -0
  43. {askai_python-0.3.3 → askai_python-0.4.1}/askai_python.egg-info/dependency_links.txt +0 -0
  44. {askai_python-0.3.3 → askai_python-0.4.1}/askai_python.egg-info/top_level.txt +0 -0
  45. {askai_python-0.3.3 → askai_python-0.4.1}/setup.cfg +0 -0
@@ -0,0 +1,229 @@
1
+ Metadata-Version: 2.4
2
+ Name: askai-python
3
+ Version: 0.4.1
4
+ Summary: AI Made Stupid Simple. Unified API for OpenAI, Groq, Google, Anthropic, and more.
5
+ Author-email: Hossein Ghorbani <hosseingh1068@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/Hosseinghorbani0/ask-ai
8
+ Project-URL: Documentation, https://github.com/Hosseinghorbani0/ask-ai#readme
9
+ Project-URL: Bug Tracker, https://github.com/Hosseinghorbani0/ask-ai/issues
10
+ Project-URL: Changelog, https://github.com/Hosseinghorbani0/ask-ai/releases
11
+ Keywords: ai,llm,openai,anthropic,gemini,groq,sdk,api
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.9
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Provides-Extra: openai
28
+ Requires-Dist: openai>=1.0.0; extra == "openai"
29
+ Provides-Extra: anthropic
30
+ Requires-Dist: anthropic>=0.20.0; extra == "anthropic"
31
+ Provides-Extra: google
32
+ Requires-Dist: google-generativeai>=0.5.0; extra == "google"
33
+ Provides-Extra: groq
34
+ Requires-Dist: groq>=0.4.0; extra == "groq"
35
+ Provides-Extra: media
36
+ Requires-Dist: Pillow>=9.0.0; extra == "media"
37
+ Provides-Extra: httpx
38
+ Requires-Dist: httpx>=0.24.0; extra == "httpx"
39
+ Provides-Extra: all
40
+ Requires-Dist: openai>=1.0.0; extra == "all"
41
+ Requires-Dist: anthropic>=0.20.0; extra == "all"
42
+ Requires-Dist: google-generativeai>=0.5.0; extra == "all"
43
+ Requires-Dist: groq>=0.4.0; extra == "all"
44
+ Requires-Dist: Pillow>=9.0.0; extra == "all"
45
+ Requires-Dist: httpx>=0.24.0; extra == "all"
46
+ Dynamic: license-file
47
+
48
+ # askai-python 🚀
49
+
50
+ **A minimal Python SDK to switch between LLM providers in one line.**
51
+ No frameworks. No servers. No overengineering.
52
+
53
+ [![PyPI version](https://img.shields.io/pypi/v/askai-python.svg)](https://pypi.org/project/askai-python/)
54
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
55
+ [![GitHub](https://img.shields.io/badge/GitHub-View%20Source-blue.svg)](https://github.com/Hosseinghorbani0/askai-python)
56
+
57
+ ---
58
+
59
+ ## ⚡ Quick Start (5 seconds)
60
+
61
+ ```bash
62
+ pip install askai-python
63
+ ```
64
+
65
+ ```python
66
+ from ask_ai import OpenAI, Groq
67
+
68
+ # Auto-detects OPENAI_API_KEY from environment
69
+ print(OpenAI().ask("Explain black holes like I'm 5").text)
70
+
71
+ # Switch provider instantly
72
+ print(Groq().ask("Explain black holes like I'm 5").text)
73
+ ```
74
+
75
+ ---
76
+
77
+ ## 🧐 Why askai-python?
78
+
79
+ - **One function**: Just call `.ask()`
80
+ - **Multiple providers**: OpenAI, Anthropic, Google Gemini, Groq, Azure, OpenRouter
81
+ - **Zero config**: Keys are pulled from the environment automatically
82
+ - **SDK-first, not a framework**: It stays out of your way.
83
+
84
+ ## 🚫 What this project is NOT
85
+
86
+ > ❌ Not an AI framework
87
+ > ❌ Not an API gateway
88
+ > ❌ Not an agent memory system
89
+
90
+ It does one thing perfectly: **Simplifying the API call to LLMs.**
91
+
92
+ ---
93
+
94
+ ## 🛠️ Advanced Usage
95
+
96
+ ### 🧰 Developer QoL Utilities (Auto-Parsing)
97
+
98
+ <p align="center">
99
+ <img src="https://raw.githubusercontent.com/Hosseinghorbani0/askai-python/main/assets/features.svg" alt="askai-python features parsing banner" width="100%">
100
+ </p>
101
+ Stop writing Regex to clean up model outputs! `askai-python` comes with built-in text processing flags:
102
+
103
+ ```python
104
+ from ask_ai import OpenAI
105
+ ai = OpenAI()
106
+
107
+ # 1. Clean Markdown (Removes ```json and ``` tags)
108
+ # Perfect for extracting raw data from models that wrap everything in markdown
109
+ clean_text = ai.ask("Write JSON", clean=True).text
110
+
111
+ # 2. Extract Code (Returns ONLY the code block, ignores conversational filler)
112
+ # Great for automation pipelines
113
+ code = ai.ask("Write a python ping script", code=True).text
114
+
115
+ # 3. Strip Tags (Removes <think> blocks and HTML)
116
+ # Essential for reasoning models like DeepSeek-R1
117
+ answer_only = ai.ask("What is 1+1?", strip=True).text
118
+
119
+ # 4. Enforce & Parse JSON (Directly returns a Parsed Python Dictionary)
120
+ # Adds JSON instructions to the prompt and safely runs json.loads()
121
+ data_dict = ai.ask("Extract user info", json=True).json
122
+ print(data_dict['name'])
123
+ ```
124
+
125
+ ## 🚀 Built-in Resiliency (Retries & Timeouts)
126
+
127
+ <p align="center">
128
+ <img src="https://raw.githubusercontent.com/Hosseinghorbani0/askai-python/main/assets/resiliency.svg" alt="askai-python resiliency banner" width="100%">
129
+ </p>
130
+
131
+ Build reliable apps without writing your own loops. `askai-python` handles rate limits (`429`) and network drops via an internal exponential backoff.
132
+
133
+ ```python
134
+ from ask_ai import OpenAI
135
+
136
+ ai = OpenAI()
137
+
138
+ # Automatically retries up to 3 times on transient errors, with a 15-second timeout
139
+ response = ai.ask(
140
+ "Write a complex python script",
141
+ retry=3,
142
+ timeout=15
143
+ )
144
+ ```
145
+
146
+ ## 🎨 Media Generation (Image & Audio)
147
+
148
+ Generate images or speech with compatible providers:
149
+
150
+ ```python
151
+ from ask_ai import OpenAI
152
+
153
+ ai = OpenAI()
154
+
155
+ # Generate an Image (DALL-E)
156
+ img_response = ai.ask("A majestic lion in a neon city", output_type="image")
157
+ img_response.save("lion.png")
158
+
159
+ # Generate Speech (TTS)
160
+ audio_response = ai.ask("Hello, this is a voice.", output_type="audio")
161
+ audio_response.save("welcome.mp3")
162
+ ```
163
+
164
+ ## 🔗 Provider Fallback
165
+
166
+ Never experience downtime by supplying fallback providers:
167
+
168
+ ```python
169
+ from ask_ai import OpenAI, Groq
170
+
171
+ ai = OpenAI()
172
+ response = ai.ask("Explain quantum physics", providers=[ai, Groq])
173
+ print(response.text)
174
+ ```
175
+
176
+ ## 📋 Structured Output (Pydantic Support)
177
+
178
+ Force LLMs to strictly respond matching a Pydantic schema:
179
+
180
+ ```python
181
+ from pydantic import BaseModel
182
+ from ask_ai import OpenAI
183
+
184
+ class User(BaseModel):
185
+ name: str
186
+ age: int
187
+
188
+ ai = OpenAI()
189
+ response = ai.ask("Extract name: Alice is 30.", response_model=User)
190
+ user = response.pydantic
191
+ print(user.name) # "Alice"
192
+ ```
193
+
194
+ ## 🔌 Supported Providers
195
+
196
+ | Provider | Class | Capabilities |
197
+ |----------|-------|-------------|
198
+ | **OpenAI** | `OpenAI` | Text, Images (DALL-E), Vision |
199
+ | **Anthropic** | `Anthropic` | Text, Vision (Claude 3.5) |
200
+ | **Google** | `Google` | Text, Images, Video, Audio |
201
+ | **Groq** | `Groq` | Ultra-fast Llama 3 & Mixtral |
202
+ | **Azure** | `Azure` | Enterprise-grade OpenAI |
203
+ | **OpenRouter**| `OpenRouter`| 100+ community models |
204
+
205
+ ---
206
+
207
+ ## 🗺️ Roadmap
208
+
209
+ ### 🚀 Roadmap 2.0 (Active)
210
+ - [x] Provider Fallback chaining & Pydantic Structured Output support
211
+ - [ ] Multi-Modal Vision input (image to text) for all key providers
212
+ - [ ] Native support for tools/function calling execution
213
+ - [ ] Memory buffer / session-based conversation management
214
+
215
+ ### 🏁 Roadmap 1.0 (Completed)
216
+ - ~~[x] Baseline multiple providers~~
217
+ - ~~[x] Automated Retry & Timeout controls~~
218
+ - ~~[x] Async API (`await ask_async`)~~
219
+ - ~~[x] Streaming Support (`ask_stream` / `ask_stream_async`)~~
220
+ - ~~[x] Provider Fallback (`fallback=[Groq()]`)~~
221
+ - ~~[x] Structured Outputs (Pydantic Support)~~
222
+
223
+ ---
224
+
225
+ ## 🔗 Important Links
226
+
227
+ - **GitHub Repository**: [Hosseinghorbani0/askai-python](https://github.com/Hosseinghorbani0/askai-python) (Star us! ⭐)
228
+ - **Official Website**: [hosseinghorbani0.ir](https://hosseinghorbani0.ir/)
229
+ - **Bug Tracker**: [Report an Issue](https://github.com/Hosseinghorbani0/askai-python/issues)
@@ -24,7 +24,7 @@
24
24
 
25
25
  [![PyPI version](https://img.shields.io/pypi/v/askai-python.svg)](https://pypi.org/project/askai-python/)
26
26
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
27
- [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
27
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
28
28
 
29
29
 
30
30
 
@@ -125,15 +125,120 @@ print(ai.ask("How do I optimize a Dockerfile?").text)
125
125
 
126
126
  ---
127
127
 
128
+ ### 🚀 Async Support (FastAPI / Aiogram)
129
+
130
+ `ask-ai` works perfectly in asynchronous environments:
131
+
132
+ ```python
133
+ import asyncio
134
+ from ask_ai import OpenAI
135
+
136
+ async def main():
137
+ ai = OpenAI()
138
+ # Runs non-blocking in your event loop
139
+ response = await ai.ask_async("What is the capital of France?")
140
+ print(response.text)
141
+
142
+ asyncio.run(main())
143
+ ```
144
+
145
+ ---
146
+
147
+ ### 🌊 Streaming Support (Sync & Async)
148
+
149
+ Stream responses token-by-token easily:
150
+
151
+ ```python
152
+ from ask_ai import OpenAI
153
+
154
+ ai = OpenAI()
155
+
156
+ # Sync Streaming
157
+ for chunk in ai.ask_stream("Write a short story about a blue dragon"):
158
+ print(chunk, end="", flush=True)
159
+
160
+ # Async Streaming
161
+ async def stream_example():
162
+ async for chunk in await ai.ask_stream_async("Write a short story"):
163
+ print(chunk, end="", flush=True)
164
+ ```
165
+
166
+ ---
167
+
168
+ ### 🎨 Media Generation (Image & Audio)
169
+
170
+ Generate images or speech with compatible providers:
171
+
172
+ ```python
173
+ from ask_ai import OpenAI
174
+
175
+ ai = OpenAI()
176
+
177
+ # Generate an Image (DALL-E)
178
+ img_response = ai.ask("A majestic lion in a neon city", output_type="image")
179
+ img_response.save("lion.png")
180
+
181
+ # Generate Speech (TTS)
182
+ audio_response = ai.ask("Hello, this is a generated voice.", output_type="audio")
183
+ audio_response.save("welcome.mp3")
184
+ ```
185
+
186
+ ---
187
+
188
+ ### 🔗 Provider Fallback
189
+
190
+ Never experience downtime by supplying alternative fallback providers:
191
+
192
+ ```python
193
+ from ask_ai import OpenAI, Groq
194
+
195
+ ai = OpenAI()
196
+
197
+ # If OpenAI fails or rate-limits, it automatically switches to Groq
198
+ response = ai.ask("Explain quantum physics", providers=[ai, Groq])
199
+ print(response.text)
200
+ ```
201
+
202
+ ---
203
+
204
+ ### 📋 Structured Output (Pydantic Support)
205
+
206
+ Force LLMs to strictly respond matching a Pydantic schema:
207
+
208
+ ```python
209
+ from pydantic import BaseModel
210
+ from ask_ai import OpenAI
211
+
212
+ class User(BaseModel):
213
+ name: str
214
+ age: int
215
+
216
+ ai = OpenAI()
217
+ response = ai.ask("Extract name: Alice is 30 years old.", response_model=User)
218
+
219
+ user = response.pydantic
220
+ print(user.name) # "Alice"
221
+ print(user.age) # 30
222
+ ```
223
+
224
+ ---
225
+
128
226
  ## 🗺️ Roadmap
129
227
 
130
- - [x] OpenAI, Groq, Gemini, Anthropic, Azure, OpenRouter support
131
- - [x] Text to Image (DALL-E) and Text to Audio
132
- - [x] Automated Retry & Timeout controls
133
- - [ ] Async Support (`await ask_async`)
134
- - [ ] Provider Fallback (`ask(..., providers=[OpenAI, Groq])`)
135
- - [ ] Streaming Support (`ask_stream`)
136
- - [ ] Structured Output (Pydantic Support)
228
+ ### 🚀 Roadmap 2.0 (Active)
229
+ - [x] Provider Fallback chaining & Pydantic Structured Output support
230
+ - [ ] Multi-Modal Vision input (image to text) for all key providers
231
+ - [ ] Native support for tools/function calling execution
232
+ - [ ] Memory buffer / session-based conversation management
233
+
234
+ ### 🏁 Roadmap 1.0 (Completed)
235
+ - ~~[x] OpenAI, Groq, Gemini, Anthropic, Azure, OpenRouter support~~
236
+ - ~~[x] Text to Image (DALL-E) and Text to Audio~~
237
+ - ~~[x] Automated Retry & Timeout controls~~
238
+ - ~~[x] Async Support (`await ask_async`)~~
239
+ - ~~[x] Streaming Support (`ask_stream` / `ask_stream_async`)~~
240
+ - ~~[x] Provider Fallback (`ask(..., providers=[OpenAI, Groq])`)~~
241
+ - ~~[x] Structured Output (Pydantic Support)~~
137
242
 
138
243
  ---
139
244
 
@@ -0,0 +1,51 @@
1
+ """
2
+ ask-ai: A minimal Python SDK to switch between LLM providers in one line.
3
+ """
4
+
5
+ __version__ = "0.4.1"
6
+
7
+ from .providers import (
8
+ OpenAI,
9
+ Anthropic,
10
+ Google,
11
+ Groq,
12
+ Azure,
13
+ OpenRouter
14
+ )
15
+ from .config import AdvancedConfig
16
+ from .base import Response
17
+ from .media import ImageObject, AudioObject
18
+ from .exceptions import (
19
+ AskAIError,
20
+ AskAIConfigError,
21
+ AskAINetworkError,
22
+ AskAIRateLimitError,
23
+ AskAIParsingError,
24
+ ProviderError,
25
+ MediaTypeNotSupportedError,
26
+ StreamNotSupportedError,
27
+ )
28
+
29
+ __all__ = [
30
+ # Providers
31
+ "OpenAI",
32
+ "Anthropic",
33
+ "Google",
34
+ "Groq",
35
+ "Azure",
36
+ "OpenRouter",
37
+ # Core
38
+ "AdvancedConfig",
39
+ "Response",
40
+ "ImageObject",
41
+ "AudioObject",
42
+ # Exceptions
43
+ "AskAIError",
44
+ "AskAIConfigError",
45
+ "AskAINetworkError",
46
+ "AskAIRateLimitError",
47
+ "AskAIParsingError",
48
+ "ProviderError",
49
+ "MediaTypeNotSupportedError",
50
+ "StreamNotSupportedError",
51
+ ]