autonomous-app 0.2.17__py3-none-any.whl → 0.2.19__py3-none-any.whl

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.
autonomous/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = "0.2.17"
1
+ __version__ = "0.2.19"
2
2
 
3
3
  from .logger import log
4
4
  from .model.automodel import AutoModel
autonomous/ai/oaiagent.py CHANGED
@@ -194,7 +194,7 @@ class OAIAgent(AutoModel):
194
194
  },
195
195
  {"role": "user", "content": text},
196
196
  ]
197
- response = self.client.chat.completions.create(model="gpt-4", messages=message)
197
+ response = self.client.chat.completions.create(model="gpt-4o", messages=message)
198
198
  try:
199
199
  result = response.choices[0].message.content
200
200
  except Exception as e:
autonomous/logger.py CHANGED
@@ -28,6 +28,8 @@ class Logger:
28
28
  level = os.environ.get("LOG_LEVEL") or self.logger.level
29
29
  self.logger.setLevel(log_levels.get(level, "DEBUG"))
30
30
  self.enabled = True
31
+ if not os.path.exists("logs"):
32
+ os.makedirs("logs")
31
33
  self.logfile = "logs/current_run_error_log.log"
32
34
  self.logarchive = (
33
35
  f"logs/error_log-{datetime.datetime.now().strftime('%Y-%m-%d')}.log"
@@ -2,7 +2,6 @@
2
2
  # default : Optional[str] = "value" # for default values
3
3
  import copy
4
4
  import importlib
5
- import json
6
5
  from abc import ABC
7
6
  from datetime import datetime
8
7
 
@@ -119,12 +118,18 @@ class AutoModel(ABC):
119
118
  v = v.default
120
119
  setattr(obj, k, result.get(k, copy.deepcopy(v)))
121
120
  obj.pk = pk
121
+ for key, val in list(kwargs.items()):
122
+ if (
123
+ getattr(cls, key, None)
124
+ and getattr(cls, key).fset
125
+ and f"_{key}" in cls.attributes
126
+ ):
127
+ kwargs[f"_{key}"] = kwargs.pop(key)
122
128
  obj.__dict__ |= kwargs
123
129
  # breakpoint()
124
130
  obj.__dict__ = AutoDecoder.decode(obj.__dict__)
125
131
  obj._automodel = obj.model_name(qualified=True)
126
132
  obj.last_updated = datetime.now()
127
-
128
133
  return obj
129
134
 
130
135
  def __getattribute__(self, name):
@@ -249,20 +254,24 @@ class AutoModel(ABC):
249
254
  val = getattr(self, key)
250
255
  if vattr.type == "TEXT":
251
256
  if not isinstance(val, str):
252
- raise TypeError(f"Value must be a string, not {type(val)}")
257
+ raise TypeError(
258
+ f"{key} value must be a string, not {type(val)}"
259
+ )
253
260
  elif vattr.type == "NUMERIC":
254
261
  if not isinstance(val, (int, float)):
255
- raise TypeError(f"Value must be a number, not {type(val)}")
262
+ raise TypeError(
263
+ f"{key} value must be a number, not {type(val)}"
264
+ )
256
265
  elif vattr.type == "MODEL":
257
266
  # log(isinstance(val, (AutoModel, DelayedModel)), type(val))
258
267
  if val is not None and not isinstance(
259
268
  val, (AutoModel, DelayedModel)
260
269
  ):
261
270
  raise TypeError(
262
- f"Value must be an AutoModel or None, not {type(val)}"
271
+ f"{key} value must be an AutoModel or None, not {type(val)}"
263
272
  )
264
273
  else:
265
- raise ValueError(f"Invalid type {self.type}")
274
+ raise ValueError(f"{key}: Invalid type {self.type}")
266
275
 
267
276
  if vattr.required and val is None:
268
277
  raise ValueError(f"{key} is required")
@@ -3,7 +3,7 @@ import os
3
3
  import shutil
4
4
  import uuid
5
5
 
6
- from PIL import Image
6
+ from PIL import Image, UnidentifiedImageError
7
7
 
8
8
  from autonomous import log
9
9
 
@@ -24,13 +24,17 @@ class ImageStorage:
24
24
  def _resize_image(self, asset_id, max_size=1024):
25
25
  # log("Resizing image", asset_id, max_size)
26
26
  file_path = f"{self.get_path(asset_id)}/orig.webp"
27
- with Image.open(file_path) as img:
28
- resized_img = img.copy()
29
- max_size = self._sizes.get(max_size) or int(max_size)
30
- resized_img.thumbnail((max_size, max_size))
31
- img_byte_arr = io.BytesIO()
32
- resized_img.save(img_byte_arr, format="WEBP")
33
- return img_byte_arr.getvalue()
27
+ try:
28
+ with Image.open(file_path) as img:
29
+ resized_img = img.copy()
30
+ max_size = self._sizes.get(max_size) or int(max_size)
31
+ resized_img.thumbnail((max_size, max_size))
32
+ img_byte_arr = io.BytesIO()
33
+ resized_img.save(img_byte_arr, format="WEBP")
34
+ return img_byte_arr.getvalue()
35
+ except UnidentifiedImageError as e:
36
+ log(f"Error resizing image: {e}")
37
+ return None
34
38
 
35
39
  def _convert_image(self, raw, crop=False):
36
40
  with Image.open(io.BytesIO(raw)) as img:
@@ -66,25 +70,40 @@ class ImageStorage:
66
70
  original_path = f"{self.get_path(asset_id)}"
67
71
  # log(f"Getting image: {asset_id}.{size}", original_path)
68
72
  if not os.path.exists(original_path):
69
- # log(f"Original image not found: {original_path}")
73
+ log(f"Original image not found: {original_path}")
70
74
  return ""
71
75
  file_path = f"{original_path}/{size}.webp"
72
76
  # log(file_path)
77
+ result_url = f"/{file_path}"
78
+ # log(
79
+ # f"{asset_id}",
80
+ # size,
81
+ # os.path.exists(original_path),
82
+ # os.path.exists(file_path),
83
+ # )
73
84
  if (
74
85
  size != "orig"
75
86
  and os.path.exists(original_path)
76
87
  and not os.path.exists(file_path)
77
88
  ):
78
89
  # If the file doesn't exist, create it
79
- result = self._resize_image(asset_id, size)
80
- with open(file_path, "wb") as asset:
81
- asset.write(result)
82
- result_url = (
83
- f"/{file_path}"
84
- if not full_url
85
- else f"{os.environ.get('APP_BASE_URL', '')}/{file_path}"
86
- )
87
- # log(f"Returning image url: {result_url}")
90
+ if result := self._resize_image(asset_id, size):
91
+ with open(file_path, "wb") as asset:
92
+ asset.write(result)
93
+ result_url = (
94
+ f"/{file_path}"
95
+ if not full_url
96
+ else f"{os.environ.get('APP_BASE_URL', '')}/{file_path}"
97
+ )
98
+ else:
99
+ log(
100
+ f"Error resizing image: {asset_id}",
101
+ size,
102
+ os.path.exists(original_path),
103
+ os.path.exists(file_path),
104
+ )
105
+ self.remove(asset_id)
106
+ # log(f"Returning image: {result_url}")
88
107
  return result_url
89
108
 
90
109
  def get_path(self, asset_id):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: autonomous-app
3
- Version: 0.2.17
3
+ Version: 0.2.19
4
4
  Summary: Containerized application framework built on Flask with additional libraries and tools for rapid development of web applications.
5
5
  Author-email: Steven A Moore <samoore@binghamton.edu>
6
6
  License: MIT License
@@ -1,8 +1,8 @@
1
- autonomous/__init__.py,sha256=ZlVHlQd6mQ5oZiv98AWlh3CaYpftWM29G0dnvPzJkWA,87
1
+ autonomous/__init__.py,sha256=oDsDNe2n6SEIsx41D8osz_TCWX7CFSxlVvmZIb4PzM4,87
2
2
  autonomous/cli.py,sha256=z4AaGeWNW_uBLFAHng0J_lfS9v3fXemK1PeT85u4Eo4,42
3
- autonomous/logger.py,sha256=hDX3gvbcWiGPvA8pfarih3xHS4aHG_NuNkF8PQfq_pM,1844
3
+ autonomous/logger.py,sha256=jePQ4kTtECTwGtIcDmpLSE6rSwhaUEiQe2vK06h5XIg,1915
4
4
  autonomous/ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- autonomous/ai/oaiagent.py,sha256=T2cUbDdyTZCjr0B9Apr_O_nZWJp4yHcYLv94QAbH4yY,7196
5
+ autonomous/ai/oaiagent.py,sha256=jOfAK6FIJN2n8CKrcrAcL8t1Jh5bgxk4bnBt0NwTXBE,7197
6
6
  autonomous/auth/__init__.py,sha256=IW5tQ8VYwHIbDfMYA0wYgx4PprwcjUWV4EoIJ8HTlMU,161
7
7
  autonomous/auth/autoauth.py,sha256=Q2DfcWjh0vTSSpf5SqyK4SElVDcxu8435GhLSPqTYco,3724
8
8
  autonomous/auth/github.py,sha256=dHf84bJdV9rXGcvRLzWCPW9CvuA-VEmqYi_QQFwd2kY,886
@@ -15,11 +15,11 @@ autonomous/errors/__init__.py,sha256=OruWG9IkAF4LN-OAo5c2K9Dnds4oZFJJQHKaXbQaWnA
15
15
  autonomous/errors/danglingreferenceerror.py,sha256=obfNjpn2vsyK4ak-UuuwFTMVzecs1SaeFPshOvnukS8,275
16
16
  autonomous/model/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
17
17
  autonomous/model/autoattribute.py,sha256=q09cORKC6-LpoZ3Ez-lRkd5kxuSFQrB2nA2f9_8k2c8,588
18
- autonomous/model/automodel.py,sha256=Z8iDZB7frSV_lQ09HL-l0ff0_ePEuPwjLzWnpbdCsJw,12391
18
+ autonomous/model/automodel.py,sha256=b3ivBawR1X4adLuL14vXYVRBwHYFsLG9B4pP-yURN3k,12772
19
19
  autonomous/model/orm.py,sha256=IJrbp15RmBgF61vLsqcS_VdnAnw9736sLW75_xFYE9Y,2521
20
20
  autonomous/model/serializer.py,sha256=0nfmw4-QNP-ozL4IVbgQyfPRF2i0-uG9pQZwgEPYuxU,3026
21
21
  autonomous/storage/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
- autonomous/storage/imagestorage.py,sha256=WOBvnpW3VhvliT2pXtaD_Msh1XEAVxqEBELblsvfdtA,3970
22
+ autonomous/storage/imagestorage.py,sha256=RlZ6F4s7FGpcyzJq8IstN-CDhhSigEQjJL5L7OVCxUM,4671
23
23
  autonomous/storage/localstorage.py,sha256=FzrR6O9mMGAZt5dDgqzkeOQVfGRXCygR0kksz2MPpwE,2286
24
24
  autonomous/storage/markdown.py,sha256=tf8vlHARiQO1X_aGbqlYozzP_TbdiDRT9EEP6aFRQo0,2153
25
25
  autonomous/storage/version_control/GHCallbacks.py,sha256=AyiUlYfV5JePi11GVyqYyXoj5UTbPKzS-HRRI94rjJo,1069
@@ -29,8 +29,8 @@ autonomous/storage/version_control/GHVersionControl.py,sha256=VIhVRxe6gJgozFWyhy
29
29
  autonomous/storage/version_control/__init__.py,sha256=tP0bAWYl1RwBRi62HsIidmgyqHuSlCUqwGuKUKKRugc,117
30
30
  autonomous/tasks/__init__.py,sha256=pn7iZ14MhcHUdzcLkfkd4-45wgPP0tXahAz_cFgb_Tg,32
31
31
  autonomous/tasks/autotask.py,sha256=_WQ8w1LyV2FVJ0Ct0FoF9q1W8ClXfS57-omnBb0LNWE,4910
32
- autonomous_app-0.2.17.dist-info/LICENSE,sha256=-PHHSuDRkodHo3PEdMkDtoIdmLAOomMq6lsLaOetU8g,1076
33
- autonomous_app-0.2.17.dist-info/METADATA,sha256=3lmrmZ2854E5DBMmbfEAhDLLMxw_iKGQq22Z24sStCo,4229
34
- autonomous_app-0.2.17.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
35
- autonomous_app-0.2.17.dist-info/top_level.txt,sha256=ZyxWWDdbvZekF3UFunxl4BQsVDb_FOW3eTn0vun_jb4,11
36
- autonomous_app-0.2.17.dist-info/RECORD,,
32
+ autonomous_app-0.2.19.dist-info/LICENSE,sha256=-PHHSuDRkodHo3PEdMkDtoIdmLAOomMq6lsLaOetU8g,1076
33
+ autonomous_app-0.2.19.dist-info/METADATA,sha256=jVxFgZdhBn-NaDeY2X-59QSJyoazF4q8WXCadiYLpxs,4229
34
+ autonomous_app-0.2.19.dist-info/WHEEL,sha256=cpQTJ5IWu9CdaPViMhC9YzF8gZuS5-vlfoFihTBC86A,91
35
+ autonomous_app-0.2.19.dist-info/top_level.txt,sha256=ZyxWWDdbvZekF3UFunxl4BQsVDb_FOW3eTn0vun_jb4,11
36
+ autonomous_app-0.2.19.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.43.0)
2
+ Generator: setuptools (70.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5