autonomous-app 0.3.15__py3-none-any.whl → 0.3.16__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.3.15"
1
+ __version__ = "0.3.16"
2
2
 
3
3
  from dotenv import load_dotenv
4
4
 
@@ -1,6 +1,6 @@
1
1
  from autonomous import log
2
- from autonomous.model.autoattr import ReferenceAttr, StringAttr
3
2
  from autonomous.ai.baseagent import BaseAgent
3
+ from autonomous.model.autoattr import ReferenceAttr, StringAttr
4
4
 
5
5
  from .models.openai import OpenAIModel
6
6
 
@@ -14,5 +14,5 @@ class AudioAgent(BaseAgent):
14
14
  default="A helpful AI assistant trained to assist with generating audio files."
15
15
  )
16
16
 
17
- def generate(self, prompt, file_path, **kwargs):
18
- return self.get_client().generate_audio(prompt, file_path, **kwargs)
17
+ def generate(self, prompt, **kwargs):
18
+ return self.get_client().generate_audio(prompt, **kwargs)
@@ -12,6 +12,14 @@ class BaseAgent(AutoModel):
12
12
 
13
13
  _ai_model = OpenAIModel
14
14
 
15
+ def delete(self):
16
+ if self.client:
17
+ self.client.delete()
18
+ return super().delete()
19
+
20
+ def get_agent_id(self):
21
+ return self.get_client().id
22
+
15
23
  def get_client(self):
16
24
  if self.client is None:
17
25
  self.client = self._ai_model(
@@ -23,9 +31,8 @@ class BaseAgent(AutoModel):
23
31
  self.save()
24
32
  return self.client
25
33
 
34
+ def clear_files(self, file_id=None):
35
+ return self.client.clear_files(file_id)
26
36
 
27
- # def clear_files(self, file_id=None):
28
- # return self.client.clear_files(file_id)
29
-
30
- # def attach_file(self, file_contents, filename="dbdata.json"):
31
- # return self.client.attach_file(file_contents, filename)
37
+ def attach_file(self, file_contents, filename="dbdata.json"):
38
+ return self.client.attach_file(file_contents, filename)
@@ -1,3 +1,4 @@
1
+ import io
1
2
  import json
2
3
  import os
3
4
  import random
@@ -36,6 +37,12 @@ class OpenAIModel(AutoModel):
36
37
  self._client = OpenAI(api_key=os.environ.get("OPENAI_KEY"))
37
38
  return self._client
38
39
 
40
+ def delete(self):
41
+ self.clear_files()
42
+ if self.agent_id:
43
+ self.client.beta.assistants.delete(self.agent_id)
44
+ return super().delete()
45
+
39
46
  def clear_agent(self):
40
47
  if self.agent_id:
41
48
  self.client.beta.assistants.delete(self.agent_id)
@@ -70,18 +77,15 @@ class OpenAIModel(AutoModel):
70
77
  self.save()
71
78
  return self.agent_id
72
79
 
73
- def clear_files(self, file_id=None, all=False):
80
+ def clear_files(self, file_id=None):
74
81
  if not file_id:
75
- store_files = self.client.files.list().data
76
-
77
82
  for vs in self.client.beta.vector_stores.list().data:
78
83
  try:
79
84
  self.client.beta.vector_stores.delete(vs.id)
80
85
  except openai_NotFoundError:
81
86
  log(f"==== Vector Store {vs.id} not found ====")
82
- if all:
83
- for sf in store_files:
84
- self.client.files.delete(file_id=sf.id)
87
+ for sf in self.client.files.list().data:
88
+ self.client.files.delete(file_id=sf.id)
85
89
  else:
86
90
  self.client.files.delete(file_id=file_id)
87
91
  self.tools.pop("file_search", None)
@@ -98,17 +102,20 @@ class OpenAIModel(AutoModel):
98
102
  vector_store_id=vs[0].id
99
103
  ).id
100
104
  else:
101
- raise openai.NotFoundError(message="No vector store found")
102
- except openai.NotFoundError:
105
+ for sf in self.client.files.list().data:
106
+ self.client.files.delete(file_id=sf.id)
107
+ raise FileNotFoundError("No vector store found")
108
+ except FileNotFoundError:
103
109
  self.vector_store = self.client.beta.vector_stores.create(
104
- name="Data Reference",
110
+ name="World Reference",
105
111
  expires_after={"anchor": "last_active_at", "days": 14},
106
112
  ).id
107
-
113
+ log(f"==== Vector Store ID: {self.vector_store}====")
114
+ # Attach File
108
115
  file_obj = self.client.files.create(
109
116
  file=(filename, file_contents), purpose="assistants"
110
117
  )
111
-
118
+ log(f"==== FileStore ID: {file_obj.id}====")
112
119
  self.client.beta.vector_stores.files.create(
113
120
  vector_store_id=self.vector_store,
114
121
  file_id=file_obj.id,
@@ -269,7 +276,7 @@ IMPORTANT: Always use the function 'response' tool to respond to the user with o
269
276
  # log("=================== END REPORT ===================", _print=True)
270
277
  return results
271
278
 
272
- def generate_audio(self, prompt, file_path, **kwargs):
279
+ def generate_audio(self, prompt, **kwargs):
273
280
  voice = kwargs.get("voice") or random.choice(
274
281
  ["alloy", "echo", "fable", "onyx", "nova", "shimmer"]
275
282
  )
@@ -278,8 +285,9 @@ IMPORTANT: Always use the function 'response' tool to respond to the user with o
278
285
  voice=voice,
279
286
  input=prompt,
280
287
  )
281
-
282
- return response.stream_to_file(file_path)
288
+ log(response)
289
+ audio_data = io.BytesIO(response["audio"].encode("utf-8"))
290
+ return audio_data
283
291
 
284
292
  def generate_image(self, prompt, **kwargs):
285
293
  image = None
@@ -43,14 +43,17 @@ class AutoAuth:
43
43
  )
44
44
 
45
45
  @classmethod
46
- def current_user(cls):
46
+ def current_user(cls, pk=None):
47
47
  """
48
48
  Returns the current user.
49
49
  """
50
+ if pk:
51
+ user = cls.user_class.get(pk)
52
+ elif session.get("user"):
53
+ user = cls.user_class.from_json(session["user"])
54
+ else:
55
+ user = None
50
56
 
51
- user = (
52
- cls.user_class.from_json(session["user"]) if session.get("user") else None
53
- )
54
57
  if not user or user.state != "authenticated":
55
58
  user = cls.user_class.get_guest()
56
59
  return user
autonomous/auth/user.py CHANGED
@@ -42,13 +42,13 @@ class AutoUser(AutoModel):
42
42
  log(email, user)
43
43
  if not user:
44
44
  log(f"Creating new user for {email}")
45
- # user = cls(name=name, email=email)
46
-
45
+ user = cls(name=name, email=email)
47
46
  # parse user_info into a user object
48
47
  user.name = name
49
48
  user.email = email
50
49
  user.last_login = datetime.now()
51
50
  user.state = "authenticated"
51
+ user.role = "user"
52
52
  user.save()
53
53
  return user
54
54
 
@@ -90,11 +90,15 @@ class AutoModel(Document):
90
90
 
91
91
  @classmethod
92
92
  def load_model(cls, model):
93
- module_name, model = (
94
- model.rsplit(".", 1) if "." in model else (f"models.{model.lower()}", model)
95
- )
96
- module = importlib.import_module(module_name)
97
- return getattr(module, model)
93
+ subclasses = AutoModel.__subclasses__()
94
+ while subclasses:
95
+ subclass = subclasses.pop()
96
+ if "_meta" in subclass.__dict__ and not subclass._meta.get("abstract"):
97
+ if subclass.__name__.lower() == model.lower():
98
+ return subclass
99
+ elif subclass not in subclasses:
100
+ subclasses += [subclass]
101
+ raise ValueError(f"Model {model} not found")
98
102
 
99
103
  @classmethod
100
104
  def get(cls, pk):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: autonomous-app
3
- Version: 0.3.15
3
+ Version: 0.3.16
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,24 +1,24 @@
1
- autonomous/__init__.py,sha256=3ly0yvUWqUwyNdwwspvj_ch1tVo7q7g6d4CJG5PG-ls,95
1
+ autonomous/__init__.py,sha256=_Imheob6ygUp8AAQctaaAImaCjsiK2EzHfEPRC2jstI,95
2
2
  autonomous/cli.py,sha256=z4AaGeWNW_uBLFAHng0J_lfS9v3fXemK1PeT85u4Eo4,42
3
3
  autonomous/logger.py,sha256=NQtgEaTWNAWfLSgqSP7ksXj1GpOuCgoUV711kSMm-WA,2022
4
4
  autonomous/ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- autonomous/ai/audioagent.py,sha256=Vqh_1YxfZ1T7sU27BR06d_d618heA0mRlOa0440_NHs,635
6
- autonomous/ai/baseagent.py,sha256=NE3OjDqu2e9Wy-cQEzzQoHPUrtFo__WPpPAN0v3zOxs,905
5
+ autonomous/ai/audioagent.py,sha256=PlDNOdYKJxsqWbql0aAv_F7dS0piBeZV3nuKKZ0-hAI,613
6
+ autonomous/ai/baseagent.py,sha256=gXOdfAWokEf3P7z2jQlbHmwSZohvXfdapZfkoLz6HuQ,1073
7
7
  autonomous/ai/imageagent.py,sha256=Tn02Hk7WX53pqvK-2Xd2xOuyHKaNuAS_yr7lRdct3rc,624
8
8
  autonomous/ai/jsonagent.py,sha256=wlTULEBlrAAb8ELMxik1b7YOgHD4ARmbWLUWc5pgxB8,1197
9
9
  autonomous/ai/textagent.py,sha256=8iVuY-cSJsJgyWKrpCoj46c0MIsB13PFPNYdxSyqlKI,1096
10
10
  autonomous/ai/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
- autonomous/ai/models/openai.py,sha256=AQ5OY4XuT8KYinFffoTDDOO9CZ5pJ0DspE1h97_F-FE,12105
11
+ autonomous/ai/models/openai.py,sha256=r9eVwN6dMCeO28JcX46Hbdpd00ZLZlT7xXcrXQ4p4Ss,12499
12
12
  autonomous/apis/version_control/GHCallbacks.py,sha256=AyiUlYfV5JePi11GVyqYyXoj5UTbPKzS-HRRI94rjJo,1069
13
13
  autonomous/apis/version_control/GHOrganization.py,sha256=mi2livdsGurKiifbvuLwiFbdDzL77IlEfhwEa-tG77I,1155
14
14
  autonomous/apis/version_control/GHRepo.py,sha256=hTFHMkxSbSlVELfh8S6mq6ijkIKPRQO-Q5775ZjRKD4,4622
15
15
  autonomous/apis/version_control/GHVersionControl.py,sha256=VIhVRxe6gJgozFWyhyKIu4spgSJI-GChiVJudnSyggI,196
16
16
  autonomous/apis/version_control/__init__.py,sha256=tP0bAWYl1RwBRi62HsIidmgyqHuSlCUqwGuKUKKRugc,117
17
17
  autonomous/auth/__init__.py,sha256=IW5tQ8VYwHIbDfMYA0wYgx4PprwcjUWV4EoIJ8HTlMU,161
18
- autonomous/auth/autoauth.py,sha256=6GFs8xikCvPYXZ29bbc5baf603QvnE8tZQIIrAfTziY,3624
18
+ autonomous/auth/autoauth.py,sha256=OizuMhmFjNzmsUijIbjGcQ5FxzVeoy9-NMFsx_TDsOE,3709
19
19
  autonomous/auth/github.py,sha256=dHf84bJdV9rXGcvRLzWCPW9CvuA-VEmqYi_QQFwd2kY,886
20
20
  autonomous/auth/google.py,sha256=cHmqbyNEPTKipc3WkYcD1XPOyqcWEFW0Ks4qJYmGvPw,1049
21
- autonomous/auth/user.py,sha256=t8R7KsHp-QK3B_OS5ERSnQ4P8Tnhjehhmdqp5gcKxuU,2702
21
+ autonomous/auth/user.py,sha256=1yDu04yNSURzBzok6C5Dn-_mv0fGefvjrxj9ikCktqY,2726
22
22
  autonomous/db/__init__.py,sha256=9frkXJrl_OUemUQteXCTPqC8ECyxjE91Gi2mgTq26Fw,1159
23
23
  autonomous/db/common.py,sha256=BUN2x_XuQBRFcq54TGPx4yLMLJdgytdbIt07QWr4CSM,2551
24
24
  autonomous/db/connection.py,sha256=j_-eMre4ade9Y8GejJcMbQQiSEimL4j2vIQxaXViKxI,17754
@@ -46,15 +46,15 @@ autonomous/db/queryset/transform.py,sha256=UhBdDxYR_bWH0ECnaSw9g9YMwgWRZtsRl_q6P
46
46
  autonomous/db/queryset/visitor.py,sha256=AN09lR6hWYUlKJC7G1sktvnWy5hrFnpoQhi58bOXbA4,5470
47
47
  autonomous/model/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
48
48
  autonomous/model/autoattr.py,sha256=eqO3QE17EMRzLvtF74gXefeK1I2N-w6uScpibdChVOw,2254
49
- autonomous/model/automodel.py,sha256=_D7s02MUEllJZX3ubpHARlWK8__3CEBT7YCQcypkkhQ,7340
49
+ autonomous/model/automodel.py,sha256=k3_15qciSlEjXRa_izWUJRIvP5d-cHVU07kK-NX2A2Q,7562
50
50
  autonomous/storage/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
51
51
  autonomous/storage/imagestorage.py,sha256=SmBjBNBlP1ZEjxdOnGVzCHZhbEhMKTUQC2TbpWbejDE,6168
52
52
  autonomous/storage/localstorage.py,sha256=FzrR6O9mMGAZt5dDgqzkeOQVfGRXCygR0kksz2MPpwE,2286
53
53
  autonomous/tasks/__init__.py,sha256=pn7iZ14MhcHUdzcLkfkd4-45wgPP0tXahAz_cFgb_Tg,32
54
54
  autonomous/tasks/autotask.py,sha256=aK5iapDhgcAic3F5ZYMAhNKJkOepj8yWwbMizKDzUwQ,4153
55
55
  autonomous/utils/markdown.py,sha256=tf8vlHARiQO1X_aGbqlYozzP_TbdiDRT9EEP6aFRQo0,2153
56
- autonomous_app-0.3.15.dist-info/LICENSE,sha256=-PHHSuDRkodHo3PEdMkDtoIdmLAOomMq6lsLaOetU8g,1076
57
- autonomous_app-0.3.15.dist-info/METADATA,sha256=CJKOgOPGRwT2u1OrlTOjnyk_lKVGwzm0-Olofu_BNbA,4189
58
- autonomous_app-0.3.15.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
59
- autonomous_app-0.3.15.dist-info/top_level.txt,sha256=ZyxWWDdbvZekF3UFunxl4BQsVDb_FOW3eTn0vun_jb4,11
60
- autonomous_app-0.3.15.dist-info/RECORD,,
56
+ autonomous_app-0.3.16.dist-info/LICENSE,sha256=-PHHSuDRkodHo3PEdMkDtoIdmLAOomMq6lsLaOetU8g,1076
57
+ autonomous_app-0.3.16.dist-info/METADATA,sha256=2oaPtvX0a-wB_rnQ_sK9sasVoq11DkZNFMhEsds-6Sc,4189
58
+ autonomous_app-0.3.16.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
59
+ autonomous_app-0.3.16.dist-info/top_level.txt,sha256=ZyxWWDdbvZekF3UFunxl4BQsVDb_FOW3eTn0vun_jb4,11
60
+ autonomous_app-0.3.16.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.3.0)
2
+ Generator: setuptools (75.5.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5