npcpy 1.0.26__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.
- npcpy/__init__.py +0 -7
- npcpy/data/audio.py +16 -99
- npcpy/data/image.py +43 -42
- npcpy/data/load.py +83 -124
- npcpy/data/text.py +28 -28
- npcpy/data/video.py +8 -32
- npcpy/data/web.py +51 -23
- npcpy/ft/diff.py +110 -0
- npcpy/ft/ge.py +115 -0
- npcpy/ft/memory_trainer.py +171 -0
- npcpy/ft/model_ensembler.py +357 -0
- npcpy/ft/rl.py +360 -0
- npcpy/ft/sft.py +248 -0
- npcpy/ft/usft.py +128 -0
- npcpy/gen/audio_gen.py +24 -0
- npcpy/gen/embeddings.py +13 -13
- npcpy/gen/image_gen.py +262 -117
- npcpy/gen/response.py +615 -415
- npcpy/gen/video_gen.py +53 -7
- npcpy/llm_funcs.py +1869 -437
- npcpy/main.py +1 -1
- npcpy/memory/command_history.py +844 -510
- npcpy/memory/kg_vis.py +833 -0
- npcpy/memory/knowledge_graph.py +892 -1845
- npcpy/memory/memory_processor.py +81 -0
- npcpy/memory/search.py +188 -90
- npcpy/mix/debate.py +192 -3
- npcpy/npc_compiler.py +1672 -801
- npcpy/npc_sysenv.py +593 -1266
- npcpy/serve.py +3120 -0
- npcpy/sql/ai_function_tools.py +257 -0
- npcpy/sql/database_ai_adapters.py +186 -0
- npcpy/sql/database_ai_functions.py +163 -0
- npcpy/sql/model_runner.py +19 -19
- npcpy/sql/npcsql.py +706 -507
- npcpy/sql/sql_model_compiler.py +156 -0
- npcpy/tools.py +183 -0
- npcpy/work/plan.py +13 -279
- npcpy/work/trigger.py +3 -3
- npcpy-1.2.32.dist-info/METADATA +803 -0
- npcpy-1.2.32.dist-info/RECORD +54 -0
- npcpy/data/dataframes.py +0 -171
- npcpy/memory/deep_research.py +0 -125
- npcpy/memory/sleep.py +0 -557
- npcpy/modes/_state.py +0 -78
- npcpy/modes/alicanto.py +0 -1075
- npcpy/modes/guac.py +0 -785
- npcpy/modes/mcp_npcsh.py +0 -822
- npcpy/modes/npc.py +0 -213
- npcpy/modes/npcsh.py +0 -1158
- npcpy/modes/plonk.py +0 -409
- npcpy/modes/pti.py +0 -234
- npcpy/modes/serve.py +0 -1637
- npcpy/modes/spool.py +0 -312
- npcpy/modes/wander.py +0 -549
- npcpy/modes/yap.py +0 -572
- npcpy/npc_team/alicanto.npc +0 -2
- npcpy/npc_team/alicanto.png +0 -0
- npcpy/npc_team/assembly_lines/test_pipeline.py +0 -181
- npcpy/npc_team/corca.npc +0 -13
- npcpy/npc_team/foreman.npc +0 -7
- npcpy/npc_team/frederic.npc +0 -6
- npcpy/npc_team/frederic4.png +0 -0
- npcpy/npc_team/guac.png +0 -0
- npcpy/npc_team/jinxs/automator.jinx +0 -18
- npcpy/npc_team/jinxs/bash_executer.jinx +0 -31
- npcpy/npc_team/jinxs/calculator.jinx +0 -11
- npcpy/npc_team/jinxs/edit_file.jinx +0 -96
- npcpy/npc_team/jinxs/file_chat.jinx +0 -14
- npcpy/npc_team/jinxs/gui_controller.jinx +0 -28
- npcpy/npc_team/jinxs/image_generation.jinx +0 -29
- npcpy/npc_team/jinxs/internet_search.jinx +0 -30
- npcpy/npc_team/jinxs/local_search.jinx +0 -152
- npcpy/npc_team/jinxs/npcsh_executor.jinx +0 -31
- npcpy/npc_team/jinxs/python_executor.jinx +0 -8
- npcpy/npc_team/jinxs/screen_cap.jinx +0 -25
- npcpy/npc_team/jinxs/sql_executor.jinx +0 -33
- npcpy/npc_team/kadiefa.npc +0 -3
- npcpy/npc_team/kadiefa.png +0 -0
- npcpy/npc_team/npcsh.ctx +0 -9
- npcpy/npc_team/npcsh_sibiji.png +0 -0
- npcpy/npc_team/plonk.npc +0 -2
- npcpy/npc_team/plonk.png +0 -0
- npcpy/npc_team/plonkjr.npc +0 -2
- npcpy/npc_team/plonkjr.png +0 -0
- npcpy/npc_team/sibiji.npc +0 -5
- npcpy/npc_team/sibiji.png +0 -0
- npcpy/npc_team/spool.png +0 -0
- npcpy/npc_team/templates/analytics/celona.npc +0 -0
- npcpy/npc_team/templates/hr_support/raone.npc +0 -0
- npcpy/npc_team/templates/humanities/eriane.npc +0 -4
- npcpy/npc_team/templates/it_support/lineru.npc +0 -0
- npcpy/npc_team/templates/marketing/slean.npc +0 -4
- npcpy/npc_team/templates/philosophy/maurawa.npc +0 -0
- npcpy/npc_team/templates/sales/turnic.npc +0 -4
- npcpy/npc_team/templates/software/welxor.npc +0 -0
- npcpy/npc_team/yap.png +0 -0
- npcpy/routes.py +0 -958
- npcpy/work/mcp_helpers.py +0 -357
- npcpy/work/mcp_server.py +0 -194
- npcpy-1.0.26.data/data/npcpy/npc_team/alicanto.npc +0 -2
- npcpy-1.0.26.data/data/npcpy/npc_team/alicanto.png +0 -0
- npcpy-1.0.26.data/data/npcpy/npc_team/automator.jinx +0 -18
- npcpy-1.0.26.data/data/npcpy/npc_team/bash_executer.jinx +0 -31
- npcpy-1.0.26.data/data/npcpy/npc_team/calculator.jinx +0 -11
- npcpy-1.0.26.data/data/npcpy/npc_team/celona.npc +0 -0
- npcpy-1.0.26.data/data/npcpy/npc_team/corca.npc +0 -13
- npcpy-1.0.26.data/data/npcpy/npc_team/edit_file.jinx +0 -96
- npcpy-1.0.26.data/data/npcpy/npc_team/eriane.npc +0 -4
- npcpy-1.0.26.data/data/npcpy/npc_team/file_chat.jinx +0 -14
- npcpy-1.0.26.data/data/npcpy/npc_team/foreman.npc +0 -7
- npcpy-1.0.26.data/data/npcpy/npc_team/frederic.npc +0 -6
- npcpy-1.0.26.data/data/npcpy/npc_team/frederic4.png +0 -0
- npcpy-1.0.26.data/data/npcpy/npc_team/guac.png +0 -0
- npcpy-1.0.26.data/data/npcpy/npc_team/gui_controller.jinx +0 -28
- npcpy-1.0.26.data/data/npcpy/npc_team/image_generation.jinx +0 -29
- npcpy-1.0.26.data/data/npcpy/npc_team/internet_search.jinx +0 -30
- npcpy-1.0.26.data/data/npcpy/npc_team/kadiefa.npc +0 -3
- npcpy-1.0.26.data/data/npcpy/npc_team/kadiefa.png +0 -0
- npcpy-1.0.26.data/data/npcpy/npc_team/lineru.npc +0 -0
- npcpy-1.0.26.data/data/npcpy/npc_team/local_search.jinx +0 -152
- npcpy-1.0.26.data/data/npcpy/npc_team/maurawa.npc +0 -0
- npcpy-1.0.26.data/data/npcpy/npc_team/npcsh.ctx +0 -9
- npcpy-1.0.26.data/data/npcpy/npc_team/npcsh_executor.jinx +0 -31
- npcpy-1.0.26.data/data/npcpy/npc_team/npcsh_sibiji.png +0 -0
- npcpy-1.0.26.data/data/npcpy/npc_team/plonk.npc +0 -2
- npcpy-1.0.26.data/data/npcpy/npc_team/plonk.png +0 -0
- npcpy-1.0.26.data/data/npcpy/npc_team/plonkjr.npc +0 -2
- npcpy-1.0.26.data/data/npcpy/npc_team/plonkjr.png +0 -0
- npcpy-1.0.26.data/data/npcpy/npc_team/python_executor.jinx +0 -8
- npcpy-1.0.26.data/data/npcpy/npc_team/raone.npc +0 -0
- npcpy-1.0.26.data/data/npcpy/npc_team/screen_cap.jinx +0 -25
- npcpy-1.0.26.data/data/npcpy/npc_team/sibiji.npc +0 -5
- npcpy-1.0.26.data/data/npcpy/npc_team/sibiji.png +0 -0
- npcpy-1.0.26.data/data/npcpy/npc_team/slean.npc +0 -4
- npcpy-1.0.26.data/data/npcpy/npc_team/spool.png +0 -0
- npcpy-1.0.26.data/data/npcpy/npc_team/sql_executor.jinx +0 -33
- npcpy-1.0.26.data/data/npcpy/npc_team/test_pipeline.py +0 -181
- npcpy-1.0.26.data/data/npcpy/npc_team/turnic.npc +0 -4
- npcpy-1.0.26.data/data/npcpy/npc_team/welxor.npc +0 -0
- npcpy-1.0.26.data/data/npcpy/npc_team/yap.png +0 -0
- npcpy-1.0.26.dist-info/METADATA +0 -827
- npcpy-1.0.26.dist-info/RECORD +0 -139
- npcpy-1.0.26.dist-info/entry_points.txt +0 -11
- /npcpy/{modes → ft}/__init__.py +0 -0
- {npcpy-1.0.26.dist-info → npcpy-1.2.32.dist-info}/WHEEL +0 -0
- {npcpy-1.0.26.dist-info → npcpy-1.2.32.dist-info}/licenses/LICENSE +0 -0
- {npcpy-1.0.26.dist-info → npcpy-1.2.32.dist-info}/top_level.txt +0 -0
npcpy/ft/usft.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
from dataclasses import dataclass, field
|
|
2
|
+
try:
|
|
3
|
+
from datasets import Dataset, load_dataset
|
|
4
|
+
import torch
|
|
5
|
+
from transformers import (
|
|
6
|
+
AutoModelForCausalLM,
|
|
7
|
+
AutoTokenizer,
|
|
8
|
+
TrainingArguments
|
|
9
|
+
)
|
|
10
|
+
from trl import SFTTrainer
|
|
11
|
+
from peft import LoraConfig
|
|
12
|
+
except:
|
|
13
|
+
Dataset = None
|
|
14
|
+
load_dataset = None
|
|
15
|
+
torch = None
|
|
16
|
+
AutoModelForCausalLM = None
|
|
17
|
+
AutoTokenizer = None
|
|
18
|
+
TrainingArguments = None
|
|
19
|
+
SFTTrainer = None
|
|
20
|
+
|
|
21
|
+
from typing import List, Optional
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass
|
|
25
|
+
class USFTConfig:
|
|
26
|
+
base_model_name: str = "Qwen/Qwen3-0.6B"
|
|
27
|
+
output_model_path: str = "models/usft_model"
|
|
28
|
+
lora_r: int = 8
|
|
29
|
+
lora_alpha: int = 16
|
|
30
|
+
lora_dropout: float = 0.15
|
|
31
|
+
lora_target_modules: List[str] = field(
|
|
32
|
+
default_factory=lambda: ["q_proj", "v_proj"]
|
|
33
|
+
)
|
|
34
|
+
num_train_epochs: int = 3
|
|
35
|
+
per_device_train_batch_size: int = 4
|
|
36
|
+
gradient_accumulation_steps: int = 4
|
|
37
|
+
learning_rate: float = 2e-5
|
|
38
|
+
logging_steps: int = 10
|
|
39
|
+
optim: str = "adamw_torch"
|
|
40
|
+
lr_scheduler_type: str = "cosine"
|
|
41
|
+
weight_decay: float = 0.01
|
|
42
|
+
max_length: int = 512
|
|
43
|
+
save_steps: int = 100
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def run_usft(
|
|
47
|
+
texts: List[str],
|
|
48
|
+
config: Optional[USFTConfig] = None
|
|
49
|
+
) -> str:
|
|
50
|
+
|
|
51
|
+
if config is None:
|
|
52
|
+
config = USFTConfig()
|
|
53
|
+
|
|
54
|
+
dataset = Dataset.from_dict({"text": texts})
|
|
55
|
+
|
|
56
|
+
model = AutoModelForCausalLM.from_pretrained(
|
|
57
|
+
config.base_model_name,
|
|
58
|
+
trust_remote_code=True,
|
|
59
|
+
attn_implementation="eager"
|
|
60
|
+
)
|
|
61
|
+
model.config.use_cache = False
|
|
62
|
+
|
|
63
|
+
tokenizer = AutoTokenizer.from_pretrained(
|
|
64
|
+
config.base_model_name,
|
|
65
|
+
trust_remote_code=True
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
if tokenizer.pad_token is None:
|
|
69
|
+
tokenizer.pad_token = tokenizer.eos_token
|
|
70
|
+
|
|
71
|
+
tokenizer.padding_side = "right"
|
|
72
|
+
|
|
73
|
+
peft_config = LoraConfig(
|
|
74
|
+
r=config.lora_r,
|
|
75
|
+
lora_alpha=config.lora_alpha,
|
|
76
|
+
lora_dropout=config.lora_dropout,
|
|
77
|
+
target_modules=config.lora_target_modules,
|
|
78
|
+
bias="none",
|
|
79
|
+
task_type="CAUSAL_LM"
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
training_args = TrainingArguments(
|
|
83
|
+
output_dir=config.output_model_path,
|
|
84
|
+
num_train_epochs=config.num_train_epochs,
|
|
85
|
+
per_device_train_batch_size=(
|
|
86
|
+
config.per_device_train_batch_size
|
|
87
|
+
),
|
|
88
|
+
gradient_accumulation_steps=(
|
|
89
|
+
config.gradient_accumulation_steps
|
|
90
|
+
),
|
|
91
|
+
optim=config.optim,
|
|
92
|
+
logging_steps=config.logging_steps,
|
|
93
|
+
learning_rate=config.learning_rate,
|
|
94
|
+
fp16=False,
|
|
95
|
+
bf16=torch.cuda.is_available(),
|
|
96
|
+
lr_scheduler_type=config.lr_scheduler_type,
|
|
97
|
+
save_steps=config.save_steps,
|
|
98
|
+
weight_decay=config.weight_decay,
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
trainer = SFTTrainer(
|
|
102
|
+
model=model,
|
|
103
|
+
train_dataset=dataset,
|
|
104
|
+
peft_config=peft_config,
|
|
105
|
+
args=training_args,
|
|
106
|
+
max_seq_length=config.max_length,
|
|
107
|
+
dataset_text_field="text"
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
print(f"Starting USFT on {len(dataset)} texts")
|
|
111
|
+
trainer.train()
|
|
112
|
+
|
|
113
|
+
trainer.save_model(config.output_model_path)
|
|
114
|
+
print(f"Model saved to {config.output_model_path}")
|
|
115
|
+
|
|
116
|
+
return config.output_model_path
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def load_corpus_from_hf(dataset_name: str, split: str = "train"):
|
|
120
|
+
|
|
121
|
+
ds = load_dataset(dataset_name, split=split)
|
|
122
|
+
|
|
123
|
+
if "text" in ds.column_names:
|
|
124
|
+
return ds["text"]
|
|
125
|
+
elif "content" in ds.column_names:
|
|
126
|
+
return ds["content"]
|
|
127
|
+
else:
|
|
128
|
+
return [str(item) for item in ds]
|
npcpy/gen/audio_gen.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import os
|
|
2
|
+
def tts_elevenlabs(text,
|
|
3
|
+
api_key=None,
|
|
4
|
+
voice_id='JBFqnCBsd6RMkjVDRZzb',
|
|
5
|
+
model_id='eleven_multilingual_v2',
|
|
6
|
+
output_format= 'mp3_44100_128'):
|
|
7
|
+
if api_key is None:
|
|
8
|
+
api_key = os.environ.get('ELEVENLABS_API_KEY')
|
|
9
|
+
from elevenlabs.client import ElevenLabs
|
|
10
|
+
from elevenlabs import play
|
|
11
|
+
|
|
12
|
+
client = ElevenLabs(
|
|
13
|
+
api_key=api_key,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
audio = client.text_to_speech.convert(
|
|
17
|
+
text=text,
|
|
18
|
+
voice_id=voice_id,
|
|
19
|
+
model_id=model_id,
|
|
20
|
+
output_format= output_format
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
play(audio)
|
|
24
|
+
return audio
|
npcpy/gen/embeddings.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
7
|
from typing import List, Dict, Optional
|
|
8
8
|
import numpy as np
|
|
9
9
|
from datetime import datetime
|
|
@@ -49,17 +49,17 @@ def store_embeddings_for_model(
|
|
|
49
49
|
collection_name = f"{provider}_{model}_embeddings"
|
|
50
50
|
collection = chroma_client.get_collection(collection_name)
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
|
|
53
53
|
if metadata is None:
|
|
54
|
-
metadata = [{"text_length": len(text)} for text in texts]
|
|
54
|
+
metadata = [{"text_length": len(text)} for text in texts]
|
|
55
55
|
print(
|
|
56
56
|
"metadata is none, creating metadata for each document as the length of the text"
|
|
57
57
|
)
|
|
58
|
-
|
|
58
|
+
|
|
59
59
|
collection.add(
|
|
60
60
|
ids=[str(i) for i in range(len(texts))],
|
|
61
61
|
embeddings=embeddings,
|
|
62
|
-
metadatas=metadata,
|
|
62
|
+
metadatas=metadata,
|
|
63
63
|
documents=texts,
|
|
64
64
|
)
|
|
65
65
|
|
|
@@ -67,7 +67,7 @@ def store_embeddings_for_model(
|
|
|
67
67
|
def delete_embeddings_from_collection(collection, ids):
|
|
68
68
|
"""Delete embeddings by id from Chroma collection."""
|
|
69
69
|
if ids:
|
|
70
|
-
collection.delete(ids=ids)
|
|
70
|
+
collection.delete(ids=ids)
|
|
71
71
|
|
|
72
72
|
|
|
73
73
|
def get_embeddings(
|
|
@@ -83,6 +83,6 @@ def get_embeddings(
|
|
|
83
83
|
else:
|
|
84
84
|
raise ValueError(f"Unsupported provider: {provider}")
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
|
|
87
|
+
|
|
88
88
|
return embeddings
|