npcpy 2.1.26__tar.gz → 2.1.28__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.
- {npcpy-2.1.26/npcpy.egg-info → npcpy-2.1.28}/PKG-INFO +66 -50
- {npcpy-2.1.26 → npcpy-2.1.28}/README.md +65 -49
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/__init__.py +0 -1
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/data/text.py +1 -1
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/data/web.py +64 -5
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/ft/system1.py +49 -13
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/gen/embeddings.py +1 -1
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/gen/response.py +170 -10
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/llm_funcs.py +9 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/ml_funcs.py +74 -38
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/npc_compiler.py +6 -6
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/serve.py +62 -137
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/streaming.py +2 -2
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/tools.py +7 -2
- {npcpy-2.1.26 → npcpy-2.1.28/npcpy.egg-info}/PKG-INFO +66 -50
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy.egg-info/SOURCES.txt +8 -11
- npcpy-2.1.28/npcpy.egg-info/entry_points.txt +6 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/setup.py +1 -9
- npcpy-2.1.28/tests/test_litellm_generation_params.py +34 -0
- npcpy-2.1.28/tests/test_litellm_tool_turn_usage.py +66 -0
- npcpy-2.1.28/tests/test_litellm_top_k.py +33 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_llm_funcs.py +163 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_npc_compiler.py +100 -0
- npcpy-2.1.28/tests/test_ollama_stream_tool_double_call.py +80 -0
- npcpy-2.1.28/tests/test_ollama_tool_turn_usage.py +55 -0
- npcpy-2.1.28/tests/test_provider_usage_cost.py +123 -0
- npcpy-2.1.28/tests/test_stream_temperature_zero.py +28 -0
- npcpy-2.1.28/tests/test_stream_usage_cost.py +30 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_tools.py +48 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_web.py +103 -0
- npcpy-2.1.26/npcpy/sql/ai_function_tools.py +0 -253
- npcpy-2.1.26/npcpy/sql/database_ai_adapters.py +0 -177
- npcpy-2.1.26/npcpy/sql/database_ai_functions.py +0 -147
- npcpy-2.1.26/npcpy/sql/npcsql.py +0 -1157
- npcpy-2.1.26/npcpy/sql/sql_model_compiler.py +0 -141
- npcpy-2.1.26/npcpy/work/__init__.py +0 -0
- npcpy-2.1.26/npcpy.egg-info/entry_points.txt +0 -14
- npcpy-2.1.26/tests/test_model_runner.py +0 -329
- npcpy-2.1.26/tests/test_npcsql.py +0 -75
- npcpy-2.1.26/tests/test_sql_adapters.py +0 -171
- npcpy-2.1.26/tests/test_sql_compiler.py +0 -287
- npcpy-2.1.26/tests/test_sql_functions.py +0 -221
- {npcpy-2.1.26 → npcpy-2.1.28}/LICENSE +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/MANIFEST.in +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/convert.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/data/__init__.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/data/audio.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/data/data_models.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/data/image.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/data/load.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/data/video.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/db.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/ft/__init__.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/ft/diff.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/ft/embeddings.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/ft/engine.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/ft/export.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/ft/ge.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/ft/memory_trainer.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/ft/model_ensembler.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/ft/neat.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/ft/rl.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/ft/sft.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/ft/usft.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/gen/__init__.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/gen/audio_gen.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/gen/cli_agent.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/gen/decision.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/gen/image_gen.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/gen/mlx_musicgen/__init__.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/gen/mlx_musicgen/encodec.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/gen/mlx_musicgen/musicgen.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/gen/mlx_musicgen/t5.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/gen/mlx_musicgen/utils.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/gen/ocr.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/gen/systemone.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/gen/video_gen.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/gen/world_gen.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/init.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/launcher.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/main.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/mcp_server.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/memory/__init__.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/memory/kg_population.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/memory/knowledge_graph.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/memory/knowledge_index.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/memory/knowledge_store.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/memory/memory_processor.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/memory/search.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/mix/__init__.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/mix/debate.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/npc2mcp.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/npc_array.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/npc_sysenv.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/plugin_setup.py +0 -0
- {npcpy-2.1.26/npcpy/sql → npcpy-2.1.28/npcpy/work}/__init__.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/work/browser.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/work/desktop.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/work/plan.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy/work/trigger.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy.egg-info/dependency_links.txt +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy.egg-info/requires.txt +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/npcpy.egg-info/top_level.txt +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/setup.cfg +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_airllm.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_api_route.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_audio.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_audio_gen_defaults.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_browser.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_data_models.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_diff.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_doc_examples.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_documentation_examples.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_ft_embeddings.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_ft_system1.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_gen_decision.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_gen_decision_systemone.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_gen_systemone.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_genetic_evolver.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_image.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_image_gen_defaults.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_load.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_mcp_and_skills.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_memory_processor.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_minimax_text.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_minimax_video_gen.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_ml_funcs.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_neat.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_npc_array.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_npc_sysenv.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_ollama_num_predict.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_readme_examples.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_response.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_serve.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_serve_systemone.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_stream_tool_call_deltas.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_text.py +0 -0
- {npcpy-2.1.26 → npcpy-2.1.28}/tests/test_video.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: npcpy
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.28
|
|
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
|
|
@@ -115,7 +115,7 @@ Dynamic: summary
|
|
|
115
115
|
<a href="https://npcpy.readthedocs.io/"><img src="https://img.shields.io/badge/docs-readthedocs-brightgreen.svg" alt="Docs"></a>
|
|
116
116
|
</p>
|
|
117
117
|
|
|
118
|
-
`npcpy` is a library that provides key primitives for research and development with multimodal language models, agentic AI, and knowledge graphs. Its flexible framework makes it easy to engineer powerful AI applications with support for local (`
|
|
118
|
+
`npcpy` is a library that provides key primitives for research and development with multimodal language models, agentic AI, and knowledge graphs. Its flexible framework makes it easy to engineer powerful AI applications with support for local (`llama.cpp`, `LM Studio`, `ollama`, `omlx`) and cloud providers. Build multi-agent teams and simplify context engineering through the NPC Context-Agent-Tool data layer which ensures compliance through software rather than prompts.
|
|
119
119
|
```bash
|
|
120
120
|
pip install npcpy
|
|
121
121
|
```
|
|
@@ -818,25 +818,6 @@ jinxes:
|
|
|
818
818
|
|
|
819
819
|
</details>
|
|
820
820
|
|
|
821
|
-
### CLI tools
|
|
822
|
-
|
|
823
|
-
```bash
|
|
824
|
-
# The NPC shell — the recommended way to use NPC teams
|
|
825
|
-
npcsh # Interactive shell with agents, tools, and jinxes
|
|
826
|
-
|
|
827
|
-
# Scaffold a new team
|
|
828
|
-
npc-init
|
|
829
|
-
|
|
830
|
-
# Launch AI coding tools as an NPC from your team
|
|
831
|
-
npc-claude --npc corca # Claude Code
|
|
832
|
-
npc-codex --npc analyst # Codex
|
|
833
|
-
npc-gemini # Gemini CLI (interactive picker)
|
|
834
|
-
npc-opencode / npc-aider / npc-amp
|
|
835
|
-
|
|
836
|
-
# Register MCP server + hooks for deeper integration
|
|
837
|
-
npc-plugin claude
|
|
838
|
-
```
|
|
839
|
-
|
|
840
821
|
### NPCArray — parallel jinx across multiple NPCs
|
|
841
822
|
|
|
842
823
|
Run any jinx in parallel across a list of NPC instances and collect results as an array:
|
|
@@ -1135,22 +1116,21 @@ model_path = run_sft(X_train, y_train, config=sft_config, format_style="llama")
|
|
|
1135
1116
|
|
|
1136
1117
|
## Providers
|
|
1137
1118
|
|
|
1138
|
-
Works with all major LLM providers through LiteLLM: `
|
|
1119
|
+
Works with all major LLM providers through LiteLLM: `airllm`, `anthropic`, `deepseek`, `gemini`, `ollama`, `openai`, `openai-like`, and more.
|
|
1139
1120
|
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
Set `MINIMAX_API_KEY` and use `provider="minimax"`. When no model is configured, `MiniMax-M3.1-Flash` is the default; the model list offers it first, followed by `MiniMax-M3`. Explicit saved or custom model IDs remain supported, including legacy IDs. The optional `MINIMAX_API_URL` setting selects the region and compatible protocol; it defaults to the global OpenAI-compatible Base URL.
|
|
1121
|
+
<details><summary>API Route</summary>
|
|
1143
1122
|
|
|
1144
|
-
|
|
1145
|
-
| --- | --- | --- |
|
|
1146
|
-
| Global | `https://api.minimax.io/v1` | `https://api.minimax.io/anthropic` |
|
|
1147
|
-
| China | `https://api.minimaxi.com/v1` | `https://api.minimaxi.com/anthropic` |
|
|
1123
|
+
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.
|
|
1148
1124
|
|
|
1149
|
-
|
|
1125
|
+
```python
|
|
1126
|
+
from npcpy import get_llm_response
|
|
1150
1127
|
|
|
1151
|
-
|
|
1128
|
+
response = get_llm_response("Say hello in one short sentence.", model="gpt-6.1-sol", provider="api-route")
|
|
1129
|
+
print(response["response"])
|
|
1130
|
+
```
|
|
1152
1131
|
|
|
1153
|
-
|
|
1132
|
+
</details>
|
|
1133
|
+
<details><summary>Atlas Cloud</summary>
|
|
1154
1134
|
|
|
1155
1135
|
Set `ATLASCLOUD_API_KEY` and use `provider="atlascloud"` with any model ID from the [Atlas Cloud model list](https://www.atlascloud.ai/models), for example `deepseek-ai/deepseek-v4-flash`, `zai-org/glm-5.2` or `moonshotai/kimi-k3`. Requests go to the OpenAI-compatible Base URL `https://api.atlascloud.ai/v1`; set `ATLASCLOUD_API_URL` to override it.
|
|
1156
1136
|
|
|
@@ -1159,18 +1139,18 @@ response = get_llm_response("Say hello in one short sentence.", model="deepseek-
|
|
|
1159
1139
|
print(response["response"])
|
|
1160
1140
|
```
|
|
1161
1141
|
|
|
1162
|
-
|
|
1142
|
+
</details>
|
|
1143
|
+
<details><summary>cheapaimodel</summary>
|
|
1163
1144
|
|
|
1164
|
-
Set `
|
|
1145
|
+
Set `CHEAPAIMODEL_API_KEY` and use `provider="cheapaimodel"` with a model ID from the [model list](https://cheapaimodel.ai/models), for example `deepseek-v4-1-flash`, `glm-5.3`, `kimi-k3` or `grok-4.7`. Requests go to the OpenAI-compatible base URL `https://api.cheapaimodel.ai/v1`; set `CHEAPAIMODEL_API_URL` to override it. Usage is billed per token from a prepaid USD balance; create a key in the [console](https://console.cheapaimodel.ai/keys). See the [docs](https://cheapaimodel.ai/docs) or [cheapaimodel.ai](https://cheapaimodel.ai/?utm_source=npcpy).
|
|
1165
1146
|
|
|
1166
1147
|
```python
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
response = get_llm_response("Say hello in one short sentence.", model="gpt-6.1-sol", provider="api-route")
|
|
1148
|
+
response = get_llm_response("Say hello in one short sentence.", model="deepseek-v4-1-flash", provider="cheapaimodel")
|
|
1170
1149
|
print(response["response"])
|
|
1171
1150
|
```
|
|
1172
1151
|
|
|
1173
|
-
|
|
1152
|
+
</details>
|
|
1153
|
+
<details><summary>Cheaper Inference</summary>
|
|
1174
1154
|
|
|
1175
1155
|
Set `CHEAPER_INFERENCE_API_KEY` and use `provider="cheaperinference"` with any model ID from the [Cheaper Inference model list](https://cheaperinference.com/markets), for example `gpt-5.4-mini`, `claude-sonnet-5` or `glm-5.3`. Requests go to the OpenAI-compatible Base URL `https://api.cheaperinference.com/v1`; set `CHEAPER_INFERENCE_API_URL` to override it.
|
|
1176
1156
|
|
|
@@ -1179,7 +1159,42 @@ response = get_llm_response("Say hello in one short sentence.", model="gpt-5.4-m
|
|
|
1179
1159
|
print(response["response"])
|
|
1180
1160
|
```
|
|
1181
1161
|
|
|
1182
|
-
|
|
1162
|
+
</details>
|
|
1163
|
+
<details><summary>CloudGPU</summary>
|
|
1164
|
+
|
|
1165
|
+
Set `CLOUDGPU_API_KEY` and use `provider="cloudgpu"` with a model ID from CloudGPU's model list (`GET https://cloudgpu.app/v1/models`), for example `deepseek-v4.1-flash`, `kimi-k2.7-code` or `glm-5.3-flash`. Requests go to the OpenAI-compatible base URL `https://cloudgpu.app/v1`; set `CLOUDGPU_API_URL` to override it. Keys are created in the CloudGPU console; see the [API docs](https://cloudgpu.app/api/docs?utm_source=github&utm_medium=referral&utm_campaign=202611_seg06_indiedev&utm_content=github_npcpy_provider).
|
|
1166
|
+
|
|
1167
|
+
```python
|
|
1168
|
+
response = get_llm_response("Say hello in one short sentence.", model="deepseek-v4.1-flash", provider="cloudgpu")
|
|
1169
|
+
print(response["response"])
|
|
1170
|
+
```
|
|
1171
|
+
|
|
1172
|
+
</details>
|
|
1173
|
+
<details><summary>MiniMax</summary>
|
|
1174
|
+
|
|
1175
|
+
Set `MINIMAX_API_KEY` and use `provider="minimax"`. When no model is configured, `MiniMax-M3.1-Flash` is the default; the model list offers it first, followed by `MiniMax-M3`. Explicit saved or custom model IDs remain supported, including legacy IDs. The optional `MINIMAX_API_URL` setting selects the region and compatible protocol; it defaults to the global OpenAI-compatible Base URL.
|
|
1176
|
+
|
|
1177
|
+
| Region | OpenAI-compatible Base URL | Anthropic-compatible Base URL |
|
|
1178
|
+
| --- | --- | --- |
|
|
1179
|
+
| Global | `https://api.minimax.io/v1` | `https://api.minimax.io/anthropic` |
|
|
1180
|
+
| China | `https://api.minimaxi.com/v1` | `https://api.minimaxi.com/anthropic` |
|
|
1181
|
+
|
|
1182
|
+
Use the Anthropic-compatible Base URL exactly as shown. The client appends `/v1/messages` when sending a request.
|
|
1183
|
+
|
|
1184
|
+
For Flash, use adaptive thinking (`thinking={"type": "adaptive"}`) and an optional `reasoning_effort` of `low`, `medium`, `high`, `xhigh`, or `max`; Anthropic-compatible requests send this as `output_config.effort`. Flash does not support disabled thinking. M3 retains its existing thinking modes. OpenRouter lists `minimax/minimax-m3.1-flash:free` first and `minimax/minimax-m3` second, using their full gateway IDs.
|
|
1185
|
+
|
|
1186
|
+
</details>
|
|
1187
|
+
<details><summary>Obscurify.ai</summary>
|
|
1188
|
+
|
|
1189
|
+
Set `OBSCURIFY_API_KEY` and use `provider="obscurify"` with a model ID from the public model list (`GET https://obscurify.ai/v1/models`, no key needed), for example `deepseek/deepseek-v4-flash`, `moonshotai/kimi-k2-0905` or `z-ai/glm-5.3`. Requests go to the OpenAI-compatible base URL `https://obscurify.ai/v1`; set `OBSCURIFY_API_URL` to override it. Accounts are a random account number with no email; the key is under "Show API Key" on the [account page](https://obscurify.ai/account). See the [API docs](https://obscurify.ai/api-docs) or [obscurify.ai](https://obscurify.ai/?utm_source=npcpy).
|
|
1190
|
+
|
|
1191
|
+
```python
|
|
1192
|
+
response = get_llm_response("Say hello in one short sentence.", model="deepseek/deepseek-v4-flash", provider="obscurify")
|
|
1193
|
+
print(response["response"])
|
|
1194
|
+
```
|
|
1195
|
+
|
|
1196
|
+
</details>
|
|
1197
|
+
<details><summary>Opper</summary>
|
|
1183
1198
|
|
|
1184
1199
|
Set `OPPER_API_KEY` and use `provider="opper"` with any model ID from the [Opper model catalogue](https://opper.ai/models), for example `claude-sonnet-4-6`, `gpt-5.4-mini` or `gemini-3.8-flash`. These pool names route across the providers serving that model; a `provider/model` ID such as `anthropic/claude-sonnet-4-6` pins one route. Requests go to the OpenAI-compatible Base URL `https://api.opper.ai/v3/compat`; set `OPPER_API_URL` to override it. Keys are created at [platform.opper.ai](https://platform.opper.ai).
|
|
1185
1200
|
|
|
@@ -1188,7 +1203,8 @@ response = get_llm_response("Say hello in one short sentence.", model="claude-so
|
|
|
1188
1203
|
print(response["response"])
|
|
1189
1204
|
```
|
|
1190
1205
|
|
|
1191
|
-
|
|
1206
|
+
</details>
|
|
1207
|
+
<details><summary>Runcrate</summary>
|
|
1192
1208
|
|
|
1193
1209
|
Set `RUNCRATE_API_KEY` and use `provider="runcrate"` with any `vendor/model` ID from Runcrate's public model list (`GET https://api.runcrate.ai/v1/models`), for example `deepseek-ai/DeepSeek-V4.1-Flash` or `openai/gpt-oss-120b`. Requests go to the OpenAI-compatible Base URL `https://api.runcrate.ai/v1`; set `RUNCRATE_API_URL` to override it. Open models are free with your GitHub account; keys are created in the [Runcrate dashboard](https://www.runcrate.ai/dashboard/api-keys?utm_source=npcpy&utm_medium=directory&utm_campaign=gpu_pricing).
|
|
1194
1210
|
|
|
@@ -1197,25 +1213,25 @@ response = get_llm_response("Say hello in one short sentence.", model="deepseek-
|
|
|
1197
1213
|
print(response["response"])
|
|
1198
1214
|
```
|
|
1199
1215
|
|
|
1200
|
-
|
|
1216
|
+
</details>
|
|
1217
|
+
<details><summary>UberLLM</summary>
|
|
1201
1218
|
|
|
1202
|
-
Set `
|
|
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).
|
|
1203
1220
|
|
|
1204
1221
|
```python
|
|
1205
|
-
response = get_llm_response("Say hello in one short sentence.", model="deepseek-v4.1-flash", provider="
|
|
1206
|
-
|
|
1207
|
-
```
|
|
1208
|
-
|
|
1209
|
-
### Obscurify.ai
|
|
1222
|
+
response = get_llm_response("Say hello in one short sentence.", model="deepseek/deepseek-v4.1-flash", provider="uberllm")
|
|
1223
|
+
<details><summary>Standard Compute</summary>
|
|
1210
1224
|
|
|
1211
|
-
Set `
|
|
1225
|
+
Set `STANDARDCOMPUTE_API_KEY` and use `provider="standardcompute"`. The model `StandardCompute` is routed: each request goes to the cheapest enabled model that can handle it, with automatic fallback. To pin a model, use any ID from the public model list (`GET https://api.stdcmpt.com/v1/models`), for example `deepseek/deepseek-v4.1-flash` or `z-ai/glm-5.3`. Requests go to the OpenAI-compatible Base URL `https://api.stdcmpt.com/v1`; set `STANDARDCOMPUTE_API_URL` to override it. Keys are created at [standardcompute.com](https://standardcompute.com/?utm_source=npcpy).
|
|
1212
1226
|
|
|
1213
1227
|
```python
|
|
1214
|
-
response = get_llm_response("Say hello in one short sentence.", model="
|
|
1228
|
+
response = get_llm_response("Say hello in one short sentence.", model="StandardCompute", provider="standardcompute")
|
|
1215
1229
|
print(response["response"])
|
|
1216
1230
|
```
|
|
1217
1231
|
|
|
1218
|
-
|
|
1232
|
+
</details>
|
|
1233
|
+
|
|
1234
|
+
## QLLM-PAM (local, attention-free)
|
|
1219
1235
|
|
|
1220
1236
|
`npcpy` can run the QLLM-PAM family of local checkpoints directly. QLLM-PAM is a complex-valued, attention-free language model based on Phase-Associative Memory (PAM); see the [Hugging Face model repo](https://huggingface.co/gowravvishwakarma/qllm-pam-v11-e3k3-chat) and the paper on arXiv ([2604.05030](https://arxiv.org/abs/2604.05030)).
|
|
1221
1237
|
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
<a href="https://npcpy.readthedocs.io/"><img src="https://img.shields.io/badge/docs-readthedocs-brightgreen.svg" alt="Docs"></a>
|
|
12
12
|
</p>
|
|
13
13
|
|
|
14
|
-
`npcpy` is a library that provides key primitives for research and development with multimodal language models, agentic AI, and knowledge graphs. Its flexible framework makes it easy to engineer powerful AI applications with support for local (`
|
|
14
|
+
`npcpy` is a library that provides key primitives for research and development with multimodal language models, agentic AI, and knowledge graphs. Its flexible framework makes it easy to engineer powerful AI applications with support for local (`llama.cpp`, `LM Studio`, `ollama`, `omlx`) and cloud providers. Build multi-agent teams and simplify context engineering through the NPC Context-Agent-Tool data layer which ensures compliance through software rather than prompts.
|
|
15
15
|
```bash
|
|
16
16
|
pip install npcpy
|
|
17
17
|
```
|
|
@@ -714,25 +714,6 @@ jinxes:
|
|
|
714
714
|
|
|
715
715
|
</details>
|
|
716
716
|
|
|
717
|
-
### CLI tools
|
|
718
|
-
|
|
719
|
-
```bash
|
|
720
|
-
# The NPC shell — the recommended way to use NPC teams
|
|
721
|
-
npcsh # Interactive shell with agents, tools, and jinxes
|
|
722
|
-
|
|
723
|
-
# Scaffold a new team
|
|
724
|
-
npc-init
|
|
725
|
-
|
|
726
|
-
# Launch AI coding tools as an NPC from your team
|
|
727
|
-
npc-claude --npc corca # Claude Code
|
|
728
|
-
npc-codex --npc analyst # Codex
|
|
729
|
-
npc-gemini # Gemini CLI (interactive picker)
|
|
730
|
-
npc-opencode / npc-aider / npc-amp
|
|
731
|
-
|
|
732
|
-
# Register MCP server + hooks for deeper integration
|
|
733
|
-
npc-plugin claude
|
|
734
|
-
```
|
|
735
|
-
|
|
736
717
|
### NPCArray — parallel jinx across multiple NPCs
|
|
737
718
|
|
|
738
719
|
Run any jinx in parallel across a list of NPC instances and collect results as an array:
|
|
@@ -1031,22 +1012,21 @@ model_path = run_sft(X_train, y_train, config=sft_config, format_style="llama")
|
|
|
1031
1012
|
|
|
1032
1013
|
## Providers
|
|
1033
1014
|
|
|
1034
|
-
Works with all major LLM providers through LiteLLM: `
|
|
1015
|
+
Works with all major LLM providers through LiteLLM: `airllm`, `anthropic`, `deepseek`, `gemini`, `ollama`, `openai`, `openai-like`, and more.
|
|
1035
1016
|
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
Set `MINIMAX_API_KEY` and use `provider="minimax"`. When no model is configured, `MiniMax-M3.1-Flash` is the default; the model list offers it first, followed by `MiniMax-M3`. Explicit saved or custom model IDs remain supported, including legacy IDs. The optional `MINIMAX_API_URL` setting selects the region and compatible protocol; it defaults to the global OpenAI-compatible Base URL.
|
|
1017
|
+
<details><summary>API Route</summary>
|
|
1039
1018
|
|
|
1040
|
-
|
|
1041
|
-
| --- | --- | --- |
|
|
1042
|
-
| Global | `https://api.minimax.io/v1` | `https://api.minimax.io/anthropic` |
|
|
1043
|
-
| China | `https://api.minimaxi.com/v1` | `https://api.minimaxi.com/anthropic` |
|
|
1019
|
+
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.
|
|
1044
1020
|
|
|
1045
|
-
|
|
1021
|
+
```python
|
|
1022
|
+
from npcpy import get_llm_response
|
|
1046
1023
|
|
|
1047
|
-
|
|
1024
|
+
response = get_llm_response("Say hello in one short sentence.", model="gpt-6.1-sol", provider="api-route")
|
|
1025
|
+
print(response["response"])
|
|
1026
|
+
```
|
|
1048
1027
|
|
|
1049
|
-
|
|
1028
|
+
</details>
|
|
1029
|
+
<details><summary>Atlas Cloud</summary>
|
|
1050
1030
|
|
|
1051
1031
|
Set `ATLASCLOUD_API_KEY` and use `provider="atlascloud"` with any model ID from the [Atlas Cloud model list](https://www.atlascloud.ai/models), for example `deepseek-ai/deepseek-v4-flash`, `zai-org/glm-5.2` or `moonshotai/kimi-k3`. Requests go to the OpenAI-compatible Base URL `https://api.atlascloud.ai/v1`; set `ATLASCLOUD_API_URL` to override it.
|
|
1052
1032
|
|
|
@@ -1055,18 +1035,18 @@ response = get_llm_response("Say hello in one short sentence.", model="deepseek-
|
|
|
1055
1035
|
print(response["response"])
|
|
1056
1036
|
```
|
|
1057
1037
|
|
|
1058
|
-
|
|
1038
|
+
</details>
|
|
1039
|
+
<details><summary>cheapaimodel</summary>
|
|
1059
1040
|
|
|
1060
|
-
Set `
|
|
1041
|
+
Set `CHEAPAIMODEL_API_KEY` and use `provider="cheapaimodel"` with a model ID from the [model list](https://cheapaimodel.ai/models), for example `deepseek-v4-1-flash`, `glm-5.3`, `kimi-k3` or `grok-4.7`. Requests go to the OpenAI-compatible base URL `https://api.cheapaimodel.ai/v1`; set `CHEAPAIMODEL_API_URL` to override it. Usage is billed per token from a prepaid USD balance; create a key in the [console](https://console.cheapaimodel.ai/keys). See the [docs](https://cheapaimodel.ai/docs) or [cheapaimodel.ai](https://cheapaimodel.ai/?utm_source=npcpy).
|
|
1061
1042
|
|
|
1062
1043
|
```python
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
response = get_llm_response("Say hello in one short sentence.", model="gpt-6.1-sol", provider="api-route")
|
|
1044
|
+
response = get_llm_response("Say hello in one short sentence.", model="deepseek-v4-1-flash", provider="cheapaimodel")
|
|
1066
1045
|
print(response["response"])
|
|
1067
1046
|
```
|
|
1068
1047
|
|
|
1069
|
-
|
|
1048
|
+
</details>
|
|
1049
|
+
<details><summary>Cheaper Inference</summary>
|
|
1070
1050
|
|
|
1071
1051
|
Set `CHEAPER_INFERENCE_API_KEY` and use `provider="cheaperinference"` with any model ID from the [Cheaper Inference model list](https://cheaperinference.com/markets), for example `gpt-5.4-mini`, `claude-sonnet-5` or `glm-5.3`. Requests go to the OpenAI-compatible Base URL `https://api.cheaperinference.com/v1`; set `CHEAPER_INFERENCE_API_URL` to override it.
|
|
1072
1052
|
|
|
@@ -1075,7 +1055,42 @@ response = get_llm_response("Say hello in one short sentence.", model="gpt-5.4-m
|
|
|
1075
1055
|
print(response["response"])
|
|
1076
1056
|
```
|
|
1077
1057
|
|
|
1078
|
-
|
|
1058
|
+
</details>
|
|
1059
|
+
<details><summary>CloudGPU</summary>
|
|
1060
|
+
|
|
1061
|
+
Set `CLOUDGPU_API_KEY` and use `provider="cloudgpu"` with a model ID from CloudGPU's model list (`GET https://cloudgpu.app/v1/models`), for example `deepseek-v4.1-flash`, `kimi-k2.7-code` or `glm-5.3-flash`. Requests go to the OpenAI-compatible base URL `https://cloudgpu.app/v1`; set `CLOUDGPU_API_URL` to override it. Keys are created in the CloudGPU console; see the [API docs](https://cloudgpu.app/api/docs?utm_source=github&utm_medium=referral&utm_campaign=202611_seg06_indiedev&utm_content=github_npcpy_provider).
|
|
1062
|
+
|
|
1063
|
+
```python
|
|
1064
|
+
response = get_llm_response("Say hello in one short sentence.", model="deepseek-v4.1-flash", provider="cloudgpu")
|
|
1065
|
+
print(response["response"])
|
|
1066
|
+
```
|
|
1067
|
+
|
|
1068
|
+
</details>
|
|
1069
|
+
<details><summary>MiniMax</summary>
|
|
1070
|
+
|
|
1071
|
+
Set `MINIMAX_API_KEY` and use `provider="minimax"`. When no model is configured, `MiniMax-M3.1-Flash` is the default; the model list offers it first, followed by `MiniMax-M3`. Explicit saved or custom model IDs remain supported, including legacy IDs. The optional `MINIMAX_API_URL` setting selects the region and compatible protocol; it defaults to the global OpenAI-compatible Base URL.
|
|
1072
|
+
|
|
1073
|
+
| Region | OpenAI-compatible Base URL | Anthropic-compatible Base URL |
|
|
1074
|
+
| --- | --- | --- |
|
|
1075
|
+
| Global | `https://api.minimax.io/v1` | `https://api.minimax.io/anthropic` |
|
|
1076
|
+
| China | `https://api.minimaxi.com/v1` | `https://api.minimaxi.com/anthropic` |
|
|
1077
|
+
|
|
1078
|
+
Use the Anthropic-compatible Base URL exactly as shown. The client appends `/v1/messages` when sending a request.
|
|
1079
|
+
|
|
1080
|
+
For Flash, use adaptive thinking (`thinking={"type": "adaptive"}`) and an optional `reasoning_effort` of `low`, `medium`, `high`, `xhigh`, or `max`; Anthropic-compatible requests send this as `output_config.effort`. Flash does not support disabled thinking. M3 retains its existing thinking modes. OpenRouter lists `minimax/minimax-m3.1-flash:free` first and `minimax/minimax-m3` second, using their full gateway IDs.
|
|
1081
|
+
|
|
1082
|
+
</details>
|
|
1083
|
+
<details><summary>Obscurify.ai</summary>
|
|
1084
|
+
|
|
1085
|
+
Set `OBSCURIFY_API_KEY` and use `provider="obscurify"` with a model ID from the public model list (`GET https://obscurify.ai/v1/models`, no key needed), for example `deepseek/deepseek-v4-flash`, `moonshotai/kimi-k2-0905` or `z-ai/glm-5.3`. Requests go to the OpenAI-compatible base URL `https://obscurify.ai/v1`; set `OBSCURIFY_API_URL` to override it. Accounts are a random account number with no email; the key is under "Show API Key" on the [account page](https://obscurify.ai/account). See the [API docs](https://obscurify.ai/api-docs) or [obscurify.ai](https://obscurify.ai/?utm_source=npcpy).
|
|
1086
|
+
|
|
1087
|
+
```python
|
|
1088
|
+
response = get_llm_response("Say hello in one short sentence.", model="deepseek/deepseek-v4-flash", provider="obscurify")
|
|
1089
|
+
print(response["response"])
|
|
1090
|
+
```
|
|
1091
|
+
|
|
1092
|
+
</details>
|
|
1093
|
+
<details><summary>Opper</summary>
|
|
1079
1094
|
|
|
1080
1095
|
Set `OPPER_API_KEY` and use `provider="opper"` with any model ID from the [Opper model catalogue](https://opper.ai/models), for example `claude-sonnet-4-6`, `gpt-5.4-mini` or `gemini-3.8-flash`. These pool names route across the providers serving that model; a `provider/model` ID such as `anthropic/claude-sonnet-4-6` pins one route. Requests go to the OpenAI-compatible Base URL `https://api.opper.ai/v3/compat`; set `OPPER_API_URL` to override it. Keys are created at [platform.opper.ai](https://platform.opper.ai).
|
|
1081
1096
|
|
|
@@ -1084,7 +1099,8 @@ response = get_llm_response("Say hello in one short sentence.", model="claude-so
|
|
|
1084
1099
|
print(response["response"])
|
|
1085
1100
|
```
|
|
1086
1101
|
|
|
1087
|
-
|
|
1102
|
+
</details>
|
|
1103
|
+
<details><summary>Runcrate</summary>
|
|
1088
1104
|
|
|
1089
1105
|
Set `RUNCRATE_API_KEY` and use `provider="runcrate"` with any `vendor/model` ID from Runcrate's public model list (`GET https://api.runcrate.ai/v1/models`), for example `deepseek-ai/DeepSeek-V4.1-Flash` or `openai/gpt-oss-120b`. Requests go to the OpenAI-compatible Base URL `https://api.runcrate.ai/v1`; set `RUNCRATE_API_URL` to override it. Open models are free with your GitHub account; keys are created in the [Runcrate dashboard](https://www.runcrate.ai/dashboard/api-keys?utm_source=npcpy&utm_medium=directory&utm_campaign=gpu_pricing).
|
|
1090
1106
|
|
|
@@ -1093,25 +1109,25 @@ response = get_llm_response("Say hello in one short sentence.", model="deepseek-
|
|
|
1093
1109
|
print(response["response"])
|
|
1094
1110
|
```
|
|
1095
1111
|
|
|
1096
|
-
|
|
1112
|
+
</details>
|
|
1113
|
+
<details><summary>UberLLM</summary>
|
|
1097
1114
|
|
|
1098
|
-
Set `
|
|
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).
|
|
1099
1116
|
|
|
1100
1117
|
```python
|
|
1101
|
-
response = get_llm_response("Say hello in one short sentence.", model="deepseek-v4.1-flash", provider="
|
|
1102
|
-
|
|
1103
|
-
```
|
|
1104
|
-
|
|
1105
|
-
### Obscurify.ai
|
|
1118
|
+
response = get_llm_response("Say hello in one short sentence.", model="deepseek/deepseek-v4.1-flash", provider="uberllm")
|
|
1119
|
+
<details><summary>Standard Compute</summary>
|
|
1106
1120
|
|
|
1107
|
-
Set `
|
|
1121
|
+
Set `STANDARDCOMPUTE_API_KEY` and use `provider="standardcompute"`. The model `StandardCompute` is routed: each request goes to the cheapest enabled model that can handle it, with automatic fallback. To pin a model, use any ID from the public model list (`GET https://api.stdcmpt.com/v1/models`), for example `deepseek/deepseek-v4.1-flash` or `z-ai/glm-5.3`. Requests go to the OpenAI-compatible Base URL `https://api.stdcmpt.com/v1`; set `STANDARDCOMPUTE_API_URL` to override it. Keys are created at [standardcompute.com](https://standardcompute.com/?utm_source=npcpy).
|
|
1108
1122
|
|
|
1109
1123
|
```python
|
|
1110
|
-
response = get_llm_response("Say hello in one short sentence.", model="
|
|
1124
|
+
response = get_llm_response("Say hello in one short sentence.", model="StandardCompute", provider="standardcompute")
|
|
1111
1125
|
print(response["response"])
|
|
1112
1126
|
```
|
|
1113
1127
|
|
|
1114
|
-
|
|
1128
|
+
</details>
|
|
1129
|
+
|
|
1130
|
+
## QLLM-PAM (local, attention-free)
|
|
1115
1131
|
|
|
1116
1132
|
`npcpy` can run the QLLM-PAM family of local checkpoints directly. QLLM-PAM is a complex-valued, attention-free language model based on Phase-Associative Memory (PAM); see the [Hugging Face model repo](https://huggingface.co/gowravvishwakarma/qllm-pam-v11-e3k3-chat) and the paper on arXiv ([2604.05030](https://arxiv.org/abs/2604.05030)).
|
|
1117
1133
|
|
|
@@ -14,11 +14,6 @@ from typing import List, Dict, Any, Optional, Union
|
|
|
14
14
|
import numpy as np
|
|
15
15
|
import json
|
|
16
16
|
|
|
17
|
-
try:
|
|
18
|
-
from sentence_transformers import util, SentenceTransformer
|
|
19
|
-
except Exception:
|
|
20
|
-
pass
|
|
21
|
-
|
|
22
17
|
def search_exa(query:str,
|
|
23
18
|
api_key:str = None,
|
|
24
19
|
top_k = 5,
|
|
@@ -199,6 +194,64 @@ def search_keenable(query: str, num_results: int = 5, api_key: str = None):
|
|
|
199
194
|
print(f"Keenable search failed: {e}")
|
|
200
195
|
return []
|
|
201
196
|
|
|
197
|
+
def search_firecrawl(query: str, num_results: int = 5, api_key: str = None):
|
|
198
|
+
"""Search the web using the Firecrawl Search API."""
|
|
199
|
+
if api_key is None:
|
|
200
|
+
api_key = os.environ.get('FIRECRAWL_API_KEY')
|
|
201
|
+
if not api_key:
|
|
202
|
+
print("Firecrawl API key not set")
|
|
203
|
+
return []
|
|
204
|
+
|
|
205
|
+
try:
|
|
206
|
+
response = requests.post(
|
|
207
|
+
'https://api.firecrawl.dev/v2/search',
|
|
208
|
+
json={'query': query, 'limit': num_results, 'sources': ['web'], 'integration': '_npcpy'},
|
|
209
|
+
headers={'Authorization': f'Bearer {api_key}', 'Content-Type': 'application/json', 'User-Agent': 'npcpy'},
|
|
210
|
+
timeout=30
|
|
211
|
+
)
|
|
212
|
+
if response.status_code == 200:
|
|
213
|
+
data = response.json()
|
|
214
|
+
results = []
|
|
215
|
+
for r in (data.get('data') or {}).get('web', [])[:num_results]:
|
|
216
|
+
results.append({
|
|
217
|
+
'title': r.get('title', ''),
|
|
218
|
+
'link': r.get('url', ''),
|
|
219
|
+
'content': r.get('description', '')
|
|
220
|
+
})
|
|
221
|
+
return results
|
|
222
|
+
except Exception as e:
|
|
223
|
+
print(f"Firecrawl search failed: {e}")
|
|
224
|
+
return []
|
|
225
|
+
|
|
226
|
+
def search_sofya(query: str, num_results: int = 5, api_key: str = None):
|
|
227
|
+
"""Search the web using the Sofya Search API."""
|
|
228
|
+
if api_key is None:
|
|
229
|
+
api_key = os.environ.get('SOFYA_API_KEY')
|
|
230
|
+
if not api_key:
|
|
231
|
+
print("Sofya API key not set")
|
|
232
|
+
return []
|
|
233
|
+
|
|
234
|
+
try:
|
|
235
|
+
response = requests.post(
|
|
236
|
+
'https://sofya.co/v1/search',
|
|
237
|
+
json={'query': query, 'max_results': max(1, min(num_results, 20)), 'search_depth': 'snippets'},
|
|
238
|
+
headers={'Authorization': f'Bearer {api_key}', 'Content-Type': 'application/json', 'User-Agent': 'npcpy'},
|
|
239
|
+
timeout=30
|
|
240
|
+
)
|
|
241
|
+
if response.status_code == 200:
|
|
242
|
+
data = response.json()
|
|
243
|
+
results = []
|
|
244
|
+
for r in data.get('results', [])[:num_results]:
|
|
245
|
+
results.append({
|
|
246
|
+
'title': r.get('title', ''),
|
|
247
|
+
'link': r.get('url', ''),
|
|
248
|
+
'content': r.get('content', '')
|
|
249
|
+
})
|
|
250
|
+
return results
|
|
251
|
+
except Exception as e:
|
|
252
|
+
print(f"Sofya search failed: {e}")
|
|
253
|
+
return []
|
|
254
|
+
|
|
202
255
|
def search_perplexity(
|
|
203
256
|
query: str,
|
|
204
257
|
api_key: str = None,
|
|
@@ -316,6 +369,12 @@ def search_web(
|
|
|
316
369
|
elif provider == 'keenable':
|
|
317
370
|
results = search_keenable(query, num_results=num_results, api_key=api_key)
|
|
318
371
|
|
|
372
|
+
elif provider == 'firecrawl':
|
|
373
|
+
results = search_firecrawl(query, num_results=num_results, api_key=api_key)
|
|
374
|
+
|
|
375
|
+
elif provider == 'sofya':
|
|
376
|
+
results = search_sofya(query, num_results=num_results, api_key=api_key)
|
|
377
|
+
|
|
319
378
|
elif provider == 'google':
|
|
320
379
|
if _google_search is None:
|
|
321
380
|
print("googlesearch-python not installed, falling back to duckduckgo")
|
|
@@ -9,19 +9,46 @@ import numpy as np
|
|
|
9
9
|
|
|
10
10
|
logger = logging.getLogger("npcpy.ft.system1")
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
from sklearn.base import BaseEstimator
|
|
15
|
-
_sklearn_available = True
|
|
16
|
-
except Exception:
|
|
17
|
-
BaseEstimator = None
|
|
12
|
+
class _LazyAvailability:
|
|
13
|
+
"""Boolean-ish availability flag that imports the dependency on first use."""
|
|
18
14
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
def __init__(self, flag_name, fn):
|
|
16
|
+
self._flag_name = flag_name
|
|
17
|
+
self._fn = fn
|
|
18
|
+
self._cached = None
|
|
19
|
+
|
|
20
|
+
def __bool__(self):
|
|
21
|
+
if self._cached is None:
|
|
22
|
+
self._cached = bool(self._fn())
|
|
23
|
+
return self._cached
|
|
24
|
+
|
|
25
|
+
def __repr__(self):
|
|
26
|
+
return f"<{self._flag_name}: lazy>"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _sklearn_available_fn():
|
|
30
|
+
try:
|
|
31
|
+
import sklearn.base # noqa: F401
|
|
32
|
+
return True
|
|
33
|
+
except Exception:
|
|
34
|
+
return False
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _sentence_transformers_available_fn():
|
|
38
|
+
try:
|
|
39
|
+
import sentence_transformers # noqa: F401
|
|
40
|
+
return True
|
|
41
|
+
except Exception:
|
|
42
|
+
return False
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
# Resolved lazily so importing this module does not pull in scikit-learn /
|
|
46
|
+
# sentence-transformers / torch. A cold `import npcpy.serve` spent ~12s here
|
|
47
|
+
# before Flask could bind its port.
|
|
48
|
+
_sklearn_available = _LazyAvailability("_sklearn_available", _sklearn_available_fn)
|
|
49
|
+
_sentence_transformers_available = _LazyAvailability(
|
|
50
|
+
"_sentence_transformers_available", _sentence_transformers_available_fn
|
|
51
|
+
)
|
|
25
52
|
|
|
26
53
|
_pydantic_available = False
|
|
27
54
|
try:
|
|
@@ -180,7 +207,14 @@ class System1Predictor:
|
|
|
180
207
|
encoder = self.encoders.get(resolved)
|
|
181
208
|
if encoder is None:
|
|
182
209
|
raise ValueError(f"No trained model for question '{question_name}'")
|
|
183
|
-
|
|
210
|
+
try:
|
|
211
|
+
from sentence_transformers import SentenceTransformer
|
|
212
|
+
except Exception:
|
|
213
|
+
# sentence-transformers is optional, and encoders passed to a
|
|
214
|
+
# System1Predictor directly may be plain callables.
|
|
215
|
+
SentenceTransformer = None
|
|
216
|
+
|
|
217
|
+
if SentenceTransformer is not None and isinstance(encoder, SentenceTransformer):
|
|
184
218
|
embeddings = encoder.encode(texts, device=self.config.device, convert_to_numpy=True, show_progress_bar=False)
|
|
185
219
|
return np.asarray(embeddings)
|
|
186
220
|
return np.asarray(encoder(texts))
|
|
@@ -267,6 +301,8 @@ class System1Predictor:
|
|
|
267
301
|
def _get_sentence_transformer_encoder(model_name: str, device: str):
|
|
268
302
|
if not _sentence_transformers_available:
|
|
269
303
|
raise ImportError("sentence-transformers is required for System 1 training. Install with: pip install sentence-transformers")
|
|
304
|
+
from sentence_transformers import SentenceTransformer
|
|
305
|
+
|
|
270
306
|
return SentenceTransformer(model_name, device=device)
|
|
271
307
|
|
|
272
308
|
|