npcpy 1.1.28__py3-none-any.whl → 1.2.32__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.
Files changed (44) hide show
  1. npcpy/data/audio.py +16 -38
  2. npcpy/data/image.py +29 -29
  3. npcpy/data/load.py +4 -3
  4. npcpy/data/text.py +28 -28
  5. npcpy/data/video.py +6 -6
  6. npcpy/data/web.py +49 -21
  7. npcpy/ft/__init__.py +0 -0
  8. npcpy/ft/diff.py +110 -0
  9. npcpy/ft/ge.py +115 -0
  10. npcpy/ft/memory_trainer.py +171 -0
  11. npcpy/ft/model_ensembler.py +357 -0
  12. npcpy/ft/rl.py +360 -0
  13. npcpy/ft/sft.py +248 -0
  14. npcpy/ft/usft.py +128 -0
  15. npcpy/gen/audio_gen.py +24 -0
  16. npcpy/gen/embeddings.py +13 -13
  17. npcpy/gen/image_gen.py +37 -15
  18. npcpy/gen/response.py +287 -111
  19. npcpy/gen/video_gen.py +10 -9
  20. npcpy/llm_funcs.py +447 -79
  21. npcpy/memory/command_history.py +201 -48
  22. npcpy/memory/kg_vis.py +74 -74
  23. npcpy/memory/knowledge_graph.py +482 -115
  24. npcpy/memory/memory_processor.py +81 -0
  25. npcpy/memory/search.py +70 -70
  26. npcpy/mix/debate.py +192 -3
  27. npcpy/npc_compiler.py +1541 -879
  28. npcpy/npc_sysenv.py +250 -78
  29. npcpy/serve.py +1036 -321
  30. npcpy/sql/ai_function_tools.py +257 -0
  31. npcpy/sql/database_ai_adapters.py +186 -0
  32. npcpy/sql/database_ai_functions.py +163 -0
  33. npcpy/sql/model_runner.py +19 -19
  34. npcpy/sql/npcsql.py +706 -507
  35. npcpy/sql/sql_model_compiler.py +156 -0
  36. npcpy/tools.py +20 -20
  37. npcpy/work/plan.py +8 -8
  38. npcpy/work/trigger.py +3 -3
  39. {npcpy-1.1.28.dist-info → npcpy-1.2.32.dist-info}/METADATA +169 -9
  40. npcpy-1.2.32.dist-info/RECORD +54 -0
  41. npcpy-1.1.28.dist-info/RECORD +0 -40
  42. {npcpy-1.1.28.dist-info → npcpy-1.2.32.dist-info}/WHEEL +0 -0
  43. {npcpy-1.1.28.dist-info → npcpy-1.2.32.dist-info}/licenses/LICENSE +0 -0
  44. {npcpy-1.1.28.dist-info → npcpy-1.2.32.dist-info}/top_level.txt +0 -0
npcpy/sql/model_runner.py CHANGED
@@ -35,7 +35,7 @@ class NPCModelRunner:
35
35
  )
36
36
 
37
37
  def _load_sample_data(self):
38
- # For testing purposes
38
+
39
39
  return pd.DataFrame(
40
40
  {
41
41
  "customer_id": range(1, 4),
@@ -50,32 +50,32 @@ class NPCModelRunner:
50
50
 
51
51
  def run_model(self, model_name: str, model_sql: str, sample_data=None):
52
52
  try:
53
- # Load or use sample data
53
+
54
54
  if sample_data is None:
55
55
  raw_data = self._load_sample_data()
56
56
  else:
57
57
  raw_data = sample_data
58
58
 
59
- # Register the raw data as a table
59
+
60
60
  self.model_registry["raw_customer_feedback"] = raw_data
61
61
 
62
- # Parse SQL and execute with our custom functions
62
+
63
63
  if "{{ ref(" in model_sql:
64
- # Handle model dependencies
64
+
65
65
  for dep in self._extract_dependencies(model_sql):
66
66
  if dep not in self.model_registry:
67
67
  raise ValueError(f"Dependent model {dep} not found")
68
68
 
69
- # Replace ref() calls with actual data
69
+
70
70
  model_sql = self._resolve_refs(model_sql)
71
71
 
72
- # Execute the model
72
+
73
73
  result_df = self._execute_model(model_sql)
74
74
 
75
- # Store in registry
75
+
76
76
  self.model_registry[model_name] = result_df
77
77
 
78
- # Log to history
78
+
79
79
  self._log_model_run(model_name, result_df)
80
80
 
81
81
  return result_df
@@ -85,8 +85,8 @@ class NPCModelRunner:
85
85
  raise e
86
86
 
87
87
  def _execute_model(self, model_sql: str) -> pd.DataFrame:
88
- # This is a simplified version - you'd want to properly parse the SQL
89
- # For now, let's implement basic synthesize functionality
88
+
89
+
90
90
 
91
91
  if "synthesize(" in model_sql:
92
92
  raw_data = self.model_registry["raw_customer_feedback"]
@@ -109,7 +109,7 @@ class NPCModelRunner:
109
109
  context=self._load_vars()["business_context"],
110
110
  )
111
111
 
112
- return pd.DataFrame() # Fallback
112
+ return pd.DataFrame()
113
113
 
114
114
  def _log_model_run(self, model_name: str, result_df, status="success", error=None):
115
115
  with sqlite3.connect(self.history_db) as conn:
@@ -139,14 +139,14 @@ class NPCModelRunner:
139
139
  return yaml.safe_load(f).get("vars", {})
140
140
 
141
141
  def _extract_dependencies(self, model_sql: str) -> List[str]:
142
- # Simple regex to extract model names from ref() calls
142
+
143
143
  import re
144
144
 
145
145
  refs = re.findall(r'{{\s*ref\([\'"](.+?)[\'"]\)\s*}}', model_sql)
146
146
  return refs
147
147
 
148
148
  def _resolve_refs(self, model_sql: str) -> str:
149
- # Replace ref() calls with actual table references
149
+
150
150
  import re
151
151
 
152
152
  def replace_ref(match):
@@ -158,25 +158,25 @@ class NPCModelRunner:
158
158
  return re.sub(r'{{\s*ref\([\'"](.+?)[\'"]\)\s*}}', replace_ref, model_sql)
159
159
 
160
160
 
161
- # Usage example:
161
+
162
162
  def main():
163
- # Initialize
163
+
164
164
 
165
165
  runner = NPCModelRunner(npc_compiler)
166
166
 
167
- # Run first model
167
+
168
168
  with open("models/customer_feedback.sql", "r") as f:
169
169
  feedback_model = runner.run_model("customer_feedback", f.read())
170
170
  print("First model results:")
171
171
  print(feedback_model.head())
172
172
 
173
- # Run second model that depends on the first
173
+
174
174
  with open("models/customer_insights.sql", "r") as f:
175
175
  insights_model = runner.run_model("customer_insights", f.read())
176
176
  print("\nSecond model results:")
177
177
  print(insights_model.head())
178
178
 
179
- # Check history
179
+
180
180
  with sqlite3.connect(runner.history_db) as conn:
181
181
  history = pd.read_sql(
182
182
  "SELECT * FROM model_runs ORDER BY run_timestamp DESC", conn