lollms-client 1.7.10__py3-none-any.whl → 1.7.13__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.
@@ -7,7 +7,7 @@ from lollms_client.lollms_types import MSG_TYPE
7
7
  # from lollms_client.lollms_utilities import encode_image
8
8
  from lollms_client.lollms_types import ELF_COMPLETION_FORMAT
9
9
  from lollms_client.lollms_discussion import LollmsDiscussion
10
- from typing import Optional, Callable, List, Union, Dict
10
+ from typing import Optional, Callable, List, Union, Dict, Any
11
11
 
12
12
  from ascii_colors import ASCIIColors, trace_exception
13
13
  import pipmaster as pm
@@ -718,6 +718,44 @@ class OllamaBinding(LollmsLLMBinding):
718
718
  trace_exception(ex)
719
719
  return {"status": False, "message": msg}
720
720
 
721
+ def get_zoo(self) -> List[Dict[str, Any]]:
722
+ """
723
+ Returns a list of models available for download.
724
+ each entry is a dict with:
725
+ name, description, size, type, link
726
+ """
727
+ return [
728
+ {"name": "Llama3 8B", "description": "Meta's Llama 3 8B model. Good for general purpose chat.", "size": "4.7GB", "type": "model", "link": "llama3"},
729
+ {"name": "Llama3 70B", "description": "Meta's Llama 3 70B model. High capability.", "size": "40GB", "type": "model", "link": "llama3:70b"},
730
+ {"name": "Phi-3 Mini", "description": "Microsoft's Phi-3 Mini 3.8B model. Lightweight and capable.", "size": "2.3GB", "type": "model", "link": "phi3"},
731
+ {"name": "Phi-3 Medium", "description": "Microsoft's Phi-3 Medium 14B model.", "size": "7.9GB", "type": "model", "link": "phi3:medium"},
732
+ {"name": "Mistral 7B", "description": "Mistral AI's 7B model v0.3.", "size": "4.1GB", "type": "model", "link": "mistral"},
733
+ {"name": "Mixtral 8x7B", "description": "Mistral AI's Mixture of Experts model.", "size": "26GB", "type": "model", "link": "mixtral"},
734
+ {"name": "Gemma 2 9B", "description": "Google's Gemma 2 9B model.", "size": "5.4GB", "type": "model", "link": "gemma2"},
735
+ {"name": "Gemma 2 27B", "description": "Google's Gemma 2 27B model.", "size": "16GB", "type": "model", "link": "gemma2:27b"},
736
+ {"name": "Qwen 2.5 7B", "description": "Alibaba Cloud's Qwen2.5 7B model.", "size": "4.5GB", "type": "model", "link": "qwen2.5"},
737
+ {"name": "Qwen 2.5 Coder 7B", "description": "Alibaba Cloud's Qwen2.5 Coder 7B model.", "size": "4.5GB", "type": "model", "link": "qwen2.5-coder"},
738
+ {"name": "CodeLlama 7B", "description": "Meta's CodeLlama 7B model.", "size": "3.8GB", "type": "model", "link": "codellama"},
739
+ {"name": "LLaVA 7B", "description": "Visual instruction tuning model (Vision).", "size": "4.5GB", "type": "model", "link": "llava"},
740
+ {"name": "Nomic Embed Text", "description": "A high-performing open embedding model.", "size": "274MB", "type": "embedding", "link": "nomic-embed-text"},
741
+ {"name": "DeepSeek Coder V2", "description": "DeepSeek Coder V2 model.", "size": "8.9GB", "type": "model", "link": "deepseek-coder-v2"},
742
+ {"name": "OpenHermes 2.5 Mistral", "description": "High quality finetune of Mistral 7B.", "size": "4.1GB", "type": "model", "link": "openhermes"},
743
+ {"name": "Dolphin Phi", "description": "Uncensored Dolphin fine-tune of Phi-2.", "size": "1.6GB", "type": "model", "link": "dolphin-phi"},
744
+ {"name": "TinyLlama", "description": "A compact 1.1B model.", "size": "637MB", "type": "model", "link": "tinyllama"},
745
+ ]
746
+
747
+ def download_from_zoo(self, index: int, progress_callback: Callable[[dict], None] = None) -> dict:
748
+ """
749
+ Downloads a model from the zoo using its index.
750
+ """
751
+ zoo = self.get_zoo()
752
+ if index < 0 or index >= len(zoo):
753
+ msg = "Index out of bounds"
754
+ ASCIIColors.error(msg)
755
+ return {"status": False, "message": msg}
756
+ item = zoo[index]
757
+ return self.pull_model(item["link"], progress_callback=progress_callback)
758
+
721
759
  def install_ollama(self, callback: Callable[[dict], None] = None, **kwargs) -> dict:
722
760
  """
723
761
  Installs Ollama based on the operating system.
@@ -1157,4 +1195,4 @@ if __name__ == '__main__':
1157
1195
  ASCIIColors.error(f"An error occurred during testing: {e}")
1158
1196
  trace_exception(e)
1159
1197
 
1160
- ASCIIColors.yellow("\nOllamaBinding test finished.")
1198
+ ASCIIColors.yellow("\nOllamaBinding test finished.")
@@ -34,8 +34,7 @@ if False:
34
34
 
35
35
  from lollms_client.lollms_utilities import build_image_dicts, robust_json_parser
36
36
  from ascii_colors import ASCIIColors, trace_exception
37
- # Assuming lollms_types is a local module providing MSG_TYPE enum/constants
38
- # from .lollms_types import MSG_TYPE
37
+ from lollms_client.lollms_types import MSG_TYPE
39
38
 
40
39
  class EncryptedString(TypeDecorator):
41
40
  """A SQLAlchemy TypeDecorator for field-level database encryption.
@@ -1054,7 +1053,7 @@ class LollmsDiscussion:
1054
1053
  debug: bool = False,
1055
1054
  remove_thinking_blocks:bool = True,
1056
1055
  **kwargs
1057
- ) -> Dict[str, 'LollmsMessage']:
1056
+ ) -> Dict[str, Any]:
1058
1057
  """Main interaction method that can invoke the dynamic, multi-modal agent.
1059
1058
 
1060
1059
  This method orchestrates the entire response generation process. It can
@@ -1095,14 +1094,35 @@ class LollmsDiscussion:
1095
1094
  where the 'ai_message' will contain rich metadata if an agentic turn was used.
1096
1095
  """
1097
1096
  callback = kwargs.get("streaming_callback")
1097
+ collected_sources = []
1098
+
1099
+
1100
+ # Step 1: Add user message, now including any images.
1101
+ if add_user_message:
1102
+ user_msg = self.add_message(
1103
+ sender=kwargs.get("user_name", "user"),
1104
+ sender_type="user",
1105
+ content=user_message,
1106
+ images=images,
1107
+ **kwargs
1108
+ )
1109
+ else: # Regeneration logic
1110
+ # _validate_and_set_active_branch ensures active_branch_id is valid and a leaf.
1111
+ # So, if we are regenerating, active_branch_id must be valid.
1112
+ if self.active_branch_id not in self._message_index: # Redundant check, but safe
1113
+ raise ValueError("Regeneration failed: active branch tip not found or is invalid.")
1114
+ user_msg_orm = self._message_index[self.active_branch_id]
1115
+ if user_msg_orm.sender_type != 'user':
1116
+ raise ValueError(f"Regeneration failed: active branch tip is a '{user_msg_orm.sender_type}' message, not 'user'.")
1117
+ user_msg = LollmsMessage(self, user_msg_orm)
1118
+ images = user_msg.images
1119
+
1098
1120
  # extract personality data
1099
1121
  if personality is not None:
1100
1122
  object.__setattr__(self, '_system_prompt', personality.system_prompt)
1101
1123
 
1102
1124
  # --- New Data Source Handling Logic ---
1103
1125
  if hasattr(personality, 'data_source') and personality.data_source is not None:
1104
- # Placeholder for MSG_TYPE if not imported
1105
- MSG_TYPE = SimpleNamespace(MSG_TYPE_STEP="step", MSG_TYPE_STEP_START="step_start", MSG_TYPE_STEP_END="step_end", MSG_TYPE_EXCEPTION="exception")
1106
1126
 
1107
1127
  if isinstance(personality.data_source, str):
1108
1128
  # --- Static Data Source ---
@@ -1154,6 +1174,15 @@ class LollmsDiscussion:
1154
1174
 
1155
1175
  if retrieved_data:
1156
1176
  self.personality_data_zone = retrieved_data.strip()
1177
+ source_item = {
1178
+ "title": "Personality Data Source",
1179
+ "content": retrieved_data,
1180
+ "source": personality.name if hasattr(personality, 'name') else "Personality",
1181
+ "query": generated_query
1182
+ }
1183
+ collected_sources.append(source_item)
1184
+ if callback:
1185
+ callback([source_item], MSG_TYPE.MSG_TYPE_SOURCES_LIST)
1157
1186
 
1158
1187
  except Exception as e:
1159
1188
  trace_exception(e)
@@ -1175,26 +1204,6 @@ class LollmsDiscussion:
1175
1204
  if self.max_context_size is not None:
1176
1205
  self.summarize_and_prune(self.max_context_size)
1177
1206
 
1178
- # Step 1: Add user message, now including any images.
1179
- if add_user_message:
1180
- user_msg = self.add_message(
1181
- sender=kwargs.get("user_name", "user"),
1182
- sender_type="user",
1183
- content=user_message,
1184
- images=images,
1185
- **kwargs
1186
- )
1187
- else: # Regeneration logic
1188
- # _validate_and_set_active_branch ensures active_branch_id is valid and a leaf.
1189
- # So, if we are regenerating, active_branch_id must be valid.
1190
- if self.active_branch_id not in self._message_index: # Redundant check, but safe
1191
- raise ValueError("Regeneration failed: active branch tip not found or is invalid.")
1192
- user_msg_orm = self._message_index[self.active_branch_id]
1193
- if user_msg_orm.sender_type != 'user':
1194
- raise ValueError(f"Regeneration failed: active branch tip is a '{user_msg_orm.sender_type}' message, not 'user'.")
1195
- user_msg = LollmsMessage(self, user_msg_orm)
1196
- images = user_msg.images
1197
-
1198
1207
  is_agentic_turn = (effective_use_mcps is not None and effective_use_mcps) or (use_data_store is not None and use_data_store)
1199
1208
 
1200
1209
  start_time = datetime.now()
@@ -1262,9 +1271,12 @@ class LollmsDiscussion:
1262
1271
  message_meta = {}
1263
1272
  if is_agentic_turn and isinstance(agent_result, dict):
1264
1273
  if "tool_calls" in agent_result: message_meta["tool_calls"] = agent_result["tool_calls"]
1265
- if "sources" in agent_result: message_meta["sources"] = agent_result["sources"]
1274
+ if "sources" in agent_result: collected_sources.extend(agent_result["sources"])
1266
1275
  if agent_result.get("clarification_required", False): message_meta["clarification_required"] = True
1267
1276
 
1277
+ if collected_sources:
1278
+ message_meta["sources"] = collected_sources
1279
+
1268
1280
  ai_message_obj = self.add_message(
1269
1281
  sender=personality.name if personality else "assistant",
1270
1282
  sender_type="assistant",
@@ -1282,9 +1294,9 @@ class LollmsDiscussion:
1282
1294
  if self._is_db_backed and self.autosave:
1283
1295
  self.commit()
1284
1296
 
1285
- return {"user_message": user_msg, "ai_message": ai_message_obj}
1297
+ return {"user_message": user_msg, "ai_message": ai_message_obj, "sources": collected_sources}
1286
1298
 
1287
- def regenerate_branch(self, branch_tip_id: Optional[str] = None, **kwargs) -> Dict[str, 'LollmsMessage']:
1299
+ def regenerate_branch(self, branch_tip_id: Optional[str] = None, **kwargs) -> Dict[str, Any]:
1288
1300
  """Regenerates the AI response for a given message or the active branch's AI response.
1289
1301
 
1290
1302
  If the target is an AI message, it's deleted and its children are re-parented to its parent
@@ -2,7 +2,7 @@
2
2
  from abc import abstractmethod
3
3
  import importlib
4
4
  from pathlib import Path
5
- from typing import Optional, Callable, List, Union, Dict
5
+ from typing import Optional, Callable, List, Union, Dict, Any
6
6
  from ascii_colors import trace_exception, ASCIIColors
7
7
  from lollms_client.lollms_types import MSG_TYPE
8
8
  from lollms_client.lollms_discussion import LollmsDiscussion
@@ -212,6 +212,20 @@ class LollmsLLMBinding(LollmsBaseBinding):
212
212
  """
213
213
  pass
214
214
 
215
+ def get_zoo(self) -> List[Dict[str, Any]]:
216
+ """
217
+ Returns a list of models available for download.
218
+ each entry is a dict with:
219
+ name, description, size, type, link
220
+ """
221
+ return []
222
+
223
+ def download_from_zoo(self, index: int, progress_callback: Callable[[dict], None] = None) -> dict:
224
+ """
225
+ Downloads a model from the zoo using its index.
226
+ """
227
+ return {"status": False, "message": "Not implemented"}
228
+
215
229
  @abstractmethod
216
230
  def load_model(self, model_name: str) -> bool:
217
231
  """
@@ -2,7 +2,7 @@
2
2
  from abc import abstractmethod
3
3
  import importlib
4
4
  from pathlib import Path
5
- from typing import Optional, List, Dict, Any, Union
5
+ from typing import Optional, List, Dict, Any, Union, Callable
6
6
  from ascii_colors import trace_exception, ASCIIColors
7
7
  import yaml
8
8
  from lollms_client.lollms_base_binding import LollmsBaseBinding
@@ -52,6 +52,20 @@ class LollmsMCPBinding(LollmsBaseBinding):
52
52
  Or could be implemented to return available tools as models if desired.
53
53
  """
54
54
  return []
55
+
56
+ def get_zoo(self) -> List[Dict[str, Any]]:
57
+ """
58
+ Returns a list of models available for download.
59
+ each entry is a dict with:
60
+ name, description, size, type, link
61
+ """
62
+ return []
63
+
64
+ def download_from_zoo(self, index: int, progress_callback: Callable[[dict], None] = None) -> dict:
65
+ """
66
+ Downloads a model from the zoo using its index.
67
+ """
68
+ return {"status": False, "message": "Not implemented"}
55
69
 
56
70
  class LollmsMCPBindingManager:
57
71
  """
@@ -67,7 +81,6 @@ class LollmsMCPBindingManager:
67
81
  self.mcp_bindings_dir = (Path(__file__).parent.parent / mcp_bindings_dir).resolve()
68
82
 
69
83
  self.available_bindings: Dict[str, type[LollmsMCPBinding]] = {}
70
- ASCIIColors.info(f"LollmsMCPBindingManager initialized. Bindings directory: {self.mcp_bindings_dir}")
71
84
 
72
85
 
73
86
  def _load_binding_class(self, binding_name: str) -> Optional[type[LollmsMCPBinding]]:
@@ -2,7 +2,7 @@
2
2
  from abc import abstractmethod
3
3
  import importlib
4
4
  from pathlib import Path
5
- from typing import Optional, List, Dict, Any, Union
5
+ from typing import Optional, List, Dict, Any, Union, Callable
6
6
  from ascii_colors import trace_exception
7
7
  import yaml
8
8
  from lollms_client.lollms_base_binding import LollmsBaseBinding
@@ -32,6 +32,20 @@ class LollmsSTTBinding(LollmsBaseBinding):
32
32
  """
33
33
  pass
34
34
 
35
+ def get_zoo(self) -> List[Dict[str, Any]]:
36
+ """
37
+ Returns a list of models available for download.
38
+ each entry is a dict with:
39
+ name, description, size, type, link
40
+ """
41
+ return []
42
+
43
+ def download_from_zoo(self, index: int, progress_callback: Callable[[dict], None] = None) -> dict:
44
+ """
45
+ Downloads a model from the zoo using its index.
46
+ """
47
+ return {"status": False, "message": "Not implemented"}
48
+
35
49
  class LollmsSTTBindingManager:
36
50
  """Manages STT binding discovery and instantiation."""
37
51
 
@@ -1,7 +1,7 @@
1
1
  from abc import abstractmethod
2
2
  import importlib
3
3
  from pathlib import Path
4
- from typing import Optional, List, Dict, Any, Union
4
+ from typing import Optional, List, Dict, Any, Union, Callable
5
5
  from ascii_colors import trace_exception
6
6
  import yaml
7
7
  from lollms_client.lollms_base_binding import LollmsBaseBinding
@@ -57,6 +57,20 @@ class LollmsTTIBinding(LollmsBaseBinding):
57
57
  def list_models(self) -> list:
58
58
  """Lists models"""
59
59
  pass
60
+
61
+ def get_zoo(self) -> List[Dict[str, Any]]:
62
+ """
63
+ Returns a list of models available for download.
64
+ each entry is a dict with:
65
+ name, description, size, type, link
66
+ """
67
+ return []
68
+
69
+ def download_from_zoo(self, index: int, progress_callback: Callable[[dict], None] = None) -> dict:
70
+ """
71
+ Downloads a model from the zoo using its index.
72
+ """
73
+ return {"status": False, "message": "Not implemented"}
60
74
 
61
75
  @abstractmethod
62
76
  def set_settings(self, settings: Dict[str, Any], **kwargs) -> bool:
@@ -2,7 +2,7 @@
2
2
  from abc import abstractmethod
3
3
  import importlib
4
4
  from pathlib import Path
5
- from typing import Optional, List, Dict, Any, Union
5
+ from typing import Optional, List, Dict, Any, Union, Callable
6
6
  from ascii_colors import trace_exception
7
7
  from lollms_client.lollms_base_binding import LollmsBaseBinding
8
8
 
@@ -32,6 +32,20 @@ class LollmsTTMBinding(LollmsBaseBinding):
32
32
  """
33
33
  pass
34
34
 
35
+ def get_zoo(self) -> List[Dict[str, Any]]:
36
+ """
37
+ Returns a list of models available for download.
38
+ each entry is a dict with:
39
+ name, description, size, type, link
40
+ """
41
+ return []
42
+
43
+ def download_from_zoo(self, index: int, progress_callback: Callable[[dict], None] = None) -> dict:
44
+ """
45
+ Downloads a model from the zoo using its index.
46
+ """
47
+ return {"status": False, "message": "Not implemented"}
48
+
35
49
  class LollmsTTMBindingManager:
36
50
  """Manages TTM binding discovery and instantiation."""
37
51
 
@@ -1,7 +1,7 @@
1
1
  from abc import abstractmethod
2
2
  import importlib
3
3
  from pathlib import Path
4
- from typing import Optional, List, Dict, Any, Union
4
+ from typing import Optional, List, Dict, Any, Union, Callable
5
5
  import yaml
6
6
  from ascii_colors import trace_exception
7
7
  from lollms_client.lollms_base_binding import LollmsBaseBinding
@@ -27,7 +27,21 @@ class LollmsTTSBinding(LollmsBaseBinding):
27
27
  @abstractmethod
28
28
  def list_models(self, **kwargs) -> List[str]:
29
29
  pass
30
+
31
+ def get_zoo(self) -> List[Dict[str, Any]]:
32
+ """
33
+ Returns a list of models available for download.
34
+ each entry is a dict with:
35
+ name, description, size, type, link
36
+ """
37
+ return []
30
38
 
39
+ def download_from_zoo(self, index: int, progress_callback: Callable[[dict], None] = None) -> dict:
40
+ """
41
+ Downloads a model from the zoo using its index.
42
+ """
43
+ return {"status": False, "message": "Not implemented"}
44
+
31
45
  def get_settings(self, **kwargs) -> Dict[str, Any]:
32
46
  return self.settings
33
47
 
@@ -2,7 +2,7 @@
2
2
  from abc import abstractmethod
3
3
  import importlib
4
4
  from pathlib import Path
5
- from typing import Optional, List, Dict, Any, Union
5
+ from typing import Optional, List, Dict, Any, Union, Callable
6
6
  from ascii_colors import trace_exception
7
7
  from lollms_client.lollms_base_binding import LollmsBaseBinding
8
8
 
@@ -31,6 +31,20 @@ class LollmsTTVBinding(LollmsBaseBinding):
31
31
  """
32
32
  pass
33
33
 
34
+ def get_zoo(self) -> List[Dict[str, Any]]:
35
+ """
36
+ Returns a list of models available for download.
37
+ each entry is a dict with:
38
+ name, description, size, type, link
39
+ """
40
+ return []
41
+
42
+ def download_from_zoo(self, index: int, progress_callback: Callable[[dict], None] = None) -> dict:
43
+ """
44
+ Downloads a model from the zoo using its index.
45
+ """
46
+ return {"status": False, "message": "Not implemented"}
47
+
34
48
  class LollmsTTVBindingManager:
35
49
  """Manages TTV binding discovery and instantiation."""
36
50