npcpy 2.1.28__tar.gz → 2.1.30__tar.gz

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 (146) hide show
  1. {npcpy-2.1.28/npcpy.egg-info → npcpy-2.1.30}/PKG-INFO +193 -4
  2. {npcpy-2.1.28 → npcpy-2.1.30}/README.md +189 -2
  3. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/__init__.py +4 -7
  4. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/convert.py +2 -4
  5. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/data/image.py +7 -1
  6. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/data/load.py +2 -2
  7. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/data/web.py +39 -0
  8. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/gen/__init__.py +8 -14
  9. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/gen/audio_gen.py +24 -20
  10. npcpy-2.1.30/npcpy/gen/decision.py +1085 -0
  11. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/gen/embeddings.py +49 -14
  12. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/gen/image_gen.py +38 -34
  13. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/gen/response.py +205 -171
  14. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/gen/systemone.py +7 -2
  15. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/llm_funcs.py +101 -1
  16. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/memory/search.py +3 -3
  17. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/npc_compiler.py +13 -14
  18. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/npc_sysenv.py +121 -0
  19. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/serve.py +51 -19
  20. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/streaming.py +27 -17
  21. {npcpy-2.1.28 → npcpy-2.1.30/npcpy.egg-info}/PKG-INFO +193 -4
  22. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy.egg-info/SOURCES.txt +15 -0
  23. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy.egg-info/requires.txt +3 -1
  24. {npcpy-2.1.28 → npcpy-2.1.30}/setup.py +3 -2
  25. npcpy-2.1.30/tests/test_airllm_params.py +74 -0
  26. npcpy-2.1.30/tests/test_audio_gen_defaults.py +95 -0
  27. npcpy-2.1.30/tests/test_auto_tools_format.py +88 -0
  28. npcpy-2.1.30/tests/test_convert.py +29 -0
  29. npcpy-2.1.30/tests/test_gen_decision.py +291 -0
  30. npcpy-2.1.30/tests/test_gen_decision_hosted.py +125 -0
  31. npcpy-2.1.30/tests/test_gen_decision_systemone.py +167 -0
  32. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_image.py +38 -0
  33. npcpy-2.1.30/tests/test_image_gen_defaults.py +127 -0
  34. npcpy-2.1.30/tests/test_litellm_reasoning_kept.py +57 -0
  35. npcpy-2.1.30/tests/test_llamacpp_params.py +127 -0
  36. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_llm_funcs.py +689 -2
  37. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_load.py +20 -0
  38. npcpy-2.1.30/tests/test_lora_temperature.py +76 -0
  39. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_mcp_and_skills.py +30 -1
  40. npcpy-2.1.30/tests/test_mlx_top_k.py +41 -0
  41. npcpy-2.1.30/tests/test_ollama_image_embeddings.py +75 -0
  42. npcpy-2.1.30/tests/test_ollama_sampling_params.py +69 -0
  43. npcpy-2.1.30/tests/test_ollama_stream_tool_calls.py +42 -0
  44. npcpy-2.1.30/tests/test_process_tool_calls_unknown_tool.py +23 -0
  45. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_readme_examples.py +17 -2
  46. npcpy-2.1.30/tests/test_search_embedding_provider.py +60 -0
  47. npcpy-2.1.30/tests/test_stream_tool_usage_totals.py +67 -0
  48. npcpy-2.1.30/tests/test_transformers_params.py +80 -0
  49. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_web.py +63 -0
  50. npcpy-2.1.28/npcpy/gen/decision.py +0 -572
  51. npcpy-2.1.28/tests/test_audio_gen_defaults.py +0 -30
  52. npcpy-2.1.28/tests/test_gen_decision.py +0 -349
  53. npcpy-2.1.28/tests/test_gen_decision_systemone.py +0 -165
  54. npcpy-2.1.28/tests/test_image_gen_defaults.py +0 -49
  55. {npcpy-2.1.28 → npcpy-2.1.30}/LICENSE +0 -0
  56. {npcpy-2.1.28 → npcpy-2.1.30}/MANIFEST.in +0 -0
  57. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/data/__init__.py +0 -0
  58. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/data/audio.py +0 -0
  59. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/data/data_models.py +0 -0
  60. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/data/text.py +0 -0
  61. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/data/video.py +0 -0
  62. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/db.py +0 -0
  63. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/ft/__init__.py +0 -0
  64. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/ft/diff.py +0 -0
  65. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/ft/embeddings.py +0 -0
  66. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/ft/engine.py +0 -0
  67. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/ft/export.py +0 -0
  68. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/ft/ge.py +0 -0
  69. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/ft/memory_trainer.py +0 -0
  70. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/ft/model_ensembler.py +0 -0
  71. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/ft/neat.py +0 -0
  72. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/ft/rl.py +0 -0
  73. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/ft/sft.py +0 -0
  74. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/ft/system1.py +0 -0
  75. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/ft/usft.py +0 -0
  76. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/gen/cli_agent.py +0 -0
  77. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/gen/mlx_musicgen/__init__.py +0 -0
  78. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/gen/mlx_musicgen/encodec.py +0 -0
  79. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/gen/mlx_musicgen/musicgen.py +0 -0
  80. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/gen/mlx_musicgen/t5.py +0 -0
  81. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/gen/mlx_musicgen/utils.py +0 -0
  82. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/gen/ocr.py +0 -0
  83. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/gen/video_gen.py +0 -0
  84. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/gen/world_gen.py +0 -0
  85. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/init.py +0 -0
  86. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/launcher.py +0 -0
  87. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/main.py +0 -0
  88. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/mcp_server.py +0 -0
  89. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/memory/__init__.py +0 -0
  90. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/memory/kg_population.py +0 -0
  91. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/memory/knowledge_graph.py +0 -0
  92. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/memory/knowledge_index.py +0 -0
  93. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/memory/knowledge_store.py +0 -0
  94. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/memory/memory_processor.py +0 -0
  95. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/mix/__init__.py +0 -0
  96. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/mix/debate.py +0 -0
  97. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/ml_funcs.py +0 -0
  98. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/npc2mcp.py +0 -0
  99. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/npc_array.py +0 -0
  100. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/plugin_setup.py +0 -0
  101. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/tools.py +0 -0
  102. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/work/__init__.py +0 -0
  103. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/work/browser.py +0 -0
  104. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/work/desktop.py +0 -0
  105. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/work/plan.py +0 -0
  106. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy/work/trigger.py +0 -0
  107. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy.egg-info/dependency_links.txt +0 -0
  108. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy.egg-info/entry_points.txt +0 -0
  109. {npcpy-2.1.28 → npcpy-2.1.30}/npcpy.egg-info/top_level.txt +0 -0
  110. {npcpy-2.1.28 → npcpy-2.1.30}/setup.cfg +0 -0
  111. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_airllm.py +0 -0
  112. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_api_route.py +0 -0
  113. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_audio.py +0 -0
  114. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_browser.py +0 -0
  115. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_data_models.py +0 -0
  116. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_diff.py +0 -0
  117. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_doc_examples.py +0 -0
  118. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_documentation_examples.py +0 -0
  119. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_ft_embeddings.py +0 -0
  120. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_ft_system1.py +0 -0
  121. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_gen_systemone.py +0 -0
  122. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_genetic_evolver.py +0 -0
  123. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_litellm_generation_params.py +0 -0
  124. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_litellm_tool_turn_usage.py +0 -0
  125. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_litellm_top_k.py +0 -0
  126. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_memory_processor.py +0 -0
  127. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_minimax_text.py +0 -0
  128. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_minimax_video_gen.py +0 -0
  129. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_ml_funcs.py +0 -0
  130. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_neat.py +0 -0
  131. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_npc_array.py +0 -0
  132. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_npc_compiler.py +0 -0
  133. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_npc_sysenv.py +0 -0
  134. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_ollama_num_predict.py +0 -0
  135. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_ollama_stream_tool_double_call.py +0 -0
  136. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_ollama_tool_turn_usage.py +0 -0
  137. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_provider_usage_cost.py +0 -0
  138. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_response.py +0 -0
  139. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_serve.py +0 -0
  140. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_serve_systemone.py +0 -0
  141. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_stream_temperature_zero.py +0 -0
  142. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_stream_tool_call_deltas.py +0 -0
  143. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_stream_usage_cost.py +0 -0
  144. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_text.py +0 -0
  145. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_tools.py +0 -0
  146. {npcpy-2.1.28 → npcpy-2.1.30}/tests/test_video.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: npcpy
3
- Version: 2.1.28
3
+ Version: 2.1.30
4
4
  Summary: npcpy is the premier open-source library for integrating LLMs and Agents into python systems.
5
5
  Home-page: https://github.com/NPC-Worldwide/npcpy
6
6
  Author: Christopher Agostino
@@ -11,7 +11,7 @@ Requires-Python: >=3.10
11
11
  Description-Content-Type: text/markdown
12
12
  License-File: LICENSE
13
13
  Requires-Dist: jinja2
14
- Requires-Dist: litellm==1.91.1
14
+ Requires-Dist: litellm==1.111.0
15
15
  Requires-Dist: scipy
16
16
  Requires-Dist: numpy
17
17
  Requires-Dist: requests
@@ -65,6 +65,7 @@ Requires-Dist: playsound==1.2.2; extra == "tts"
65
65
  Requires-Dist: pygame; extra == "tts"
66
66
  Requires-Dist: faster_whisper; extra == "tts"
67
67
  Requires-Dist: pyttsx3; extra == "tts"
68
+ Requires-Dist: websockets>=14; extra == "tts"
68
69
  Provides-Extra: system1
69
70
  Requires-Dist: sentence_transformers; extra == "system1"
70
71
  Requires-Dist: scikit-learn; extra == "system1"
@@ -88,6 +89,7 @@ Requires-Dist: playsound==1.2.2; extra == "all"
88
89
  Requires-Dist: pygame; extra == "all"
89
90
  Requires-Dist: faster_whisper; extra == "all"
90
91
  Requires-Dist: pyttsx3; extra == "all"
92
+ Requires-Dist: websockets>=14; extra == "all"
91
93
  Requires-Dist: sentence_transformers; extra == "all"
92
94
  Requires-Dist: scikit-learn; extra == "all"
93
95
  Dynamic: author
@@ -172,6 +174,133 @@ When a traveler sees that soft, phosphorescent light, it isn’t just a pretty s
172
174
  The bird **shows the way to hidden water (and sometimes to buried silver or gold)** in the Atacama Desert.
173
175
  ```
174
176
 
177
+ ### Typed decisions instead of generated text
178
+
179
+ Sometimes you do not want prose back from a model. You want a label, a yes/no
180
+ probability, or a value on a rubric, fast, with a confidence your code can
181
+ threshold on. That is what the npcpy Decision Module is for. It exposes a single
182
+ flat function, get_decision_response, that works with any supported provider
183
+ and returns a typed answer with probabilities.
184
+
185
+ The local Ollama backend needs no API key and no training, so it is the quickest
186
+ way to try this:
187
+
188
+ ```python
189
+ from npcpy.llm_funcs import get_decision_response
190
+
191
+ result = get_decision_response(
192
+ prompt='Customer wrote: I was charged twice for order #4411 and want one refunded today.',
193
+ model='tev1:0.8b',
194
+ provider='ollama',
195
+ question_type='choice',
196
+ instructions='What should happen to this ticket next?',
197
+ criteria={
198
+ 'refund': 'the customer is owed money back',
199
+ 'escalate': 'a human agent needs to take over',
200
+ 'close': 'nothing further is needed',
201
+ },
202
+ )
203
+
204
+ print(result['response']['choice']) # 'refund'
205
+ print(result['response']['confidence']) # 0.82
206
+ print(result['response']['probabilities']) # {'refund': 0.82, 'escalate': 0.14, 'close': 0.04}
207
+ ```
208
+
209
+ `question_type` selects the answer shape: `'choice'` picks one label from
210
+ `criteria`, `'noul'` returns a yes/no probability, and `'score'` returns a
211
+ value on an ordered scale.
212
+
213
+ ```python
214
+ # yes/no: does this message contain a refund request?
215
+ result = get_decision_response(
216
+ prompt='Customer wrote: I was charged twice, please refund the duplicate.',
217
+ model='tev1:0.8b', provider='ollama',
218
+ question_type='noul',
219
+ instructions='Is the customer asking for a refund?',
220
+ )
221
+ print(result['response']['noul']) # 0.99
222
+
223
+ # rubric: how urgent is this?
224
+ result = get_decision_response(
225
+ prompt='Customer wrote: this is the third time I have asked. Fix it now.',
226
+ model='tev1:0.8b', provider='ollama',
227
+ question_type='score',
228
+ instructions='How urgent is this request?',
229
+ criteria=['can wait a week', 'needs attention today', 'breach of SLA'],
230
+ )
231
+ print(result['response']['score']) # 2.1
232
+ ```
233
+
234
+ You can also call the lower-level helpers in npcpy.gen.decision directly:
235
+
236
+ ```python
237
+ from npcpy.gen.decision import decision_choice, decision_noul, decision_score
238
+
239
+ label = decision_choice(
240
+ state='Customer wrote: I was charged twice, please refund the duplicate.',
241
+ instructions='What should happen to this ticket next?',
242
+ criteria={'refund': 'money back', 'escalate': 'needs a human', 'close': 'no action'},
243
+ model='tev1:0.8b', provider='ollama',
244
+ )
245
+
246
+ probability = decision_noul(
247
+ state='Customer wrote: I was charged twice.',
248
+ instructions='Is the customer asking for a refund?',
249
+ model='tev1:0.8b', provider='ollama',
250
+ )
251
+
252
+ score = decision_score(
253
+ state='Customer wrote: this is the third time I have asked.',
254
+ instructions='How urgent is this?',
255
+ criteria=['low', 'medium', 'high'],
256
+ model='tev1:0.8b', provider='ollama',
257
+ )
258
+ ```
259
+
260
+ Hosted decision models take the same model / provider / api_key arguments:
261
+
262
+ ```python
263
+ from npcpy.llm_funcs import get_decision_response
264
+
265
+ result = get_decision_response(
266
+ prompt='Customer wrote: I was charged twice for order #4411.',
267
+ model='gemini-decision-1',
268
+ provider='gemini',
269
+ api_key='...',
270
+ question_type='choice',
271
+ instructions='Which team should handle this?',
272
+ criteria={'billing': 'payments and refunds', 'support': 'product questions'},
273
+ )
274
+ print(result['response']['choice'])
275
+ ```
276
+
277
+ | provider | example model |
278
+ | --- | --- |
279
+ | `openai` | `gpt-6-luna` |
280
+ | `gemini` | `gemini-decision-1` |
281
+ | `perplexity` | `pplx-decider-v1-27b` |
282
+ | `typesafe` | `jev-1.14.0` |
283
+ | `cloudflare` | `clef`, `clef-flash`, `clef-omni` |
284
+ | `openrouter` | `openai/gpt-6-luna-decisions` |
285
+ | `databricks` | `databricks-openjev-qwen35-4b` |
286
+ | `fireworks_ai` | `accounts/fireworks/routers/rune` |
287
+ | `azure_ai` | `<your-deployment>` with base model `Microsoft-Decision-1` |
288
+ | `ollama` | `tev1:0.8b`, `clef-flash` |
289
+
290
+ To point at a self-hosted LiteLLM proxy, pass `api_url`:
291
+
292
+ ```python
293
+ result = get_decision_response(
294
+ prompt='...', model='jev', provider='litellm_proxy',
295
+ api_url='https://litellm.example.com', api_key='sk-...',
296
+ question_type='noul', instructions='Is this a refund request?',
297
+ )
298
+ ```
299
+
300
+ Every provider returns the same shape: `{choice, noul, score, confidence,
301
+ probabilities}`, so downstream code does not branch on provider. See the
302
+ [System One Decisions guide](docs/guides/system-one.md) for the full reference.
303
+
175
304
  ### Agent with tools
176
305
  The `Agent` class in `npcpy` comes with a set of default tools (sh, python, edit_file, web_search, etc.)
177
306
 
@@ -1118,6 +1247,16 @@ model_path = run_sft(X_train, y_train, config=sft_config, format_style="llama")
1118
1247
 
1119
1248
  Works with all major LLM providers through LiteLLM: `airllm`, `anthropic`, `deepseek`, `gemini`, `ollama`, `openai`, `openai-like`, and more.
1120
1249
 
1250
+ <details><summary>AIGROW</summary>
1251
+
1252
+ Set `AIGROW_API_KEY` and use `provider="aigrow"` with a model ID from AIGROW's public model list (`GET https://aigrow.gg/v1/models`, no key needed, per-token prices included), for example `claude-haiku-5.5`, `gpt-6.2-sol` or `gemini-4-neon`. IDs are plain slugs without a vendor prefix. Requests go to the OpenAI-compatible Base URL `https://aigrow.gg/v1`; set `AIGROW_API_URL` to override it. Usage is prepaid; keys are created in the [AIGROW dashboard](https://aigrow.gg/dashboard/api).
1253
+
1254
+ ```python
1255
+ response = get_llm_response("Say hello in one short sentence.", model="claude-haiku-5.5", provider="aigrow")
1256
+ print(response["response"])
1257
+ ```
1258
+
1259
+ </details>
1121
1260
  <details><summary>API Route</summary>
1122
1261
 
1123
1262
  Set `API_ROUTE_API_KEY` and use `provider="api-route"` with an exact model ID from your account's authenticated `GET /v1/models` response, for example `gpt-6.1-sol`. [API Route](https://api-route.com) uses the OpenAI-compatible Base URL `https://global.api-route.com/v1`; set `API_ROUTE_API_URL` to override it. The alias `api_route` is also accepted. Explicit `api_url` and `api_key` arguments take precedence.
@@ -1169,6 +1308,16 @@ response = get_llm_response("Say hello in one short sentence.", model="deepseek-
1169
1308
  print(response["response"])
1170
1309
  ```
1171
1310
 
1311
+ </details>
1312
+ <details><summary>LLMTR</summary>
1313
+
1314
+ Set `LLMTR_API_KEY` and use `provider="llmtr"` with a `vendor/model` ID from LLMTR's public model list (`GET https://llmtr.com/v1/models`), for example `qwen/qwen3.8-flash` (default), `qwen/qwen3.8-max` or `mistral/devstral-medium-latest`. Requests go to the OpenAI-compatible Base URL `https://llmtr.com/v1`; set `LLMTR_API_URL` to override it. Usage is prepaid; keys are created in the [LLMTR dashboard](https://llmtr.com/dashboard/keys).
1315
+
1316
+ ```python
1317
+ response = get_llm_response("Say hello in one short sentence.", model="qwen/qwen3.8-flash", provider="llmtr")
1318
+ print(response["response"])
1319
+ ```
1320
+
1172
1321
  </details>
1173
1322
  <details><summary>MiniMax</summary>
1174
1323
 
@@ -1193,6 +1342,16 @@ response = get_llm_response("Say hello in one short sentence.", model="deepseek/
1193
1342
  print(response["response"])
1194
1343
  ```
1195
1344
 
1345
+ </details>
1346
+ <details><summary>onomeo</summary>
1347
+
1348
+ Set `ONOMEO_API_KEY` and use `provider="onomeo"` with a model ID from onomeo's model list (`GET https://onomeo.com/v1/models` with your key, or the [models page](https://onomeo.com/models)), for example `deepseek-v4.1-flash`, `claude-sonnet-5.5` or `gpt-6.1-sol`. IDs are plain slugs without a vendor prefix. Requests go to the OpenAI-compatible Base URL `https://onomeo.com/v1`; set `ONOMEO_API_URL` to override it. Free models are available within limits; paid models are charged to a prepaid balance. Keys are created in the [onomeo dashboard](https://onomeo.com/dashboard).
1349
+
1350
+ ```python
1351
+ response = get_llm_response("Say hello in one short sentence.", model="deepseek-v4.1-flash", provider="onomeo")
1352
+ print(response["response"])
1353
+ ```
1354
+
1196
1355
  </details>
1197
1356
  <details><summary>Opper</summary>
1198
1357
 
@@ -1203,6 +1362,16 @@ response = get_llm_response("Say hello in one short sentence.", model="claude-so
1203
1362
  print(response["response"])
1204
1363
  ```
1205
1364
 
1365
+ </details>
1366
+ <details><summary>Requesty</summary>
1367
+
1368
+ Set `REQUESTY_API_KEY` and use `provider="requesty"` with a `vendor/model` ID from Requesty's public model list (`GET https://router.requesty.ai/v1/models`), for example `openai/gpt-4o-mini`, `anthropic/claude-sonnet-5` or `google/gemini-2.5-flash`. Requests go to the OpenAI-compatible Base URL `https://router.requesty.ai/v1` and are routed to the first-party providers (OpenAI, Anthropic, Google and others); set `REQUESTY_API_URL` to override it, for example `https://router.eu.requesty.ai/v1` for the EU endpoint. Keys are created in the [Requesty dashboard](https://app.requesty.ai/api-keys).
1369
+
1370
+ ```python
1371
+ response = get_llm_response("Say hello in one short sentence.", model="openai/gpt-4o-mini", provider="requesty")
1372
+ print(response["response"])
1373
+ ```
1374
+
1206
1375
  </details>
1207
1376
  <details><summary>Runcrate</summary>
1208
1377
 
@@ -1214,9 +1383,29 @@ print(response["response"])
1214
1383
  ```
1215
1384
 
1216
1385
  </details>
1217
- <details><summary>UberLLM</summary>
1386
+ <details><summary>TeamoRouter</summary>
1387
+
1388
+ Set `TEAMOROUTER_API_KEY` and use `provider="teamorouter"` with a model ID from TeamoRouter's model list (`GET https://api.teamorouter.com/v1/models` with your key), for example `glm-5.3`, `deepseek-v4-pro`, `kimi-k3.1-pro` or `claude-sonnet-5-5`. Requests go to the OpenAI-compatible Base URL `https://api.teamorouter.com/v1`; set `TEAMOROUTER_API_URL` to override it. Keys are created in the [TeamoRouter dashboard](https://teamorouter.com/dashboard?tab=api-keys).
1389
+
1390
+ ```python
1391
+ response = get_llm_response("Say hello in one short sentence.", model="glm-5.3", provider="teamorouter")
1392
+ print(response["response"])
1393
+ ```
1394
+
1395
+ </details>
1396
+ <details><summary>TrustedRouter</summary>
1397
+
1398
+ Set `TRUSTEDROUTER_API_KEY` and use `provider="trustedrouter"` with any model ID from TrustedRouter's live public catalog (`GET https://api.trustedrouter.com/v1/models`), for example `deepseek/deepseek-v4-flash` (default) or privacy presets such as `trustedrouter/zdr`, `trustedrouter/e2e`, and `trustedrouter/auto` (or `nyte/*` aliases). Requests go through hardware-attested Confidential Space TEEs at `https://api.trustedrouter.com/v1`; set `TRUSTEDROUTER_API_URL` to override it, and pass `extra_body={"min_privacy": 2}` to enforce a minimum privacy floor per request. Keys are created at [trustedrouter.com](https://trustedrouter.com).
1399
+
1400
+ ```python
1401
+ response = get_llm_response("Say hello in one short sentence.", model="trustedrouter/zdr", provider="trustedrouter")
1402
+ print(response["response"])
1403
+ ```
1404
+
1405
+ </details>
1406
+ <details><summary>MartLLM</summary>
1218
1407
 
1219
- Set `UBERLLM_API_KEY` and use `provider="uberllm"` with a `vendor/model` ID from UberLLM's public model list (`GET https://api.uberllm.dev/v1/models`), for example `deepseek/deepseek-v4.1-flash`, `openai/gpt-5.4-mini` or `anthropic/claude-sonnet-4.6`. Requests go to the OpenAI-compatible base URL `https://api.uberllm.dev/v1`; set `UBERLLM_API_URL` to override it. Usage is prepaid and billed per request (failed requests are not billed); per-model prices are on the [model list](https://uberllm.dev/models) and keys are created at [uberllm.dev/signup](https://uberllm.dev/signup). See the [quickstart](https://uberllm.dev/docs/quickstart).
1408
+ Set `UBERLLM_API_KEY` and use `provider="uberllm"` with a `vendor/model` ID from MartLLM's public model list (`GET https://api.martllm.com/v1/models`), for example `deepseek/deepseek-v4.1-flash`, `openai/gpt-5.4-mini` or `anthropic/claude-sonnet-4.6`. Requests go to the OpenAI-compatible base URL `https://api.martllm.com/v1`; set `UBERLLM_API_URL` to override it. Usage is prepaid and billed per request (failed requests are not billed); per-model prices are on the [model list](https://martllm.com/models) and keys are created at [martllm.com/signup](https://martllm.com/signup). See the [quickstart](https://martllm.com/docs/quickstart).
1220
1409
 
1221
1410
  ```python
1222
1411
  response = get_llm_response("Say hello in one short sentence.", model="deepseek/deepseek-v4.1-flash", provider="uberllm")
@@ -68,6 +68,133 @@ When a traveler sees that soft, phosphorescent light, it isn’t just a pretty s
68
68
  The bird **shows the way to hidden water (and sometimes to buried silver or gold)** in the Atacama Desert.
69
69
  ```
70
70
 
71
+ ### Typed decisions instead of generated text
72
+
73
+ Sometimes you do not want prose back from a model. You want a label, a yes/no
74
+ probability, or a value on a rubric, fast, with a confidence your code can
75
+ threshold on. That is what the npcpy Decision Module is for. It exposes a single
76
+ flat function, get_decision_response, that works with any supported provider
77
+ and returns a typed answer with probabilities.
78
+
79
+ The local Ollama backend needs no API key and no training, so it is the quickest
80
+ way to try this:
81
+
82
+ ```python
83
+ from npcpy.llm_funcs import get_decision_response
84
+
85
+ result = get_decision_response(
86
+ prompt='Customer wrote: I was charged twice for order #4411 and want one refunded today.',
87
+ model='tev1:0.8b',
88
+ provider='ollama',
89
+ question_type='choice',
90
+ instructions='What should happen to this ticket next?',
91
+ criteria={
92
+ 'refund': 'the customer is owed money back',
93
+ 'escalate': 'a human agent needs to take over',
94
+ 'close': 'nothing further is needed',
95
+ },
96
+ )
97
+
98
+ print(result['response']['choice']) # 'refund'
99
+ print(result['response']['confidence']) # 0.82
100
+ print(result['response']['probabilities']) # {'refund': 0.82, 'escalate': 0.14, 'close': 0.04}
101
+ ```
102
+
103
+ `question_type` selects the answer shape: `'choice'` picks one label from
104
+ `criteria`, `'noul'` returns a yes/no probability, and `'score'` returns a
105
+ value on an ordered scale.
106
+
107
+ ```python
108
+ # yes/no: does this message contain a refund request?
109
+ result = get_decision_response(
110
+ prompt='Customer wrote: I was charged twice, please refund the duplicate.',
111
+ model='tev1:0.8b', provider='ollama',
112
+ question_type='noul',
113
+ instructions='Is the customer asking for a refund?',
114
+ )
115
+ print(result['response']['noul']) # 0.99
116
+
117
+ # rubric: how urgent is this?
118
+ result = get_decision_response(
119
+ prompt='Customer wrote: this is the third time I have asked. Fix it now.',
120
+ model='tev1:0.8b', provider='ollama',
121
+ question_type='score',
122
+ instructions='How urgent is this request?',
123
+ criteria=['can wait a week', 'needs attention today', 'breach of SLA'],
124
+ )
125
+ print(result['response']['score']) # 2.1
126
+ ```
127
+
128
+ You can also call the lower-level helpers in npcpy.gen.decision directly:
129
+
130
+ ```python
131
+ from npcpy.gen.decision import decision_choice, decision_noul, decision_score
132
+
133
+ label = decision_choice(
134
+ state='Customer wrote: I was charged twice, please refund the duplicate.',
135
+ instructions='What should happen to this ticket next?',
136
+ criteria={'refund': 'money back', 'escalate': 'needs a human', 'close': 'no action'},
137
+ model='tev1:0.8b', provider='ollama',
138
+ )
139
+
140
+ probability = decision_noul(
141
+ state='Customer wrote: I was charged twice.',
142
+ instructions='Is the customer asking for a refund?',
143
+ model='tev1:0.8b', provider='ollama',
144
+ )
145
+
146
+ score = decision_score(
147
+ state='Customer wrote: this is the third time I have asked.',
148
+ instructions='How urgent is this?',
149
+ criteria=['low', 'medium', 'high'],
150
+ model='tev1:0.8b', provider='ollama',
151
+ )
152
+ ```
153
+
154
+ Hosted decision models take the same model / provider / api_key arguments:
155
+
156
+ ```python
157
+ from npcpy.llm_funcs import get_decision_response
158
+
159
+ result = get_decision_response(
160
+ prompt='Customer wrote: I was charged twice for order #4411.',
161
+ model='gemini-decision-1',
162
+ provider='gemini',
163
+ api_key='...',
164
+ question_type='choice',
165
+ instructions='Which team should handle this?',
166
+ criteria={'billing': 'payments and refunds', 'support': 'product questions'},
167
+ )
168
+ print(result['response']['choice'])
169
+ ```
170
+
171
+ | provider | example model |
172
+ | --- | --- |
173
+ | `openai` | `gpt-6-luna` |
174
+ | `gemini` | `gemini-decision-1` |
175
+ | `perplexity` | `pplx-decider-v1-27b` |
176
+ | `typesafe` | `jev-1.14.0` |
177
+ | `cloudflare` | `clef`, `clef-flash`, `clef-omni` |
178
+ | `openrouter` | `openai/gpt-6-luna-decisions` |
179
+ | `databricks` | `databricks-openjev-qwen35-4b` |
180
+ | `fireworks_ai` | `accounts/fireworks/routers/rune` |
181
+ | `azure_ai` | `<your-deployment>` with base model `Microsoft-Decision-1` |
182
+ | `ollama` | `tev1:0.8b`, `clef-flash` |
183
+
184
+ To point at a self-hosted LiteLLM proxy, pass `api_url`:
185
+
186
+ ```python
187
+ result = get_decision_response(
188
+ prompt='...', model='jev', provider='litellm_proxy',
189
+ api_url='https://litellm.example.com', api_key='sk-...',
190
+ question_type='noul', instructions='Is this a refund request?',
191
+ )
192
+ ```
193
+
194
+ Every provider returns the same shape: `{choice, noul, score, confidence,
195
+ probabilities}`, so downstream code does not branch on provider. See the
196
+ [System One Decisions guide](docs/guides/system-one.md) for the full reference.
197
+
71
198
  ### Agent with tools
72
199
  The `Agent` class in `npcpy` comes with a set of default tools (sh, python, edit_file, web_search, etc.)
73
200
 
@@ -1014,6 +1141,16 @@ model_path = run_sft(X_train, y_train, config=sft_config, format_style="llama")
1014
1141
 
1015
1142
  Works with all major LLM providers through LiteLLM: `airllm`, `anthropic`, `deepseek`, `gemini`, `ollama`, `openai`, `openai-like`, and more.
1016
1143
 
1144
+ <details><summary>AIGROW</summary>
1145
+
1146
+ Set `AIGROW_API_KEY` and use `provider="aigrow"` with a model ID from AIGROW's public model list (`GET https://aigrow.gg/v1/models`, no key needed, per-token prices included), for example `claude-haiku-5.5`, `gpt-6.2-sol` or `gemini-4-neon`. IDs are plain slugs without a vendor prefix. Requests go to the OpenAI-compatible Base URL `https://aigrow.gg/v1`; set `AIGROW_API_URL` to override it. Usage is prepaid; keys are created in the [AIGROW dashboard](https://aigrow.gg/dashboard/api).
1147
+
1148
+ ```python
1149
+ response = get_llm_response("Say hello in one short sentence.", model="claude-haiku-5.5", provider="aigrow")
1150
+ print(response["response"])
1151
+ ```
1152
+
1153
+ </details>
1017
1154
  <details><summary>API Route</summary>
1018
1155
 
1019
1156
  Set `API_ROUTE_API_KEY` and use `provider="api-route"` with an exact model ID from your account's authenticated `GET /v1/models` response, for example `gpt-6.1-sol`. [API Route](https://api-route.com) uses the OpenAI-compatible Base URL `https://global.api-route.com/v1`; set `API_ROUTE_API_URL` to override it. The alias `api_route` is also accepted. Explicit `api_url` and `api_key` arguments take precedence.
@@ -1065,6 +1202,16 @@ response = get_llm_response("Say hello in one short sentence.", model="deepseek-
1065
1202
  print(response["response"])
1066
1203
  ```
1067
1204
 
1205
+ </details>
1206
+ <details><summary>LLMTR</summary>
1207
+
1208
+ Set `LLMTR_API_KEY` and use `provider="llmtr"` with a `vendor/model` ID from LLMTR's public model list (`GET https://llmtr.com/v1/models`), for example `qwen/qwen3.8-flash` (default), `qwen/qwen3.8-max` or `mistral/devstral-medium-latest`. Requests go to the OpenAI-compatible Base URL `https://llmtr.com/v1`; set `LLMTR_API_URL` to override it. Usage is prepaid; keys are created in the [LLMTR dashboard](https://llmtr.com/dashboard/keys).
1209
+
1210
+ ```python
1211
+ response = get_llm_response("Say hello in one short sentence.", model="qwen/qwen3.8-flash", provider="llmtr")
1212
+ print(response["response"])
1213
+ ```
1214
+
1068
1215
  </details>
1069
1216
  <details><summary>MiniMax</summary>
1070
1217
 
@@ -1089,6 +1236,16 @@ response = get_llm_response("Say hello in one short sentence.", model="deepseek/
1089
1236
  print(response["response"])
1090
1237
  ```
1091
1238
 
1239
+ </details>
1240
+ <details><summary>onomeo</summary>
1241
+
1242
+ Set `ONOMEO_API_KEY` and use `provider="onomeo"` with a model ID from onomeo's model list (`GET https://onomeo.com/v1/models` with your key, or the [models page](https://onomeo.com/models)), for example `deepseek-v4.1-flash`, `claude-sonnet-5.5` or `gpt-6.1-sol`. IDs are plain slugs without a vendor prefix. Requests go to the OpenAI-compatible Base URL `https://onomeo.com/v1`; set `ONOMEO_API_URL` to override it. Free models are available within limits; paid models are charged to a prepaid balance. Keys are created in the [onomeo dashboard](https://onomeo.com/dashboard).
1243
+
1244
+ ```python
1245
+ response = get_llm_response("Say hello in one short sentence.", model="deepseek-v4.1-flash", provider="onomeo")
1246
+ print(response["response"])
1247
+ ```
1248
+
1092
1249
  </details>
1093
1250
  <details><summary>Opper</summary>
1094
1251
 
@@ -1099,6 +1256,16 @@ response = get_llm_response("Say hello in one short sentence.", model="claude-so
1099
1256
  print(response["response"])
1100
1257
  ```
1101
1258
 
1259
+ </details>
1260
+ <details><summary>Requesty</summary>
1261
+
1262
+ Set `REQUESTY_API_KEY` and use `provider="requesty"` with a `vendor/model` ID from Requesty's public model list (`GET https://router.requesty.ai/v1/models`), for example `openai/gpt-4o-mini`, `anthropic/claude-sonnet-5` or `google/gemini-2.5-flash`. Requests go to the OpenAI-compatible Base URL `https://router.requesty.ai/v1` and are routed to the first-party providers (OpenAI, Anthropic, Google and others); set `REQUESTY_API_URL` to override it, for example `https://router.eu.requesty.ai/v1` for the EU endpoint. Keys are created in the [Requesty dashboard](https://app.requesty.ai/api-keys).
1263
+
1264
+ ```python
1265
+ response = get_llm_response("Say hello in one short sentence.", model="openai/gpt-4o-mini", provider="requesty")
1266
+ print(response["response"])
1267
+ ```
1268
+
1102
1269
  </details>
1103
1270
  <details><summary>Runcrate</summary>
1104
1271
 
@@ -1110,9 +1277,29 @@ print(response["response"])
1110
1277
  ```
1111
1278
 
1112
1279
  </details>
1113
- <details><summary>UberLLM</summary>
1280
+ <details><summary>TeamoRouter</summary>
1281
+
1282
+ Set `TEAMOROUTER_API_KEY` and use `provider="teamorouter"` with a model ID from TeamoRouter's model list (`GET https://api.teamorouter.com/v1/models` with your key), for example `glm-5.3`, `deepseek-v4-pro`, `kimi-k3.1-pro` or `claude-sonnet-5-5`. Requests go to the OpenAI-compatible Base URL `https://api.teamorouter.com/v1`; set `TEAMOROUTER_API_URL` to override it. Keys are created in the [TeamoRouter dashboard](https://teamorouter.com/dashboard?tab=api-keys).
1283
+
1284
+ ```python
1285
+ response = get_llm_response("Say hello in one short sentence.", model="glm-5.3", provider="teamorouter")
1286
+ print(response["response"])
1287
+ ```
1288
+
1289
+ </details>
1290
+ <details><summary>TrustedRouter</summary>
1291
+
1292
+ Set `TRUSTEDROUTER_API_KEY` and use `provider="trustedrouter"` with any model ID from TrustedRouter's live public catalog (`GET https://api.trustedrouter.com/v1/models`), for example `deepseek/deepseek-v4-flash` (default) or privacy presets such as `trustedrouter/zdr`, `trustedrouter/e2e`, and `trustedrouter/auto` (or `nyte/*` aliases). Requests go through hardware-attested Confidential Space TEEs at `https://api.trustedrouter.com/v1`; set `TRUSTEDROUTER_API_URL` to override it, and pass `extra_body={"min_privacy": 2}` to enforce a minimum privacy floor per request. Keys are created at [trustedrouter.com](https://trustedrouter.com).
1293
+
1294
+ ```python
1295
+ response = get_llm_response("Say hello in one short sentence.", model="trustedrouter/zdr", provider="trustedrouter")
1296
+ print(response["response"])
1297
+ ```
1298
+
1299
+ </details>
1300
+ <details><summary>MartLLM</summary>
1114
1301
 
1115
- Set `UBERLLM_API_KEY` and use `provider="uberllm"` with a `vendor/model` ID from UberLLM's public model list (`GET https://api.uberllm.dev/v1/models`), for example `deepseek/deepseek-v4.1-flash`, `openai/gpt-5.4-mini` or `anthropic/claude-sonnet-4.6`. Requests go to the OpenAI-compatible base URL `https://api.uberllm.dev/v1`; set `UBERLLM_API_URL` to override it. Usage is prepaid and billed per request (failed requests are not billed); per-model prices are on the [model list](https://uberllm.dev/models) and keys are created at [uberllm.dev/signup](https://uberllm.dev/signup). See the [quickstart](https://uberllm.dev/docs/quickstart).
1302
+ Set `UBERLLM_API_KEY` and use `provider="uberllm"` with a `vendor/model` ID from MartLLM's public model list (`GET https://api.martllm.com/v1/models`), for example `deepseek/deepseek-v4.1-flash`, `openai/gpt-5.4-mini` or `anthropic/claude-sonnet-4.6`. Requests go to the OpenAI-compatible base URL `https://api.martllm.com/v1`; set `UBERLLM_API_URL` to override it. Usage is prepaid and billed per request (failed requests are not billed); per-model prices are on the [model list](https://martllm.com/models) and keys are created at [martllm.com/signup](https://martllm.com/signup). See the [quickstart](https://martllm.com/docs/quickstart).
1116
1303
 
1117
1304
  ```python
1118
1305
  response = get_llm_response("Say hello in one short sentence.", model="deepseek/deepseek-v4.1-flash", provider="uberllm")
@@ -41,18 +41,15 @@ from .ft.system1 import (
41
41
  )
42
42
 
43
43
  from .gen.decision import (
44
- DecisionQuestion,
45
- DecisionRouter,
46
- DecisionSystem1,
47
- BatchDecisions,
48
- train_decision_model,
49
- load_decision_model,
50
- load_decision_examples,
44
+ DecisionError,
51
45
  decision_choice,
52
46
  decision_score,
53
47
  decision_noul,
54
48
  decision_predict,
55
49
  decision_route,
50
+ train_decision_model,
51
+ load_decision_model,
52
+ load_decision_examples,
56
53
  )
57
54
 
58
55
  from .gen.systemone import (
@@ -63,10 +63,8 @@ def _load_compiled_yaml(path: str) -> Dict[str, Any]:
63
63
 
64
64
  def _parse_frontmatter(text: str) -> Tuple[Dict[str, Any], str]:
65
65
  """Split `---\n...\n---\nbody` into (frontmatter_dict, body_str)."""
66
- if not text.startswith('---'):
67
- return {}, text
68
- parts = text.split('---', 2)
69
- if len(parts) < 3:
66
+ parts = re.split(r'^---[ \t]*\r?$', text, maxsplit=2, flags=re.MULTILINE)
67
+ if len(parts) < 3 or parts[0]:
70
68
  return {}, text
71
69
  try:
72
70
  fm = yaml.safe_load(parts[1]) or {}
@@ -129,10 +129,16 @@ def compress_image(image_bytes, max_size=(800, 600)):
129
129
  img.load()
130
130
 
131
131
 
132
- if img.mode == "RGBA":
132
+ has_alpha = img.mode in ("RGBA", "LA", "PA") or (
133
+ img.mode == "P" and "transparency" in img.info
134
+ )
135
+ if has_alpha:
136
+ img = img.convert("RGBA")
133
137
  background = Image.new("RGB", img.size, (255, 255, 255))
134
138
  background.paste(img, mask=img.split()[3])
135
139
  img = background
140
+ elif img.mode not in ("RGB", "L", "CMYK"):
141
+ img = img.convert("RGB")
136
142
 
137
143
 
138
144
  if img.size[0] > max_size[0] or img.size[1] > max_size[1]:
@@ -269,11 +269,11 @@ def load_file_contents(file_path, chunk_size=None):
269
269
  elif file_ext in ['XLS', 'XLSX']:
270
270
  df = load_excel(file_path)
271
271
  full_content = df.to_string()
272
- elif file_ext in ['TXT', 'MD', 'PY', 'JSX', 'TSX', 'TS', 'JS', 'JSON', 'SQL', 'NPC', 'JINX', 'LINE', 'YAML', 'DART', 'JAVA']:
273
- full_content = load_txt(file_path)
274
272
  elif file_ext == 'JSON':
275
273
  data = load_json(file_path)
276
274
  full_content = json.dumps(data, indent=2)
275
+ elif file_ext in ['TXT', 'MD', 'PY', 'JSX', 'TSX', 'TS', 'JS', 'SQL', 'NPC', 'JINX', 'LINE', 'YAML', 'DART', 'JAVA']:
276
+ full_content = load_txt(file_path)
277
277
  elif file_ext in ['MP3', 'WAV', 'M4A', 'AAC', 'FLAC', 'OGG']:
278
278
  full_content = load_audio(file_path)
279
279
  elif file_ext in ['MP4', 'AVI', 'MOV', 'WMV', 'MPG', 'MPEG', 'WEBM', 'MKV']:
@@ -158,6 +158,42 @@ def search_serply(query: str, num_results: int = 5, api_key: str = None):
158
158
  print(f"Serply search failed: {e}")
159
159
  return []
160
160
 
161
+ def search_searchapi(query: str, num_results: int = 5, api_key: str = None):
162
+ """Search Google results using the SearchApi API (https://www.searchapi.io/docs/google)."""
163
+ if api_key is None:
164
+ api_key = os.environ.get('SEARCHAPI_API_KEY')
165
+ if not api_key:
166
+ print("SearchApi API key not set")
167
+ return []
168
+
169
+ try:
170
+ # Google ignores a per-request result count, so one page (~10 rows) is
171
+ # requested and trimmed client-side. The key travels only in the header.
172
+ response = requests.get(
173
+ 'https://www.searchapi.io/api/v1/search',
174
+ params={'engine': 'google', 'q': query},
175
+ headers={'Authorization': f'Bearer {api_key}', 'Accept': 'application/json', 'User-Agent': 'npcpy'},
176
+ timeout=30
177
+ )
178
+ if response.status_code == 200:
179
+ data = response.json()
180
+ results = []
181
+ for r in data.get('organic_results', [])[:num_results]:
182
+ results.append({
183
+ 'title': r.get('title', ''),
184
+ 'link': r.get('link', ''),
185
+ 'content': r.get('snippet', '')
186
+ })
187
+ return results
188
+ try:
189
+ error = response.json().get('error') or response.text[:200]
190
+ except Exception:
191
+ error = response.text[:200]
192
+ print(f"SearchApi search failed ({response.status_code}): {error}")
193
+ except Exception as e:
194
+ print(f"SearchApi search failed: {e}")
195
+ return []
196
+
161
197
  def search_keenable(query: str, num_results: int = 5, api_key: str = None):
162
198
  """Search using the Keenable API. Works without a key; KEENABLE_API_KEY lifts rate limits."""
163
199
  if api_key is None:
@@ -366,6 +402,9 @@ def search_web(
366
402
  elif provider == 'serply':
367
403
  results = search_serply(query, num_results=num_results, api_key=api_key)
368
404
 
405
+ elif provider == 'searchapi':
406
+ results = search_searchapi(query, num_results=num_results, api_key=api_key)
407
+
369
408
  elif provider == 'keenable':
370
409
  results = search_keenable(query, num_results=num_results, api_key=api_key)
371
410