baalebos-ai 1.0.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,18 @@
1
+ Metadata-Version: 2.4
2
+ Name: baalebos-ai
3
+ Version: 1.0.0
4
+ Summary: Official Python client and terminal CLI for the Baalebos AI Gateway
5
+ Home-page: https://github.com/baalebos-cloud/nexus-ai-gateway
6
+ Author: Baalebos AI Team
7
+ License: MIT
8
+ Project-URL: Source, https://github.com/baalebos-cloud/nexus-ai-gateway
9
+ Project-URL: Bug Tracker, https://github.com/baalebos-cloud/nexus-ai-gateway/issues
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.8
14
+ Description-Content-Type: text/markdown
15
+ Requires-Dist: requests
16
+ Requires-Dist: httpx
17
+ Dynamic: home-page
18
+ Dynamic: requires-python
@@ -0,0 +1,19 @@
1
+ from baalebos_ai.client import BaalebosAI, AsyncBaalebosAI
2
+ from baalebos_ai.exceptions import (
3
+ BaalebosError,
4
+ BaalebosConfigError,
5
+ BaalebosConnectionError,
6
+ BaalebosAPIError,
7
+ BaalebosAuthError,
8
+ )
9
+
10
+ __all__ = [
11
+ "BaalebosAI",
12
+ "AsyncBaalebosAI",
13
+ "BaalebosError",
14
+ "BaalebosConfigError",
15
+ "BaalebosConnectionError",
16
+ "BaalebosAPIError",
17
+ "BaalebosAuthError",
18
+ ]
19
+ __version__ = "1.0.0"
@@ -0,0 +1,27 @@
1
+ import sys
2
+ import argparse
3
+ from baalebos_ai.client import BaalebosAI
4
+
5
+
6
+ def main():
7
+ parser = argparse.ArgumentParser(description='Baalebos AI Gateway Terminal CLI')
8
+ parser.add_argument('prompt', nargs='*', help='The prompt to send to the AI gateway')
9
+ parser.add_argument('--mode', default='auto', help='Execution mode (auto, fast, smart)')
10
+ args = parser.parse_args()
11
+
12
+ if not args.prompt:
13
+ print('Usage: ai "Your prompt here"')
14
+ sys.exit(1)
15
+
16
+ full_prompt = ' '.join(args.prompt)
17
+ try:
18
+ client = BaalebosAI()
19
+ response = client.chat(prompt=full_prompt, mode=args.mode)
20
+ print('\n' + response + '\n')
21
+ except Exception as e:
22
+ print(f'Error: {e}', file=sys.stderr)
23
+ sys.exit(1)
24
+
25
+
26
+ if __name__ == '__main__':
27
+ main()
@@ -0,0 +1,98 @@
1
+ import os
2
+ import requests
3
+ import httpx
4
+
5
+ from baalebos_ai.exceptions import (
6
+ BaalebosConfigError,
7
+ BaalebosConnectionError,
8
+ BaalebosAPIError,
9
+ BaalebosAuthError,
10
+ )
11
+
12
+
13
+ def _resolve_config(api_url: str, api_key: str):
14
+ api_url = api_url or os.getenv('BAALEBOS_API_URL')
15
+ api_key = api_key or os.getenv('BAALEBOS_API_KEY')
16
+
17
+ if not api_url:
18
+ raise BaalebosConfigError(
19
+ 'BAALEBOS_API_URL is missing. Set environment variable or pass to constructor.'
20
+ )
21
+ if not api_key:
22
+ raise BaalebosConfigError(
23
+ 'BAALEBOS_API_KEY is missing. Set environment variable or pass to constructor.'
24
+ )
25
+ return api_url, api_key
26
+
27
+
28
+ def _build_request(api_key: str, prompt: str, mode: str, temperature: float):
29
+ headers = {
30
+ 'Content-Type': 'application/json',
31
+ 'x-api-key': api_key,
32
+ }
33
+ payload = {
34
+ 'message': prompt,
35
+ 'mode': mode,
36
+ 'temperature': temperature,
37
+ }
38
+ return headers, payload
39
+
40
+
41
+ def _parse_response(status_code: int, reason: str, data: dict) -> str:
42
+ if status_code == 401:
43
+ raise BaalebosAuthError(
44
+ 'Unauthorized - check that BAALEBOS_API_KEY is correct.',
45
+ status_code=401,
46
+ )
47
+ if status_code >= 400:
48
+ raise BaalebosAPIError(
49
+ f'Gateway returned {status_code} {reason}',
50
+ status_code=status_code,
51
+ )
52
+
53
+ if 'data' in data and 'choices' in data['data']:
54
+ return data['data']['choices'][0]['message']['content']
55
+ elif 'output' in data:
56
+ return data['output']
57
+ return str(data)
58
+
59
+
60
+ class BaalebosAI:
61
+ """Synchronous client - use this in regular scripts and the CLI."""
62
+
63
+ def __init__(self, api_url: str = None, api_key: str = None):
64
+ self.api_url, self.api_key = _resolve_config(api_url, api_key)
65
+
66
+ def chat(self, prompt: str, mode: str = 'auto', temperature: float = 0.7) -> str:
67
+ headers, payload = _build_request(self.api_key, prompt, mode, temperature)
68
+
69
+ try:
70
+ response = requests.post(self.api_url, json=payload, headers=headers, timeout=60)
71
+ except requests.exceptions.Timeout:
72
+ raise BaalebosConnectionError(f'Request to {self.api_url} timed out after 60s.')
73
+ except requests.exceptions.ConnectionError as e:
74
+ raise BaalebosConnectionError(f'Could not reach {self.api_url}: {e}')
75
+
76
+ return _parse_response(response.status_code, response.reason, response.json())
77
+
78
+
79
+ class AsyncBaalebosAI:
80
+ """Async client - use this with `await` in async codebases (e.g. FastAPI,
81
+ asyncio scripts). Same behavior and same error types as BaalebosAI, just
82
+ non-blocking. Requires the `httpx` package."""
83
+
84
+ def __init__(self, api_url: str = None, api_key: str = None):
85
+ self.api_url, self.api_key = _resolve_config(api_url, api_key)
86
+
87
+ async def chat(self, prompt: str, mode: str = 'auto', temperature: float = 0.7) -> str:
88
+ headers, payload = _build_request(self.api_key, prompt, mode, temperature)
89
+
90
+ try:
91
+ async with httpx.AsyncClient(timeout=60) as client:
92
+ response = await client.post(self.api_url, json=payload, headers=headers)
93
+ except httpx.TimeoutException:
94
+ raise BaalebosConnectionError(f'Request to {self.api_url} timed out after 60s.')
95
+ except httpx.ConnectError as e:
96
+ raise BaalebosConnectionError(f'Could not reach {self.api_url}: {e}')
97
+
98
+ return _parse_response(response.status_code, response.reason_phrase, response.json())
@@ -0,0 +1,28 @@
1
+ class BaalebosError(Exception):
2
+ """Base class for all errors raised by this SDK. Catch this to catch anything we raise."""
3
+ pass
4
+
5
+
6
+ class BaalebosConfigError(BaalebosError):
7
+ """Raised when required configuration (api_url / api_key) is missing."""
8
+ pass
9
+
10
+
11
+ class BaalebosConnectionError(BaalebosError):
12
+ """Raised when the request never reached the gateway at all
13
+ (DNS failure, connection refused, timeout)."""
14
+ pass
15
+
16
+
17
+ class BaalebosAPIError(BaalebosError):
18
+ """Raised when the gateway responded, but with an error status
19
+ (401 Unauthorized, 429 rate-limited, 5xx server error, etc.)."""
20
+
21
+ def __init__(self, message: str, status_code: int = None):
22
+ super().__init__(message)
23
+ self.status_code = status_code
24
+
25
+
26
+ class BaalebosAuthError(BaalebosAPIError):
27
+ """Raised specifically for 401 Unauthorized - a bad or missing x-api-key."""
28
+ pass
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.4
2
+ Name: baalebos-ai
3
+ Version: 1.0.0
4
+ Summary: Official Python client and terminal CLI for the Baalebos AI Gateway
5
+ Home-page: https://github.com/baalebos-cloud/nexus-ai-gateway
6
+ Author: Baalebos AI Team
7
+ License: MIT
8
+ Project-URL: Source, https://github.com/baalebos-cloud/nexus-ai-gateway
9
+ Project-URL: Bug Tracker, https://github.com/baalebos-cloud/nexus-ai-gateway/issues
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.8
14
+ Description-Content-Type: text/markdown
15
+ Requires-Dist: requests
16
+ Requires-Dist: httpx
17
+ Dynamic: home-page
18
+ Dynamic: requires-python
@@ -0,0 +1,12 @@
1
+ pyproject.toml
2
+ setup.py
3
+ baalebos_ai/__init__.py
4
+ baalebos_ai/cli.py
5
+ baalebos_ai/client.py
6
+ baalebos_ai/exceptions.py
7
+ baalebos_ai.egg-info/PKG-INFO
8
+ baalebos_ai.egg-info/SOURCES.txt
9
+ baalebos_ai.egg-info/dependency_links.txt
10
+ baalebos_ai.egg-info/entry_points.txt
11
+ baalebos_ai.egg-info/requires.txt
12
+ baalebos_ai.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ ai = baalebos_ai.cli:main
@@ -0,0 +1,2 @@
1
+ requests
2
+ httpx
@@ -0,0 +1 @@
1
+ baalebos_ai
@@ -0,0 +1,30 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "baalebos-ai"
7
+ version = "1.0.0"
8
+ description = "Official Python client and terminal CLI for the Baalebos AI Gateway"
9
+ readme = "README.md"
10
+ authors = [
11
+ { name = "Baalebos AI Team" }
12
+ ]
13
+ license = { text = "MIT" }
14
+ requires-python = ">=3.8"
15
+ dependencies = [
16
+ "requests",
17
+ "httpx",
18
+ ]
19
+ classifiers = [
20
+ "Programming Language :: Python :: 3",
21
+ "License :: OSI Approved :: MIT License",
22
+ "Operating System :: OS Independent",
23
+ ]
24
+
25
+ [project.urls]
26
+ Source = "https://github.com/baalebos-cloud/nexus-ai-gateway"
27
+ "Bug Tracker" = "https://github.com/baalebos-cloud/nexus-ai-gateway/issues"
28
+
29
+ [project.scripts]
30
+ ai = "baalebos_ai.cli:main"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,33 @@
1
+ from setuptools import setup, find_packages
2
+ from pathlib import Path
3
+
4
+ this_dir = Path(__file__).parent
5
+ long_description = (this_dir / "README.md").read_text(encoding="utf-8") if (this_dir / "README.md").exists() else ""
6
+
7
+ setup(
8
+ name='baalebos-ai',
9
+ version='1.0.0',
10
+ description='Official Python client and terminal CLI for the Baalebos AI Gateway',
11
+ long_description=long_description,
12
+ long_description_content_type='text/markdown',
13
+ author='Baalebos AI Team',
14
+ url='https://github.com/baalebos-cloud/nexus-ai-gateway',
15
+ project_urls={
16
+ 'Source': 'https://github.com/baalebos-cloud/nexus-ai-gateway',
17
+ 'Bug Tracker': 'https://github.com/baalebos-cloud/nexus-ai-gateway/issues',
18
+ },
19
+ packages=find_packages(),
20
+ install_requires=['requests', 'httpx'],
21
+ python_requires='>=3.8',
22
+ classifiers=[
23
+ 'Programming Language :: Python :: 3',
24
+ 'License :: OSI Approved :: MIT License',
25
+ 'Operating System :: OS Independent',
26
+ ],
27
+ license='MIT',
28
+ entry_points={
29
+ 'console_scripts': [
30
+ 'ai = baalebos_ai.cli:main',
31
+ ],
32
+ },
33
+ )