autonomous-app 0.3.38__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.38"
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,28 +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.2, # <--- Increases structural stability
130
+ "num_ctx": 8192,
131
+ "temperature": 0.8, # Keep high for creativity
132
+ "top_p": 0.9,
133
+ "repeat_penalty": 1.1,
116
134
  },
117
135
  }
118
136
 
119
137
  log("==== LocalAI JSON Payload ====", payload, _print=True)
138
+
120
139
  result_text = ""
121
140
  try:
122
- # print(f"==== {self._ollama_url}: LocalAI JSON Payload ====")
123
141
  response = requests.post(f"{self._ollama_url}/chat", json=payload)
124
142
  log(response)
125
143
  response.raise_for_status()
126
144
 
127
145
  result_text = response.json().get("message", {}).get("content", "{}")
128
146
 
129
- # Clean
147
+ # Clean & Parse
130
148
  clean_text = self._clean_json_response(result_text)
131
-
132
- # Parse
133
149
  result_dict = json.loads(clean_text)
134
150
 
135
- # Unwrap
151
+ # Unwrap (Handle cases where model wraps in 'parameters' key)
136
152
  if "parameters" in result_dict and isinstance(
137
153
  result_dict["parameters"], dict
138
154
  ):
@@ -142,15 +158,12 @@ class LocalAIModel(AutoModel):
142
158
  return result_dict
143
159
 
144
160
  except Exception as e:
145
- # If it fails, print the RAW text so you can see WHERE it broke.
146
161
  log(f"==== LocalAI JSON Error: {e} ====", _print=True)
147
162
  if result_text:
148
163
  log(
149
164
  f"--- FAILED RAW OUTPUT ---\n{result_text}\n-----------------------",
150
165
  _print=True,
151
166
  )
152
-
153
- # Returning empty prevents the whole app from dying on one bad generation.
154
167
  return {}
155
168
 
156
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.38
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=aY9AoxbQyS88VAP7J_QuUHj1ER70KsYmagTnOKAp9uE,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=xnCgnqmQXxeG-t2Z1PCE3aEHVq2STYFNI5mJSBQ1MmM,11907
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.38.dist-info/METADATA,sha256=keKvI0j6sAWHgKrakbZF1Q2G5m-D3biIM_CSBOC1M1M,3024
59
- autonomous_app-0.3.38.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
60
- autonomous_app-0.3.38.dist-info/top_level.txt,sha256=ZyxWWDdbvZekF3UFunxl4BQsVDb_FOW3eTn0vun_jb4,11
61
- autonomous_app-0.3.38.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,,