askai-python 0.1.6__tar.gz → 0.2.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 (32) hide show
  1. askai_python-0.2.1/PKG-INFO +137 -0
  2. askai_python-0.2.1/README.md +130 -0
  3. {askai_python-0.1.6 → askai_python-0.2.1}/ask_ai/base.py +81 -8
  4. askai_python-0.2.1/ask_ai/exceptions.py +30 -0
  5. askai_python-0.2.1/ask_ai/utils.py +43 -0
  6. askai_python-0.2.1/askai_python.egg-info/PKG-INFO +137 -0
  7. {askai_python-0.1.6 → askai_python-0.2.1}/askai_python.egg-info/SOURCES.txt +1 -0
  8. askai_python-0.2.1/docs/PYPI_README.md +118 -0
  9. {askai_python-0.1.6 → askai_python-0.2.1}/pyproject.toml +1 -1
  10. askai_python-0.1.6/PKG-INFO +0 -135
  11. askai_python-0.1.6/README.md +0 -111
  12. askai_python-0.1.6/ask_ai/exceptions.py +0 -15
  13. askai_python-0.1.6/askai_python.egg-info/PKG-INFO +0 -135
  14. askai_python-0.1.6/docs/PYPI_README.md +0 -116
  15. {askai_python-0.1.6 → askai_python-0.2.1}/LICENSE +0 -0
  16. {askai_python-0.1.6 → askai_python-0.2.1}/ask_ai/__init__.py +0 -0
  17. {askai_python-0.1.6 → askai_python-0.2.1}/ask_ai/__main__.py +0 -0
  18. {askai_python-0.1.6 → askai_python-0.2.1}/ask_ai/cli.py +0 -0
  19. {askai_python-0.1.6 → askai_python-0.2.1}/ask_ai/config.py +0 -0
  20. {askai_python-0.1.6 → askai_python-0.2.1}/ask_ai/media.py +0 -0
  21. {askai_python-0.1.6 → askai_python-0.2.1}/ask_ai/providers/__init__.py +0 -0
  22. {askai_python-0.1.6 → askai_python-0.2.1}/ask_ai/providers/anthropic_provider.py +0 -0
  23. {askai_python-0.1.6 → askai_python-0.2.1}/ask_ai/providers/azure_provider.py +0 -0
  24. {askai_python-0.1.6 → askai_python-0.2.1}/ask_ai/providers/google_provider.py +0 -0
  25. {askai_python-0.1.6 → askai_python-0.2.1}/ask_ai/providers/groq_provider.py +0 -0
  26. {askai_python-0.1.6 → askai_python-0.2.1}/ask_ai/providers/openai_provider.py +0 -0
  27. {askai_python-0.1.6 → askai_python-0.2.1}/ask_ai/providers/openrouter_provider.py +0 -0
  28. {askai_python-0.1.6 → askai_python-0.2.1}/askai_python.egg-info/dependency_links.txt +0 -0
  29. {askai_python-0.1.6 → askai_python-0.2.1}/askai_python.egg-info/requires.txt +0 -0
  30. {askai_python-0.1.6 → askai_python-0.2.1}/askai_python.egg-info/top_level.txt +0 -0
  31. {askai_python-0.1.6 → askai_python-0.2.1}/setup.cfg +0 -0
  32. {askai_python-0.1.6 → askai_python-0.2.1}/tests/test_core.py +0 -0
@@ -0,0 +1,137 @@
1
+ Metadata-Version: 2.4
2
+ Name: askai-python
3
+ Version: 0.2.1
4
+ Summary: AI Made Stupid Simple. Unified API for OpenAI, Groq, Google, and more.
5
+ Author-email: Hossein Ghorbani <hosseingh1068@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://hosseinghorbani0.ir/
8
+ Project-URL: Bug Tracker, https://github.com/Hosseinghorbani0/ask-ai/issues
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: openai>=1.0.0
13
+ Requires-Dist: groq
14
+ Requires-Dist: google-generativeai
15
+ Requires-Dist: anthropic
16
+ Requires-Dist: requests
17
+ Requires-Dist: Pillow
18
+ Dynamic: license-file
19
+
20
+ # askai-python 🚀
21
+
22
+ **A minimal Python SDK to switch between LLM providers in one line.**
23
+ No frameworks. No servers. No overengineering.
24
+
25
+ [![PyPI version](https://img.shields.io/pypi/v/askai-python.svg)](https://pypi.org/project/askai-python/)
26
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
27
+ [![GitHub](https://img.shields.io/badge/GitHub-View%20Source-blue.svg)](https://github.com/Hosseinghorbani0/ask-ai)
28
+
29
+ ---
30
+
31
+ ## ⚡ Quick Start (5 seconds)
32
+
33
+ ```bash
34
+ pip install askai-python
35
+ ```
36
+
37
+ ```python
38
+ from ask_ai import OpenAI, Groq
39
+
40
+ # Auto-detects OPENAI_API_KEY from environment
41
+ print(OpenAI().ask("Explain black holes like I'm 5").text)
42
+
43
+ # Switch provider instantly
44
+ print(Groq().ask("Explain black holes like I'm 5").text)
45
+ ```
46
+
47
+ ---
48
+
49
+ ## 🧐 Why ask-ai?
50
+
51
+ - **One function**: Just call `.ask()`
52
+ - **Multiple providers**: OpenAI, Anthropic, Google Gemini, Groq, Azure, OpenRouter
53
+ - **Zero config**: Keys are pulled from the environment automatically
54
+ - **SDK-first, not a framework**: It stays out of your way.
55
+
56
+ ## 🚫 What this project is NOT
57
+
58
+ > ❌ Not an AI framework
59
+ > ❌ Not an API gateway
60
+ > ❌ Not an agent memory system
61
+
62
+ It does one thing perfectly: **Simplifying the API call to LLMs.**
63
+
64
+ ---
65
+
66
+ ## 🛠️ Advanced Usage
67
+
68
+ ### 🧰 Developer QoL Utilities (Auto-Parsing)
69
+ Stop writing Regex to clean up model outputs! `ask-ai` comes with built-in text processing flags:
70
+
71
+ ```python
72
+ from ask_ai import OpenAI
73
+ ai = OpenAI()
74
+
75
+ # 1. Clean Markdown (Removes ```json and ``` tags)
76
+ # Perfect for extracting raw data from models that wrap everything in markdown
77
+ clean_text = ai.ask("Write JSON", clean=True).text
78
+
79
+ # 2. Extract Code (Returns ONLY the code block, ignores conversational filler)
80
+ # Great for automation pipelines
81
+ code = ai.ask("Write a python ping script", code=True).text
82
+
83
+ # 3. Strip Tags (Removes <think> blocks and HTML)
84
+ # Essential for reasoning models like DeepSeek-R1
85
+ answer_only = ai.ask("What is 1+1?", strip=True).text
86
+
87
+ # 4. Enforce & Parse JSON (Directly returns a Parsed Python Dictionary)
88
+ # Adds JSON instructions to the prompt and safely runs json.loads()
89
+ data_dict = ai.ask("Extract user info", json=True).json
90
+ print(data_dict['name'])
91
+ ```
92
+
93
+ ## 🚀 Built-in Resiliency (Retries & Timeouts)
94
+
95
+ Build reliable apps without writing your own loops. `askai-python` handles rate limits (`429`) and network drops via an internal exponential backoff.
96
+
97
+ ```python
98
+ from ask_ai import OpenAI
99
+
100
+ ai = OpenAI()
101
+
102
+ # Automatically retries up to 3 times on transient errors, with a 15-second timeout
103
+ response = ai.ask(
104
+ "Write a complex python script",
105
+ retry=3,
106
+ timeout=15
107
+ )
108
+ ```
109
+
110
+ ## 🔌 Supported Providers
111
+
112
+ | Provider | Class | Capabilities |
113
+ |----------|-------|-------------|
114
+ | **OpenAI** | `OpenAI` | Text, Images (DALL-E), Vision |
115
+ | **Anthropic** | `Anthropic` | Text, Vision (Claude 3.5) |
116
+ | **Google** | `Google` | Text, Images, Video, Audio |
117
+ | **Groq** | `Groq` | Ultra-fast Llama 3 & Mixtral |
118
+ | **Azure** | `Azure` | Enterprise-grade OpenAI |
119
+ | **OpenRouter**| `OpenRouter`| 100+ community models |
120
+
121
+ ---
122
+
123
+ ## 🗺️ Roadmap
124
+
125
+ - [x] Baseline multiple providers
126
+ - [x] Automated Retry & Timeout controls
127
+ - [ ] Async API (`await ask_async`)
128
+ - [ ] Provider Fallback (`fallback=[Groq()]`)
129
+ - [ ] Structured Outputs (Pydantic Support)
130
+
131
+ ---
132
+
133
+ ## 🔗 Important Links
134
+
135
+ - **GitHub Repository**: [Hosseinghorbani0/ask-ai](https://github.com/Hosseinghorbani0/ask-ai) (Star us! ⭐)
136
+ - **Official Website**: [hosseinghorbani0.ir](https://hosseinghorbani0.ir/)
137
+ - **Bug Tracker**: [Report an Issue](https://github.com/Hosseinghorbani0/ask-ai/issues)
@@ -0,0 +1,130 @@
1
+ # ask-ai
2
+
3
+ <p align="center">
4
+ 🌍 <b>Readme:</b>
5
+ <a href="README.md"><img src="https://flagcdn.com/20x15/us.png" alt="English"> English</a> ·
6
+ <a href="docs/README_fa.md"><img src="https://flagcdn.com/20x15/ir.png" alt="Persian"> فارسی</a> ·
7
+ <a href="docs/README_zh.md"><img src="https://flagcdn.com/20x15/cn.png" alt="Chinese"> 中文</a> ·
8
+ <a href="docs/README_tr.md"><img src="https://flagcdn.com/20x15/tr.png" alt="Turkish"> Türkçe</a> ·
9
+ <a href="docs/README_ar.md"><img src="https://flagcdn.com/20x15/sa.png" alt="Arabic"> العربية</a> ·
10
+ <a href="docs/README_ru.md"><img src="https://flagcdn.com/20x15/ru.png" alt="Russian"> Русский</a> ·
11
+ <a href="docs/README_es.md"><img src="https://flagcdn.com/20x15/es.png" alt="Spanish"> Español</a> ·
12
+ <a href="docs/README_ja.md"><img src="https://flagcdn.com/20x15/jp.png" alt="Japanese"> 日本語</a>
13
+ </p>
14
+
15
+ <p align="center">
16
+ <b>A minimal Python SDK to switch between LLM providers in one line.</b><br/>
17
+ No frameworks. No servers. No overengineering.
18
+ </p>
19
+
20
+ [![PyPI version](https://img.shields.io/pypi/v/askai-python.svg)](https://pypi.org/project/askai-python/)
21
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
22
+ [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
23
+
24
+ ---
25
+
26
+ ## ⚡ Quick Start (5 seconds)
27
+
28
+ ```bash
29
+ pip install askai-python
30
+ ```
31
+
32
+ ```python
33
+ from ask_ai import OpenAI, Groq
34
+
35
+ # Auto-detects OPENAI_API_KEY from environment
36
+ OpenAI().ask("Explain black holes like I'm 5").text
37
+
38
+ # Switch provider effortlessly
39
+ Groq().ask("Explain black holes like I'm 5").text
40
+ ```
41
+
42
+ ---
43
+
44
+ ## 🧐 Why ask-ai?
45
+
46
+ - **One function**: Just call `.ask()`
47
+ - **Multiple providers**: OpenAI, Anthropic, Google Gemini, Groq, Azure, OpenRouter
48
+ - **Zero config**: Keys are pulled from the environment automatically
49
+ - **SDK-first, not a framework**: It stays out of your way.
50
+
51
+ ## 🚫 What this project is NOT
52
+
53
+ > ❌ Not an AI framework
54
+ > ❌ Not an API gateway
55
+ > ❌ Not an agent memory system
56
+
57
+ It does one thing perfectly: **Simplifying the API call to LLMs.**
58
+
59
+ ---
60
+
61
+ ## 🛠️ Advanced Usage
62
+
63
+ ### 🧰 Developer QoL Utilities (Auto-Parsing)
64
+ Stop writing Regex to clean up model outputs! `ask-ai` comes with built-in text processing flags:
65
+
66
+ ```python
67
+ from ask_ai import OpenAI
68
+ ai = OpenAI()
69
+
70
+ # 1. Clean Markdown (Removes ```json and ``` tags)
71
+ # Perfect for extracting raw data from models that wrap everything in markdown
72
+ clean_text = ai.ask("Write JSON", clean=True).text
73
+
74
+ # 2. Extract Code (Returns ONLY the code block, ignores conversational filler)
75
+ # Great for automation pipelines
76
+ code = ai.ask("Write a python ping script", code=True).text
77
+
78
+ # 3. Strip Tags (Removes <think> blocks and HTML)
79
+ # Essential for reasoning models like DeepSeek-R1
80
+ answer_only = ai.ask("What is 1+1?", strip=True).text
81
+
82
+ # 4. Enforce & Parse JSON (Directly returns a Parsed Python Dictionary)
83
+ # Adds JSON instructions to the prompt and safely runs json.loads()
84
+ data_dict = ai.ask("Extract user info", json=True).json
85
+ print(data_dict['name'])
86
+ ```
87
+
88
+ ### 🔄 Built-in Retries & Timeout (Resiliency)
89
+ Handle rate limits (`429`) and network drops automatically:
90
+
91
+ ```python
92
+ from ask_ai import OpenAI
93
+ ai = OpenAI()
94
+
95
+ # Will retry up to 3 times on RateLimit/Network errors, with generic timeout
96
+ response = ai.ask("Write a script", retry=3, timeout=10)
97
+ ```
98
+
99
+ ### System Configuration
100
+ Set system prompts and temperature directly:
101
+
102
+ ```python
103
+ ai.advanced(
104
+ temperature=0.7,
105
+ prompt="You are a senior DevOps engineer."
106
+ )
107
+
108
+ print(ai.ask("How do I optimize a Dockerfile?").text)
109
+ ```
110
+
111
+ ---
112
+
113
+ ## 🗺️ Roadmap
114
+
115
+ - [x] OpenAI, Groq, Gemini, Anthropic, Azure, OpenRouter support
116
+ - [x] Text to Image (DALL-E) and Text to Audio
117
+ - [x] Automated Retry & Timeout controls
118
+ - [ ] Async Support (`await ask_async`)
119
+ - [ ] Provider Fallback (`ask(..., providers=[OpenAI, Groq])`)
120
+ - [ ] Streaming Support (`ask_stream`)
121
+ - [ ] Structured Output (Pydantic Support)
122
+
123
+ ---
124
+
125
+ ## 🔗 Important Links
126
+
127
+ - **PyPI**: [askai-python](https://pypi.org/project/askai-python/)
128
+ - **GitHub Repository**: [Hosseinghorbani0/ask-ai](https://github.com/Hosseinghorbani0/ask-ai) (Star us! ⭐)
129
+ - **Official Website**: [hosseinghorbani0.ir](https://hosseinghorbani0.ir/)
130
+ - **Bug Tracker**: [Report an Issue](https://github.com/Hosseinghorbani0/ask-ai/issues)
@@ -9,9 +9,30 @@ class Response:
9
9
  """
10
10
  Unified response object for all easyai requests.
11
11
  """
12
- def __init__(self, text: str = "", media: Union[ImageObject, AudioObject, None] = None):
13
- self.text = text
12
+ def __init__(self, text: str = "", media: Union[ImageObject, AudioObject, None] = None, **kwargs):
13
+ self._raw_text = text
14
14
  self.media = media
15
+ self._kwargs = kwargs
16
+
17
+ @property
18
+ def text(self) -> str:
19
+ text = self._raw_text
20
+ if self._kwargs.get('strip'):
21
+ from .utils import strip_tags
22
+ text = strip_tags(text)
23
+ if self._kwargs.get('clean'):
24
+ from .utils import clean_markdown
25
+ text = clean_markdown(text)
26
+ if self._kwargs.get('code'):
27
+ from .utils import extract_code
28
+ text = extract_code(text)
29
+ return text
30
+
31
+ @property
32
+ def json(self) -> Union[Dict[str, Any], list]:
33
+ """Returns parsed JSON. If 'json=True' was passed, this is highly reliable."""
34
+ from .utils import parse_json
35
+ return parse_json(self._raw_text)
15
36
 
16
37
  def __str__(self):
17
38
  return self.text
@@ -82,18 +103,70 @@ class BaseProvider:
82
103
  # 3. Check for specific output_type override (e.g. user forced image)
83
104
  output_type = kwargs.get('output_type')
84
105
 
85
- # 4. Call Provider Implementation
86
- return self._send_request(messages, final_config, output_type)
106
+ # 4. Extract timeout and retry safely
107
+ timeout_val = kwargs.get('timeout', final_config.extra.get('timeout', 30))
108
+ retry_val = kwargs.get('retry', final_config.extra.get('retry', 0))
109
+
110
+ timeout = float(timeout_val) if timeout_val is not None else 30.0
111
+ retry = int(retry_val) if retry_val is not None else 0
112
+
113
+ final_config.extra['timeout'] = timeout # Pass down to providers
114
+
115
+ # 5. Execute with Retry Logic
116
+ attempts = 0
117
+ last_error = None
118
+ while attempts <= retry:
119
+ try:
120
+ response = self._send_request(messages, final_config, output_type)
121
+ # Attach parsing arguments to the response object dynamically
122
+ response._kwargs.update(kwargs)
123
+ return response
124
+ except Exception as e:
125
+ last_error = e
126
+ if self._is_retryable_error(e) and attempts < retry:
127
+ attempts += 1
128
+ delay = 2 ** attempts # 2s, 4s, 8s...
129
+ print(f"[ask-ai] Transient error ({e.__class__.__name__}). Retrying in {delay}s... ({attempts}/{retry})")
130
+ import time
131
+ time.sleep(delay)
132
+ else:
133
+ raise e
134
+
135
+ # Fallback if loop exits without returning
136
+ from .exceptions import AskAINetworkError
137
+ raise AskAINetworkError(f"Request failed after {retry} retries. Last error: {last_error}")
138
+
139
+ def _is_retryable_error(self, e: Exception) -> bool:
140
+ """Dynamically detect rate limits and network timeouts across different provider SDKs."""
141
+ err_str = str(e).lower()
142
+ err_cls = e.__class__.__name__.lower()
143
+
144
+ # Explicit ask-ai errors
145
+ from .exceptions import AskAINetworkError, AskAIRateLimitError
146
+ if isinstance(e, (AskAINetworkError, AskAIRateLimitError)): return True
147
+
148
+ # Heuristics for underlying provider SDKs (OpenAI, Anthropic, etc.)
149
+ if "ratelimit" in err_cls or "rate_limit" in err_cls or "429" in err_str: return True
150
+ if "timeout" in err_cls or "timeout" in err_str: return True
151
+ if "connection" in err_cls or "connecterror" in err_cls: return True
152
+
153
+ return False
87
154
 
88
155
  def _merge_configs(self, global_conf: AdvancedConfig, req_conf: AdvancedConfig) -> AdvancedConfig:
89
156
  return global_conf.merge(req_conf) # We need to implement merge logic in AdvancedConfig properly or here
90
157
 
91
158
  def _prepare_messages(self, query: str, config: AdvancedConfig) -> List[Dict[str, str]]:
92
159
  messages = []
93
- if config.system_message:
94
- messages.append({"role": "system", "content": config.system_message})
95
- elif self.persona:
96
- messages.append({"role": "system", "content": self.persona})
160
+
161
+ system_msg = config.system_message or self.persona or ""
162
+
163
+ # Smart capability: if json=True, enforce JSON system prompt
164
+ if config.extra.get('json'):
165
+ json_instruction = "You must respond with valid JSON only, without any markdown formatting or tags."
166
+ system_msg = f"{system_msg}\n{json_instruction}".strip()
167
+
168
+ if system_msg:
169
+ messages.append({"role": "system", "content": system_msg})
97
170
 
98
171
  messages.append({"role": "user", "content": query})
99
172
  return messages
@@ -0,0 +1,30 @@
1
+ class AskAIError(Exception):
2
+ """Base exception for all ask-ai errors."""
3
+ pass
4
+
5
+ class AskAIConfigError(AskAIError):
6
+ """Raised when configuration (like API keys) is missing or invalid."""
7
+ pass
8
+
9
+ class AskAINetworkError(AskAIError):
10
+ """Raised when a network connection fails (timeout, disconnect)."""
11
+ pass
12
+
13
+ class AskAIRateLimitError(AskAIError):
14
+ """Raised when the provider rate limits the request (429)."""
15
+ pass
16
+
17
+ class ProviderError(AskAIError):
18
+ """Raised when the provider API fails (e.g. 500 error or bad request)."""
19
+ pass
20
+
21
+ class MediaTypeNotSupportedError(AskAIError):
22
+ """Raised when a provider can't handle the requested media type."""
23
+ pass
24
+
25
+ class AskAIParsingError(AskAIError):
26
+ """Raised when expect_json is True but the response cannot be parsed."""
27
+ pass
28
+
29
+ # Alias for backwards compatibility internally
30
+ APIKeyError = AskAIConfigError
@@ -0,0 +1,43 @@
1
+ import re
2
+ import json
3
+ from typing import Dict, Any, Union
4
+
5
+ def clean_markdown(text: str) -> str:
6
+ """Removes markdown code blocks like ```json ... ```"""
7
+ text = text.strip()
8
+ if text.startswith("```"):
9
+ # find the first newline
10
+ first_newline = text.find("\n")
11
+ if first_newline != -1:
12
+ text = text[first_newline+1:]
13
+ if text.endswith("```"):
14
+ text = text[:-3]
15
+ return text.strip()
16
+
17
+ def extract_code(text: str) -> str:
18
+ """Extracts code blocks from text, ignoring conversational filler."""
19
+ text = str(text)
20
+ matches = re.findall(r'```(?:[\w]*\n)?(.*?)```', text, re.DOTALL)
21
+ if matches:
22
+ return "\n\n".join(m.strip() for m in matches)
23
+ return text
24
+
25
+ def strip_tags(text: str) -> str:
26
+ """Removes XML/HTML tags, including <think>...</think> blocks."""
27
+ # First remove <think>...</think> entirely if we don't want the thought process
28
+ text = re.sub(r'<think>.*?</think>', '', text, flags=re.DOTALL)
29
+ # Remove any other HTML tags
30
+ text = re.sub(r'<[^>]+>', '', text)
31
+ return text.strip()
32
+
33
+ def parse_json(text: str) -> Union[Dict[str, Any], list]:
34
+ """Tries to parse JSON from text, employing cleaning if necessary."""
35
+ try:
36
+ return json.loads(text)
37
+ except json.JSONDecodeError:
38
+ cleaned = clean_markdown(text)
39
+ try:
40
+ return json.loads(cleaned)
41
+ except json.JSONDecodeError as e:
42
+ from .exceptions import AskAIParsingError
43
+ raise AskAIParsingError(f"Failed to parse JSON: {e}\nContent snippet: {text[:100]}...")
@@ -0,0 +1,137 @@
1
+ Metadata-Version: 2.4
2
+ Name: askai-python
3
+ Version: 0.2.1
4
+ Summary: AI Made Stupid Simple. Unified API for OpenAI, Groq, Google, and more.
5
+ Author-email: Hossein Ghorbani <hosseingh1068@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://hosseinghorbani0.ir/
8
+ Project-URL: Bug Tracker, https://github.com/Hosseinghorbani0/ask-ai/issues
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: openai>=1.0.0
13
+ Requires-Dist: groq
14
+ Requires-Dist: google-generativeai
15
+ Requires-Dist: anthropic
16
+ Requires-Dist: requests
17
+ Requires-Dist: Pillow
18
+ Dynamic: license-file
19
+
20
+ # askai-python 🚀
21
+
22
+ **A minimal Python SDK to switch between LLM providers in one line.**
23
+ No frameworks. No servers. No overengineering.
24
+
25
+ [![PyPI version](https://img.shields.io/pypi/v/askai-python.svg)](https://pypi.org/project/askai-python/)
26
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
27
+ [![GitHub](https://img.shields.io/badge/GitHub-View%20Source-blue.svg)](https://github.com/Hosseinghorbani0/ask-ai)
28
+
29
+ ---
30
+
31
+ ## ⚡ Quick Start (5 seconds)
32
+
33
+ ```bash
34
+ pip install askai-python
35
+ ```
36
+
37
+ ```python
38
+ from ask_ai import OpenAI, Groq
39
+
40
+ # Auto-detects OPENAI_API_KEY from environment
41
+ print(OpenAI().ask("Explain black holes like I'm 5").text)
42
+
43
+ # Switch provider instantly
44
+ print(Groq().ask("Explain black holes like I'm 5").text)
45
+ ```
46
+
47
+ ---
48
+
49
+ ## 🧐 Why ask-ai?
50
+
51
+ - **One function**: Just call `.ask()`
52
+ - **Multiple providers**: OpenAI, Anthropic, Google Gemini, Groq, Azure, OpenRouter
53
+ - **Zero config**: Keys are pulled from the environment automatically
54
+ - **SDK-first, not a framework**: It stays out of your way.
55
+
56
+ ## 🚫 What this project is NOT
57
+
58
+ > ❌ Not an AI framework
59
+ > ❌ Not an API gateway
60
+ > ❌ Not an agent memory system
61
+
62
+ It does one thing perfectly: **Simplifying the API call to LLMs.**
63
+
64
+ ---
65
+
66
+ ## 🛠️ Advanced Usage
67
+
68
+ ### 🧰 Developer QoL Utilities (Auto-Parsing)
69
+ Stop writing Regex to clean up model outputs! `ask-ai` comes with built-in text processing flags:
70
+
71
+ ```python
72
+ from ask_ai import OpenAI
73
+ ai = OpenAI()
74
+
75
+ # 1. Clean Markdown (Removes ```json and ``` tags)
76
+ # Perfect for extracting raw data from models that wrap everything in markdown
77
+ clean_text = ai.ask("Write JSON", clean=True).text
78
+
79
+ # 2. Extract Code (Returns ONLY the code block, ignores conversational filler)
80
+ # Great for automation pipelines
81
+ code = ai.ask("Write a python ping script", code=True).text
82
+
83
+ # 3. Strip Tags (Removes <think> blocks and HTML)
84
+ # Essential for reasoning models like DeepSeek-R1
85
+ answer_only = ai.ask("What is 1+1?", strip=True).text
86
+
87
+ # 4. Enforce & Parse JSON (Directly returns a Parsed Python Dictionary)
88
+ # Adds JSON instructions to the prompt and safely runs json.loads()
89
+ data_dict = ai.ask("Extract user info", json=True).json
90
+ print(data_dict['name'])
91
+ ```
92
+
93
+ ## 🚀 Built-in Resiliency (Retries & Timeouts)
94
+
95
+ Build reliable apps without writing your own loops. `askai-python` handles rate limits (`429`) and network drops via an internal exponential backoff.
96
+
97
+ ```python
98
+ from ask_ai import OpenAI
99
+
100
+ ai = OpenAI()
101
+
102
+ # Automatically retries up to 3 times on transient errors, with a 15-second timeout
103
+ response = ai.ask(
104
+ "Write a complex python script",
105
+ retry=3,
106
+ timeout=15
107
+ )
108
+ ```
109
+
110
+ ## 🔌 Supported Providers
111
+
112
+ | Provider | Class | Capabilities |
113
+ |----------|-------|-------------|
114
+ | **OpenAI** | `OpenAI` | Text, Images (DALL-E), Vision |
115
+ | **Anthropic** | `Anthropic` | Text, Vision (Claude 3.5) |
116
+ | **Google** | `Google` | Text, Images, Video, Audio |
117
+ | **Groq** | `Groq` | Ultra-fast Llama 3 & Mixtral |
118
+ | **Azure** | `Azure` | Enterprise-grade OpenAI |
119
+ | **OpenRouter**| `OpenRouter`| 100+ community models |
120
+
121
+ ---
122
+
123
+ ## 🗺️ Roadmap
124
+
125
+ - [x] Baseline multiple providers
126
+ - [x] Automated Retry & Timeout controls
127
+ - [ ] Async API (`await ask_async`)
128
+ - [ ] Provider Fallback (`fallback=[Groq()]`)
129
+ - [ ] Structured Outputs (Pydantic Support)
130
+
131
+ ---
132
+
133
+ ## 🔗 Important Links
134
+
135
+ - **GitHub Repository**: [Hosseinghorbani0/ask-ai](https://github.com/Hosseinghorbani0/ask-ai) (Star us! ⭐)
136
+ - **Official Website**: [hosseinghorbani0.ir](https://hosseinghorbani0.ir/)
137
+ - **Bug Tracker**: [Report an Issue](https://github.com/Hosseinghorbani0/ask-ai/issues)
@@ -8,6 +8,7 @@ ask_ai/cli.py
8
8
  ask_ai/config.py
9
9
  ask_ai/exceptions.py
10
10
  ask_ai/media.py
11
+ ask_ai/utils.py
11
12
  ask_ai/providers/__init__.py
12
13
  ask_ai/providers/anthropic_provider.py
13
14
  ask_ai/providers/azure_provider.py
@@ -0,0 +1,118 @@
1
+ # askai-python 🚀
2
+
3
+ **A minimal Python SDK to switch between LLM providers in one line.**
4
+ No frameworks. No servers. No overengineering.
5
+
6
+ [![PyPI version](https://img.shields.io/pypi/v/askai-python.svg)](https://pypi.org/project/askai-python/)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
+ [![GitHub](https://img.shields.io/badge/GitHub-View%20Source-blue.svg)](https://github.com/Hosseinghorbani0/ask-ai)
9
+
10
+ ---
11
+
12
+ ## ⚡ Quick Start (5 seconds)
13
+
14
+ ```bash
15
+ pip install askai-python
16
+ ```
17
+
18
+ ```python
19
+ from ask_ai import OpenAI, Groq
20
+
21
+ # Auto-detects OPENAI_API_KEY from environment
22
+ print(OpenAI().ask("Explain black holes like I'm 5").text)
23
+
24
+ # Switch provider instantly
25
+ print(Groq().ask("Explain black holes like I'm 5").text)
26
+ ```
27
+
28
+ ---
29
+
30
+ ## 🧐 Why ask-ai?
31
+
32
+ - **One function**: Just call `.ask()`
33
+ - **Multiple providers**: OpenAI, Anthropic, Google Gemini, Groq, Azure, OpenRouter
34
+ - **Zero config**: Keys are pulled from the environment automatically
35
+ - **SDK-first, not a framework**: It stays out of your way.
36
+
37
+ ## 🚫 What this project is NOT
38
+
39
+ > ❌ Not an AI framework
40
+ > ❌ Not an API gateway
41
+ > ❌ Not an agent memory system
42
+
43
+ It does one thing perfectly: **Simplifying the API call to LLMs.**
44
+
45
+ ---
46
+
47
+ ## 🛠️ Advanced Usage
48
+
49
+ ### 🧰 Developer QoL Utilities (Auto-Parsing)
50
+ Stop writing Regex to clean up model outputs! `ask-ai` comes with built-in text processing flags:
51
+
52
+ ```python
53
+ from ask_ai import OpenAI
54
+ ai = OpenAI()
55
+
56
+ # 1. Clean Markdown (Removes ```json and ``` tags)
57
+ # Perfect for extracting raw data from models that wrap everything in markdown
58
+ clean_text = ai.ask("Write JSON", clean=True).text
59
+
60
+ # 2. Extract Code (Returns ONLY the code block, ignores conversational filler)
61
+ # Great for automation pipelines
62
+ code = ai.ask("Write a python ping script", code=True).text
63
+
64
+ # 3. Strip Tags (Removes <think> blocks and HTML)
65
+ # Essential for reasoning models like DeepSeek-R1
66
+ answer_only = ai.ask("What is 1+1?", strip=True).text
67
+
68
+ # 4. Enforce & Parse JSON (Directly returns a Parsed Python Dictionary)
69
+ # Adds JSON instructions to the prompt and safely runs json.loads()
70
+ data_dict = ai.ask("Extract user info", json=True).json
71
+ print(data_dict['name'])
72
+ ```
73
+
74
+ ## 🚀 Built-in Resiliency (Retries & Timeouts)
75
+
76
+ Build reliable apps without writing your own loops. `askai-python` handles rate limits (`429`) and network drops via an internal exponential backoff.
77
+
78
+ ```python
79
+ from ask_ai import OpenAI
80
+
81
+ ai = OpenAI()
82
+
83
+ # Automatically retries up to 3 times on transient errors, with a 15-second timeout
84
+ response = ai.ask(
85
+ "Write a complex python script",
86
+ retry=3,
87
+ timeout=15
88
+ )
89
+ ```
90
+
91
+ ## 🔌 Supported Providers
92
+
93
+ | Provider | Class | Capabilities |
94
+ |----------|-------|-------------|
95
+ | **OpenAI** | `OpenAI` | Text, Images (DALL-E), Vision |
96
+ | **Anthropic** | `Anthropic` | Text, Vision (Claude 3.5) |
97
+ | **Google** | `Google` | Text, Images, Video, Audio |
98
+ | **Groq** | `Groq` | Ultra-fast Llama 3 & Mixtral |
99
+ | **Azure** | `Azure` | Enterprise-grade OpenAI |
100
+ | **OpenRouter**| `OpenRouter`| 100+ community models |
101
+
102
+ ---
103
+
104
+ ## 🗺️ Roadmap
105
+
106
+ - [x] Baseline multiple providers
107
+ - [x] Automated Retry & Timeout controls
108
+ - [ ] Async API (`await ask_async`)
109
+ - [ ] Provider Fallback (`fallback=[Groq()]`)
110
+ - [ ] Structured Outputs (Pydantic Support)
111
+
112
+ ---
113
+
114
+ ## 🔗 Important Links
115
+
116
+ - **GitHub Repository**: [Hosseinghorbani0/ask-ai](https://github.com/Hosseinghorbani0/ask-ai) (Star us! ⭐)
117
+ - **Official Website**: [hosseinghorbani0.ir](https://hosseinghorbani0.ir/)
118
+ - **Bug Tracker**: [Report an Issue](https://github.com/Hosseinghorbani0/ask-ai/issues)
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "askai-python"
7
- version = "0.1.6"
7
+ version = "0.2.1"
8
8
  description = "AI Made Stupid Simple. Unified API for OpenAI, Groq, Google, and more."
9
9
  readme = "docs/PYPI_README.md"
10
10
  requires-python = ">=3.8"
@@ -1,135 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: askai-python
3
- Version: 0.1.6
4
- Summary: AI Made Stupid Simple. Unified API for OpenAI, Groq, Google, and more.
5
- Author-email: Hossein Ghorbani <hosseingh1068@gmail.com>
6
- License: MIT
7
- Project-URL: Homepage, https://hosseinghorbani0.ir/
8
- Project-URL: Bug Tracker, https://github.com/Hosseinghorbani0/ask-ai/issues
9
- Requires-Python: >=3.8
10
- Description-Content-Type: text/markdown
11
- License-File: LICENSE
12
- Requires-Dist: openai>=1.0.0
13
- Requires-Dist: groq
14
- Requires-Dist: google-generativeai
15
- Requires-Dist: anthropic
16
- Requires-Dist: requests
17
- Requires-Dist: Pillow
18
- Dynamic: license-file
19
-
20
- # askai-python 🚀
21
-
22
- **AI Made Stupid Simple.** One unified Python client for OpenAI, Claude, Gemini, Groq, and Azure.
23
-
24
- [![PyPI version](https://img.shields.io/pypi/v/askai-python.svg)](https://pypi.org/project/askai-python/)
25
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
26
- [![GitHub](https://img.shields.io/badge/GitHub-View%20Source-blue.svg)](https://github.com/Hosseinghorbani0/ask-ai)
27
-
28
- ---
29
-
30
- ## ⚡ What is askai-python?
31
-
32
- `askai-python` is a lightweight, zero-dependency-logic wrapper that provides a **single API** for all major AI providers. Stop learning multiple SDKs; just call `.ask()` and get your answer.
33
-
34
- - **Unified Interface**: One syntax for OpenAI, Anthropic, Google, and more.
35
- - **Zero-Config**: Seamlessly uses environment variables for API keys.
36
- - **Smart Media**: Easy handling of images and audio (Provider permitting).
37
- - **Production Grade**: Built-in robust error handling and type hints.
38
-
39
- ---
40
-
41
- ## 📦 Installation
42
-
43
- ```bash
44
- pip install askai-python
45
- ```
46
-
47
- ---
48
-
49
- ## 🚀 Examples & Tutorials
50
-
51
- ### 1. Basic Usage (The 3-Line Magic)
52
- ```python
53
- from ask_ai import OpenAI
54
-
55
- ai = OpenAI() # Auto-loads OPENAI_API_KEY from env
56
- print(ai.ask("What is the capital of France?").text)
57
- ```
58
-
59
- ### 2. Multi-Provider Mastery
60
- Switching between top-tier models has never been easier:
61
-
62
- ```python
63
- from ask_ai import OpenAI, Anthropic, Google
64
-
65
- prompt = "Explain quantum computing to a 5-year-old."
66
-
67
- # OpenAI (GPT-4o)
68
- print(OpenAI().ask(prompt).text)
69
-
70
- # Anthropic (Claude 3.5 Sonnet)
71
- print(Anthropic().ask(prompt).text)
72
-
73
- # Google (Gemini 1.5 Pro)
74
- print(Google().ask(prompt).text)
75
- ```
76
-
77
- ### 3. Advanced Configuration (System Personas)
78
- You can set a system prompt and temperature globally for an instance or per-request.
79
-
80
- ```python
81
- from ask_ai import OpenAI
82
-
83
- ai = OpenAI()
84
-
85
- # Global config
86
- ai.advanced(
87
- prompt="You are a sarcastic robot from the year 3000.",
88
- temperature=0.9
89
- )
90
-
91
- print(ai.ask("What is love?").text)
92
-
93
- # Per-request override
94
- print(ai.ask("What is 1+1?", temperature=0.1).text)
95
- ```
96
-
97
- ### 4. Handling Structured Exceptions
98
- Build reliable apps by catching specific AI errors:
99
-
100
- ```python
101
- from ask_ai import OpenAI
102
- from ask_ai.exceptions import AskAIError, APIKeyError
103
-
104
- try:
105
- ai = OpenAI(api_key="invalid-key")
106
- ai.ask("Hello")
107
- except APIKeyError:
108
- print("Check your API keys!")
109
- except AskAIError as e:
110
- print(f"An AI error occurred: {e}")
111
- ```
112
-
113
- ---
114
-
115
- ## 🔌 Supported Providers
116
-
117
- | Provider | Class | Capabilities |
118
- |----------|-------|-------------|
119
- | **OpenAI** | `OpenAI` | Text, Images (DALL-E), Vision |
120
- | **Anthropic** | `Anthropic` | Text, Vision (Claude 3.5) |
121
- | **Google** | `Google` | Text, Images, Video, Audio |
122
- | **Groq** | `Groq` | Ultra-fast Llama 3 & Mixtral |
123
- | **Azure** | `Azure` | Enterprise-grade OpenAI |
124
- | **OpenRouter**| `OpenRouter`| 100+ community models |
125
-
126
- ---
127
-
128
- ## 🔗 Important Links
129
-
130
- - **GitHub Repository**: [Hosseinghorbani0/ask-ai](https://github.com/Hosseinghorbani0/ask-ai) (Star us! ⭐)
131
- - **Official Website**: [hosseinghorbani0.ir](https://hosseinghorbani0.ir/)
132
- - **Bug Tracker**: [Report an Issue](https://github.com/Hosseinghorbani0/ask-ai/issues)
133
-
134
- ---
135
- *Built with ❤️ by [Hossein Ghorbani](https://github.com/Hosseinghorbani0).*
@@ -1,111 +0,0 @@
1
- # ask-ai
2
-
3
- <p align="center">
4
- 🌍 <b>Readme:</b>
5
- <a href="README.md"><img src="https://flagcdn.com/20x15/us.png" alt="English"> English</a> ·
6
- <a href="docs/README_fa.md"><img src="https://flagcdn.com/20x15/ir.png" alt="Persian"> فارسی</a> ·
7
- <a href="docs/README_zh.md"><img src="https://flagcdn.com/20x15/cn.png" alt="Chinese"> 中文</a> ·
8
- <a href="docs/README_tr.md"><img src="https://flagcdn.com/20x15/tr.png" alt="Turkish"> Türkçe</a> ·
9
- <a href="docs/README_ar.md"><img src="https://flagcdn.com/20x15/sa.png" alt="Arabic"> العربية</a> ·
10
- <a href="docs/README_ru.md"><img src="https://flagcdn.com/20x15/ru.png" alt="Russian"> Русский</a> ·
11
- <a href="docs/README_es.md"><img src="https://flagcdn.com/20x15/es.png" alt="Spanish"> Español</a> ·
12
- <a href="docs/README_ja.md"><img src="https://flagcdn.com/20x15/jp.png" alt="Japanese"> 日本語</a>
13
- </p>
14
-
15
- <p align="center">
16
- <b>AI Made Simple.</b><br/>
17
- One unified Python client for OpenAI, Claude, Gemini, Groq & more.
18
- </p>
19
-
20
- > Stop rewriting AI code for every provider. Use one line. Switch models anytime.
21
-
22
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
23
- [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
24
-
25
- ---
26
-
27
- ## ⚡ Why ask-ai?
28
-
29
- - **No SDK lock-in**: Don't learn 5 different libraries. Learn one.
30
- - **Unified API**: `ai.ask()` works for text, images, and audio across all providers.
31
- - **Production Ready**: Built-in type safety, error handling, and environment management.
32
- - **Zero-Config**: Auto-detects API keys from your environment.
33
-
34
- ---
35
-
36
- ## 🚀 The Golden Example
37
-
38
- See the power of `ask-ai` in 3 lines of code:
39
-
40
- ```python
41
- from ask_ai import OpenAI, Anthropic, Google
42
-
43
- prompt = "Explain quantum computing in one sentence."
44
-
45
- # Switch providers instantly
46
- print("OpenAI: ", OpenAI().ask(prompt))
47
- print("Claude: ", Anthropic().ask(prompt))
48
- print("Gemini: ", Google().ask(prompt))
49
- ```
50
-
51
- ---
52
-
53
- ## 📦 Installation
54
-
55
- ```bash
56
- pip install askai-python
57
- ```
58
-
59
- ---
60
-
61
- ## 📖 Quick Start
62
-
63
- ### 1. Setup
64
- Export your API keys (or pass them explicitly).
65
- ```bash
66
- export OPENAI_API_KEY="sk-..."
67
- export ANTHROPIC_API_KEY="sk-ant-..."
68
- ```
69
-
70
- ### 2. Standard Usage
71
- ```python
72
- from ask_ai import OpenAI
73
-
74
- ai = OpenAI()
75
- print(ai.ask("Hello, World!"))
76
- ```
77
-
78
- ### 3. Advanced Usage
79
- Control `temperature`, `top_p`, and system personas for professional results.
80
- ```python
81
- ai.advanced(
82
- temperature=0.7,
83
- prompt="You are a senior DevOps engineer."
84
- )
85
-
86
- print(ai.ask("How do I optimize a Dockerfile?"))
87
- ```
88
-
89
- ---
90
-
91
- ## 🔌 Supported Providers
92
-
93
- | Provider | Class | Feature Set |
94
- |----------|-------|-------------|
95
- | **OpenAI** | `OpenAI` | All Models (GPT-4o, o1, etc.) |
96
- | **Anthropic** | `Anthropic` | All Models (Claude 3.5, Opus) |
97
- | **Google** | `Google` | All Models (Gemini 1.5 Pro/Flash) |
98
- | **Groq** | `Groq` | All Models (Llama 3, Mixtral) |
99
- | **Azure** | `Azure` | All Deployments |
100
- | **OpenRouter**| `OpenRouter`| All Models (100+) |
101
-
102
- ---
103
-
104
- ## ⭐ Support the Project
105
-
106
- If this project saved you time, please consider giving it a star on GitHub! It helps us grow.
107
-
108
- **[Give it a Star!](https://github.com/Hosseinghorbani0/ask-ai)**
109
-
110
- ---
111
- *Built by [Hossein Ghorbani](https://hosseinghorbani0.ir/) | [GitHub](https://github.com/Hosseinghorbani0).*
@@ -1,15 +0,0 @@
1
- class AskAIError(Exception):
2
- """Base exception for all ask-ai errors."""
3
- pass
4
-
5
- class APIKeyError(AskAIError):
6
- """Raised when API key is missing or invalid."""
7
- pass
8
-
9
- class ProviderError(AskAIError):
10
- """Raised when the provider API fails (e.g. 500 error)."""
11
- pass
12
-
13
- class MediaTypeNotSupportedError(AskAIError):
14
- """Raised when a provider can't handle the requested media type."""
15
- pass
@@ -1,135 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: askai-python
3
- Version: 0.1.6
4
- Summary: AI Made Stupid Simple. Unified API for OpenAI, Groq, Google, and more.
5
- Author-email: Hossein Ghorbani <hosseingh1068@gmail.com>
6
- License: MIT
7
- Project-URL: Homepage, https://hosseinghorbani0.ir/
8
- Project-URL: Bug Tracker, https://github.com/Hosseinghorbani0/ask-ai/issues
9
- Requires-Python: >=3.8
10
- Description-Content-Type: text/markdown
11
- License-File: LICENSE
12
- Requires-Dist: openai>=1.0.0
13
- Requires-Dist: groq
14
- Requires-Dist: google-generativeai
15
- Requires-Dist: anthropic
16
- Requires-Dist: requests
17
- Requires-Dist: Pillow
18
- Dynamic: license-file
19
-
20
- # askai-python 🚀
21
-
22
- **AI Made Stupid Simple.** One unified Python client for OpenAI, Claude, Gemini, Groq, and Azure.
23
-
24
- [![PyPI version](https://img.shields.io/pypi/v/askai-python.svg)](https://pypi.org/project/askai-python/)
25
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
26
- [![GitHub](https://img.shields.io/badge/GitHub-View%20Source-blue.svg)](https://github.com/Hosseinghorbani0/ask-ai)
27
-
28
- ---
29
-
30
- ## ⚡ What is askai-python?
31
-
32
- `askai-python` is a lightweight, zero-dependency-logic wrapper that provides a **single API** for all major AI providers. Stop learning multiple SDKs; just call `.ask()` and get your answer.
33
-
34
- - **Unified Interface**: One syntax for OpenAI, Anthropic, Google, and more.
35
- - **Zero-Config**: Seamlessly uses environment variables for API keys.
36
- - **Smart Media**: Easy handling of images and audio (Provider permitting).
37
- - **Production Grade**: Built-in robust error handling and type hints.
38
-
39
- ---
40
-
41
- ## 📦 Installation
42
-
43
- ```bash
44
- pip install askai-python
45
- ```
46
-
47
- ---
48
-
49
- ## 🚀 Examples & Tutorials
50
-
51
- ### 1. Basic Usage (The 3-Line Magic)
52
- ```python
53
- from ask_ai import OpenAI
54
-
55
- ai = OpenAI() # Auto-loads OPENAI_API_KEY from env
56
- print(ai.ask("What is the capital of France?").text)
57
- ```
58
-
59
- ### 2. Multi-Provider Mastery
60
- Switching between top-tier models has never been easier:
61
-
62
- ```python
63
- from ask_ai import OpenAI, Anthropic, Google
64
-
65
- prompt = "Explain quantum computing to a 5-year-old."
66
-
67
- # OpenAI (GPT-4o)
68
- print(OpenAI().ask(prompt).text)
69
-
70
- # Anthropic (Claude 3.5 Sonnet)
71
- print(Anthropic().ask(prompt).text)
72
-
73
- # Google (Gemini 1.5 Pro)
74
- print(Google().ask(prompt).text)
75
- ```
76
-
77
- ### 3. Advanced Configuration (System Personas)
78
- You can set a system prompt and temperature globally for an instance or per-request.
79
-
80
- ```python
81
- from ask_ai import OpenAI
82
-
83
- ai = OpenAI()
84
-
85
- # Global config
86
- ai.advanced(
87
- prompt="You are a sarcastic robot from the year 3000.",
88
- temperature=0.9
89
- )
90
-
91
- print(ai.ask("What is love?").text)
92
-
93
- # Per-request override
94
- print(ai.ask("What is 1+1?", temperature=0.1).text)
95
- ```
96
-
97
- ### 4. Handling Structured Exceptions
98
- Build reliable apps by catching specific AI errors:
99
-
100
- ```python
101
- from ask_ai import OpenAI
102
- from ask_ai.exceptions import AskAIError, APIKeyError
103
-
104
- try:
105
- ai = OpenAI(api_key="invalid-key")
106
- ai.ask("Hello")
107
- except APIKeyError:
108
- print("Check your API keys!")
109
- except AskAIError as e:
110
- print(f"An AI error occurred: {e}")
111
- ```
112
-
113
- ---
114
-
115
- ## 🔌 Supported Providers
116
-
117
- | Provider | Class | Capabilities |
118
- |----------|-------|-------------|
119
- | **OpenAI** | `OpenAI` | Text, Images (DALL-E), Vision |
120
- | **Anthropic** | `Anthropic` | Text, Vision (Claude 3.5) |
121
- | **Google** | `Google` | Text, Images, Video, Audio |
122
- | **Groq** | `Groq` | Ultra-fast Llama 3 & Mixtral |
123
- | **Azure** | `Azure` | Enterprise-grade OpenAI |
124
- | **OpenRouter**| `OpenRouter`| 100+ community models |
125
-
126
- ---
127
-
128
- ## 🔗 Important Links
129
-
130
- - **GitHub Repository**: [Hosseinghorbani0/ask-ai](https://github.com/Hosseinghorbani0/ask-ai) (Star us! ⭐)
131
- - **Official Website**: [hosseinghorbani0.ir](https://hosseinghorbani0.ir/)
132
- - **Bug Tracker**: [Report an Issue](https://github.com/Hosseinghorbani0/ask-ai/issues)
133
-
134
- ---
135
- *Built with ❤️ by [Hossein Ghorbani](https://github.com/Hosseinghorbani0).*
@@ -1,116 +0,0 @@
1
- # askai-python 🚀
2
-
3
- **AI Made Stupid Simple.** One unified Python client for OpenAI, Claude, Gemini, Groq, and Azure.
4
-
5
- [![PyPI version](https://img.shields.io/pypi/v/askai-python.svg)](https://pypi.org/project/askai-python/)
6
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
- [![GitHub](https://img.shields.io/badge/GitHub-View%20Source-blue.svg)](https://github.com/Hosseinghorbani0/ask-ai)
8
-
9
- ---
10
-
11
- ## ⚡ What is askai-python?
12
-
13
- `askai-python` is a lightweight, zero-dependency-logic wrapper that provides a **single API** for all major AI providers. Stop learning multiple SDKs; just call `.ask()` and get your answer.
14
-
15
- - **Unified Interface**: One syntax for OpenAI, Anthropic, Google, and more.
16
- - **Zero-Config**: Seamlessly uses environment variables for API keys.
17
- - **Smart Media**: Easy handling of images and audio (Provider permitting).
18
- - **Production Grade**: Built-in robust error handling and type hints.
19
-
20
- ---
21
-
22
- ## 📦 Installation
23
-
24
- ```bash
25
- pip install askai-python
26
- ```
27
-
28
- ---
29
-
30
- ## 🚀 Examples & Tutorials
31
-
32
- ### 1. Basic Usage (The 3-Line Magic)
33
- ```python
34
- from ask_ai import OpenAI
35
-
36
- ai = OpenAI() # Auto-loads OPENAI_API_KEY from env
37
- print(ai.ask("What is the capital of France?").text)
38
- ```
39
-
40
- ### 2. Multi-Provider Mastery
41
- Switching between top-tier models has never been easier:
42
-
43
- ```python
44
- from ask_ai import OpenAI, Anthropic, Google
45
-
46
- prompt = "Explain quantum computing to a 5-year-old."
47
-
48
- # OpenAI (GPT-4o)
49
- print(OpenAI().ask(prompt).text)
50
-
51
- # Anthropic (Claude 3.5 Sonnet)
52
- print(Anthropic().ask(prompt).text)
53
-
54
- # Google (Gemini 1.5 Pro)
55
- print(Google().ask(prompt).text)
56
- ```
57
-
58
- ### 3. Advanced Configuration (System Personas)
59
- You can set a system prompt and temperature globally for an instance or per-request.
60
-
61
- ```python
62
- from ask_ai import OpenAI
63
-
64
- ai = OpenAI()
65
-
66
- # Global config
67
- ai.advanced(
68
- prompt="You are a sarcastic robot from the year 3000.",
69
- temperature=0.9
70
- )
71
-
72
- print(ai.ask("What is love?").text)
73
-
74
- # Per-request override
75
- print(ai.ask("What is 1+1?", temperature=0.1).text)
76
- ```
77
-
78
- ### 4. Handling Structured Exceptions
79
- Build reliable apps by catching specific AI errors:
80
-
81
- ```python
82
- from ask_ai import OpenAI
83
- from ask_ai.exceptions import AskAIError, APIKeyError
84
-
85
- try:
86
- ai = OpenAI(api_key="invalid-key")
87
- ai.ask("Hello")
88
- except APIKeyError:
89
- print("Check your API keys!")
90
- except AskAIError as e:
91
- print(f"An AI error occurred: {e}")
92
- ```
93
-
94
- ---
95
-
96
- ## 🔌 Supported Providers
97
-
98
- | Provider | Class | Capabilities |
99
- |----------|-------|-------------|
100
- | **OpenAI** | `OpenAI` | Text, Images (DALL-E), Vision |
101
- | **Anthropic** | `Anthropic` | Text, Vision (Claude 3.5) |
102
- | **Google** | `Google` | Text, Images, Video, Audio |
103
- | **Groq** | `Groq` | Ultra-fast Llama 3 & Mixtral |
104
- | **Azure** | `Azure` | Enterprise-grade OpenAI |
105
- | **OpenRouter**| `OpenRouter`| 100+ community models |
106
-
107
- ---
108
-
109
- ## 🔗 Important Links
110
-
111
- - **GitHub Repository**: [Hosseinghorbani0/ask-ai](https://github.com/Hosseinghorbani0/ask-ai) (Star us! ⭐)
112
- - **Official Website**: [hosseinghorbani0.ir](https://hosseinghorbani0.ir/)
113
- - **Bug Tracker**: [Report an Issue](https://github.com/Hosseinghorbani0/ask-ai/issues)
114
-
115
- ---
116
- *Built with ❤️ by [Hossein Ghorbani](https://github.com/Hosseinghorbani0).*
File without changes
File without changes
File without changes