wizard-ai-pro 0.1.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.
- wizard_ai_pro-0.1.0/LICENSE +21 -0
- wizard_ai_pro-0.1.0/PKG-INFO +33 -0
- wizard_ai_pro-0.1.0/README.md +17 -0
- wizard_ai_pro-0.1.0/pyproject.toml +30 -0
- wizard_ai_pro-0.1.0/setup.cfg +13 -0
- wizard_ai_pro-0.1.0/src/wizard/__init__.py +7 -0
- wizard_ai_pro-0.1.0/src/wizard/client.py +498 -0
- wizard_ai_pro-0.1.0/src/wizard/errors.py +17 -0
- wizard_ai_pro-0.1.0/src/wizard_ai_pro.egg-info/PKG-INFO +33 -0
- wizard_ai_pro-0.1.0/src/wizard_ai_pro.egg-info/SOURCES.txt +12 -0
- wizard_ai_pro-0.1.0/src/wizard_ai_pro.egg-info/dependency_links.txt +1 -0
- wizard_ai_pro-0.1.0/src/wizard_ai_pro.egg-info/requires.txt +1 -0
- wizard_ai_pro-0.1.0/src/wizard_ai_pro.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Arnav Gupta
|
|
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,33 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wizard-ai-pro
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Python SDK for Wizard.AI API - Chat with JARVIS, ORACLE, and more!
|
|
5
|
+
Author-email: Arnav Gupta <arnav@wizardai.dpdns.org>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://wizardai.dpdns.org
|
|
8
|
+
Project-URL: Repository, https://github.com/ag-ultima/wizard-ai-python
|
|
9
|
+
Project-URL: Documentation, https://github.com/ag-ultima/wizard-ai-python#readme
|
|
10
|
+
Keywords: ai,chatbot,wizard,jarvis,oracle,llm,api
|
|
11
|
+
Requires-Python: >=3.7
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: requests>=2.25.0
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# 🧙 Wizard.AI Python SDK
|
|
18
|
+
|
|
19
|
+
The official Python client for the [Wizard.AI API](https://wizardai.dpdns.org).
|
|
20
|
+
Chat with JARVIS, ORACLE, Nerd, Fun, and more!
|
|
21
|
+
|
|
22
|
+
## ✨ Features
|
|
23
|
+
|
|
24
|
+
- 🎭 **7+ Personalities** - JARVIS, ORACLE, Nerd, Fun, Sarcastic, Fast, Normal
|
|
25
|
+
- 📡 **Streaming Support** - Real-time token-by-token responses
|
|
26
|
+
- 🔑 **Simple Authentication** - Just your API key
|
|
27
|
+
- 🐍 **Python 3.7+** - Works with all modern Python versions
|
|
28
|
+
- ⚡ **Fast & Lightweight** - Only depends on `requests`
|
|
29
|
+
|
|
30
|
+
## 📦 Installation
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install wizard-ai
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# 🧙 Wizard.AI Python SDK
|
|
2
|
+
|
|
3
|
+
The official Python client for the [Wizard.AI API](https://wizardai.dpdns.org).
|
|
4
|
+
Chat with JARVIS, ORACLE, Nerd, Fun, and more!
|
|
5
|
+
|
|
6
|
+
## ✨ Features
|
|
7
|
+
|
|
8
|
+
- 🎭 **7+ Personalities** - JARVIS, ORACLE, Nerd, Fun, Sarcastic, Fast, Normal
|
|
9
|
+
- 📡 **Streaming Support** - Real-time token-by-token responses
|
|
10
|
+
- 🔑 **Simple Authentication** - Just your API key
|
|
11
|
+
- 🐍 **Python 3.7+** - Works with all modern Python versions
|
|
12
|
+
- ⚡ **Fast & Lightweight** - Only depends on `requests`
|
|
13
|
+
|
|
14
|
+
## 📦 Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install wizard-ai
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "wizard-ai-pro"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Official Python SDK for Wizard.AI API - Chat with JARVIS, ORACLE, and more!"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.7"
|
|
11
|
+
license = { text = "MIT" } # Keep the table format but remove classifiers
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Arnav Gupta", email = "arnav@wizardai.dpdns.org" },
|
|
14
|
+
]
|
|
15
|
+
keywords = ["ai", "chatbot", "wizard", "jarvis", "oracle", "llm", "api"]
|
|
16
|
+
|
|
17
|
+
# REMOVE ALL CLASSIFIERS - they're causing the error
|
|
18
|
+
# The license classifiers are conflicting with license expression
|
|
19
|
+
|
|
20
|
+
dependencies = [
|
|
21
|
+
"requests>=2.25.0",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Homepage = "https://wizardai.dpdns.org"
|
|
26
|
+
Repository = "https://github.com/ag-ultima/wizard-ai-python"
|
|
27
|
+
Documentation = "https://github.com/ag-ultima/wizard-ai-python#readme"
|
|
28
|
+
|
|
29
|
+
[tool.setuptools.packages.find]
|
|
30
|
+
where = ["src"]
|
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Wizard.AI Python Client Library
|
|
3
|
+
Official SDK for Wizard.AI API
|
|
4
|
+
Created by Arnav Gupta
|
|
5
|
+
|
|
6
|
+
This client provides a simple interface to interact with Wizard.AI's API,
|
|
7
|
+
supporting all personalities (JARVIS, ORACLE, Nerd, Fun, etc.) and both
|
|
8
|
+
standard and streaming responses.
|
|
9
|
+
|
|
10
|
+
Usage:
|
|
11
|
+
from wizard import Wizard
|
|
12
|
+
|
|
13
|
+
client = Wizard(api_key="your-api-key")
|
|
14
|
+
|
|
15
|
+
# Simple completion
|
|
16
|
+
response = client.chat.completions.create(
|
|
17
|
+
messages=[
|
|
18
|
+
{"role": "user", "content": "Hello!"}
|
|
19
|
+
],
|
|
20
|
+
model="wizard-jarvis"
|
|
21
|
+
)
|
|
22
|
+
print(response.choices[0].message.content)
|
|
23
|
+
|
|
24
|
+
# Streaming
|
|
25
|
+
stream = client.chat.completions.create(
|
|
26
|
+
messages=[{"role": "user", "content": "Tell me a story"}],
|
|
27
|
+
model="wizard-fun",
|
|
28
|
+
stream=True
|
|
29
|
+
)
|
|
30
|
+
for chunk in stream:
|
|
31
|
+
print(chunk.choices[0].delta.content, end="")
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
import requests
|
|
35
|
+
import json
|
|
36
|
+
from typing import List, Dict, Optional, Union, Any, Generator
|
|
37
|
+
from errors import AuthenticationError, APIError, RateLimitError
|
|
38
|
+
|
|
39
|
+
# Version is imported from __init__.py
|
|
40
|
+
__all__ = ['Wizard', 'ChatCompletions', 'Completion', 'StreamWrapper']
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class Wizard:
|
|
44
|
+
"""
|
|
45
|
+
Main Wizard.AI client
|
|
46
|
+
|
|
47
|
+
This is the main entry point for interacting with the Wizard.AI API.
|
|
48
|
+
Create an instance with your API key and use the `chat` property to
|
|
49
|
+
access chat completion functionality.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
api_key: Your Wizard.AI API key (starts with 'wiz_')
|
|
53
|
+
base_url: Optional custom base URL (defaults to production API)
|
|
54
|
+
timeout: Request timeout in seconds (default 60)
|
|
55
|
+
|
|
56
|
+
Example:
|
|
57
|
+
>>> client = Wizard(api_key="wiz_abc123")
|
|
58
|
+
>>> response = client.chat.completions.create(
|
|
59
|
+
... messages=[{"role": "user", "content": "Hello!"}]
|
|
60
|
+
... )
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
def __init__(
|
|
64
|
+
self,
|
|
65
|
+
api_key: str,
|
|
66
|
+
base_url: str = "https://api.wizardai.dpdns.org/v1",
|
|
67
|
+
timeout: int = 60
|
|
68
|
+
):
|
|
69
|
+
if not api_key:
|
|
70
|
+
raise ValueError("API key is required")
|
|
71
|
+
if not api_key.startswith('wiz_'):
|
|
72
|
+
raise ValueError("Invalid API key format. Should start with 'wiz_'")
|
|
73
|
+
|
|
74
|
+
self.api_key = api_key
|
|
75
|
+
self.base_url = base_url.rstrip('/')
|
|
76
|
+
self.timeout = timeout
|
|
77
|
+
self._session = requests.Session()
|
|
78
|
+
self._session.headers.update({
|
|
79
|
+
"Authorization": f"Bearer {self.api_key}",
|
|
80
|
+
"Content-Type": "application/json",
|
|
81
|
+
"User-Agent": f"Wizard.AI-Python-SDK/{self._get_version()}"
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
# Initialize endpoints
|
|
85
|
+
self.chat = ChatCompletions(self)
|
|
86
|
+
|
|
87
|
+
def _get_version(self) -> str:
|
|
88
|
+
"""Get package version"""
|
|
89
|
+
try:
|
|
90
|
+
from . import __version__
|
|
91
|
+
return __version__
|
|
92
|
+
except ImportError:
|
|
93
|
+
return "unknown"
|
|
94
|
+
|
|
95
|
+
def _request(
|
|
96
|
+
self,
|
|
97
|
+
method: str,
|
|
98
|
+
endpoint: str,
|
|
99
|
+
json_data: Optional[Dict] = None,
|
|
100
|
+
stream: bool = False
|
|
101
|
+
) -> Union[Dict, Generator]:
|
|
102
|
+
"""
|
|
103
|
+
Make HTTP request to Wizard.AI API
|
|
104
|
+
|
|
105
|
+
Args:
|
|
106
|
+
method: HTTP method (GET, POST, etc.)
|
|
107
|
+
endpoint: API endpoint (e.g., "chat/completions")
|
|
108
|
+
json_data: Request body as dictionary
|
|
109
|
+
stream: Whether to stream the response
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
Parsed JSON response or generator for streaming
|
|
113
|
+
"""
|
|
114
|
+
url = f"{self.base_url}/{endpoint.lstrip('/')}"
|
|
115
|
+
|
|
116
|
+
if stream:
|
|
117
|
+
return self._stream_request(method, url, json_data)
|
|
118
|
+
|
|
119
|
+
try:
|
|
120
|
+
response = self._session.request(
|
|
121
|
+
method=method,
|
|
122
|
+
url=url,
|
|
123
|
+
json=json_data,
|
|
124
|
+
timeout=self.timeout
|
|
125
|
+
)
|
|
126
|
+
except requests.exceptions.ConnectionError:
|
|
127
|
+
raise APIError("Failed to connect to Wizard.AI API. Check your internet connection.")
|
|
128
|
+
except requests.exceptions.Timeout:
|
|
129
|
+
raise APIError(f"Request timed out after {self.timeout} seconds")
|
|
130
|
+
except requests.exceptions.RequestException as e:
|
|
131
|
+
raise APIError(f"Request failed: {str(e)}")
|
|
132
|
+
|
|
133
|
+
if response.status_code == 200:
|
|
134
|
+
return response.json()
|
|
135
|
+
elif response.status_code == 401:
|
|
136
|
+
raise AuthenticationError("Invalid API key. Please check your credentials.")
|
|
137
|
+
elif response.status_code == 403:
|
|
138
|
+
raise AuthenticationError("API key does not have permission for this action.")
|
|
139
|
+
elif response.status_code == 404:
|
|
140
|
+
raise APIError(f"Endpoint not found: {endpoint}")
|
|
141
|
+
elif response.status_code == 429:
|
|
142
|
+
raise RateLimitError("Rate limit exceeded. Please try again later.")
|
|
143
|
+
elif response.status_code >= 500:
|
|
144
|
+
raise APIError(f"Wizard.AI server error (HTTP {response.status_code}). Please try again later.")
|
|
145
|
+
else:
|
|
146
|
+
self._handle_error_response(response)
|
|
147
|
+
|
|
148
|
+
def _stream_request(self, method: str, url: str, json_data: Optional[Dict] = None) -> Generator:
|
|
149
|
+
"""
|
|
150
|
+
Handle streaming requests with Server-Sent Events
|
|
151
|
+
|
|
152
|
+
Args:
|
|
153
|
+
method: HTTP method
|
|
154
|
+
url: Full URL
|
|
155
|
+
json_data: Request body
|
|
156
|
+
|
|
157
|
+
Yields:
|
|
158
|
+
Parsed JSON chunks from the stream
|
|
159
|
+
"""
|
|
160
|
+
try:
|
|
161
|
+
response = self._session.request(
|
|
162
|
+
method=method,
|
|
163
|
+
url=url,
|
|
164
|
+
json=json_data,
|
|
165
|
+
stream=True,
|
|
166
|
+
timeout=self.timeout
|
|
167
|
+
)
|
|
168
|
+
except requests.exceptions.RequestException as e:
|
|
169
|
+
raise APIError(f"Streaming request failed: {str(e)}")
|
|
170
|
+
|
|
171
|
+
if response.status_code != 200:
|
|
172
|
+
if response.status_code == 401:
|
|
173
|
+
raise AuthenticationError("Invalid API key")
|
|
174
|
+
elif response.status_code == 429:
|
|
175
|
+
raise RateLimitError("Rate limit exceeded")
|
|
176
|
+
elif response.status_code >= 500:
|
|
177
|
+
raise APIError(f"Server error (HTTP {response.status_code})")
|
|
178
|
+
else:
|
|
179
|
+
self._handle_error_response(response)
|
|
180
|
+
|
|
181
|
+
for line in response.iter_lines():
|
|
182
|
+
if line:
|
|
183
|
+
line = line.decode('utf-8')
|
|
184
|
+
if line.startswith('data: '):
|
|
185
|
+
data = line[6:] # Remove 'data: ' prefix
|
|
186
|
+
if data == '[DONE]':
|
|
187
|
+
break
|
|
188
|
+
try:
|
|
189
|
+
yield json.loads(data)
|
|
190
|
+
except json.JSONDecodeError:
|
|
191
|
+
# Ignore malformed JSON
|
|
192
|
+
continue
|
|
193
|
+
|
|
194
|
+
def _handle_error_response(self, response):
|
|
195
|
+
"""Parse and raise appropriate error from response"""
|
|
196
|
+
try:
|
|
197
|
+
error_data = response.json()
|
|
198
|
+
error_msg = error_data.get('error', {}).get('message', 'Unknown error')
|
|
199
|
+
if 'type' in error_data.get('error', {}):
|
|
200
|
+
error_type = error_data['error']['type']
|
|
201
|
+
if 'rate_limit' in error_type.lower():
|
|
202
|
+
raise RateLimitError(error_msg)
|
|
203
|
+
elif 'auth' in error_type.lower():
|
|
204
|
+
raise AuthenticationError(error_msg)
|
|
205
|
+
except (json.JSONDecodeError, AttributeError):
|
|
206
|
+
error_msg = f"HTTP {response.status_code}: {response.reason}"
|
|
207
|
+
|
|
208
|
+
raise APIError(f"Wizard.AI API Error: {error_msg}")
|
|
209
|
+
|
|
210
|
+
def list_models(self) -> List[Dict]:
|
|
211
|
+
"""
|
|
212
|
+
List all available models/personalities
|
|
213
|
+
|
|
214
|
+
Returns:
|
|
215
|
+
List of model objects with id, name, and capabilities
|
|
216
|
+
|
|
217
|
+
Example:
|
|
218
|
+
>>> client.list_models()
|
|
219
|
+
[
|
|
220
|
+
{'id': 'wizard-jarvis', 'object': 'model', ...},
|
|
221
|
+
{'id': 'wizard-oracle', ...}
|
|
222
|
+
]
|
|
223
|
+
"""
|
|
224
|
+
return self._request("GET", "models").get('data', [])
|
|
225
|
+
|
|
226
|
+
def close(self):
|
|
227
|
+
"""Close the underlying session"""
|
|
228
|
+
self._session.close()
|
|
229
|
+
|
|
230
|
+
def __enter__(self):
|
|
231
|
+
return self
|
|
232
|
+
|
|
233
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
234
|
+
self.close()
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
class ChatCompletions:
|
|
238
|
+
"""
|
|
239
|
+
Chat completions endpoint handler
|
|
240
|
+
|
|
241
|
+
This class provides methods for creating chat completions with
|
|
242
|
+
Wizard.AI's various personalities.
|
|
243
|
+
"""
|
|
244
|
+
|
|
245
|
+
def __init__(self, client: Wizard):
|
|
246
|
+
self.client = client
|
|
247
|
+
|
|
248
|
+
def create(
|
|
249
|
+
self,
|
|
250
|
+
messages: List[Dict[str, str]],
|
|
251
|
+
model: str = "wizard-ai-pro",
|
|
252
|
+
temperature: float = 0.7,
|
|
253
|
+
max_tokens: Optional[int] = None,
|
|
254
|
+
top_p: float = 1.0,
|
|
255
|
+
frequency_penalty: float = 0.0,
|
|
256
|
+
presence_penalty: float = 0.0,
|
|
257
|
+
stop: Optional[Union[str, List[str]]] = None,
|
|
258
|
+
stream: bool = False,
|
|
259
|
+
**kwargs
|
|
260
|
+
) -> Union['Completion', 'StreamWrapper']:
|
|
261
|
+
"""
|
|
262
|
+
Create a chat completion
|
|
263
|
+
|
|
264
|
+
This is the main method for interacting with Wizard.AI's chat models.
|
|
265
|
+
It supports both standard and streaming responses.
|
|
266
|
+
|
|
267
|
+
Args:
|
|
268
|
+
messages: List of message objects with 'role' and 'content'
|
|
269
|
+
Each message can have role: 'system', 'user', or 'assistant'
|
|
270
|
+
model: Model/personality to use. Options:
|
|
271
|
+
- wizard-jarvis: Sophisticated AI assistant
|
|
272
|
+
- wizard-oracle: Mystical, all-knowing
|
|
273
|
+
- wizard-nerd: Detailed, academic
|
|
274
|
+
- wizard-fun: Playful, energetic
|
|
275
|
+
- wizard-sarcastic: Witty, sarcastic
|
|
276
|
+
- wizard-fast: Quick responses
|
|
277
|
+
- wizard-normal: Balanced conversation
|
|
278
|
+
- wizard-ai-pro: Default (JARVIS)
|
|
279
|
+
temperature: Sampling temperature (0-2). Higher values = more random
|
|
280
|
+
max_tokens: Maximum number of tokens to generate
|
|
281
|
+
top_p: Nucleus sampling parameter (0-1)
|
|
282
|
+
frequency_penalty: Penalize frequent tokens (-2 to 2)
|
|
283
|
+
presence_penalty: Penalize tokens that have appeared (-2 to 2)
|
|
284
|
+
stop: Stop sequence(s) that end generation
|
|
285
|
+
stream: Whether to stream the response token by token
|
|
286
|
+
**kwargs: Additional parameters to pass to the API
|
|
287
|
+
|
|
288
|
+
Returns:
|
|
289
|
+
If stream=False: A Completion object with the full response
|
|
290
|
+
If stream=True: A StreamWrapper that yields StreamChunk objects
|
|
291
|
+
|
|
292
|
+
Raises:
|
|
293
|
+
AuthenticationError: Invalid API key
|
|
294
|
+
RateLimitError: Rate limit exceeded
|
|
295
|
+
APIError: Other API errors
|
|
296
|
+
|
|
297
|
+
Examples:
|
|
298
|
+
>>> # Standard completion
|
|
299
|
+
>>> response = client.chat.completions.create(
|
|
300
|
+
... messages=[
|
|
301
|
+
... {"role": "system", "content": "You are JARVIS"},
|
|
302
|
+
... {"role": "user", "content": "What's the status?"}
|
|
303
|
+
... ],
|
|
304
|
+
... model="wizard-jarvis"
|
|
305
|
+
... )
|
|
306
|
+
>>> print(response.choices[0].message.content)
|
|
307
|
+
|
|
308
|
+
>>> # Streaming
|
|
309
|
+
>>> stream = client.chat.completions.create(
|
|
310
|
+
... messages=[{"role": "user", "content": "Tell a story"}],
|
|
311
|
+
... model="wizard-fun",
|
|
312
|
+
... stream=True
|
|
313
|
+
... )
|
|
314
|
+
>>> for chunk in stream:
|
|
315
|
+
... print(chunk.choices[0].delta.content, end="")
|
|
316
|
+
"""
|
|
317
|
+
# Validate messages
|
|
318
|
+
if not messages or not isinstance(messages, list):
|
|
319
|
+
raise ValueError("Messages must be a non-empty list")
|
|
320
|
+
|
|
321
|
+
for msg in messages:
|
|
322
|
+
if not isinstance(msg, dict):
|
|
323
|
+
raise ValueError("Each message must be a dictionary")
|
|
324
|
+
if 'role' not in msg or 'content' not in msg:
|
|
325
|
+
raise ValueError("Each message must have 'role' and 'content' keys")
|
|
326
|
+
if msg['role'] not in ['system', 'user', 'assistant']:
|
|
327
|
+
raise ValueError(f"Invalid role: {msg['role']}. Must be 'system', 'user', or 'assistant'")
|
|
328
|
+
|
|
329
|
+
# Validate temperature
|
|
330
|
+
if not 0 <= temperature <= 2:
|
|
331
|
+
raise ValueError("Temperature must be between 0 and 2")
|
|
332
|
+
|
|
333
|
+
# Validate penalties
|
|
334
|
+
if not -2 <= frequency_penalty <= 2:
|
|
335
|
+
raise ValueError("Frequency penalty must be between -2 and 2")
|
|
336
|
+
if not -2 <= presence_penalty <= 2:
|
|
337
|
+
raise ValueError("Presence penalty must be between -2 and 2")
|
|
338
|
+
|
|
339
|
+
# Prepare request data
|
|
340
|
+
data = {
|
|
341
|
+
"messages": messages,
|
|
342
|
+
"model": model,
|
|
343
|
+
"temperature": temperature,
|
|
344
|
+
"top_p": top_p,
|
|
345
|
+
"frequency_penalty": frequency_penalty,
|
|
346
|
+
"presence_penalty": presence_penalty,
|
|
347
|
+
"stream": stream,
|
|
348
|
+
**kwargs
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if max_tokens is not None:
|
|
352
|
+
if max_tokens <= 0:
|
|
353
|
+
raise ValueError("max_tokens must be positive")
|
|
354
|
+
data["max_tokens"] = max_tokens
|
|
355
|
+
|
|
356
|
+
if stop is not None:
|
|
357
|
+
data["stop"] = stop
|
|
358
|
+
|
|
359
|
+
response = self.client._request(
|
|
360
|
+
"POST",
|
|
361
|
+
"chat/completions",
|
|
362
|
+
json_data=data,
|
|
363
|
+
stream=stream
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
if stream:
|
|
367
|
+
return StreamWrapper(response)
|
|
368
|
+
|
|
369
|
+
return Completion(response)
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
class Completion:
|
|
373
|
+
"""
|
|
374
|
+
Wrapper for non-streaming completion response
|
|
375
|
+
|
|
376
|
+
Provides easy access to the completion results and metadata.
|
|
377
|
+
"""
|
|
378
|
+
|
|
379
|
+
def __init__(self, data: Dict):
|
|
380
|
+
self._data = data
|
|
381
|
+
self.id = data.get('id')
|
|
382
|
+
self.object = data.get('object')
|
|
383
|
+
self.created = data.get('created')
|
|
384
|
+
self.model = data.get('model')
|
|
385
|
+
self.choices = [Choice(c) for c in data.get('choices', [])]
|
|
386
|
+
self.usage = Usage(data.get('usage', {}))
|
|
387
|
+
|
|
388
|
+
def __repr__(self):
|
|
389
|
+
return f"<Completion id={self.id} model={self.model} tokens={self.usage.total_tokens}>"
|
|
390
|
+
|
|
391
|
+
def __str__(self):
|
|
392
|
+
if self.choices:
|
|
393
|
+
return self.choices[0].message.content
|
|
394
|
+
return ""
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
class Choice:
|
|
398
|
+
"""Wrapper for a single completion choice"""
|
|
399
|
+
|
|
400
|
+
def __init__(self, data: Dict):
|
|
401
|
+
self.index = data.get('index')
|
|
402
|
+
self.message = Message(data.get('message', {}))
|
|
403
|
+
self.finish_reason = data.get('finish_reason')
|
|
404
|
+
|
|
405
|
+
def __repr__(self):
|
|
406
|
+
return f"<Choice index={self.index} finish_reason={self.finish_reason}>"
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
class Message:
|
|
410
|
+
"""Wrapper for a message object in non-streaming responses"""
|
|
411
|
+
|
|
412
|
+
def __init__(self, data: Dict):
|
|
413
|
+
self.role = data.get('role')
|
|
414
|
+
self.content = data.get('content')
|
|
415
|
+
|
|
416
|
+
def __repr__(self):
|
|
417
|
+
return f"<Message role={self.role}>"
|
|
418
|
+
|
|
419
|
+
def __str__(self):
|
|
420
|
+
return self.content or ""
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
class Delta:
|
|
424
|
+
"""Wrapper for streaming delta content"""
|
|
425
|
+
|
|
426
|
+
def __init__(self, data: Dict):
|
|
427
|
+
self.role = data.get('role')
|
|
428
|
+
self.content = data.get('content')
|
|
429
|
+
|
|
430
|
+
def __repr__(self):
|
|
431
|
+
return f"<Delta content={self.content}>"
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
class StreamChoice:
|
|
435
|
+
"""Wrapper for a streaming choice containing delta updates"""
|
|
436
|
+
|
|
437
|
+
def __init__(self, data: Dict):
|
|
438
|
+
self.index = data.get('index')
|
|
439
|
+
self.delta = Delta(data.get('delta', {}))
|
|
440
|
+
self.finish_reason = data.get('finish_reason')
|
|
441
|
+
|
|
442
|
+
def __repr__(self):
|
|
443
|
+
return f"<StreamChoice index={self.index}>"
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
class StreamWrapper:
|
|
447
|
+
"""
|
|
448
|
+
Wrapper for streaming responses
|
|
449
|
+
|
|
450
|
+
This class allows iteration over streaming chunks from the API.
|
|
451
|
+
Each iteration yields a StreamChunk object.
|
|
452
|
+
"""
|
|
453
|
+
|
|
454
|
+
def __init__(self, generator):
|
|
455
|
+
self.generator = generator
|
|
456
|
+
|
|
457
|
+
def __iter__(self):
|
|
458
|
+
return self
|
|
459
|
+
|
|
460
|
+
def __next__(self):
|
|
461
|
+
try:
|
|
462
|
+
chunk = next(self.generator)
|
|
463
|
+
return StreamChunk(chunk)
|
|
464
|
+
except StopIteration:
|
|
465
|
+
raise StopIteration
|
|
466
|
+
|
|
467
|
+
def __enter__(self):
|
|
468
|
+
return self
|
|
469
|
+
|
|
470
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
471
|
+
pass
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
class StreamChunk:
|
|
475
|
+
"""Wrapper for a single streaming chunk"""
|
|
476
|
+
|
|
477
|
+
def __init__(self, data: Dict):
|
|
478
|
+
self._data = data
|
|
479
|
+
self.id = data.get('id')
|
|
480
|
+
self.object = data.get('object')
|
|
481
|
+
self.created = data.get('created')
|
|
482
|
+
self.model = data.get('model')
|
|
483
|
+
self.choices = [StreamChoice(c) for c in data.get('choices', [])]
|
|
484
|
+
|
|
485
|
+
def __repr__(self):
|
|
486
|
+
return f"<StreamChunk id={self.id}>"
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
class Usage:
|
|
490
|
+
"""Wrapper for token usage information"""
|
|
491
|
+
|
|
492
|
+
def __init__(self, data: Dict):
|
|
493
|
+
self.prompt_tokens = data.get('prompt_tokens', 0)
|
|
494
|
+
self.completion_tokens = data.get('completion_tokens', 0)
|
|
495
|
+
self.total_tokens = data.get('total_tokens', 0)
|
|
496
|
+
|
|
497
|
+
def __repr__(self):
|
|
498
|
+
return f"<Usage total_tokens={self.total_tokens}>"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Custom exceptions for Wizard.AI SDK"""
|
|
2
|
+
|
|
3
|
+
class WizardError(Exception):
|
|
4
|
+
"""Base exception for all Wizard.AI errors"""
|
|
5
|
+
pass
|
|
6
|
+
|
|
7
|
+
class AuthenticationError(WizardError):
|
|
8
|
+
"""Raised when API key is invalid"""
|
|
9
|
+
pass
|
|
10
|
+
|
|
11
|
+
class APIError(WizardError):
|
|
12
|
+
"""Raised when API returns an error"""
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
class RateLimitError(WizardError):
|
|
16
|
+
"""Raised when rate limit is exceeded"""
|
|
17
|
+
pass
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wizard-ai-pro
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Python SDK for Wizard.AI API - Chat with JARVIS, ORACLE, and more!
|
|
5
|
+
Author-email: Arnav Gupta <arnav@wizardai.dpdns.org>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://wizardai.dpdns.org
|
|
8
|
+
Project-URL: Repository, https://github.com/ag-ultima/wizard-ai-python
|
|
9
|
+
Project-URL: Documentation, https://github.com/ag-ultima/wizard-ai-python#readme
|
|
10
|
+
Keywords: ai,chatbot,wizard,jarvis,oracle,llm,api
|
|
11
|
+
Requires-Python: >=3.7
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: requests>=2.25.0
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# 🧙 Wizard.AI Python SDK
|
|
18
|
+
|
|
19
|
+
The official Python client for the [Wizard.AI API](https://wizardai.dpdns.org).
|
|
20
|
+
Chat with JARVIS, ORACLE, Nerd, Fun, and more!
|
|
21
|
+
|
|
22
|
+
## ✨ Features
|
|
23
|
+
|
|
24
|
+
- 🎭 **7+ Personalities** - JARVIS, ORACLE, Nerd, Fun, Sarcastic, Fast, Normal
|
|
25
|
+
- 📡 **Streaming Support** - Real-time token-by-token responses
|
|
26
|
+
- 🔑 **Simple Authentication** - Just your API key
|
|
27
|
+
- 🐍 **Python 3.7+** - Works with all modern Python versions
|
|
28
|
+
- ⚡ **Fast & Lightweight** - Only depends on `requests`
|
|
29
|
+
|
|
30
|
+
## 📦 Installation
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install wizard-ai
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.cfg
|
|
5
|
+
src/wizard/__init__.py
|
|
6
|
+
src/wizard/client.py
|
|
7
|
+
src/wizard/errors.py
|
|
8
|
+
src/wizard_ai_pro.egg-info/PKG-INFO
|
|
9
|
+
src/wizard_ai_pro.egg-info/SOURCES.txt
|
|
10
|
+
src/wizard_ai_pro.egg-info/dependency_links.txt
|
|
11
|
+
src/wizard_ai_pro.egg-info/requires.txt
|
|
12
|
+
src/wizard_ai_pro.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests>=2.25.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
wizard
|