lollms-client 0.32.0__py3-none-any.whl → 0.32.1__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.

Potentially problematic release.


This version of lollms-client might be problematic. Click here for more details.

lollms_client/__init__.py CHANGED
@@ -8,7 +8,7 @@ from lollms_client.lollms_utilities import PromptReshaper # Keep general utiliti
8
8
  from lollms_client.lollms_mcp_binding import LollmsMCPBinding, LollmsMCPBindingManager
9
9
  from lollms_client.lollms_llm_binding import LollmsLLMBindingManager
10
10
 
11
- __version__ = "0.32.0" # Updated version
11
+ __version__ = "0.32.1" # Updated version
12
12
 
13
13
  # Optionally, you could define __all__ if you want to be explicit about exports
14
14
  __all__ = [
@@ -901,6 +901,77 @@ class LlamaCppServerBinding(LollmsLLMBinding):
901
901
  def __del__(self):
902
902
  self.unload_model()
903
903
 
904
+ def get_ctx_size(self, model_name: Optional[str] = None) -> Optional[int]:
905
+ """
906
+ Retrieves context size for a model from a hardcoded list.
907
+
908
+ This method checks if the model name contains a known base model identifier
909
+ (e.g., 'llama3.1', 'gemma2') to determine its context length. It's intended
910
+ as a failsafe when the context size cannot be retrieved directly from the
911
+ Ollama API.
912
+ """
913
+ if model_name is None:
914
+ model_name = self.model_name
915
+
916
+ # Hardcoded context sizes for popular models. More specific names (e.g., 'llama3.1')
917
+ # should appear, as they will be checked first due to the sorting logic below.
918
+ known_contexts = {
919
+ 'llama3.1': 131072, # Llama 3.1 extended context
920
+ 'llama3.2': 131072, # Llama 3.2 extended context
921
+ 'llama3.3': 131072, # Assuming similar to 3.1/3.2
922
+ 'llama3': 8192, # Llama 3 default
923
+ 'llama2': 4096, # Llama 2 default
924
+ 'mixtral8x22b': 65536, # Mixtral 8x22B default
925
+ 'mixtral': 32768, # Mixtral 8x7B default
926
+ 'mistral': 32768, # Mistral 7B v0.2+ default
927
+ 'gemma3': 131072, # Gemma 3 with 128K context
928
+ 'gemma2': 8192, # Gemma 2 default
929
+ 'gemma': 8192, # Gemma default
930
+ 'phi3': 131072, # Phi-3 variants often use 128K (mini/medium extended)
931
+ 'phi2': 2048, # Phi-2 default
932
+ 'phi': 2048, # Phi default (older)
933
+ 'qwen2.5': 131072, # Qwen2.5 with 128K
934
+ 'qwen2': 32768, # Qwen2 default for 7B
935
+ 'qwen': 8192, # Qwen default
936
+ 'codellama': 16384, # CodeLlama extended
937
+ 'codegemma': 8192, # CodeGemma default
938
+ 'deepseek-coder-v2': 131072, # DeepSeek-Coder V2 with 128K
939
+ 'deepseek-coder': 16384, # DeepSeek-Coder V1 default
940
+ 'deepseek-v2': 131072, # DeepSeek-V2 with 128K
941
+ 'deepseek-llm': 4096, # DeepSeek-LLM default
942
+ 'yi1.5': 32768, # Yi-1.5 with 32K
943
+ 'yi': 4096, # Yi base default
944
+ 'command-r': 131072, # Command-R with 128K
945
+ 'wizardlm2': 32768, # WizardLM2 (Mistral-based)
946
+ 'wizardlm': 16384, # WizardLM default
947
+ 'zephyr': 65536, # Zephyr beta (Mistral-based extended)
948
+ 'vicuna': 2048, # Vicuna default (up to 16K in some variants)
949
+ 'falcon': 2048, # Falcon default
950
+ 'starcoder': 8192, # StarCoder default
951
+ 'stablelm': 4096, # StableLM default
952
+ 'orca2': 4096, # Orca 2 default
953
+ 'orca': 4096, # Orca default
954
+ 'dolphin': 32768, # Dolphin (often Mistral-based)
955
+ 'openhermes': 8192, # OpenHermes default
956
+ }
957
+
958
+ normalized_model_name = model_name.lower().strip()
959
+
960
+ # Sort keys by length in descending order. This ensures that a more specific
961
+ # name like 'llama3.1' is checked before a less specific name like 'llama3'.
962
+ sorted_base_models = sorted(known_contexts.keys(), key=len, reverse=True)
963
+
964
+ for base_name in sorted_base_models:
965
+ if base_name in normalized_model_name:
966
+ context_size = known_contexts[base_name]
967
+ ASCIIColors.warning(
968
+ f"Using hardcoded context size for model '{model_name}' "
969
+ f"based on base name '{base_name}': {context_size}"
970
+ )
971
+ return context_size
972
+
973
+ ASCIIColors.warning(f"Context size not found for model '{model_name}' in the hardcoded list.")
974
+ return None
904
975
 
905
976
  if __name__ == '__main__':
906
977
  global full_streamed_text # Define for the callback
@@ -598,6 +598,94 @@ class OllamaBinding(LollmsLLMBinding):
598
598
  ASCIIColors.info(f"Ollama model set to: {model_name}. It will be loaded by the server on first use.")
599
599
  return True
600
600
 
601
+ def get_ctx_size(self, model_name: Optional[str] = None) -> Optional[int]:
602
+ """
603
+ Retrieves the context size for an Ollama model.
604
+
605
+ The effective context size is the `num_ctx` parameter if overridden in the Modelfile,
606
+ otherwise it falls back to the model's default context length from its architecture details.
607
+ As a final failsafe, uses a hardcoded list of known popular models' context lengths.
608
+ """
609
+ if model_name is None:
610
+ model_name = self.model_name
611
+
612
+ try:
613
+ info = ollama.show(model_name)
614
+
615
+ # Parse num_ctx from the 'parameters' string (e.g., "PARAMETER num_ctx 4096")
616
+ parameters = info.get('parameters', '')
617
+ num_ctx = None
618
+ for param in parameters.split('\n'):
619
+ if param.strip().startswith('num_ctx'):
620
+ num_ctx = int(param.split()[1])
621
+ break
622
+
623
+ if num_ctx is not None:
624
+ return num_ctx
625
+
626
+ # Fall back to model_info context_length (e.g., 'llama.context_length')
627
+ model_info = info.get('model_info', {})
628
+ arch = model_info.get('general.architecture', '')
629
+ context_key = f'{arch}.context_length' if arch else 'general.context_length'
630
+ context_length = model_info.get(context_key)
631
+
632
+ if context_length is not None:
633
+ return int(context_length)
634
+
635
+ except Exception as e:
636
+ ASCIIColors.warning(f"Error fetching model info: {str(e)}")
637
+
638
+ # Failsafe: Hardcoded context sizes for popular Ollama models
639
+ known_contexts = {
640
+ 'llama2': 4096, # Llama 2 default
641
+ 'llama3': 8192, # Llama 3 default
642
+ 'llama3.1': 131072, # Llama 3.1 extended context
643
+ 'llama3.2': 131072, # Llama 3.2 extended context
644
+ 'llama3.3': 131072, # Assuming similar to 3.1/3.2
645
+ 'mistral': 32768, # Mistral 7B v0.2+ default
646
+ 'mixtral': 32768, # Mixtral 8x7B default
647
+ 'mixtral8x22b': 65536, # Mixtral 8x22B default
648
+ 'gemma': 8192, # Gemma default
649
+ 'gemma2': 8192, # Gemma 2 default
650
+ 'gemma3': 131072, # Gemma 3 with 128K context
651
+ 'phi': 2048, # Phi default (older)
652
+ 'phi2': 2048, # Phi-2 default
653
+ 'phi3': 131072, # Phi-3 variants often use 128K (mini/medium extended)
654
+ 'qwen': 8192, # Qwen default
655
+ 'qwen2': 32768, # Qwen2 default for 7B
656
+ 'qwen2.5': 131072, # Qwen2.5 with 128K
657
+ 'codellama': 16384, # CodeLlama extended
658
+ 'codegemma': 8192, # CodeGemma default
659
+ 'deepseek-coder': 16384, # DeepSeek-Coder V1 default
660
+ 'deepseek-coder-v2': 131072, # DeepSeek-Coder V2 with 128K
661
+ 'deepseek-llm': 4096, # DeepSeek-LLM default
662
+ 'deepseek-v2': 131072, # DeepSeek-V2 with 128K
663
+ 'yi': 4096, # Yi base default
664
+ 'yi1.5': 32768, # Yi-1.5 with 32K
665
+ 'command-r': 131072, # Command-R with 128K
666
+ 'vicuna': 2048, # Vicuna default (up to 16K in some variants)
667
+ 'wizardlm': 16384, # WizardLM default
668
+ 'wizardlm2': 32768, # WizardLM2 (Mistral-based)
669
+ 'zephyr': 65536, # Zephyr beta (Mistral-based extended)
670
+ 'falcon': 2048, # Falcon default
671
+ 'starcoder': 8192, # StarCoder default
672
+ 'stablelm': 4096, # StableLM default
673
+ 'orca': 4096, # Orca default
674
+ 'orca2': 4096, # Orca 2 default
675
+ 'dolphin': 32768, # Dolphin (often Mistral-based)
676
+ 'openhermes': 8192, # OpenHermes default
677
+ }
678
+
679
+ # Extract base model name (e.g., 'llama3' from 'llama3:8b-instruct')
680
+ base_name = model_name.split(':')[0].lower().strip()
681
+
682
+ if base_name in known_contexts:
683
+ ASCIIColors.warning(f"Using hardcoded context size for model '{model_name}': {known_contexts[base_name]}")
684
+ return known_contexts[base_name]
685
+
686
+ ASCIIColors.warning(f"Context size not found for model '{model_name}'")
687
+ return None
688
+
601
689
  if __name__ == '__main__':
602
690
  global full_streamed_text
603
691
  # Example Usage (requires an Ollama server running)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lollms_client
3
- Version: 0.32.0
3
+ Version: 0.32.1
4
4
  Summary: A client library for LoLLMs generate endpoint
5
5
  Author-email: ParisNeo <parisneoai@gmail.com>
6
6
  License: Apache Software License
@@ -29,7 +29,7 @@ examples/mcp_examples/openai_mcp.py,sha256=7IEnPGPXZgYZyiES_VaUbQ6viQjenpcUxGiHE
29
29
  examples/mcp_examples/run_remote_mcp_example_v2.py,sha256=bbNn93NO_lKcFzfIsdvJJijGx2ePFTYfknofqZxMuRM,14626
30
30
  examples/mcp_examples/run_standard_mcp_example.py,sha256=GSZpaACPf3mDPsjA8esBQVUsIi7owI39ca5avsmvCxA,9419
31
31
  examples/test_local_models/local_chat.py,sha256=slakja2zaHOEAUsn2tn_VmI4kLx6luLBrPqAeaNsix8,456
32
- lollms_client/__init__.py,sha256=7Vw58C6Ala6ESJmnETjGFRBG1C1H-3SKmTnfbL46eVI,1147
32
+ lollms_client/__init__.py,sha256=5paEgQrICKx3_3wtk257FCKOwolkgmfFPJPwc9aYkWY,1147
33
33
  lollms_client/lollms_config.py,sha256=goEseDwDxYJf3WkYJ4IrLXwg3Tfw73CXV2Avg45M_hE,21876
34
34
  lollms_client/lollms_core.py,sha256=gDhpB62AluEmbVFvPm7vdnZgP2hGBymDLun57K1jrOM,177352
35
35
  lollms_client/lollms_discussion.py,sha256=TT-AIKMdEuNNBjrWgMLcww8z6vIETO0J3cnoQgb9dhU,85448
@@ -54,11 +54,11 @@ lollms_client/llm_bindings/grok/__init__.py,sha256=5tIf3348RgAEaSp6FdG-LM9N8R7aR
54
54
  lollms_client/llm_bindings/groq/__init__.py,sha256=zyWKM78qHwSt5g0Bb8Njj7Jy8CYuLMyplx2maOKFFpg,12218
55
55
  lollms_client/llm_bindings/hugging_face_inference_api/__init__.py,sha256=PxgeRqT8dpa9GZoXwtSncy9AUgAN2cDKrvp_nbaWq0E,14027
56
56
  lollms_client/llm_bindings/litellm/__init__.py,sha256=pNkwyRPeENvTM4CDh6Pj3kQfxHfhX2pvXhGJDjKjp30,12340
57
- lollms_client/llm_bindings/llamacpp/__init__.py,sha256=gER3lYd4Ez_Ng_yLO5zSZH52KgUosHXfdTr5W2wX_Jk,69000
57
+ lollms_client/llm_bindings/llamacpp/__init__.py,sha256=uNqOoxFYnsgrYb-lVXQ0QrENWTJC5Np5NMTXfOAYoko,72800
58
58
  lollms_client/llm_bindings/lollms/__init__.py,sha256=scGHEKzlGX5fw2XwefVicsf28GrwgN3wU5nl4EPJ_Sk,24424
59
59
  lollms_client/llm_bindings/lollms_webui/__init__.py,sha256=Thoq3PJR2e03Y2Kd_FBb-DULJK0zT5-2ID1YIJLcPlw,17864
60
60
  lollms_client/llm_bindings/mistral/__init__.py,sha256=624Gr462yBh52ttHFOapKgJOn8zZ1vZcTEcC3i4FYt8,12750
61
- lollms_client/llm_bindings/ollama/__init__.py,sha256=_plx8cO3Bl9igmIEvTkJ6tkZ2imHS_L76hCHdJAGIhQ,36851
61
+ lollms_client/llm_bindings/ollama/__init__.py,sha256=dXKHIeQCS9pz5AS07GF1eWj3ieWiz3aFOtxOX7yojbs,41314
62
62
  lollms_client/llm_bindings/open_router/__init__.py,sha256=v91BpNcuQCbbA6r82gbgMP8UYhSrJUMOf4UtOzEo18Q,13235
63
63
  lollms_client/llm_bindings/openai/__init__.py,sha256=Z0zNTfBgBGwkwArN375kBt4otrUTI_84pHgVuyuDy0c,26253
64
64
  lollms_client/llm_bindings/openllm/__init__.py,sha256=xv2XDhJNCYe6NPnWBboDs24AQ1VJBOzsTuMcmuQ6xYY,29864
@@ -93,9 +93,9 @@ lollms_client/tts_bindings/piper_tts/__init__.py,sha256=0IEWG4zH3_sOkSb9WbZzkeV5
93
93
  lollms_client/tts_bindings/xtts/__init__.py,sha256=FgcdUH06X6ZR806WQe5ixaYx0QoxtAcOgYo87a2qxYc,18266
94
94
  lollms_client/ttv_bindings/__init__.py,sha256=UZ8o2izQOJLQgtZ1D1cXoNST7rzqW22rL2Vufc7ddRc,3141
95
95
  lollms_client/ttv_bindings/lollms/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
96
- lollms_client-0.32.0.dist-info/licenses/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
96
+ lollms_client-0.32.1.dist-info/licenses/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
97
97
  test/test_lollms_discussion.py,sha256=KxTsV1bPdNz8QqZd7tIof9kTWkeXLUtAMU08BQmoY6U,16829
98
- lollms_client-0.32.0.dist-info/METADATA,sha256=uuOa7NYNuAQ8ibP6D24yqMQqg6Asl1Cep1UIIH1b6Dw,38717
99
- lollms_client-0.32.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
100
- lollms_client-0.32.0.dist-info/top_level.txt,sha256=1jIpjTnOSGEGtIW2rGAFM6tVRzgsDdMOiox_SmDH_zw,28
101
- lollms_client-0.32.0.dist-info/RECORD,,
98
+ lollms_client-0.32.1.dist-info/METADATA,sha256=mw11ol3fFJpA2_sxa4olRXLkfVDeMfR_WCd63aLZdXw,38717
99
+ lollms_client-0.32.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
100
+ lollms_client-0.32.1.dist-info/top_level.txt,sha256=1jIpjTnOSGEGtIW2rGAFM6tVRzgsDdMOiox_SmDH_zw,28
101
+ lollms_client-0.32.1.dist-info/RECORD,,