autonomous-app 0.3.39__py3-none-any.whl → 0.3.40__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.39"
1
+ __version__ = "0.3.40"
2
2
 
3
3
  from dotenv import load_dotenv
4
4
 
@@ -18,13 +18,11 @@ class JSONAgent(BaseAgent):
18
18
  default="A helpful AI assistant trained to assist with generating JSON formatted data."
19
19
  )
20
20
 
21
- def generate(
22
- self, message, function, additional_instructions="", uri="", context=""
23
- ):
21
+ def generate(self, message, function, system_prompt="", uri="", context=""):
24
22
  result = self.get_client(
25
23
  os.environ.get("JSON_AI_AGENT", self.provider)
26
24
  ).generate_json(
27
- message, function, additional_instructions, uri=uri, context=context
25
+ message, function, system_prompt=system_prompt, uri=uri, context=context
28
26
  )
29
27
  if isinstance(result, str):
30
28
  try:
@@ -75,32 +75,48 @@ class LocalAIModel(AutoModel):
75
75
  return text.strip()
76
76
 
77
77
  def generate_json(
78
- self, message, function, additional_instructions="", uri="", context={}
78
+ self,
79
+ message,
80
+ function=None,
81
+ system_prompt=None,
82
+ uri="",
83
+ context={},
79
84
  ):
80
- schema_str = self._convert_tools_to_json_schema(function)
81
-
82
- # 1. Improved System Prompt
83
- # We explicitly warn about nested quotes, which is the #1 killer of complex JSON
84
- full_system_prompt = (
85
- f"{self.instructions}. {additional_instructions}\n"
86
- f"You are a strict JSON generator. Output ONLY a valid JSON object matching this schema:\n"
87
- f"{schema_str}\n"
88
- f"IMPORTANT RULES:\n"
89
- f"1. Do not include markdown formatting or explanations.\n"
90
- f"2. DOUBLE CHECK nested quotes inside strings. Escape them properly.\n"
91
- f"3. Ensure all arrays and objects are closed.\n"
92
- )
85
+ # 1. Determine System Prompt Strategy
86
+ if system_prompt:
87
+ # STRATEGY A: Custom System Prompt (Highest Priority)
88
+ full_system_prompt = system_prompt
89
+ elif function:
90
+ # STRATEGY B: Strict Schema Enforcement (Default)
91
+ schema_str = self._convert_tools_to_json_schema(function)
92
+
93
+ full_system_prompt = (
94
+ f"{self.instructions}.\n"
95
+ f"You are a strict JSON generator. Output ONLY a valid JSON object matching this schema:\n"
96
+ f"{schema_str}\n"
97
+ f"IMPORTANT RULES:\n"
98
+ f"1. Do not include markdown formatting or explanations.\n"
99
+ f"2. DOUBLE CHECK nested quotes inside strings. Escape them properly.\n"
100
+ f"3. Ensure all arrays and objects are closed.\n"
101
+ )
102
+ else:
103
+ # STRATEGY C: Fallback
104
+ full_system_prompt = (
105
+ f"{self.instructions}.\n"
106
+ f"You are a strict JSON generator. Output valid JSON."
107
+ )
93
108
 
109
+ # 2. Add Context (Applies to all strategies)
94
110
  if context:
95
111
  full_system_prompt += (
96
112
  f"\n\n### GROUND TRUTH CONTEXT ###\n"
97
113
  f"Adhere strictly to this context:\n"
98
114
  f"{json.dumps(context, indent=2)}"
99
115
  )
100
- elif uri:
116
+ if uri:
101
117
  full_system_prompt += f"Use the following URI for reference: {uri}"
102
118
 
103
- # 3. Payload with INCREASED CONTEXT and LOWER TEMPERATURE
119
+ # 3. Payload Construction
104
120
  payload = {
105
121
  "model": self._json_model,
106
122
  "messages": [
@@ -111,30 +127,28 @@ class LocalAIModel(AutoModel):
111
127
  "stream": False,
112
128
  "keep_alive": "24h",
113
129
  "options": {
114
- "num_ctx": 8192, # <--- Prevents cutoff on large schemas
115
- "temperature": 0.8, # <--- INCREASED from 0.2 to 0.8 for creativity
116
- "top_p": 0.9, # <--- Adds nuance to word choice
117
- "repeat_penalty": 1.1, # <--- Prevents it from saying "rust" 5 times
130
+ "num_ctx": 8192,
131
+ "temperature": 0.8, # Keep high for creativity
132
+ "top_p": 0.9,
133
+ "repeat_penalty": 1.1,
118
134
  },
119
135
  }
120
136
 
121
137
  log("==== LocalAI JSON Payload ====", payload, _print=True)
138
+
122
139
  result_text = ""
123
140
  try:
124
- # print(f"==== {self._ollama_url}: LocalAI JSON Payload ====")
125
141
  response = requests.post(f"{self._ollama_url}/chat", json=payload)
126
142
  log(response)
127
143
  response.raise_for_status()
128
144
 
129
145
  result_text = response.json().get("message", {}).get("content", "{}")
130
146
 
131
- # Clean
147
+ # Clean & Parse
132
148
  clean_text = self._clean_json_response(result_text)
133
-
134
- # Parse
135
149
  result_dict = json.loads(clean_text)
136
150
 
137
- # Unwrap
151
+ # Unwrap (Handle cases where model wraps in 'parameters' key)
138
152
  if "parameters" in result_dict and isinstance(
139
153
  result_dict["parameters"], dict
140
154
  ):
@@ -144,15 +158,12 @@ class LocalAIModel(AutoModel):
144
158
  return result_dict
145
159
 
146
160
  except Exception as e:
147
- # If it fails, print the RAW text so you can see WHERE it broke.
148
161
  log(f"==== LocalAI JSON Error: {e} ====", _print=True)
149
162
  if result_text:
150
163
  log(
151
164
  f"--- FAILED RAW OUTPUT ---\n{result_text}\n-----------------------",
152
165
  _print=True,
153
166
  )
154
-
155
- # Returning empty prevents the whole app from dying on one bad generation.
156
167
  return {}
157
168
 
158
169
  def generate_text(self, message, additional_instructions="", uri="", context={}):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: autonomous-app
3
- Version: 0.3.39
3
+ Version: 0.3.40
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
  Project-URL: homepage, https://github.com/Sallenmoore/autonomous
@@ -1,15 +1,15 @@
1
- autonomous/__init__.py,sha256=q_VjpmLkH8iiS1RkA2Lz2bc4RrMxOIWaOGNgqo7YkTE,95
1
+ autonomous/__init__.py,sha256=wctZMLFlIhnHGpW9CgIwEUymYQdUxRVESGOAinyM10M,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
5
  autonomous/ai/audioagent.py,sha256=aZ25eEdze8S060-a4S0k319tgyl2aDTUa8dJu07mXn0,1092
6
6
  autonomous/ai/baseagent.py,sha256=icOPygr1NdH64u1ZYbwHHywYIY1ZtaLY9HtfNmUbx4k,4702
7
7
  autonomous/ai/imageagent.py,sha256=yN-Qv1QSBsFvw0fVXLVqdh_3cveRETJGILgeBI3GRoc,955
8
- autonomous/ai/jsonagent.py,sha256=OZeQthp5WOSCV6pmbPfPQRjARkvbK5lk7A0QTEPUrUk,1228
8
+ autonomous/ai/jsonagent.py,sha256=DNfZHMVCfc5nrkWJm2OebTYDkBwm_ZCeVWGIFGjB_Cg,1208
9
9
  autonomous/ai/textagent.py,sha256=0y2Hvb9pup1OnsA51hGPcD8yllZOZtztDLQvCNYABaw,1043
10
10
  autonomous/ai/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  autonomous/ai/models/gemini.py,sha256=eu48gywNFpUFaqBt-4MFX2oRM5IED9rUTgtavM_HRG0,14468
12
- autonomous/ai/models/local_model.py,sha256=JbU_BC-7qqgF8hsuk-7S3l2CsxUFc-wsL1a8ID2AdNY,12068
12
+ autonomous/ai/models/local_model.py,sha256=OagrbF6WkWKmmGf1oBmdAt4VBRLzvk6Gj-xoV9HdwLs,12152
13
13
  autonomous/apis/version_control/GHCallbacks.py,sha256=AyiUlYfV5JePi11GVyqYyXoj5UTbPKzS-HRRI94rjJo,1069
14
14
  autonomous/apis/version_control/GHOrganization.py,sha256=mi2livdsGurKiifbvuLwiFbdDzL77IlEfhwEa-tG77I,1155
15
15
  autonomous/apis/version_control/GHRepo.py,sha256=hTFHMkxSbSlVELfh8S6mq6ijkIKPRQO-Q5775ZjRKD4,4622
@@ -55,7 +55,7 @@ autonomous/taskrunner/__init__.py,sha256=ughX-QfWBas5W3aB2SiF887SWJ3Dzc2X43Yxtmp
55
55
  autonomous/taskrunner/autotasks.py,sha256=2zRaqHYqfdlgC_BQm6B6D2svN1ukyWeJJHwweZFHVoo,2616
56
56
  autonomous/taskrunner/task_router.py,sha256=W09HtRUuhwlnGxM5w4l6Hzw6mfS6L4ljWiMzD3ZVFeU,601
57
57
  autonomous/utils/markdown.py,sha256=tf8vlHARiQO1X_aGbqlYozzP_TbdiDRT9EEP6aFRQo0,2153
58
- autonomous_app-0.3.39.dist-info/METADATA,sha256=9rRFFf_IvOxHp4PHGlYyac6GbeVVYViT5614cANQvwE,3024
59
- autonomous_app-0.3.39.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
60
- autonomous_app-0.3.39.dist-info/top_level.txt,sha256=ZyxWWDdbvZekF3UFunxl4BQsVDb_FOW3eTn0vun_jb4,11
61
- autonomous_app-0.3.39.dist-info/RECORD,,
58
+ autonomous_app-0.3.40.dist-info/METADATA,sha256=kT_NvMRU_Mac8iEZ49Lo2YkETd5y9abW5A24e_1JjWE,3024
59
+ autonomous_app-0.3.40.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
60
+ autonomous_app-0.3.40.dist-info/top_level.txt,sha256=ZyxWWDdbvZekF3UFunxl4BQsVDb_FOW3eTn0vun_jb4,11
61
+ autonomous_app-0.3.40.dist-info/RECORD,,