orgo 0.0.27__tar.gz → 0.0.29__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.
- {orgo-0.0.27 → orgo-0.0.29}/PKG-INFO +1 -1
- {orgo-0.0.27 → orgo-0.0.29}/pyproject.toml +1 -1
- {orgo-0.0.27 → orgo-0.0.29}/src/orgo/api/client.py +20 -31
- {orgo-0.0.27 → orgo-0.0.29}/src/orgo/computer.py +15 -18
- {orgo-0.0.27 → orgo-0.0.29}/src/orgo.egg-info/PKG-INFO +1 -1
- {orgo-0.0.27 → orgo-0.0.29}/README.md +0 -0
- {orgo-0.0.27 → orgo-0.0.29}/setup.cfg +0 -0
- {orgo-0.0.27 → orgo-0.0.29}/src/orgo/__init__.py +0 -0
- {orgo-0.0.27 → orgo-0.0.29}/src/orgo/api/__init__.py +0 -0
- {orgo-0.0.27 → orgo-0.0.29}/src/orgo/project.py +0 -0
- {orgo-0.0.27 → orgo-0.0.29}/src/orgo/prompt.py +0 -0
- {orgo-0.0.27 → orgo-0.0.29}/src/orgo/utils/__init__.py +0 -0
- {orgo-0.0.27 → orgo-0.0.29}/src/orgo/utils/auth.py +0 -0
- {orgo-0.0.27 → orgo-0.0.29}/src/orgo.egg-info/SOURCES.txt +0 -0
- {orgo-0.0.27 → orgo-0.0.29}/src/orgo.egg-info/dependency_links.txt +0 -0
- {orgo-0.0.27 → orgo-0.0.29}/src/orgo.egg-info/requires.txt +0 -0
- {orgo-0.0.27 → orgo-0.0.29}/src/orgo.egg-info/top_level.txt +0 -0
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
import requests
|
|
4
4
|
from typing import Dict, Any, Optional, List
|
|
5
|
+
import logging
|
|
6
|
+
import sys
|
|
5
7
|
|
|
6
8
|
from orgo.utils.auth import get_api_key
|
|
7
9
|
|
|
10
|
+
logger = logging.getLogger(__name__)
|
|
11
|
+
|
|
8
12
|
class ApiClient:
|
|
9
13
|
def __init__(self, api_key: Optional[str] = None, base_url: Optional[str] = None):
|
|
10
14
|
self.api_key = get_api_key(api_key)
|
|
@@ -28,16 +32,20 @@ class ApiClient:
|
|
|
28
32
|
response.raise_for_status()
|
|
29
33
|
return response.json()
|
|
30
34
|
except requests.exceptions.RequestException as e:
|
|
35
|
+
# Log the full error for debugging
|
|
36
|
+
logger.debug(f"API request failed: {method} {url}", exc_info=True)
|
|
37
|
+
|
|
31
38
|
if hasattr(e, 'response') and e.response is not None:
|
|
32
|
-
error_message = f"API error: {e.response.status_code}"
|
|
33
39
|
try:
|
|
34
40
|
error_data = e.response.json()
|
|
35
41
|
if 'error' in error_data:
|
|
36
|
-
|
|
37
|
-
except ValueError:
|
|
42
|
+
raise Exception(error_data['error']) from None
|
|
43
|
+
except (ValueError, KeyError):
|
|
38
44
|
pass
|
|
39
|
-
raise Exception(
|
|
40
|
-
|
|
45
|
+
raise Exception(f"Request failed with status {e.response.status_code}") from None
|
|
46
|
+
|
|
47
|
+
# Generic error message without exposing internal details
|
|
48
|
+
raise Exception("Failed to connect to Orgo service. Please check your connection and try again.") from None
|
|
41
49
|
|
|
42
50
|
# Project methods
|
|
43
51
|
def create_project(self, name: str) -> Dict[str, Any]:
|
|
@@ -57,28 +65,17 @@ class ApiClient:
|
|
|
57
65
|
response = self._request("GET", "projects")
|
|
58
66
|
return response.get("projects", [])
|
|
59
67
|
|
|
60
|
-
def start_project(self, project_id: str) -> Dict[str, Any]:
|
|
61
|
-
"""Start a project"""
|
|
62
|
-
return self._request("POST", f"projects/{project_id}/start")
|
|
63
|
-
|
|
64
|
-
def stop_project(self, project_id: str) -> Dict[str, Any]:
|
|
65
|
-
"""Stop a project"""
|
|
66
|
-
return self._request("POST", f"projects/{project_id}/stop")
|
|
67
|
-
|
|
68
|
-
def restart_project(self, project_id: str) -> Dict[str, Any]:
|
|
69
|
-
"""Restart a project"""
|
|
70
|
-
return self._request("POST", f"projects/{project_id}/restart")
|
|
71
|
-
|
|
72
68
|
def delete_project(self, project_id: str) -> Dict[str, Any]:
|
|
73
69
|
"""Delete a project and all its computers"""
|
|
74
|
-
return self._request("
|
|
70
|
+
return self._request("DELETE", f"projects/{project_id}")
|
|
75
71
|
|
|
76
72
|
# Computer methods
|
|
77
|
-
def create_computer(self,
|
|
73
|
+
def create_computer(self, project_id: str, computer_name: str,
|
|
78
74
|
os: str = "linux", ram: int = 2, cpu: int = 2,
|
|
79
75
|
gpu: str = "none") -> Dict[str, Any]:
|
|
80
76
|
"""Create a new computer within a project"""
|
|
81
|
-
return self._request("POST",
|
|
77
|
+
return self._request("POST", "computers", {
|
|
78
|
+
"project_id": project_id,
|
|
82
79
|
"name": computer_name,
|
|
83
80
|
"os": os,
|
|
84
81
|
"ram": ram,
|
|
@@ -86,10 +83,10 @@ class ApiClient:
|
|
|
86
83
|
"gpu": gpu
|
|
87
84
|
})
|
|
88
85
|
|
|
89
|
-
def list_computers(self,
|
|
86
|
+
def list_computers(self, project_id: str) -> List[Dict[str, Any]]:
|
|
90
87
|
"""List all computers in a project"""
|
|
91
|
-
|
|
92
|
-
return
|
|
88
|
+
project = self.get_project(project_id)
|
|
89
|
+
return project.get("desktops", [])
|
|
93
90
|
|
|
94
91
|
def get_computer(self, computer_id: str) -> Dict[str, Any]:
|
|
95
92
|
"""Get computer details"""
|
|
@@ -99,14 +96,6 @@ class ApiClient:
|
|
|
99
96
|
"""Delete a computer"""
|
|
100
97
|
return self._request("DELETE", f"computers/{computer_id}")
|
|
101
98
|
|
|
102
|
-
def start_computer(self, computer_id: str) -> Dict[str, Any]:
|
|
103
|
-
"""Start a computer"""
|
|
104
|
-
return self._request("POST", f"computers/{computer_id}/start")
|
|
105
|
-
|
|
106
|
-
def stop_computer(self, computer_id: str) -> Dict[str, Any]:
|
|
107
|
-
"""Stop a computer"""
|
|
108
|
-
return self._request("POST", f"computers/{computer_id}/stop")
|
|
109
|
-
|
|
110
99
|
def restart_computer(self, computer_id: str) -> Dict[str, Any]:
|
|
111
100
|
"""Restart a computer"""
|
|
112
101
|
return self._request("POST", f"computers/{computer_id}/restart")
|
|
@@ -3,6 +3,7 @@ import os as operating_system
|
|
|
3
3
|
import base64
|
|
4
4
|
import logging
|
|
5
5
|
import uuid
|
|
6
|
+
import io
|
|
6
7
|
from typing import Dict, List, Any, Optional, Callable, Literal, Union
|
|
7
8
|
from PIL import Image
|
|
8
9
|
import requests
|
|
@@ -89,8 +90,12 @@ class Computer:
|
|
|
89
90
|
"""Connect to existing computer by ID"""
|
|
90
91
|
self.computer_id = computer_id
|
|
91
92
|
self._info = self.api.get_computer(computer_id)
|
|
92
|
-
self.
|
|
93
|
+
self.project_id = self._info.get("project_id")
|
|
93
94
|
self.name = self._info.get("name")
|
|
95
|
+
# Get project name
|
|
96
|
+
if self.project_id:
|
|
97
|
+
project = self.api.get_project(self.project_id)
|
|
98
|
+
self.project_name = project.get("name")
|
|
94
99
|
|
|
95
100
|
def _initialize_with_project_name(self, project_name: str, computer_name: Optional[str]):
|
|
96
101
|
"""Initialize with a project name (create project if needed)"""
|
|
@@ -100,7 +105,7 @@ class Computer:
|
|
|
100
105
|
self.project_id = project.get("id")
|
|
101
106
|
|
|
102
107
|
# Check for existing computers
|
|
103
|
-
computers = self.api.list_computers(
|
|
108
|
+
computers = self.api.list_computers(self.project_id)
|
|
104
109
|
|
|
105
110
|
if computer_name:
|
|
106
111
|
# Look for specific computer
|
|
@@ -109,20 +114,20 @@ class Computer:
|
|
|
109
114
|
self._connect_to_existing_computer(existing)
|
|
110
115
|
else:
|
|
111
116
|
# Create new computer with specified name
|
|
112
|
-
self._create_computer(
|
|
117
|
+
self._create_computer(self.project_id, computer_name)
|
|
113
118
|
elif computers:
|
|
114
119
|
# No name specified, use first available computer
|
|
115
120
|
self._connect_to_existing_computer(computers[0])
|
|
116
121
|
else:
|
|
117
122
|
# No computers exist, create new one
|
|
118
|
-
self._create_computer(
|
|
123
|
+
self._create_computer(self.project_id, computer_name)
|
|
119
124
|
|
|
120
125
|
except Exception:
|
|
121
126
|
# Project doesn't exist, create it
|
|
122
127
|
logger.info(f"Project {project_name} not found, creating new project")
|
|
123
128
|
project = self.api.create_project(project_name)
|
|
124
129
|
self.project_id = project.get("id")
|
|
125
|
-
self._create_computer(
|
|
130
|
+
self._create_computer(self.project_id, computer_name)
|
|
126
131
|
|
|
127
132
|
def _initialize_with_project_instance(self, project: 'Project', computer_name: Optional[str]):
|
|
128
133
|
"""Initialize with a Project instance"""
|
|
@@ -135,13 +140,13 @@ class Computer:
|
|
|
135
140
|
self._connect_to_existing_computer(existing)
|
|
136
141
|
else:
|
|
137
142
|
# Create new computer with specified name
|
|
138
|
-
self._create_computer(project.
|
|
143
|
+
self._create_computer(project.id, computer_name)
|
|
139
144
|
elif computers:
|
|
140
145
|
# No name specified, use first available computer
|
|
141
146
|
self._connect_to_existing_computer(computers[0])
|
|
142
147
|
else:
|
|
143
148
|
# No computers exist, create new one
|
|
144
|
-
self._create_computer(project.
|
|
149
|
+
self._create_computer(project.id, computer_name)
|
|
145
150
|
|
|
146
151
|
def _create_new_project_and_computer(self, computer_name: Optional[str]):
|
|
147
152
|
"""Create a new project and computer"""
|
|
@@ -154,7 +159,7 @@ class Computer:
|
|
|
154
159
|
self.project_name = project_name
|
|
155
160
|
|
|
156
161
|
# Create a computer in the new project
|
|
157
|
-
self._create_computer(
|
|
162
|
+
self._create_computer(self.project_id, computer_name)
|
|
158
163
|
|
|
159
164
|
def _connect_to_existing_computer(self, computer_info: Dict[str, Any]):
|
|
160
165
|
"""Connect to an existing computer"""
|
|
@@ -163,7 +168,7 @@ class Computer:
|
|
|
163
168
|
self._info = computer_info
|
|
164
169
|
logger.info(f"Connected to existing computer {self.name} (ID: {self.computer_id})")
|
|
165
170
|
|
|
166
|
-
def _create_computer(self,
|
|
171
|
+
def _create_computer(self, project_id: str, computer_name: Optional[str]):
|
|
167
172
|
"""Create a new computer in the project"""
|
|
168
173
|
# Generate name if not provided
|
|
169
174
|
if not computer_name:
|
|
@@ -182,7 +187,7 @@ class Computer:
|
|
|
182
187
|
raise ValueError("gpu must be one of: 'none', 'a10', 'l40s', 'a100-40gb', 'a100-80gb'")
|
|
183
188
|
|
|
184
189
|
computer = self.api.create_computer(
|
|
185
|
-
|
|
190
|
+
project_id=project_id,
|
|
186
191
|
computer_name=computer_name,
|
|
187
192
|
os=self.os,
|
|
188
193
|
ram=self.ram,
|
|
@@ -197,14 +202,6 @@ class Computer:
|
|
|
197
202
|
"""Get current computer status"""
|
|
198
203
|
return self.api.get_computer(self.computer_id)
|
|
199
204
|
|
|
200
|
-
def start(self) -> Dict[str, Any]:
|
|
201
|
-
"""Start the computer"""
|
|
202
|
-
return self.api.start_computer(self.computer_id)
|
|
203
|
-
|
|
204
|
-
def stop(self) -> Dict[str, Any]:
|
|
205
|
-
"""Stop the computer"""
|
|
206
|
-
return self.api.stop_computer(self.computer_id)
|
|
207
|
-
|
|
208
205
|
def restart(self) -> Dict[str, Any]:
|
|
209
206
|
"""Restart the computer"""
|
|
210
207
|
return self.api.restart_computer(self.computer_id)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|