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

Files changed (74) hide show
  1. lollms_client/__init__.py +1 -1
  2. lollms_client/llm_bindings/azure_openai/__init__.py +6 -10
  3. lollms_client/llm_bindings/claude/__init__.py +4 -7
  4. lollms_client/llm_bindings/gemini/__init__.py +3 -7
  5. lollms_client/llm_bindings/grok/__init__.py +3 -7
  6. lollms_client/llm_bindings/groq/__init__.py +4 -6
  7. lollms_client/llm_bindings/hugging_face_inference_api/__init__.py +4 -6
  8. lollms_client/llm_bindings/litellm/__init__.py +15 -6
  9. lollms_client/llm_bindings/llamacpp/__init__.py +27 -9
  10. lollms_client/llm_bindings/lollms/__init__.py +24 -14
  11. lollms_client/llm_bindings/lollms_webui/__init__.py +6 -12
  12. lollms_client/llm_bindings/mistral/__init__.py +3 -5
  13. lollms_client/llm_bindings/ollama/__init__.py +6 -11
  14. lollms_client/llm_bindings/open_router/__init__.py +4 -6
  15. lollms_client/llm_bindings/openai/__init__.py +7 -14
  16. lollms_client/llm_bindings/openllm/__init__.py +12 -12
  17. lollms_client/llm_bindings/pythonllamacpp/__init__.py +1 -1
  18. lollms_client/llm_bindings/tensor_rt/__init__.py +8 -13
  19. lollms_client/llm_bindings/transformers/__init__.py +14 -6
  20. lollms_client/llm_bindings/vllm/__init__.py +16 -12
  21. lollms_client/lollms_core.py +303 -490
  22. lollms_client/lollms_discussion.py +431 -78
  23. lollms_client/lollms_llm_binding.py +192 -381
  24. lollms_client/lollms_mcp_binding.py +33 -2
  25. lollms_client/lollms_tti_binding.py +107 -2
  26. lollms_client/mcp_bindings/local_mcp/__init__.py +3 -2
  27. lollms_client/mcp_bindings/remote_mcp/__init__.py +6 -5
  28. lollms_client/mcp_bindings/standard_mcp/__init__.py +3 -5
  29. lollms_client/stt_bindings/lollms/__init__.py +6 -8
  30. lollms_client/stt_bindings/whisper/__init__.py +2 -4
  31. lollms_client/stt_bindings/whispercpp/__init__.py +15 -16
  32. lollms_client/tti_bindings/dalle/__init__.py +50 -29
  33. lollms_client/tti_bindings/diffusers/__init__.py +227 -439
  34. lollms_client/tti_bindings/gemini/__init__.py +320 -0
  35. lollms_client/tti_bindings/lollms/__init__.py +8 -9
  36. lollms_client-1.1.0.dist-info/METADATA +1214 -0
  37. lollms_client-1.1.0.dist-info/RECORD +69 -0
  38. {lollms_client-0.33.0.dist-info → lollms_client-1.1.0.dist-info}/top_level.txt +0 -2
  39. examples/article_summary/article_summary.py +0 -58
  40. examples/console_discussion/console_app.py +0 -266
  41. examples/console_discussion.py +0 -448
  42. examples/deep_analyze/deep_analyse.py +0 -30
  43. examples/deep_analyze/deep_analyze_multiple_files.py +0 -32
  44. examples/function_calling_with_local_custom_mcp.py +0 -250
  45. examples/generate_a_benchmark_for_safe_store.py +0 -89
  46. examples/generate_and_speak/generate_and_speak.py +0 -251
  47. examples/generate_game_sfx/generate_game_fx.py +0 -240
  48. examples/generate_text_with_multihop_rag_example.py +0 -210
  49. examples/gradio_chat_app.py +0 -228
  50. examples/gradio_lollms_chat.py +0 -259
  51. examples/internet_search_with_rag.py +0 -226
  52. examples/lollms_chat/calculator.py +0 -59
  53. examples/lollms_chat/derivative.py +0 -48
  54. examples/lollms_chat/test_openai_compatible_with_lollms_chat.py +0 -12
  55. examples/lollms_discussions_test.py +0 -155
  56. examples/mcp_examples/external_mcp.py +0 -267
  57. examples/mcp_examples/local_mcp.py +0 -171
  58. examples/mcp_examples/openai_mcp.py +0 -203
  59. examples/mcp_examples/run_remote_mcp_example_v2.py +0 -290
  60. examples/mcp_examples/run_standard_mcp_example.py +0 -204
  61. examples/simple_text_gen_test.py +0 -173
  62. examples/simple_text_gen_with_image_test.py +0 -178
  63. examples/test_local_models/local_chat.py +0 -9
  64. examples/text_2_audio.py +0 -77
  65. examples/text_2_image.py +0 -144
  66. examples/text_2_image_diffusers.py +0 -274
  67. examples/text_and_image_2_audio.py +0 -59
  68. examples/text_gen.py +0 -30
  69. examples/text_gen_system_prompt.py +0 -29
  70. lollms_client-0.33.0.dist-info/METADATA +0 -854
  71. lollms_client-0.33.0.dist-info/RECORD +0 -101
  72. test/test_lollms_discussion.py +0 -368
  73. {lollms_client-0.33.0.dist-info → lollms_client-1.1.0.dist-info}/WHEEL +0 -0
  74. {lollms_client-0.33.0.dist-info → lollms_client-1.1.0.dist-info}/licenses/LICENSE +0 -0
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.33.0" # Updated version
11
+ __version__ = "1.1.0" # Updated version
12
12
 
13
13
  # Optionally, you could define __all__ if you want to be explicit about exports
14
14
  __all__ = [
@@ -45,10 +45,6 @@ class AzureOpenAIBinding(LollmsLLMBinding):
45
45
  """
46
46
 
47
47
  def __init__(self,
48
- model_name: str, # In Azure, this is the DEPLOYMENT NAME
49
- azure_api_key: str = None,
50
- azure_endpoint: str = None,
51
- azure_api_version: str = "2024-02-01",
52
48
  **kwargs
53
49
  ):
54
50
  """
@@ -56,15 +52,15 @@ class AzureOpenAIBinding(LollmsLLMBinding):
56
52
 
57
53
  Args:
58
54
  model_name (str): The name of the Azure OpenAI DEPLOYMENT to use.
59
- azure_api_key (str): The API key for the Azure OpenAI service.
55
+ service_key (str): The API key for the Azure OpenAI service.
60
56
  azure_endpoint (str): The endpoint URL for the Azure OpenAI service.
61
57
  azure_api_version (str): The API version to use.
62
58
  """
63
- super().__init__(binding_name=BindingName)
64
- self.model_name = model_name # Here, it's the deployment name
65
- self.azure_api_key = azure_api_key or os.getenv("AZURE_OPENAI_API_KEY")
66
- self.azure_endpoint = azure_endpoint or os.getenv("AZURE_OPENAI_ENDPOINT")
67
- self.azure_api_version = azure_api_version or os.getenv("AZURE_OPENAI_API_VERSION", "2024-02-01")
59
+ super().__init__(BindingName, **kwargs)
60
+ self.model_name = kwargs.get("model_name") # Here, it's the deployment name
61
+ self.azure_api_key = kwargs.get("service_key") or os.getenv("AZURE_OPENAI_API_KEY")
62
+ self.azure_endpoint = kwargs.get("azure_endpoint") or os.getenv("AZURE_OPENAI_ENDPOINT")
63
+ self.azure_api_version = kwargs.get("azure_api_version") or os.getenv("AZURE_OPENAI_API_VERSION", "2024-02-01")
68
64
 
69
65
  if not self.model_name:
70
66
  raise ValueError("Azure deployment name ('model_name') is required.")
@@ -66,10 +66,6 @@ class ClaudeBinding(LollmsLLMBinding):
66
66
  """Anthropic Claude-specific binding implementation."""
67
67
 
68
68
  def __init__(self,
69
- host_address: str = None, # Ignored, for compatibility
70
- model_name: str = "claude-3-sonnet-20240229",
71
- service_key: str = None,
72
- verify_ssl_certificate: bool = True, # Ignored, for compatibility
73
69
  **kwargs
74
70
  ):
75
71
  """
@@ -79,9 +75,9 @@ class ClaudeBinding(LollmsLLMBinding):
79
75
  model_name (str): Name of the Claude model to use.
80
76
  service_key (str): Anthropic API key.
81
77
  """
82
- super().__init__(binding_name=BindingName)
83
- self.model_name = model_name
84
- self.service_key = service_key
78
+ super().__init__(BindingName, **kwargs)
79
+ self.model_name = kwargs.get("model_name")
80
+ self.service_key = kwargs.get("service_key")
85
81
  self._cached_models: Optional[List[Dict[str, str]]] = None
86
82
 
87
83
  if not self.service_key:
@@ -335,6 +331,7 @@ class ClaudeBinding(LollmsLLMBinding):
335
331
  )
336
332
  return response.token_count # Updated to correct response attribute
337
333
  except Exception as e:
334
+ trace_exception(e)
338
335
  ASCIIColors.error(f"Failed to count tokens with Claude API: {e}")
339
336
  return len(self.tokenize(text))
340
337
 
@@ -33,10 +33,6 @@ class GeminiBinding(LollmsLLMBinding):
33
33
  """Google Gemini-specific binding implementation."""
34
34
 
35
35
  def __init__(self,
36
- host_address: str = None, # Ignored, for compatibility
37
- model_name: str = "gemini-1.5-pro-latest",
38
- service_key: str = None,
39
- verify_ssl_certificate: bool = True, # Ignored, for compatibility
40
36
  **kwargs
41
37
  ):
42
38
  """
@@ -46,9 +42,9 @@ class GeminiBinding(LollmsLLMBinding):
46
42
  model_name (str): Name of the Gemini model to use.
47
43
  service_key (str): Google AI Studio API key.
48
44
  """
49
- super().__init__(binding_name=BindingName)
50
- self.model_name = model_name
51
- self.service_key = service_key
45
+ super().__init__(BindingName, **kwargs)
46
+ self.model_name = kwargs.get("model_name", None)
47
+ self.service_key = kwargs.get("service_key", None)
52
48
 
53
49
  if not self.service_key:
54
50
  self.service_key = os.getenv("GOOGLE_API_KEY")
@@ -60,10 +60,6 @@ class GrokBinding(LollmsLLMBinding):
60
60
  """xAI Grok-specific binding implementation."""
61
61
 
62
62
  def __init__(self,
63
- host_address: str = None, # Ignored, for compatibility
64
- model_name: str = "grok-1.5-vision-preview",
65
- service_key: str = None,
66
- verify_ssl_certificate: bool = True, # Ignored, for compatibility
67
63
  **kwargs
68
64
  ):
69
65
  """
@@ -73,9 +69,9 @@ class GrokBinding(LollmsLLMBinding):
73
69
  model_name (str): Name of the Grok model to use.
74
70
  service_key (str): xAI API key.
75
71
  """
76
- super().__init__(binding_name=BindingName)
77
- self.model_name = model_name
78
- self.service_key = service_key
72
+ super().__init__(BindingName, **kwargs)
73
+ self.model_name = kwargs.get("model_name", "grok-1.5-vision-preview")
74
+ self.service_key = kwargs.get("service_key")
79
75
  self.base_url = kwargs.get("base_url", GROK_API_BASE_URL)
80
76
  self._cached_models: Optional[List[Dict[str, str]]] = None
81
77
 
@@ -29,8 +29,6 @@ class GroqBinding(LollmsLLMBinding):
29
29
  """
30
30
 
31
31
  def __init__(self,
32
- model_name: str = "llama3-8b-8192",
33
- service_key: str|None = None,
34
32
  **kwargs
35
33
  ):
36
34
  """
@@ -38,11 +36,11 @@ class GroqBinding(LollmsLLMBinding):
38
36
 
39
37
  Args:
40
38
  model_name (str): The name of the Groq model to use.
41
- groq_api_key (str): The API key for the Groq service.
39
+ service_key (str): The API key for the Groq service.
42
40
  """
43
- super().__init__(binding_name=BindingName)
44
- self.model_name = model_name
45
- self.groq_api_key = service_key or os.getenv("GROQ_API_KEY")
41
+ super().__init__(BindingName, **kwargs)
42
+ self.model_name = kwargs.get("model_name", "llama3-8b-8192")
43
+ self.groq_api_key = kwargs.get("service_key") or os.getenv("GROQ_API_KEY")
46
44
 
47
45
  if not self.groq_api_key:
48
46
  raise ValueError("Groq API key is required. Set it via 'groq_api_key' or GROQ_API_KEY env var.")
@@ -25,8 +25,6 @@ class HuggingFaceInferenceAPIBinding(LollmsLLMBinding):
25
25
  """
26
26
 
27
27
  def __init__(self,
28
- model_name: str = "mistralai/Mistral-7B-Instruct-v0.2",
29
- hf_api_key: str = None,
30
28
  **kwargs
31
29
  ):
32
30
  """
@@ -34,11 +32,11 @@ class HuggingFaceInferenceAPIBinding(LollmsLLMBinding):
34
32
 
35
33
  Args:
36
34
  model_name (str): The repository ID of the model on the Hugging Face Hub.
37
- hf_api_key (str): The Hugging Face API key.
35
+ service_key (str): The Hugging Face API key.
38
36
  """
39
- super().__init__(binding_name=BindingName)
40
- self.model_name = model_name
41
- self.hf_api_key = hf_api_key or os.getenv("HUGGING_FACE_HUB_TOKEN")
37
+ super().__init__(BindingName, **kwargs)
38
+ self.model_name = kwargs.get("model_name")
39
+ self.hf_api_key = kwargs.get("service_key") or os.getenv("HUGGING_FACE_HUB_TOKEN")
42
40
 
43
41
  if not self.hf_api_key:
44
42
  raise ValueError("Hugging Face API key is required. Set it via 'hf_api_key' or HUGGING_FACE_HUB_TOKEN env var.")
@@ -36,12 +36,21 @@ class LiteLLMBinding(LollmsLLMBinding):
36
36
  and correct payload formatting for both streaming and non-streaming modes.
37
37
  """
38
38
 
39
- def __init__(self, host_address: str, model_name: str, service_key: str = "anything", verify_ssl_certificate: bool = True, **kwargs):
40
- super().__init__(binding_name="litellm")
41
- self.host_address = host_address.rstrip('/')
42
- self.model_name = model_name
43
- self.service_key = service_key
44
- self.verify_ssl_certificate = verify_ssl_certificate
39
+ def __init__(self,
40
+ **kwargs):
41
+ """ Initializes the LiteLLM binding with the provided parameters.
42
+ Args:
43
+ host_address (str): The base URL of the LiteLLM server.
44
+ model_name (str): The name of the model to use.
45
+ service_key (str): The API key for authentication.
46
+ verify_ssl_certificate (bool): Whether to verify SSL certificates.
47
+ """
48
+ super().__init__(BindingName, **kwargs)
49
+ self.host_address = kwargs.get("host_address")
50
+ if self.host_address: self.host_address = self.host_address.rstrip('/')
51
+ self.model_name = kwargs.get("model_name")
52
+ self.service_key = kwargs.get("service_key")
53
+ self.verify_ssl_certificate = kwargs.get("verify_ssl_certificate")
45
54
 
46
55
  def _perform_generation(self, messages: List[Dict], n_predict: Optional[int], stream: bool, temperature: float, top_p: float, repeat_penalty: float, seed: Optional[int], streaming_callback: Optional[Callable[[str, MSG_TYPE], None]]) -> Union[str, dict]:
47
56
  url = f'{self.host_address}/v1/chat/completions'
@@ -121,7 +121,14 @@ BindingName = "LlamaCppServerBinding"
121
121
  DEFAULT_LLAMACPP_SERVER_HOST = "127.0.0.1"
122
122
 
123
123
  class LlamaCppServerProcess:
124
- def __init__(self, model_path: Union[str, Path], clip_model_path: Optional[Union[str, Path]] = None, server_binary_path: Optional[Union[str, Path]]=None, server_args: Dict[str, Any]={}):
124
+ def __init__(self,
125
+ model_path: Union[str, Path],
126
+ clip_model_path: Optional[Union[str, Path]] = None,
127
+ server_binary_path: Optional[Union[str, Path]]=None,
128
+ server_args: Dict[str, Any]={}
129
+ ):
130
+ """Initialize the Llama.cpp server process.
131
+ """
125
132
  self.model_path = Path(model_path)
126
133
  self.clip_model_path = Path(clip_model_path) if clip_model_path else None
127
134
 
@@ -264,24 +271,35 @@ class LlamaCppServerBinding(LollmsLLMBinding):
264
271
  "parallel_slots": 4, # Default parallel slots for server
265
272
  }
266
273
 
267
- def __init__(self, model_name: Optional[str], models_path: str, clip_model_name: Optional[str] = None,
268
- config: Optional[Dict[str, Any]] = None, default_completion_format: ELF_COMPLETION_FORMAT = ELF_COMPLETION_FORMAT.Chat, **kwargs):
269
- super().__init__(binding_name=BindingName)
274
+ def __init__(self,
275
+ **kwargs
276
+ ):
277
+ """Initialize the Llama.cpp server binding.
278
+ Args:
279
+ model_name (str): Name of the model to load. If None, will use initial_model_name_preference.
280
+ models_path (str): Path to the directory containing model files.
281
+ clip_model_name (str): Optional name of the clip model to use. If None, will try to auto-detect based on the main model.
282
+ config (dict): Additional configuration options for the server.
283
+ default_completion_format (ELF_COMPLETION_FORMAT): Default format for completions.
284
+
285
+ """
286
+ super().__init__(BindingName, **kwargs)
270
287
  if llama_cpp_binaries is None: raise ImportError("llama-cpp-binaries package is required but not found.")
271
288
 
289
+ models_path = kwargs.get("models_path", Path(__file__).parent/"models")
272
290
  self.models_path = Path(models_path)
273
291
  # Store initial preferences, but do not load/start server yet.
274
- self.initial_model_name_preference: Optional[str] = model_name
275
- self.user_provided_model_name: Optional[str] = model_name # Tracks the latest requested model
276
- self.initial_clip_model_name_preference: Optional[str] = clip_model_name
292
+ self.initial_model_name_preference: Optional[str] = kwargs.get("model_name")
293
+ self.user_provided_model_name: Optional[str] = kwargs.get("model_name") # Tracks the latest requested model
294
+ self.initial_clip_model_name_preference: Optional[str] = kwargs.get("clip_model_name")
277
295
 
278
296
  self._model_path_map: Dict[str, Path] = {} # Maps unique name to full Path
279
297
 
280
298
  # Initial scan for available models (to populate listModels)
281
299
  self._scan_models()
282
300
 
283
- self.default_completion_format = default_completion_format
284
- self.server_args = {**self.DEFAULT_SERVER_ARGS, **(config or {}), **kwargs}
301
+ self.default_completion_format = kwargs.get("default_completion_format", ELF_COMPLETION_FORMAT.Chat)
302
+ self.server_args = {**self.DEFAULT_SERVER_ARGS, **(kwargs.get("config") or {}), **kwargs}
285
303
  self.server_binary_path = self._get_server_binary_path()
286
304
 
287
305
  # Current state of the loaded model and server
@@ -26,11 +26,6 @@ class LollmsBinding(LollmsLLMBinding):
26
26
 
27
27
 
28
28
  def __init__(self,
29
- host_address: str = "http://localhost:9642", #This is the default local installation
30
- model_name: str = "",
31
- service_key: str|None = None, # a key generated on the lollms interface (it is advised to use LOLLMS_API_KEY environment variable instead)
32
- verify_ssl_certificate: bool = True,
33
- default_completion_format: ELF_COMPLETION_FORMAT = ELF_COMPLETION_FORMAT.Chat,
34
29
  **kwargs):
35
30
  """
36
31
  Initialize the OpenAI binding.
@@ -43,20 +38,35 @@ class LollmsBinding(LollmsLLMBinding):
43
38
  verify_ssl_certificate (bool): Whether to verify SSL certificates. Defaults to True.
44
39
  personality (Optional[int]): Ignored parameter for compatibility with LollmsLLMBinding.
45
40
  """
46
- super().__init__(
47
- binding_name = "openai",
48
- )
49
- self.host_address=host_address
50
- self.model_name=model_name
51
- self.service_key=service_key
52
- self.verify_ssl_certificate=verify_ssl_certificate
53
- self.default_completion_format=default_completion_format
41
+ super().__init__(BindingName, **kwargs)
42
+ self.host_address=kwargs.get("host_address","http://localhost:9642/v1").rstrip("/")
43
+ if not self.host_address.endswith("v1"):
44
+ self.host_address += "/v1"
45
+ self.model_name=kwargs.get("model_name")
46
+ self.service_key=kwargs.get("service_key")
47
+ self.verify_ssl_certificate=kwargs.get("verify_ssl_certificate", True)
48
+ self.default_completion_format=kwargs.get("default_completion_format", ELF_COMPLETION_FORMAT.Chat)
54
49
 
55
50
  if not self.service_key:
56
51
  self.service_key = os.getenv("LOLLMS_API_KEY", self.service_key)
57
- self.client = openai.OpenAI(api_key=self.service_key, base_url=None if host_address is None else host_address if len(host_address)>0 else None)
52
+ self.client = openai.OpenAI(api_key=self.service_key, base_url=None if self.host_address is None else self.host_address if len(self.host_address)>0 else None)
58
53
  self.completion_format = ELF_COMPLETION_FORMAT.Chat
59
54
 
55
+ def lollms_listMountedPersonalities(self, host_address:str|None=None):
56
+ host_address = host_address if host_address else self.host_address
57
+ url = f"{host_address}/list_mounted_personalities"
58
+
59
+ response = requests.get(url)
60
+
61
+ if response.status_code == 200:
62
+ try:
63
+ text = json.loads(response.content.decode("utf-8"))
64
+ return text
65
+ except Exception as ex:
66
+ return {"status": False, "error": str(ex)}
67
+ else:
68
+ return {"status": False, "error": response.text}
69
+
60
70
 
61
71
  def generate_text(self,
62
72
  prompt: str,
@@ -18,10 +18,6 @@ class LollmsWebuiLLMBinding(LollmsLLMBinding):
18
18
  DEFAULT_HOST_ADDRESS = "http://localhost:9600"
19
19
 
20
20
  def __init__(self,
21
- host_address: str = None,
22
- model_name: str = "",
23
- service_key: str = None,
24
- verify_ssl_certificate: bool = True,
25
21
  personality: Optional[int] = None,
26
22
  **kwargs
27
23
  ):
@@ -35,16 +31,14 @@ class LollmsWebuiLLMBinding(LollmsLLMBinding):
35
31
  verify_ssl_certificate (bool): Whether to verify SSL certificates. Defaults to True.
36
32
  personality (Optional[int]): Personality ID for generation. Defaults to None.
37
33
  """
38
- super().__init__(
39
- binding_name = "lollms"
40
- )
41
-
34
+ super().__init__(BindingName, **kwargs)
35
+ host_address = kwargs.get("host_address")
42
36
  self.host_address=host_address if host_address is not None else self.DEFAULT_HOST_ADDRESS
43
- self.model_name=model_name
44
- self.service_key=service_key
45
- self.verify_ssl_certificate=verify_ssl_certificate
37
+ self.model_name=kwargs.get("model_name")
38
+ self.service_key=kwargs.get("service_key")
39
+ self.verify_ssl_certificate=kwargs.get("verify_ssl_certificate")
46
40
  self.default_completion_format=kwargs.get("default_completion_format",ELF_COMPLETION_FORMAT.Chat)
47
- self.personality = personality
41
+ self.personality = kwargs.get("personality")
48
42
  self.model = None
49
43
 
50
44
  def generate_text(self,
@@ -27,8 +27,6 @@ class MistralBinding(LollmsLLMBinding):
27
27
  """
28
28
 
29
29
  def __init__(self,
30
- model_name: str = "mistral-large-latest",
31
- service_key: str|None = None,
32
30
  **kwargs
33
31
  ):
34
32
  """
@@ -38,9 +36,9 @@ class MistralBinding(LollmsLLMBinding):
38
36
  model_name (str): The name of the Mistral model to use.
39
37
  mistral_api_key (str): The API key for the Mistral service.
40
38
  """
41
- super().__init__(binding_name=BindingName)
42
- self.model_name = model_name
43
- self.mistral_api_key = service_key or os.getenv("MISTRAL_API_KEY")
39
+ super().__init__(BindingName, **kwargs)
40
+ self.model_name = kwargs.get("model_name","mistral-large-latest")
41
+ self.mistral_api_key = kwargs.get("service_key") or os.getenv("MISTRAL_API_KEY")
44
42
 
45
43
  if not self.mistral_api_key:
46
44
  raise ValueError("Mistral API key is required. Set it via 'mistral_api_key' or MISTRAL_API_KEY env var.")
@@ -67,10 +67,6 @@ class OllamaBinding(LollmsLLMBinding):
67
67
  DEFAULT_HOST_ADDRESS = "http://localhost:11434"
68
68
 
69
69
  def __init__(self,
70
- host_address: str = None,
71
- model_name: str = "",
72
- service_key: str = None,
73
- verify_ssl_certificate: bool = True,
74
70
  **kwargs
75
71
  ):
76
72
  """
@@ -83,14 +79,13 @@ class OllamaBinding(LollmsLLMBinding):
83
79
  verify_ssl_certificate (bool): Whether to verify SSL certificates. Defaults to True.
84
80
  default_completion_format (ELF_COMPLETION_FORMAT): Default completion format.
85
81
  """
82
+ host_address = kwargs.get("host_address")
86
83
  _host_address = host_address if host_address is not None else self.DEFAULT_HOST_ADDRESS
87
- super().__init__(
88
- binding_name=BindingName, # Use the module-level BindingName
89
- )
84
+ super().__init__(BindingName, **kwargs)
90
85
  self.host_address=_host_address
91
- self.model_name=model_name
92
- self.service_key=service_key
93
- self.verify_ssl_certificate=verify_ssl_certificate
86
+ self.model_name=kwargs.get("model_name")
87
+ self.service_key=kwargs.get("service_key")
88
+ self.verify_ssl_certificate=kwargs.get("verify_ssl_certificate", True)
94
89
  self.default_completion_format=kwargs.get("default_completion_format",ELF_COMPLETION_FORMAT.Chat)
95
90
 
96
91
  if ollama is None:
@@ -376,7 +371,7 @@ class OllamaBinding(LollmsLLMBinding):
376
371
  # 2. Build the generation options dictionary
377
372
  options = {
378
373
  'num_predict': n_predict,
379
- 'temperature': float(temperature),
374
+ 'temperature': float(temperature) if temperature else None,
380
375
  'top_k': top_k,
381
376
  'top_p': top_p,
382
377
  'repeat_penalty': repeat_penalty,
@@ -28,8 +28,6 @@ class OpenRouterBinding(LollmsLLMBinding):
28
28
  BASE_URL = "https://openrouter.ai/api/v1"
29
29
 
30
30
  def __init__(self,
31
- model_name: str = "google/gemini-flash-1.5", # A good, fast default
32
- service_key: str|None = None,
33
31
  **kwargs
34
32
  ):
35
33
  """
@@ -39,9 +37,9 @@ class OpenRouterBinding(LollmsLLMBinding):
39
37
  model_name (str): The name of the model to use from OpenRouter (e.g., 'anthropic/claude-3-haiku-20240307').
40
38
  service_key (str): The API key for the OpenRouter service.
41
39
  """
42
- super().__init__(binding_name=BindingName)
43
- self.model_name = model_name
44
- self.api_key = service_key or os.getenv("OPENROUTER_API_KEY")
40
+ super().__init__(BindingName, **kwargs)
41
+ self.model_name = kwargs.get("model_name","google/gemini-flash-1.5")
42
+ self.api_key = kwargs.get("service_key") or os.getenv("OPENROUTER_API_KEY")
45
43
 
46
44
  if not self.api_key:
47
45
  raise ValueError("OpenRouter API key is required. Set it via 'open_router_api_key' or OPENROUTER_API_KEY env var.")
@@ -154,7 +152,7 @@ class OpenRouterBinding(LollmsLLMBinding):
154
152
  response = self.client.chat.completions.create(
155
153
  model=self.model_name,
156
154
  messages=messages,
157
- stream=stream,
155
+ stream=stream if stream else False,
158
156
  **api_params
159
157
  )
160
158
 
@@ -27,11 +27,6 @@ class OpenAIBinding(LollmsLLMBinding):
27
27
 
28
28
 
29
29
  def __init__(self,
30
- host_address: str = None,
31
- model_name: str = "",
32
- service_key: str = None,
33
- verify_ssl_certificate: bool = True,
34
- default_completion_format: ELF_COMPLETION_FORMAT = ELF_COMPLETION_FORMAT.Chat,
35
30
  **kwargs):
36
31
  """
37
32
  Initialize the OpenAI binding.
@@ -43,18 +38,16 @@ class OpenAIBinding(LollmsLLMBinding):
43
38
  verify_ssl_certificate (bool): Whether to verify SSL certificates. Defaults to True.
44
39
  personality (Optional[int]): Ignored parameter for compatibility with LollmsLLMBinding.
45
40
  """
46
- super().__init__(
47
- binding_name = "openai",
48
- )
49
- self.host_address=host_address
50
- self.model_name=model_name
51
- self.service_key=service_key
52
- self.verify_ssl_certificate=verify_ssl_certificate
53
- self.default_completion_format=default_completion_format
41
+ super().__init__(BindingName, **kwargs)
42
+ self.host_address=kwargs.get("host_address")
43
+ self.model_name=kwargs.get("model_name")
44
+ self.service_key=kwargs.get("service_key")
45
+ self.verify_ssl_certificate=kwargs.get("verify_ssl_certificate", True)
46
+ self.default_completion_format=kwargs.get("default_completion_format", ELF_COMPLETION_FORMAT.Chat)
54
47
 
55
48
  if not self.service_key:
56
49
  self.service_key = os.getenv("OPENAI_API_KEY", self.service_key)
57
- self.client = openai.OpenAI(api_key=self.service_key, base_url=None if host_address is None else host_address if len(host_address)>0 else None)
50
+ self.client = openai.OpenAI(api_key=self.service_key, base_url=None if self.host_address is None else self.host_address if len(self.host_address)>0 else None)
58
51
  self.completion_format = ELF_COMPLETION_FORMAT.Chat
59
52
 
60
53
  def _build_openai_params(self, messages: list, **kwargs) -> dict:
@@ -61,23 +61,23 @@ class OpenLLMBinding(LollmsLLMBinding):
61
61
  DEFAULT_HOST_ADDRESS = "http://localhost:3000" # Default OpenLLM server address
62
62
 
63
63
  def __init__(self,
64
- host_address: str = None,
65
- model_name: str = "", # Informational, as client connects to specific model server
66
- # service_key and verify_ssl_certificate are not directly used by openllm.client.HTTPClient constructor
67
- # but kept for potential future extensions or custom client logic.
68
- service_key: Optional[str] = None,
69
- verify_ssl_certificate: bool = True,
70
- timeout: int = 120, # Timeout for client requests
71
64
  **kwargs
72
65
  ):
66
+ """ Initialize the OpenLLM binding.
67
+ Args:
68
+ host_address (str): The address of the OpenLLM server (default: http://localhost:3000).
69
+ model_name (str): The name of the model to connect to. This is primarily for informational purposes.
70
+ service_key (Optional[str]): Optional service key for authentication, not used by openllm client.
71
+ verify_ssl_certificate (bool): Whether to verify SSL certificates (default: True).
72
+ timeout (int): Timeout for client requests in seconds (default: 120).
73
+ """
74
+ host_address = kwargs.get("host_address")
73
75
  _host_address = host_address if host_address is not None else self.DEFAULT_HOST_ADDRESS
74
- super().__init__(
75
- binding_name=BindingName,
76
- )
76
+ super().__init__(BindingName, **kwargs)
77
77
  self.host_address = _host_address
78
- self.model_name = model_name # Can be set by load_model or from config
78
+ self.model_name = kwargs.get("model_name") # Can be set by load_model or from config
79
79
  self.default_completion_format=kwargs.get("default_completion_format",ELF_COMPLETION_FORMAT.Chat)
80
- self.timeout = timeout
80
+ self.timeout = kwargs.get("timeout")
81
81
 
82
82
  if openllm is None or openllm.client is None:
83
83
  raise ImportError("OpenLLM library is not installed or client module not found. Please run 'pip install openllm'.")
@@ -89,7 +89,7 @@ class PythonLlamaCppBinding(LollmsLLMBinding):
89
89
  **kwargs
90
90
  ):
91
91
 
92
- super().__init__(binding_name=BindingName)
92
+ super().__init__(BindingName, **kwargs)
93
93
 
94
94
  if Llama is None: # Check if import failed
95
95
  raise ImportError("Llama-cpp-python library is not available. Please install it.")
@@ -232,25 +232,20 @@ def resolve_hf_model_path(model_id_or_gguf_id: str, models_base_path: Path) -> P
232
232
  # --- VLLM Binding Class ---
233
233
  class VLLMBinding(LollmsLLMBinding):
234
234
  def __init__(self,
235
- models_folder: Optional[Union[str, Path]] = None,
236
- model_name: str = "",
237
- service_key: Optional[str] = None,
238
- verify_ssl_certificate: bool = True,
239
- default_completion_format: ELF_COMPLETION_FORMAT = ELF_COMPLETION_FORMAT.Chat,
240
235
  **kwargs
241
236
  ):
242
237
  if not _vllm_deps_installed:
243
238
  raise ImportError(f"vLLM or its dependencies not installed. Binding unusable. Error: {_vllm_installation_error}")
244
239
  if engine_manager is None:
245
240
  raise RuntimeError("VLLMEngineManager failed to initialize. Binding unusable.")
246
-
241
+ models_folder = kwargs.get("models_folder")
247
242
  _models_folder = Path(models_folder) if models_folder is not None else DEFAULT_models_folder
248
243
  _models_folder.mkdir(parents=True, exist_ok=True)
249
244
 
250
- super().__init__(BindingName)
251
- self.models_folder= models_folder
252
- self.model_name=model_name
253
- self.default_completion_format=default_completion_format
245
+ super().__init__(BindingName, **kwargs)
246
+ self.models_folder= _models_folder
247
+ self.model_name=kwargs.get("model_name", "")
248
+ self.default_completion_format=kwargs.get("default_completion_format", ELF_COMPLETION_FORMAT.Chat)
254
249
 
255
250
 
256
251
  self.models_folder: Path = _models_folder
@@ -261,11 +256,11 @@ class VLLMBinding(LollmsLLMBinding):
261
256
  self.current_engine_params: Optional[Dict[str, Any]] = None
262
257
  self.vllm_engine_kwargs_config = kwargs.copy()
263
258
 
264
- if model_name:
259
+ if self.model_name:
265
260
  try:
266
- self.load_model(model_name)
261
+ self.load_model(self.model_name)
267
262
  except Exception as e:
268
- ASCIIColors.error(f"Auto-load model '{model_name}' failed: {e}")
263
+ ASCIIColors.error(f"Auto-load model '{self.model_name}' failed: {e}")
269
264
  trace_exception(e)
270
265
 
271
266
  def _get_vllm_engine_params_for_load(self) -> Dict[str, Any]:
@@ -91,14 +91,22 @@ class HuggingFaceHubBinding(LollmsLLMBinding):
91
91
  }
92
92
 
93
93
  def __init__(self,
94
- model_name_or_id: str, # Can be HF Hub ID or local folder name relative to models_path
95
- models_path: Union[str, Path],
96
- config: Optional[Dict[str, Any]] = None,
97
- default_completion_format: ELF_COMPLETION_FORMAT = ELF_COMPLETION_FORMAT.Chat,
98
94
  **kwargs # Overrides for config_args
99
95
  ):
100
-
101
- super().__init__(binding_name=BindingName)
96
+ """
97
+ Initializes the Hugging Face Hub binding.
98
+ Args:
99
+ model_name (str): Hugging Face Hub model ID or local folder name.
100
+ models_path (str or Path): Path to the directory containing local models.
101
+ config (Optional[Dict[str, Any]]): Optional configuration dictionary to override defaults.
102
+ default_completion_format (ELF_COMPLETION_FORMAT): Default format for text generation.
103
+ """
104
+ super().__init__(BindingName, **kwargs)
105
+
106
+ model_name_or_id = kwargs.get("model_name")
107
+ models_path = kwargs.get("models_path")
108
+ config = kwargs.get("config")
109
+ default_completion_format = kwargs.get("default_completion_format", ELF_COMPLETION_FORMAT.Chat)
102
110
 
103
111
  if torch is None or transformers is None: # Check if core imports failed
104
112
  raise ImportError("Core libraries (torch, transformers) not available. Binding cannot function.")