lollms-client 0.25.6__tar.gz → 0.26.0__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.
Potentially problematic release.
This version of lollms-client might be problematic. Click here for more details.
- {lollms_client-0.25.6 → lollms_client-0.26.0}/PKG-INFO +265 -1
- {lollms_client-0.25.6 → lollms_client-0.26.0}/README.md +264 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/__init__.py +1 -1
- lollms_client-0.26.0/lollms_client/llm_bindings/azure_openai/__init__.py +364 -0
- lollms_client-0.26.0/lollms_client/llm_bindings/claude/__init__.py +549 -0
- lollms_client-0.26.0/lollms_client/llm_bindings/groq/__init__.py +292 -0
- lollms_client-0.26.0/lollms_client/llm_bindings/hugging_face_inference_api/__init__.py +307 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/llm_bindings/lollms/__init__.py +1 -0
- lollms_client-0.26.0/lollms_client/llm_bindings/mistral/__init__.py +298 -0
- lollms_client-0.26.0/lollms_client/llm_bindings/open_router/__init__.py +304 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/lollms_discussion.py +16 -20
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client.egg-info/PKG-INFO +265 -1
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client.egg-info/SOURCES.txt +6 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/LICENSE +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/article_summary/article_summary.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/console_discussion/console_app.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/console_discussion.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/deep_analyze/deep_analyse.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/deep_analyze/deep_analyze_multiple_files.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/function_calling_with_local_custom_mcp.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/generate_a_benchmark_for_safe_store.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/generate_and_speak/generate_and_speak.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/generate_game_sfx/generate_game_fx.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/generate_text_with_multihop_rag_example.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/gradio_chat_app.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/gradio_lollms_chat.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/internet_search_with_rag.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/lollms_discussions_test.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/mcp_examples/external_mcp.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/mcp_examples/local_mcp.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/mcp_examples/openai_mcp.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/mcp_examples/run_remote_mcp_example_v2.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/mcp_examples/run_standard_mcp_example.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/simple_text_gen_test.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/simple_text_gen_with_image_test.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/test_local_models/local_chat.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/text_2_audio.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/text_2_image.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/text_2_image_diffusers.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/text_and_image_2_audio.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/text_gen.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/examples/text_gen_system_prompt.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/llm_bindings/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/llm_bindings/gemini/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/llm_bindings/litellm/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/llm_bindings/llamacpp/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/llm_bindings/ollama/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/llm_bindings/openai/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/llm_bindings/openllm/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/llm_bindings/pythonllamacpp/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/llm_bindings/tensor_rt/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/llm_bindings/transformers/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/llm_bindings/vllm/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/lollms_config.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/lollms_core.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/lollms_js_analyzer.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/lollms_llm_binding.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/lollms_mcp_binding.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/lollms_personality.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/lollms_python_analyzer.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/lollms_stt_binding.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/lollms_tti_binding.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/lollms_ttm_binding.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/lollms_tts_binding.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/lollms_ttv_binding.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/lollms_types.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/lollms_utilities.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/mcp_bindings/local_mcp/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/mcp_bindings/local_mcp/default_tools/file_writer/file_writer.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/mcp_bindings/local_mcp/default_tools/generate_image_from_prompt/generate_image_from_prompt.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/mcp_bindings/local_mcp/default_tools/internet_search/internet_search.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/mcp_bindings/local_mcp/default_tools/python_interpreter/python_interpreter.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/mcp_bindings/remote_mcp/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/mcp_bindings/standard_mcp/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/stt_bindings/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/stt_bindings/lollms/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/stt_bindings/whisper/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/stt_bindings/whispercpp/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/tti_bindings/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/tti_bindings/dalle/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/tti_bindings/diffusers/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/tti_bindings/gemini/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/tti_bindings/lollms/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/ttm_bindings/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/ttm_bindings/audiocraft/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/ttm_bindings/bark/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/ttm_bindings/lollms/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/tts_bindings/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/tts_bindings/bark/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/tts_bindings/lollms/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/tts_bindings/piper_tts/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/tts_bindings/xtts/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/ttv_bindings/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client/ttv_bindings/lollms/__init__.py +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client.egg-info/dependency_links.txt +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client.egg-info/requires.txt +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/lollms_client.egg-info/top_level.txt +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/pyproject.toml +0 -0
- {lollms_client-0.25.6 → lollms_client-0.26.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: lollms_client
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.26.0
|
|
4
4
|
Summary: A client library for LoLLMs generate endpoint
|
|
5
5
|
Author-email: ParisNeo <parisneoai@gmail.com>
|
|
6
6
|
License: Apache Software License
|
|
@@ -327,6 +327,270 @@ The `examples/` directory in this repository contains a rich set of scripts demo
|
|
|
327
327
|
|
|
328
328
|
Explore these examples to see `lollms-client` in action!
|
|
329
329
|
|
|
330
|
+
## Using LoLLMs Client with Different Bindings
|
|
331
|
+
|
|
332
|
+
`lollms-client` supports a wide range of LLM backends through its binding system. This section provides practical examples of how to initialize `LollmsClient` for each of the major supported bindings.
|
|
333
|
+
|
|
334
|
+
### A Note on Configuration
|
|
335
|
+
|
|
336
|
+
The recommended way to provide credentials and other binding-specific settings is through the `llm_binding_config` dictionary during `LollmsClient` initialization. While many bindings can fall back to reading environment variables (e.g., `OPENAI_API_KEY`), passing them explicitly in the config is clearer and less error-prone.
|
|
337
|
+
|
|
338
|
+
```python
|
|
339
|
+
# General configuration pattern
|
|
340
|
+
lc = LollmsClient(
|
|
341
|
+
binding_name="your_binding_name",
|
|
342
|
+
model_name="a_model_name",
|
|
343
|
+
llm_binding_config={
|
|
344
|
+
"specific_api_key_param": "your_api_key_here",
|
|
345
|
+
"another_specific_param": "some_value"
|
|
346
|
+
}
|
|
347
|
+
)
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
### 1. Local Bindings
|
|
353
|
+
|
|
354
|
+
These bindings run models directly on your local machine, giving you full control and privacy.
|
|
355
|
+
|
|
356
|
+
#### **Ollama**
|
|
357
|
+
|
|
358
|
+
The `ollama` binding connects to a running Ollama server instance on your machine or network.
|
|
359
|
+
|
|
360
|
+
**Prerequisites:**
|
|
361
|
+
* [Ollama installed and running](https://ollama.com/).
|
|
362
|
+
* Models pulled, e.g., `ollama pull llama3`.
|
|
363
|
+
|
|
364
|
+
**Usage:**
|
|
365
|
+
|
|
366
|
+
```python
|
|
367
|
+
from lollms_client import LollmsClient
|
|
368
|
+
|
|
369
|
+
# Configuration for a local Ollama server
|
|
370
|
+
lc = LollmsClient(
|
|
371
|
+
binding_name="ollama",
|
|
372
|
+
model_name="llama3", # Or any other model you have pulled
|
|
373
|
+
host_address="http://localhost:11434" # Default Ollama address
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
# Now you can use lc.generate_text(), lc.chat(), etc.
|
|
377
|
+
response = lc.generate_text("Why is the sky blue?")
|
|
378
|
+
print(response)
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
#### **PythonLlamaCpp (Local GGUF Models)**
|
|
382
|
+
|
|
383
|
+
The `pythonllamacpp` binding loads and runs GGUF model files directly using the powerful `llama-cpp-python` library. This is ideal for high-performance, local inference on CPU or GPU.
|
|
384
|
+
|
|
385
|
+
**Prerequisites:**
|
|
386
|
+
* A GGUF model file downloaded to your machine.
|
|
387
|
+
* `llama-cpp-python` installed. For GPU support, it must be compiled with the correct flags (e.g., `CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python`).
|
|
388
|
+
|
|
389
|
+
**Usage:**
|
|
390
|
+
|
|
391
|
+
```python
|
|
392
|
+
from lollms_client import LollmsClient
|
|
393
|
+
|
|
394
|
+
# --- Configuration for Llama.cpp ---
|
|
395
|
+
# Path to your GGUF model file
|
|
396
|
+
MODEL_PATH = "/path/to/your/model.gguf"
|
|
397
|
+
|
|
398
|
+
# Binding-specific configuration
|
|
399
|
+
LLAMACPP_CONFIG = {
|
|
400
|
+
"n_gpu_layers": -1, # -1 for all layers to GPU, 0 for CPU
|
|
401
|
+
"n_ctx": 4096, # Context size
|
|
402
|
+
"seed": -1, # -1 for random seed
|
|
403
|
+
"chat_format": "chatml" # Or another format like 'llama-2'
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
try:
|
|
407
|
+
lc = LollmsClient(
|
|
408
|
+
binding_name="pythonllamacpp",
|
|
409
|
+
model_name=MODEL_PATH, # For this binding, model_name is the file path
|
|
410
|
+
llm_binding_config=LLAMACPP_CONFIG
|
|
411
|
+
)
|
|
412
|
+
|
|
413
|
+
response = lc.generate_text("Write a recipe for a great day.")
|
|
414
|
+
print(response)
|
|
415
|
+
|
|
416
|
+
except Exception as e:
|
|
417
|
+
print(f"Error initializing Llama.cpp binding: {e}")
|
|
418
|
+
print("Please ensure llama-cpp-python is installed and the model path is correct.")
|
|
419
|
+
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
---
|
|
423
|
+
|
|
424
|
+
### 2. Cloud Service Bindings
|
|
425
|
+
|
|
426
|
+
These bindings connect to hosted LLM APIs from major providers.
|
|
427
|
+
|
|
428
|
+
#### **OpenAI**
|
|
429
|
+
|
|
430
|
+
Connects to the official OpenAI API to use models like GPT-4o, GPT-4, and GPT-3.5.
|
|
431
|
+
|
|
432
|
+
**Prerequisites:**
|
|
433
|
+
* An OpenAI API key.
|
|
434
|
+
|
|
435
|
+
**Usage:**
|
|
436
|
+
|
|
437
|
+
```python
|
|
438
|
+
from lollms_client import LollmsClient
|
|
439
|
+
|
|
440
|
+
OPENAI_CONFIG = {
|
|
441
|
+
"service_key": "your_openai_api_key_here" # sk-...
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
lc = LollmsClient(
|
|
445
|
+
binding_name="openai",
|
|
446
|
+
model_name="gpt-4o",
|
|
447
|
+
llm_binding_config=OPENAI_CONFIG
|
|
448
|
+
)
|
|
449
|
+
|
|
450
|
+
response = lc.generate_text("What is the difference between AI and machine learning?")
|
|
451
|
+
print(response)
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
#### **Google Gemini**
|
|
455
|
+
|
|
456
|
+
Connects to Google's Gemini family of models via the Google AI Studio API.
|
|
457
|
+
|
|
458
|
+
**Prerequisites:**
|
|
459
|
+
* A Google AI Studio API key.
|
|
460
|
+
|
|
461
|
+
**Usage:**
|
|
462
|
+
|
|
463
|
+
```python
|
|
464
|
+
from lollms_client import LollmsClient
|
|
465
|
+
|
|
466
|
+
GEMINI_CONFIG = {
|
|
467
|
+
"service_key": "your_google_api_key_here"
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
lc = LollmsClient(
|
|
471
|
+
binding_name="gemini",
|
|
472
|
+
model_name="gemini-1.5-pro-latest",
|
|
473
|
+
llm_binding_config=GEMINI_CONFIG
|
|
474
|
+
)
|
|
475
|
+
|
|
476
|
+
response = lc.generate_text("Summarize the plot of 'Dune' in three sentences.")
|
|
477
|
+
print(response)
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
#### **Anthropic Claude**
|
|
481
|
+
|
|
482
|
+
Connects to Anthropic's API to use the Claude family of models, including Claude 3.5 Sonnet, Opus, and Haiku.
|
|
483
|
+
|
|
484
|
+
**Prerequisites:**
|
|
485
|
+
* An Anthropic API key.
|
|
486
|
+
|
|
487
|
+
**Usage:**
|
|
488
|
+
|
|
489
|
+
```python
|
|
490
|
+
from lollms_client import LollmsClient
|
|
491
|
+
|
|
492
|
+
CLAUDE_CONFIG = {
|
|
493
|
+
"service_key": "your_anthropic_api_key_here"
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
lc = LollmsClient(
|
|
497
|
+
binding_name="claude",
|
|
498
|
+
model_name="claude-3-5-sonnet-20240620",
|
|
499
|
+
llm_binding_config=CLAUDE_CONFIG
|
|
500
|
+
)
|
|
501
|
+
|
|
502
|
+
response = lc.generate_text("What are the core principles of constitutional AI?")
|
|
503
|
+
print(response)
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
---
|
|
507
|
+
|
|
508
|
+
### 3. API Aggregator Bindings
|
|
509
|
+
|
|
510
|
+
These bindings connect to services that provide access to many different models through a single API.
|
|
511
|
+
|
|
512
|
+
#### **OpenRouter**
|
|
513
|
+
|
|
514
|
+
OpenRouter provides a unified, OpenAI-compatible interface to access models from dozens of providers (Google, Anthropic, Mistral, Groq, etc.) with one API key.
|
|
515
|
+
|
|
516
|
+
**Prerequisites:**
|
|
517
|
+
* An OpenRouter API key (starts with `sk-or-...`).
|
|
518
|
+
|
|
519
|
+
**Usage:**
|
|
520
|
+
Model names must be specified in the format `provider/model-name`.
|
|
521
|
+
|
|
522
|
+
```python
|
|
523
|
+
from lollms_client import LollmsClient
|
|
524
|
+
|
|
525
|
+
OPENROUTER_CONFIG = {
|
|
526
|
+
"open_router_api_key": "your_openrouter_api_key_here"
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
# Example using a Claude model through OpenRouter
|
|
530
|
+
lc = LollmsClient(
|
|
531
|
+
binding_name="open_router",
|
|
532
|
+
model_name="anthropic/claude-3-haiku-20240307",
|
|
533
|
+
llm_binding_config=OPENROUTER_CONFIG
|
|
534
|
+
)
|
|
535
|
+
|
|
536
|
+
response = lc.generate_text("Explain what an API aggregator is, as if to a beginner.")
|
|
537
|
+
print(response)
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
#### **Groq**
|
|
541
|
+
|
|
542
|
+
While Groq is a direct provider, it's famous as an aggregator of speed. It runs open-source models on custom LPU hardware for exceptionally fast inference.
|
|
543
|
+
|
|
544
|
+
**Prerequisites:**
|
|
545
|
+
* A Groq API key.
|
|
546
|
+
|
|
547
|
+
**Usage:**
|
|
548
|
+
|
|
549
|
+
```python
|
|
550
|
+
from lollms_client import LollmsClient
|
|
551
|
+
|
|
552
|
+
GROQ_CONFIG = {
|
|
553
|
+
"groq_api_key": "your_groq_api_key_here"
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
lc = LollmsClient(
|
|
557
|
+
binding_name="groq",
|
|
558
|
+
model_name="llama3-8b-8192",
|
|
559
|
+
llm_binding_config=GROQ_CONFIG
|
|
560
|
+
)
|
|
561
|
+
|
|
562
|
+
response = lc.generate_text("Write a 3-line poem about incredible speed.")
|
|
563
|
+
print(response)
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
#### **Hugging Face Inference API**
|
|
567
|
+
|
|
568
|
+
This connects to the serverless Hugging Face Inference API, allowing experimentation with thousands of open-source models without local hardware.
|
|
569
|
+
|
|
570
|
+
**Note:** This API can have "cold starts," so the first request might be slow.
|
|
571
|
+
|
|
572
|
+
**Prerequisites:**
|
|
573
|
+
* A Hugging Face User Access Token (starts with `hf_...`).
|
|
574
|
+
|
|
575
|
+
**Usage:**
|
|
576
|
+
|
|
577
|
+
```python
|
|
578
|
+
from lollms_client import LollmsClient
|
|
579
|
+
|
|
580
|
+
HF_CONFIG = {
|
|
581
|
+
"hf_api_key": "your_hugging_face_token_here"
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
lc = LollmsClient(
|
|
585
|
+
binding_name="hugging_face_inference_api",
|
|
586
|
+
model_name="google/gemma-1.1-7b-it",
|
|
587
|
+
llm_binding_config=HF_CONFIG
|
|
588
|
+
)
|
|
589
|
+
|
|
590
|
+
response = lc.generate_text("Write a short story about a robot who discovers music.")
|
|
591
|
+
print(response)
|
|
592
|
+
```
|
|
593
|
+
|
|
330
594
|
## Contributing
|
|
331
595
|
|
|
332
596
|
Contributions are welcome! Whether it's bug reports, feature suggestions, documentation improvements, or new bindings, please feel free to open an issue or submit a pull request on our [GitHub repository](https://github.com/ParisNeo/lollms_client).
|
|
@@ -296,6 +296,270 @@ The `examples/` directory in this repository contains a rich set of scripts demo
|
|
|
296
296
|
|
|
297
297
|
Explore these examples to see `lollms-client` in action!
|
|
298
298
|
|
|
299
|
+
## Using LoLLMs Client with Different Bindings
|
|
300
|
+
|
|
301
|
+
`lollms-client` supports a wide range of LLM backends through its binding system. This section provides practical examples of how to initialize `LollmsClient` for each of the major supported bindings.
|
|
302
|
+
|
|
303
|
+
### A Note on Configuration
|
|
304
|
+
|
|
305
|
+
The recommended way to provide credentials and other binding-specific settings is through the `llm_binding_config` dictionary during `LollmsClient` initialization. While many bindings can fall back to reading environment variables (e.g., `OPENAI_API_KEY`), passing them explicitly in the config is clearer and less error-prone.
|
|
306
|
+
|
|
307
|
+
```python
|
|
308
|
+
# General configuration pattern
|
|
309
|
+
lc = LollmsClient(
|
|
310
|
+
binding_name="your_binding_name",
|
|
311
|
+
model_name="a_model_name",
|
|
312
|
+
llm_binding_config={
|
|
313
|
+
"specific_api_key_param": "your_api_key_here",
|
|
314
|
+
"another_specific_param": "some_value"
|
|
315
|
+
}
|
|
316
|
+
)
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
### 1. Local Bindings
|
|
322
|
+
|
|
323
|
+
These bindings run models directly on your local machine, giving you full control and privacy.
|
|
324
|
+
|
|
325
|
+
#### **Ollama**
|
|
326
|
+
|
|
327
|
+
The `ollama` binding connects to a running Ollama server instance on your machine or network.
|
|
328
|
+
|
|
329
|
+
**Prerequisites:**
|
|
330
|
+
* [Ollama installed and running](https://ollama.com/).
|
|
331
|
+
* Models pulled, e.g., `ollama pull llama3`.
|
|
332
|
+
|
|
333
|
+
**Usage:**
|
|
334
|
+
|
|
335
|
+
```python
|
|
336
|
+
from lollms_client import LollmsClient
|
|
337
|
+
|
|
338
|
+
# Configuration for a local Ollama server
|
|
339
|
+
lc = LollmsClient(
|
|
340
|
+
binding_name="ollama",
|
|
341
|
+
model_name="llama3", # Or any other model you have pulled
|
|
342
|
+
host_address="http://localhost:11434" # Default Ollama address
|
|
343
|
+
)
|
|
344
|
+
|
|
345
|
+
# Now you can use lc.generate_text(), lc.chat(), etc.
|
|
346
|
+
response = lc.generate_text("Why is the sky blue?")
|
|
347
|
+
print(response)
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
#### **PythonLlamaCpp (Local GGUF Models)**
|
|
351
|
+
|
|
352
|
+
The `pythonllamacpp` binding loads and runs GGUF model files directly using the powerful `llama-cpp-python` library. This is ideal for high-performance, local inference on CPU or GPU.
|
|
353
|
+
|
|
354
|
+
**Prerequisites:**
|
|
355
|
+
* A GGUF model file downloaded to your machine.
|
|
356
|
+
* `llama-cpp-python` installed. For GPU support, it must be compiled with the correct flags (e.g., `CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python`).
|
|
357
|
+
|
|
358
|
+
**Usage:**
|
|
359
|
+
|
|
360
|
+
```python
|
|
361
|
+
from lollms_client import LollmsClient
|
|
362
|
+
|
|
363
|
+
# --- Configuration for Llama.cpp ---
|
|
364
|
+
# Path to your GGUF model file
|
|
365
|
+
MODEL_PATH = "/path/to/your/model.gguf"
|
|
366
|
+
|
|
367
|
+
# Binding-specific configuration
|
|
368
|
+
LLAMACPP_CONFIG = {
|
|
369
|
+
"n_gpu_layers": -1, # -1 for all layers to GPU, 0 for CPU
|
|
370
|
+
"n_ctx": 4096, # Context size
|
|
371
|
+
"seed": -1, # -1 for random seed
|
|
372
|
+
"chat_format": "chatml" # Or another format like 'llama-2'
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
try:
|
|
376
|
+
lc = LollmsClient(
|
|
377
|
+
binding_name="pythonllamacpp",
|
|
378
|
+
model_name=MODEL_PATH, # For this binding, model_name is the file path
|
|
379
|
+
llm_binding_config=LLAMACPP_CONFIG
|
|
380
|
+
)
|
|
381
|
+
|
|
382
|
+
response = lc.generate_text("Write a recipe for a great day.")
|
|
383
|
+
print(response)
|
|
384
|
+
|
|
385
|
+
except Exception as e:
|
|
386
|
+
print(f"Error initializing Llama.cpp binding: {e}")
|
|
387
|
+
print("Please ensure llama-cpp-python is installed and the model path is correct.")
|
|
388
|
+
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
---
|
|
392
|
+
|
|
393
|
+
### 2. Cloud Service Bindings
|
|
394
|
+
|
|
395
|
+
These bindings connect to hosted LLM APIs from major providers.
|
|
396
|
+
|
|
397
|
+
#### **OpenAI**
|
|
398
|
+
|
|
399
|
+
Connects to the official OpenAI API to use models like GPT-4o, GPT-4, and GPT-3.5.
|
|
400
|
+
|
|
401
|
+
**Prerequisites:**
|
|
402
|
+
* An OpenAI API key.
|
|
403
|
+
|
|
404
|
+
**Usage:**
|
|
405
|
+
|
|
406
|
+
```python
|
|
407
|
+
from lollms_client import LollmsClient
|
|
408
|
+
|
|
409
|
+
OPENAI_CONFIG = {
|
|
410
|
+
"service_key": "your_openai_api_key_here" # sk-...
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
lc = LollmsClient(
|
|
414
|
+
binding_name="openai",
|
|
415
|
+
model_name="gpt-4o",
|
|
416
|
+
llm_binding_config=OPENAI_CONFIG
|
|
417
|
+
)
|
|
418
|
+
|
|
419
|
+
response = lc.generate_text("What is the difference between AI and machine learning?")
|
|
420
|
+
print(response)
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
#### **Google Gemini**
|
|
424
|
+
|
|
425
|
+
Connects to Google's Gemini family of models via the Google AI Studio API.
|
|
426
|
+
|
|
427
|
+
**Prerequisites:**
|
|
428
|
+
* A Google AI Studio API key.
|
|
429
|
+
|
|
430
|
+
**Usage:**
|
|
431
|
+
|
|
432
|
+
```python
|
|
433
|
+
from lollms_client import LollmsClient
|
|
434
|
+
|
|
435
|
+
GEMINI_CONFIG = {
|
|
436
|
+
"service_key": "your_google_api_key_here"
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
lc = LollmsClient(
|
|
440
|
+
binding_name="gemini",
|
|
441
|
+
model_name="gemini-1.5-pro-latest",
|
|
442
|
+
llm_binding_config=GEMINI_CONFIG
|
|
443
|
+
)
|
|
444
|
+
|
|
445
|
+
response = lc.generate_text("Summarize the plot of 'Dune' in three sentences.")
|
|
446
|
+
print(response)
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
#### **Anthropic Claude**
|
|
450
|
+
|
|
451
|
+
Connects to Anthropic's API to use the Claude family of models, including Claude 3.5 Sonnet, Opus, and Haiku.
|
|
452
|
+
|
|
453
|
+
**Prerequisites:**
|
|
454
|
+
* An Anthropic API key.
|
|
455
|
+
|
|
456
|
+
**Usage:**
|
|
457
|
+
|
|
458
|
+
```python
|
|
459
|
+
from lollms_client import LollmsClient
|
|
460
|
+
|
|
461
|
+
CLAUDE_CONFIG = {
|
|
462
|
+
"service_key": "your_anthropic_api_key_here"
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
lc = LollmsClient(
|
|
466
|
+
binding_name="claude",
|
|
467
|
+
model_name="claude-3-5-sonnet-20240620",
|
|
468
|
+
llm_binding_config=CLAUDE_CONFIG
|
|
469
|
+
)
|
|
470
|
+
|
|
471
|
+
response = lc.generate_text("What are the core principles of constitutional AI?")
|
|
472
|
+
print(response)
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
---
|
|
476
|
+
|
|
477
|
+
### 3. API Aggregator Bindings
|
|
478
|
+
|
|
479
|
+
These bindings connect to services that provide access to many different models through a single API.
|
|
480
|
+
|
|
481
|
+
#### **OpenRouter**
|
|
482
|
+
|
|
483
|
+
OpenRouter provides a unified, OpenAI-compatible interface to access models from dozens of providers (Google, Anthropic, Mistral, Groq, etc.) with one API key.
|
|
484
|
+
|
|
485
|
+
**Prerequisites:**
|
|
486
|
+
* An OpenRouter API key (starts with `sk-or-...`).
|
|
487
|
+
|
|
488
|
+
**Usage:**
|
|
489
|
+
Model names must be specified in the format `provider/model-name`.
|
|
490
|
+
|
|
491
|
+
```python
|
|
492
|
+
from lollms_client import LollmsClient
|
|
493
|
+
|
|
494
|
+
OPENROUTER_CONFIG = {
|
|
495
|
+
"open_router_api_key": "your_openrouter_api_key_here"
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
# Example using a Claude model through OpenRouter
|
|
499
|
+
lc = LollmsClient(
|
|
500
|
+
binding_name="open_router",
|
|
501
|
+
model_name="anthropic/claude-3-haiku-20240307",
|
|
502
|
+
llm_binding_config=OPENROUTER_CONFIG
|
|
503
|
+
)
|
|
504
|
+
|
|
505
|
+
response = lc.generate_text("Explain what an API aggregator is, as if to a beginner.")
|
|
506
|
+
print(response)
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
#### **Groq**
|
|
510
|
+
|
|
511
|
+
While Groq is a direct provider, it's famous as an aggregator of speed. It runs open-source models on custom LPU hardware for exceptionally fast inference.
|
|
512
|
+
|
|
513
|
+
**Prerequisites:**
|
|
514
|
+
* A Groq API key.
|
|
515
|
+
|
|
516
|
+
**Usage:**
|
|
517
|
+
|
|
518
|
+
```python
|
|
519
|
+
from lollms_client import LollmsClient
|
|
520
|
+
|
|
521
|
+
GROQ_CONFIG = {
|
|
522
|
+
"groq_api_key": "your_groq_api_key_here"
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
lc = LollmsClient(
|
|
526
|
+
binding_name="groq",
|
|
527
|
+
model_name="llama3-8b-8192",
|
|
528
|
+
llm_binding_config=GROQ_CONFIG
|
|
529
|
+
)
|
|
530
|
+
|
|
531
|
+
response = lc.generate_text("Write a 3-line poem about incredible speed.")
|
|
532
|
+
print(response)
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
#### **Hugging Face Inference API**
|
|
536
|
+
|
|
537
|
+
This connects to the serverless Hugging Face Inference API, allowing experimentation with thousands of open-source models without local hardware.
|
|
538
|
+
|
|
539
|
+
**Note:** This API can have "cold starts," so the first request might be slow.
|
|
540
|
+
|
|
541
|
+
**Prerequisites:**
|
|
542
|
+
* A Hugging Face User Access Token (starts with `hf_...`).
|
|
543
|
+
|
|
544
|
+
**Usage:**
|
|
545
|
+
|
|
546
|
+
```python
|
|
547
|
+
from lollms_client import LollmsClient
|
|
548
|
+
|
|
549
|
+
HF_CONFIG = {
|
|
550
|
+
"hf_api_key": "your_hugging_face_token_here"
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
lc = LollmsClient(
|
|
554
|
+
binding_name="hugging_face_inference_api",
|
|
555
|
+
model_name="google/gemma-1.1-7b-it",
|
|
556
|
+
llm_binding_config=HF_CONFIG
|
|
557
|
+
)
|
|
558
|
+
|
|
559
|
+
response = lc.generate_text("Write a short story about a robot who discovers music.")
|
|
560
|
+
print(response)
|
|
561
|
+
```
|
|
562
|
+
|
|
299
563
|
## Contributing
|
|
300
564
|
|
|
301
565
|
Contributions are welcome! Whether it's bug reports, feature suggestions, documentation improvements, or new bindings, please feel free to open an issue or submit a pull request on our [GitHub repository](https://github.com/ParisNeo/lollms_client).
|
|
@@ -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
|
|
|
10
10
|
|
|
11
|
-
__version__ = "0.
|
|
11
|
+
__version__ = "0.26.0" # Updated version
|
|
12
12
|
|
|
13
13
|
# Optionally, you could define __all__ if you want to be explicit about exports
|
|
14
14
|
__all__ = [
|