lollms-client 0.19.0__tar.gz → 0.19.5__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.19.0 → lollms_client-0.19.5}/PKG-INFO +71 -16
- {lollms_client-0.19.0 → lollms_client-0.19.5}/README.md +70 -15
- lollms_client-0.19.5/examples/generate_text_with_multihop_rag_example.py +211 -0
- lollms_client-0.19.5/examples/internet_search_with_rag.py +189 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/__init__.py +1 -1
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/lollms_core.py +238 -1
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client.egg-info/PKG-INFO +71 -16
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client.egg-info/SOURCES.txt +2 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/LICENSE +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/examples/article_summary/article_summary.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/examples/deep_analyze/deep_analyse.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/examples/deep_analyze/deep_analyze_multiple_files.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/examples/function_calling_with_local_custom_mcp.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/examples/generate_and_speak/generate_and_speak.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/examples/generate_game_sfx/generate_game_fx.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/examples/local_mcp.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/examples/personality_test/chat_test.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/examples/personality_test/chat_with_aristotle.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/examples/personality_test/tesks_test.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/examples/simple_text_gen_test.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/examples/simple_text_gen_with_image_test.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/examples/test_local_models/local_chat.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/examples/text_2_audio.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/examples/text_2_image.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/examples/text_2_image_diffusers.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/examples/text_and_image_2_audio.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/examples/text_gen.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/examples/text_gen_system_prompt.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/llm_bindings/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/llm_bindings/llamacpp/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/llm_bindings/lollms/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/llm_bindings/ollama/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/llm_bindings/openai/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/llm_bindings/openllm/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/llm_bindings/pythonllamacpp/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/llm_bindings/tensor_rt/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/llm_bindings/transformers/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/llm_bindings/vllm/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/lollms_config.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/lollms_discussion.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/lollms_js_analyzer.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/lollms_llm_binding.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/lollms_mcp_binding.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/lollms_python_analyzer.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/lollms_stt_binding.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/lollms_tti_binding.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/lollms_ttm_binding.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/lollms_tts_binding.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/lollms_ttv_binding.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/lollms_types.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/lollms_utilities.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/mcp_bindings/local_mcp/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/mcp_bindings/local_mcp/default_tools/file_writer/file_writer.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/mcp_bindings/local_mcp/default_tools/generate_image_from_prompt/generate_image_from_prompt.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/mcp_bindings/local_mcp/default_tools/internet_search/internet_search.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/mcp_bindings/local_mcp/default_tools/python_interpreter/python_interpreter.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/stt_bindings/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/stt_bindings/lollms/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/stt_bindings/whisper/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/stt_bindings/whispercpp/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/tti_bindings/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/tti_bindings/dalle/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/tti_bindings/diffusers/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/tti_bindings/gemini/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/tti_bindings/lollms/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/ttm_bindings/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/ttm_bindings/audiocraft/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/ttm_bindings/bark/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/ttm_bindings/lollms/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/tts_bindings/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/tts_bindings/bark/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/tts_bindings/lollms/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/tts_bindings/piper_tts/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/tts_bindings/xtts/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/ttv_bindings/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client/ttv_bindings/lollms/__init__.py +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client.egg-info/dependency_links.txt +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client.egg-info/requires.txt +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/lollms_client.egg-info/top_level.txt +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/pyproject.toml +0 -0
- {lollms_client-0.19.0 → lollms_client-0.19.5}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: lollms_client
|
|
3
|
-
Version: 0.19.
|
|
3
|
+
Version: 0.19.5
|
|
4
4
|
Summary: A client library for LoLLMs generate endpoint
|
|
5
5
|
Author-email: ParisNeo <parisneoai@gmail.com>
|
|
6
6
|
License: Apache Software License
|
|
@@ -39,7 +39,7 @@ Dynamic: license-file
|
|
|
39
39
|
[](https://github.com/ParisNeo/lollms_client/stargazers/)
|
|
40
40
|
[](https://github.com/ParisNeo/lollms_client/issues)
|
|
41
41
|
|
|
42
|
-
**`lollms_client`** is a powerful and flexible Python library designed to simplify interactions with the **LoLLMs (Lord of Large Language Models)** ecosystem and various other Large Language Model (LLM) backends. It provides a unified API for text generation, multimodal operations (text-to-image, text-to-speech, etc.), function calling
|
|
42
|
+
**`lollms_client`** is a powerful and flexible Python library designed to simplify interactions with the **LoLLMs (Lord of Large Language Models)** ecosystem and various other Large Language Model (LLM) backends. It provides a unified API for text generation, multimodal operations (text-to-image, text-to-speech, etc.), and robust function calling through the Model Context Protocol (MCP).
|
|
43
43
|
|
|
44
44
|
Whether you're connecting to a remote LoLLMs server, an Ollama instance, the OpenAI API, or running models locally using GGUF (via `llama-cpp-python` or a managed `llama.cpp` server), Hugging Face Transformers, or vLLM, `lollms-client` offers a consistent and developer-friendly experience.
|
|
45
45
|
|
|
@@ -47,12 +47,12 @@ Whether you're connecting to a remote LoLLMs server, an Ollama instance, the Ope
|
|
|
47
47
|
|
|
48
48
|
* 🔌 **Versatile Binding System:** Seamlessly switch between different LLM backends (LoLLMs, Ollama, OpenAI, Llama.cpp, Transformers, vLLM, OpenLLM) without major code changes.
|
|
49
49
|
* 🗣️ **Multimodal Support:** Interact with models capable of processing images and generate various outputs like speech (TTS) and images (TTI).
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* 📞 **Function Calling:** Enable LLMs to invoke your custom Python functions, bridging the gap between language models and external tools or data sources.
|
|
50
|
+
* 🤖 **Function Calling with MCP:** Empowers LLMs to use external tools and functions through the Model Context Protocol (MCP), with built-in support for local Python tool execution via `local_mcp` binding and its default tools (file I/O, internet search, Python interpreter, image generation).
|
|
51
|
+
* 🚀 **Streaming & Callbacks:** Efficiently handle real-time text generation with customizable callback functions, including during MCP interactions.
|
|
53
52
|
* 💬 **Discussion Management:** Utilities to easily manage and format conversation histories for chat applications.
|
|
54
53
|
* ⚙️ **Configuration Management:** Flexible ways to configure bindings and generation parameters.
|
|
55
|
-
* 🧩 **Extensible:** Designed to easily incorporate new LLM backends and modality services.
|
|
54
|
+
* 🧩 **Extensible:** Designed to easily incorporate new LLM backends and modality services, including custom MCP toolsets.
|
|
55
|
+
* 📝 **High-Level Operations:** Includes convenience methods for complex tasks like sequential summarization and deep text analysis directly within `LollmsClient`.
|
|
56
56
|
|
|
57
57
|
## Installation
|
|
58
58
|
|
|
@@ -119,12 +119,61 @@ except Exception as e:
|
|
|
119
119
|
|
|
120
120
|
```
|
|
121
121
|
|
|
122
|
+
### Function Calling with MCP
|
|
123
|
+
|
|
124
|
+
`lollms-client` supports robust function calling via the Model Context Protocol (MCP), allowing LLMs to interact with your custom Python tools or pre-defined utilities.
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
from lollms_client import LollmsClient, MSG_TYPE
|
|
128
|
+
from ascii_colors import ASCIIColors
|
|
129
|
+
import json # For pretty printing results
|
|
130
|
+
|
|
131
|
+
# Example callback for MCP streaming
|
|
132
|
+
def mcp_stream_callback(chunk: str, msg_type: MSG_TYPE, metadata: dict = None, turn_history: list = None) -> bool:
|
|
133
|
+
if msg_type == MSG_TYPE.MSG_TYPE_CHUNK: ASCIIColors.success(chunk, end="", flush=True) # LLM's final answer or thought process
|
|
134
|
+
elif msg_type == MSG_TYPE.MSG_TYPE_STEP_START: ASCIIColors.info(f"\n>> MCP Step Start: {metadata.get('tool_name', chunk)}", flush=True)
|
|
135
|
+
elif msg_type == MSG_TYPE.MSG_TYPE_STEP_END: ASCIIColors.success(f"\n<< MCP Step End: {metadata.get('tool_name', chunk)} -> Result: {json.dumps(metadata.get('result', ''))}", flush=True)
|
|
136
|
+
elif msg_type == MSG_TYPE.MSG_TYPE_INFO and metadata and metadata.get("type") == "tool_call_request": ASCIIColors.info(f"\nAI requests: {metadata.get('name')}({metadata.get('params')})", flush=True)
|
|
137
|
+
return True
|
|
138
|
+
|
|
139
|
+
try:
|
|
140
|
+
# Initialize LollmsClient with an LLM binding and the local_mcp binding
|
|
141
|
+
lc = LollmsClient(
|
|
142
|
+
binding_name="ollama", model_name="mistral", # Example LLM
|
|
143
|
+
mcp_binding_name="local_mcp" # Enables default tools (file_writer, internet_search, etc.)
|
|
144
|
+
# or custom tools if mcp_binding_config.tools_folder_path is set.
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
user_query = "What were the main AI headlines last week and write a summary to 'ai_news.txt'?"
|
|
148
|
+
ASCIIColors.blue(f"User Query: {user_query}")
|
|
149
|
+
ASCIIColors.yellow("AI Processing with MCP (streaming):")
|
|
150
|
+
|
|
151
|
+
mcp_result = lc.generate_with_mcp(
|
|
152
|
+
prompt=user_query,
|
|
153
|
+
streaming_callback=mcp_stream_callback
|
|
154
|
+
)
|
|
155
|
+
print("\n--- End of MCP Interaction ---")
|
|
156
|
+
|
|
157
|
+
if mcp_result.get("error"):
|
|
158
|
+
ASCIIColors.error(f"MCP Error: {mcp_result['error']}")
|
|
159
|
+
else:
|
|
160
|
+
ASCIIColors.cyan(f"\nFinal Answer from AI: {mcp_result.get('final_answer', 'N/A')}")
|
|
161
|
+
ASCIIColors.magenta("\nTool Calls Made:")
|
|
162
|
+
for tc in mcp_result.get("tool_calls", []):
|
|
163
|
+
print(f" - Tool: {tc.get('name')}, Params: {tc.get('params')}, Result (first 50 chars): {str(tc.get('result'))[:50]}...")
|
|
164
|
+
|
|
165
|
+
except Exception as e:
|
|
166
|
+
ASCIIColors.error(f"An error occurred in MCP example: {e}")
|
|
167
|
+
trace_exception(e) # Assuming you have trace_exception utility
|
|
168
|
+
```
|
|
169
|
+
For a comprehensive guide on function calling and setting up tools, please refer to the [Usage Guide (DOC_USE.md)](DOC_USE.md).
|
|
170
|
+
|
|
122
171
|
## Documentation
|
|
123
172
|
|
|
124
173
|
For more in-depth information, please refer to:
|
|
125
174
|
|
|
126
|
-
* **[Usage Guide (DOC_USE.md)](DOC_USE.md):** Learn how to use `LollmsClient`, different bindings, modality features,
|
|
127
|
-
* **[Developer Guide (DOC_DEV.md)](DOC_DEV.md):** Understand the architecture, how to create new bindings, and contribute to the library.
|
|
175
|
+
* **[Usage Guide (DOC_USE.md)](DOC_USE.md):** Learn how to use `LollmsClient`, different bindings, modality features, function calling with MCP, and high-level operations.
|
|
176
|
+
* **[Developer Guide (DOC_DEV.md)](DOC_DEV.md):** Understand the architecture, how to create new bindings (LLM, modality, MCP), and contribute to the library.
|
|
128
177
|
|
|
129
178
|
## Core Concepts
|
|
130
179
|
|
|
@@ -134,8 +183,9 @@ graph LR
|
|
|
134
183
|
|
|
135
184
|
subgraph LollmsClient_Core
|
|
136
185
|
LC -- Manages --> LLB[LLM Binding];
|
|
137
|
-
LC --
|
|
138
|
-
LC --
|
|
186
|
+
LC -- Manages --> MCPB[MCP Binding];
|
|
187
|
+
LC -- Orchestrates --> MCP_Interaction[generate_with_mcp];
|
|
188
|
+
LC -- Provides --> HighLevelOps[High-Level Ops<br>(summarize, deep_analyze etc.)];
|
|
139
189
|
LC -- Provides Access To --> DM[DiscussionManager];
|
|
140
190
|
LC -- Provides Access To --> ModalityBindings[TTS, TTI, STT etc.];
|
|
141
191
|
end
|
|
@@ -148,14 +198,19 @@ graph LR
|
|
|
148
198
|
LLB --> LocalHF[Local HuggingFace<br>(transformers / vLLM)];
|
|
149
199
|
end
|
|
150
200
|
|
|
151
|
-
|
|
201
|
+
MCP_Interaction --> MCPB;
|
|
202
|
+
MCPB --> LocalTools[Local Python Tools<br>(via local_mcp)];
|
|
203
|
+
MCPB --> RemoteTools[Remote MCP Tool Servers<br>(Future Potential)];
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
ModalityBindings --> ModalityServices[Modality Services<br>(e.g., LoLLMs Server TTS/TTI, local Bark/XTTS)];
|
|
152
207
|
```
|
|
153
208
|
|
|
154
|
-
* **`LollmsClient`**: The central class for all interactions. It holds the currently active LLM binding and provides access to modality bindings and
|
|
209
|
+
* **`LollmsClient`**: The central class for all interactions. It holds the currently active LLM binding, an optional MCP binding, and provides access to modality bindings and high-level operations.
|
|
155
210
|
* **LLM Bindings**: These are plugins that allow `LollmsClient` to communicate with different LLM backends. You choose a binding (e.g., `"ollama"`, `"lollms"`, `"pythonllamacpp"`) when you initialize `LollmsClient`.
|
|
211
|
+
* **🔧 MCP Bindings**: Enable tool use and function calling. `lollms-client` includes `local_mcp` for executing Python tools. It discovers tools from a specified folder (or uses its default set), each defined by a `.py` script and a `.mcp.json` metadata file.
|
|
156
212
|
* **Modality Bindings**: Similar to LLM bindings, but for services like Text-to-Speech (`tts`), Text-to-Image (`tti`), etc.
|
|
157
|
-
*
|
|
158
|
-
* **`FunctionCalling_Library`**: Enables you to define Python functions that the LLM can request to execute, allowing for tool usage.
|
|
213
|
+
* **High-Level Operations**: Methods directly on `LollmsClient` (e.g., `sequential_summarize`, `deep_analyze`, `generate_code`, `yes_no`) for performing complex, multi-step AI tasks.
|
|
159
214
|
* **`LollmsDiscussion`**: Helps manage and format conversation histories for chat applications.
|
|
160
215
|
|
|
161
216
|
## Examples
|
|
@@ -164,8 +219,8 @@ The `examples/` directory in this repository contains a rich set of scripts demo
|
|
|
164
219
|
* Basic text generation with different bindings.
|
|
165
220
|
* Streaming and non-streaming examples.
|
|
166
221
|
* Multimodal generation (text with images).
|
|
167
|
-
* Using
|
|
168
|
-
* Implementing and using function calls.
|
|
222
|
+
* Using built-in methods for summarization and Q&A.
|
|
223
|
+
* Implementing and using function calls with **`generate_with_mcp`** and the `local_mcp` binding (see `examples/function_calling_with_local_custom_mcp.py` and `examples/local_mcp.py`).
|
|
169
224
|
* Text-to-Speech and Text-to-Image generation.
|
|
170
225
|
|
|
171
226
|
Explore these examples to see `lollms-client` in action!
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
[](https://github.com/ParisNeo/lollms_client/stargazers/)
|
|
10
10
|
[](https://github.com/ParisNeo/lollms_client/issues)
|
|
11
11
|
|
|
12
|
-
**`lollms_client`** is a powerful and flexible Python library designed to simplify interactions with the **LoLLMs (Lord of Large Language Models)** ecosystem and various other Large Language Model (LLM) backends. It provides a unified API for text generation, multimodal operations (text-to-image, text-to-speech, etc.), function calling
|
|
12
|
+
**`lollms_client`** is a powerful and flexible Python library designed to simplify interactions with the **LoLLMs (Lord of Large Language Models)** ecosystem and various other Large Language Model (LLM) backends. It provides a unified API for text generation, multimodal operations (text-to-image, text-to-speech, etc.), and robust function calling through the Model Context Protocol (MCP).
|
|
13
13
|
|
|
14
14
|
Whether you're connecting to a remote LoLLMs server, an Ollama instance, the OpenAI API, or running models locally using GGUF (via `llama-cpp-python` or a managed `llama.cpp` server), Hugging Face Transformers, or vLLM, `lollms-client` offers a consistent and developer-friendly experience.
|
|
15
15
|
|
|
@@ -17,12 +17,12 @@ Whether you're connecting to a remote LoLLMs server, an Ollama instance, the Ope
|
|
|
17
17
|
|
|
18
18
|
* 🔌 **Versatile Binding System:** Seamlessly switch between different LLM backends (LoLLMs, Ollama, OpenAI, Llama.cpp, Transformers, vLLM, OpenLLM) without major code changes.
|
|
19
19
|
* 🗣️ **Multimodal Support:** Interact with models capable of processing images and generate various outputs like speech (TTS) and images (TTI).
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* 📞 **Function Calling:** Enable LLMs to invoke your custom Python functions, bridging the gap between language models and external tools or data sources.
|
|
20
|
+
* 🤖 **Function Calling with MCP:** Empowers LLMs to use external tools and functions through the Model Context Protocol (MCP), with built-in support for local Python tool execution via `local_mcp` binding and its default tools (file I/O, internet search, Python interpreter, image generation).
|
|
21
|
+
* 🚀 **Streaming & Callbacks:** Efficiently handle real-time text generation with customizable callback functions, including during MCP interactions.
|
|
23
22
|
* 💬 **Discussion Management:** Utilities to easily manage and format conversation histories for chat applications.
|
|
24
23
|
* ⚙️ **Configuration Management:** Flexible ways to configure bindings and generation parameters.
|
|
25
|
-
* 🧩 **Extensible:** Designed to easily incorporate new LLM backends and modality services.
|
|
24
|
+
* 🧩 **Extensible:** Designed to easily incorporate new LLM backends and modality services, including custom MCP toolsets.
|
|
25
|
+
* 📝 **High-Level Operations:** Includes convenience methods for complex tasks like sequential summarization and deep text analysis directly within `LollmsClient`.
|
|
26
26
|
|
|
27
27
|
## Installation
|
|
28
28
|
|
|
@@ -89,12 +89,61 @@ except Exception as e:
|
|
|
89
89
|
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
+
### Function Calling with MCP
|
|
93
|
+
|
|
94
|
+
`lollms-client` supports robust function calling via the Model Context Protocol (MCP), allowing LLMs to interact with your custom Python tools or pre-defined utilities.
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from lollms_client import LollmsClient, MSG_TYPE
|
|
98
|
+
from ascii_colors import ASCIIColors
|
|
99
|
+
import json # For pretty printing results
|
|
100
|
+
|
|
101
|
+
# Example callback for MCP streaming
|
|
102
|
+
def mcp_stream_callback(chunk: str, msg_type: MSG_TYPE, metadata: dict = None, turn_history: list = None) -> bool:
|
|
103
|
+
if msg_type == MSG_TYPE.MSG_TYPE_CHUNK: ASCIIColors.success(chunk, end="", flush=True) # LLM's final answer or thought process
|
|
104
|
+
elif msg_type == MSG_TYPE.MSG_TYPE_STEP_START: ASCIIColors.info(f"\n>> MCP Step Start: {metadata.get('tool_name', chunk)}", flush=True)
|
|
105
|
+
elif msg_type == MSG_TYPE.MSG_TYPE_STEP_END: ASCIIColors.success(f"\n<< MCP Step End: {metadata.get('tool_name', chunk)} -> Result: {json.dumps(metadata.get('result', ''))}", flush=True)
|
|
106
|
+
elif msg_type == MSG_TYPE.MSG_TYPE_INFO and metadata and metadata.get("type") == "tool_call_request": ASCIIColors.info(f"\nAI requests: {metadata.get('name')}({metadata.get('params')})", flush=True)
|
|
107
|
+
return True
|
|
108
|
+
|
|
109
|
+
try:
|
|
110
|
+
# Initialize LollmsClient with an LLM binding and the local_mcp binding
|
|
111
|
+
lc = LollmsClient(
|
|
112
|
+
binding_name="ollama", model_name="mistral", # Example LLM
|
|
113
|
+
mcp_binding_name="local_mcp" # Enables default tools (file_writer, internet_search, etc.)
|
|
114
|
+
# or custom tools if mcp_binding_config.tools_folder_path is set.
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
user_query = "What were the main AI headlines last week and write a summary to 'ai_news.txt'?"
|
|
118
|
+
ASCIIColors.blue(f"User Query: {user_query}")
|
|
119
|
+
ASCIIColors.yellow("AI Processing with MCP (streaming):")
|
|
120
|
+
|
|
121
|
+
mcp_result = lc.generate_with_mcp(
|
|
122
|
+
prompt=user_query,
|
|
123
|
+
streaming_callback=mcp_stream_callback
|
|
124
|
+
)
|
|
125
|
+
print("\n--- End of MCP Interaction ---")
|
|
126
|
+
|
|
127
|
+
if mcp_result.get("error"):
|
|
128
|
+
ASCIIColors.error(f"MCP Error: {mcp_result['error']}")
|
|
129
|
+
else:
|
|
130
|
+
ASCIIColors.cyan(f"\nFinal Answer from AI: {mcp_result.get('final_answer', 'N/A')}")
|
|
131
|
+
ASCIIColors.magenta("\nTool Calls Made:")
|
|
132
|
+
for tc in mcp_result.get("tool_calls", []):
|
|
133
|
+
print(f" - Tool: {tc.get('name')}, Params: {tc.get('params')}, Result (first 50 chars): {str(tc.get('result'))[:50]}...")
|
|
134
|
+
|
|
135
|
+
except Exception as e:
|
|
136
|
+
ASCIIColors.error(f"An error occurred in MCP example: {e}")
|
|
137
|
+
trace_exception(e) # Assuming you have trace_exception utility
|
|
138
|
+
```
|
|
139
|
+
For a comprehensive guide on function calling and setting up tools, please refer to the [Usage Guide (DOC_USE.md)](DOC_USE.md).
|
|
140
|
+
|
|
92
141
|
## Documentation
|
|
93
142
|
|
|
94
143
|
For more in-depth information, please refer to:
|
|
95
144
|
|
|
96
|
-
* **[Usage Guide (DOC_USE.md)](DOC_USE.md):** Learn how to use `LollmsClient`, different bindings, modality features,
|
|
97
|
-
* **[Developer Guide (DOC_DEV.md)](DOC_DEV.md):** Understand the architecture, how to create new bindings, and contribute to the library.
|
|
145
|
+
* **[Usage Guide (DOC_USE.md)](DOC_USE.md):** Learn how to use `LollmsClient`, different bindings, modality features, function calling with MCP, and high-level operations.
|
|
146
|
+
* **[Developer Guide (DOC_DEV.md)](DOC_DEV.md):** Understand the architecture, how to create new bindings (LLM, modality, MCP), and contribute to the library.
|
|
98
147
|
|
|
99
148
|
## Core Concepts
|
|
100
149
|
|
|
@@ -104,8 +153,9 @@ graph LR
|
|
|
104
153
|
|
|
105
154
|
subgraph LollmsClient_Core
|
|
106
155
|
LC -- Manages --> LLB[LLM Binding];
|
|
107
|
-
LC --
|
|
108
|
-
LC --
|
|
156
|
+
LC -- Manages --> MCPB[MCP Binding];
|
|
157
|
+
LC -- Orchestrates --> MCP_Interaction[generate_with_mcp];
|
|
158
|
+
LC -- Provides --> HighLevelOps[High-Level Ops<br>(summarize, deep_analyze etc.)];
|
|
109
159
|
LC -- Provides Access To --> DM[DiscussionManager];
|
|
110
160
|
LC -- Provides Access To --> ModalityBindings[TTS, TTI, STT etc.];
|
|
111
161
|
end
|
|
@@ -118,14 +168,19 @@ graph LR
|
|
|
118
168
|
LLB --> LocalHF[Local HuggingFace<br>(transformers / vLLM)];
|
|
119
169
|
end
|
|
120
170
|
|
|
121
|
-
|
|
171
|
+
MCP_Interaction --> MCPB;
|
|
172
|
+
MCPB --> LocalTools[Local Python Tools<br>(via local_mcp)];
|
|
173
|
+
MCPB --> RemoteTools[Remote MCP Tool Servers<br>(Future Potential)];
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
ModalityBindings --> ModalityServices[Modality Services<br>(e.g., LoLLMs Server TTS/TTI, local Bark/XTTS)];
|
|
122
177
|
```
|
|
123
178
|
|
|
124
|
-
* **`LollmsClient`**: The central class for all interactions. It holds the currently active LLM binding and provides access to modality bindings and
|
|
179
|
+
* **`LollmsClient`**: The central class for all interactions. It holds the currently active LLM binding, an optional MCP binding, and provides access to modality bindings and high-level operations.
|
|
125
180
|
* **LLM Bindings**: These are plugins that allow `LollmsClient` to communicate with different LLM backends. You choose a binding (e.g., `"ollama"`, `"lollms"`, `"pythonllamacpp"`) when you initialize `LollmsClient`.
|
|
181
|
+
* **🔧 MCP Bindings**: Enable tool use and function calling. `lollms-client` includes `local_mcp` for executing Python tools. It discovers tools from a specified folder (or uses its default set), each defined by a `.py` script and a `.mcp.json` metadata file.
|
|
126
182
|
* **Modality Bindings**: Similar to LLM bindings, but for services like Text-to-Speech (`tts`), Text-to-Image (`tti`), etc.
|
|
127
|
-
*
|
|
128
|
-
* **`FunctionCalling_Library`**: Enables you to define Python functions that the LLM can request to execute, allowing for tool usage.
|
|
183
|
+
* **High-Level Operations**: Methods directly on `LollmsClient` (e.g., `sequential_summarize`, `deep_analyze`, `generate_code`, `yes_no`) for performing complex, multi-step AI tasks.
|
|
129
184
|
* **`LollmsDiscussion`**: Helps manage and format conversation histories for chat applications.
|
|
130
185
|
|
|
131
186
|
## Examples
|
|
@@ -134,8 +189,8 @@ The `examples/` directory in this repository contains a rich set of scripts demo
|
|
|
134
189
|
* Basic text generation with different bindings.
|
|
135
190
|
* Streaming and non-streaming examples.
|
|
136
191
|
* Multimodal generation (text with images).
|
|
137
|
-
* Using
|
|
138
|
-
* Implementing and using function calls.
|
|
192
|
+
* Using built-in methods for summarization and Q&A.
|
|
193
|
+
* Implementing and using function calls with **`generate_with_mcp`** and the `local_mcp` binding (see `examples/function_calling_with_local_custom_mcp.py` and `examples/local_mcp.py`).
|
|
139
194
|
* Text-to-Speech and Text-to-Image generation.
|
|
140
195
|
|
|
141
196
|
Explore these examples to see `lollms-client` in action!
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
from lollms_client import LollmsClient, MSG_TYPE
|
|
2
|
+
from ascii_colors import ASCIIColors, trace_exception
|
|
3
|
+
from typing import List, Dict, Any, Optional, Callable
|
|
4
|
+
import json
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
# --- Mock RAG Implementation ---
|
|
8
|
+
# In a real application, this would interact with your vector database (Pinecone, ChromaDB, FAISS, etc.)
|
|
9
|
+
# and use a real sentence transformer for vectorization.
|
|
10
|
+
|
|
11
|
+
MOCK_KNOWLEDGE_BASE = {
|
|
12
|
+
"python_basics.md": [
|
|
13
|
+
{"chunk_id": 1, "text": "Python is a high-level, interpreted programming language known for its readability and versatility. It was created by Guido van Rossum and first released in 1991."},
|
|
14
|
+
{"chunk_id": 2, "text": "Key features of Python include dynamic typing, automatic memory management (garbage collection), and a large standard library. It supports multiple programming paradigms, such as procedural, object-oriented, and functional programming."},
|
|
15
|
+
{"chunk_id": 3, "text": "Common applications of Python include web development (e.g., Django, Flask), data science (e.g., Pandas, NumPy, Scikit-learn), machine learning, artificial intelligence, automation, and scripting."},
|
|
16
|
+
],
|
|
17
|
+
"javascript_info.js": [
|
|
18
|
+
{"chunk_id": 1, "text": "JavaScript is a scripting language primarily used for front-end web development to create interactive effects within web browsers. It is also used in back-end development (Node.js), mobile app development, and game development."},
|
|
19
|
+
{"chunk_id": 2, "text": "JavaScript is dynamically typed, prototype-based, and multi-paradigm. Along with HTML and CSS, it is one of the core technologies of the World Wide Web."},
|
|
20
|
+
{"chunk_id": 3, "text": "Popular JavaScript frameworks and libraries include React, Angular, Vue.js for front-end, and Express.js for Node.js back-end applications."},
|
|
21
|
+
],
|
|
22
|
+
"ai_concepts.txt": [
|
|
23
|
+
{"chunk_id": 1, "text": "Artificial Intelligence (AI) refers to the simulation of human intelligence in machines that are programmed to think like humans and mimic their actions. The term may also be applied to any machine that exhibits traits associated with a human mind such as learning and problem-solving."},
|
|
24
|
+
{"chunk_id": 2, "text": "Machine Learning (ML) is a subset of AI that provides systems the ability to automatically learn and improve from experience without being explicitly programmed. Deep Learning (DL) is a further subset of ML based on artificial neural networks with representation learning."},
|
|
25
|
+
{"chunk_id": 3, "text": "Retrieval Augmented Generation (RAG) is an AI framework for improving the quality of LLM-generated responses by grounding the model on external sources of knowledge to supplement the LLM’s internal representation of information."},
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
def mock_rag_query_function(
|
|
30
|
+
query_text: str,
|
|
31
|
+
vectorizer_name: Optional[str] = None, # Ignored in mock
|
|
32
|
+
top_k: int = 3,
|
|
33
|
+
min_similarity_percent: float = 0.0 # Ignored in mock, simple keyword match
|
|
34
|
+
) -> List[Dict[str, Any]]:
|
|
35
|
+
"""
|
|
36
|
+
A mock RAG query function.
|
|
37
|
+
Performs a simple keyword search in the MOCK_KNOWLEDGE_BASE.
|
|
38
|
+
"""
|
|
39
|
+
ASCIIColors.magenta(f" [MOCK RAG] Querying with: '{query_text}', top_k={top_k}")
|
|
40
|
+
results = []
|
|
41
|
+
query_lower = query_text.lower()
|
|
42
|
+
|
|
43
|
+
all_chunks = []
|
|
44
|
+
for file_path, chunks_in_file in MOCK_KNOWLEDGE_BASE.items():
|
|
45
|
+
for chunk_data in chunks_in_file:
|
|
46
|
+
all_chunks.append({"file_path": file_path, **chunk_data})
|
|
47
|
+
|
|
48
|
+
# Simple keyword matching and scoring (very basic)
|
|
49
|
+
scored_chunks = []
|
|
50
|
+
for chunk_info in all_chunks:
|
|
51
|
+
score = 0
|
|
52
|
+
for keyword in query_lower.split():
|
|
53
|
+
if keyword in chunk_info["text"].lower() and len(keyword)>2: # Basic relevance
|
|
54
|
+
score += 1
|
|
55
|
+
if "python" in query_lower and "python" in chunk_info["file_path"].lower(): score+=5
|
|
56
|
+
if "javascript" in query_lower and "javascript" in chunk_info["file_path"].lower(): score+=5
|
|
57
|
+
if "ai" in query_lower and "ai" in chunk_info["file_path"].lower(): score+=3
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
if score > 0 : # Only include if some keywords match
|
|
61
|
+
# Simulate similarity percentage (higher score = higher similarity)
|
|
62
|
+
similarity = min(100.0, score * 20.0 + 40.0) # Arbitrary scaling
|
|
63
|
+
if similarity >= min_similarity_percent:
|
|
64
|
+
scored_chunks.append({
|
|
65
|
+
"file_path": chunk_info["file_path"],
|
|
66
|
+
"chunk_text": chunk_info["text"],
|
|
67
|
+
"similarity_percent": similarity,
|
|
68
|
+
"_score_for_ranking": score # Internal score for sorting
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
# Sort by internal score (descending) and take top_k
|
|
72
|
+
scored_chunks.sort(key=lambda x: x["_score_for_ranking"], reverse=True)
|
|
73
|
+
results = [
|
|
74
|
+
{"file_path": c["file_path"], "chunk_text": c["chunk_text"], "similarity_percent": c["similarity_percent"]}
|
|
75
|
+
for c in scored_chunks[:top_k]
|
|
76
|
+
]
|
|
77
|
+
ASCIIColors.magenta(f" [MOCK RAG] Found {len(results)} relevant chunks.")
|
|
78
|
+
return results
|
|
79
|
+
|
|
80
|
+
# --- Streaming Callback for RAG and LLM ---
|
|
81
|
+
def rag_streaming_callback(
|
|
82
|
+
chunk: str,
|
|
83
|
+
msg_type: MSG_TYPE,
|
|
84
|
+
metadata: Optional[Dict] = None,
|
|
85
|
+
turn_history: Optional[List] = None # history of this specific RAG turn
|
|
86
|
+
) -> bool:
|
|
87
|
+
"""
|
|
88
|
+
Handles various stages of RAG and final LLM generation.
|
|
89
|
+
"""
|
|
90
|
+
metadata = metadata or {}
|
|
91
|
+
turn_history = turn_history or [] # Should be populated by LollmsClient
|
|
92
|
+
|
|
93
|
+
if msg_type == MSG_TYPE.MSG_TYPE_CHUNK: # Final answer chunks
|
|
94
|
+
ASCIIColors.success(chunk, end="", flush=True)
|
|
95
|
+
elif msg_type == MSG_TYPE.MSG_TYPE_STEP_START:
|
|
96
|
+
step_type = metadata.get("type", "step")
|
|
97
|
+
hop = metadata.get("hop", "")
|
|
98
|
+
info = metadata.get("query", chunk) if step_type == "rag_query_generation" or step_type == "rag_retrieval" else chunk
|
|
99
|
+
ASCIIColors.yellow(f"\n>> RAG Step Start (Hop {hop}): {step_type} - Info: {str(info)[:100]}...", flush=True)
|
|
100
|
+
elif msg_type == MSG_TYPE.MSG_TYPE_STEP_END:
|
|
101
|
+
step_type = metadata.get("type", "step")
|
|
102
|
+
hop = metadata.get("hop", "")
|
|
103
|
+
num_chunks = metadata.get("num_chunks", "")
|
|
104
|
+
query = metadata.get("query", "")
|
|
105
|
+
decision = metadata.get("decision", "")
|
|
106
|
+
|
|
107
|
+
info_str = ""
|
|
108
|
+
if step_type == "rag_query_generation" and query: info_str = f"Generated Query: {query}"
|
|
109
|
+
elif step_type == "rag_retrieval": info_str = f"Retrieved {num_chunks} chunks"
|
|
110
|
+
elif step_type == "rag_llm_decision": info_str = f"LLM Decision: {json.dumps(decision)}"
|
|
111
|
+
elif step_type == "final_answer_generation": info_str = "Final answer generation complete."
|
|
112
|
+
else: info_str = chunk
|
|
113
|
+
|
|
114
|
+
ASCIIColors.green(f"\n<< RAG Step End (Hop {hop}): {step_type} - {info_str}", flush=True)
|
|
115
|
+
elif msg_type == MSG_TYPE.MSG_TYPE_EXCEPTION:
|
|
116
|
+
ASCIIColors.error(f"\nError in RAG stream: {chunk}", flush=True)
|
|
117
|
+
|
|
118
|
+
# You can inspect turn_history here if needed:
|
|
119
|
+
# ASCIIColors.debug(f"Current RAG Turn History: {turn_history}")
|
|
120
|
+
return True
|
|
121
|
+
|
|
122
|
+
# --- Main Example ---
|
|
123
|
+
if __name__ == "__main__":
|
|
124
|
+
ASCIIColors.red("--- Multi-Hop RAG Example with LollmsClient ---")
|
|
125
|
+
|
|
126
|
+
# LLM Configuration (use a model good at instruction following and JSON)
|
|
127
|
+
# Ensure your Ollama server is running and has this model pulled.
|
|
128
|
+
LLM_BINDING_NAME = "ollama"
|
|
129
|
+
LLM_MODEL_NAME = "qwen3:4b" # or llama3, phi3 etc.
|
|
130
|
+
# LLM_MODEL_NAME = "qwen2:1.5b" # Smaller model for quicker tests, but might struggle with complex JSON
|
|
131
|
+
|
|
132
|
+
try:
|
|
133
|
+
lc = LollmsClient(
|
|
134
|
+
binding_name=LLM_BINDING_NAME,
|
|
135
|
+
model_name=LLM_MODEL_NAME,
|
|
136
|
+
temperature=0.1, # Default temp for final answer if not overridden
|
|
137
|
+
# Other LollmsClient params as needed
|
|
138
|
+
)
|
|
139
|
+
ASCIIColors.green(f"LollmsClient initialized with LLM: {LLM_BINDING_NAME}/{LLM_MODEL_NAME}")
|
|
140
|
+
|
|
141
|
+
# --- Test Case 1: Classic RAG (max_rag_hops = 0) ---
|
|
142
|
+
ASCIIColors.cyan("\n\n--- Test Case 1: Classic RAG (max_rag_hops = 0) ---")
|
|
143
|
+
classic_rag_prompt = "What are the key features of Python?"
|
|
144
|
+
ASCIIColors.blue(f"User Prompt: {classic_rag_prompt}")
|
|
145
|
+
|
|
146
|
+
classic_rag_result = lc.generate_text_with_rag(
|
|
147
|
+
prompt=classic_rag_prompt,
|
|
148
|
+
rag_query_function=mock_rag_query_function,
|
|
149
|
+
# rag_query_text=None, # Will use `prompt` for query
|
|
150
|
+
max_rag_hops=0,
|
|
151
|
+
rag_top_k=2, # Get 2 best chunks
|
|
152
|
+
rag_min_similarity_percent=50.0,
|
|
153
|
+
streaming_callback=rag_streaming_callback,
|
|
154
|
+
n_predict=1024 # Max tokens for final answer
|
|
155
|
+
)
|
|
156
|
+
print("\n--- End of Classic RAG ---")
|
|
157
|
+
ASCIIColors.magenta("\nClassic RAG Final Output:")
|
|
158
|
+
print(json.dumps(classic_rag_result, indent=2))
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
# --- Test Case 2: Multi-Hop RAG (max_rag_hops = 1) ---
|
|
162
|
+
ASCIIColors.cyan("\n\n--- Test Case 2: Multi-Hop RAG (max_rag_hops = 1) ---")
|
|
163
|
+
multihop_prompt_1 = "Compare Python and JavaScript for web development based on their common applications and core technologies."
|
|
164
|
+
ASCIIColors.blue(f"User Prompt: {multihop_prompt_1}")
|
|
165
|
+
|
|
166
|
+
multihop_rag_result_1 = lc.generate_text_with_rag(
|
|
167
|
+
prompt=multihop_prompt_1,
|
|
168
|
+
rag_query_function=mock_rag_query_function,
|
|
169
|
+
# rag_query_text="Python web development applications", # Optional: provide an initial query
|
|
170
|
+
max_rag_hops=1, # Allow one hop for LLM to refine search or decide
|
|
171
|
+
rag_top_k=2,
|
|
172
|
+
rag_min_similarity_percent=60.0,
|
|
173
|
+
streaming_callback=rag_streaming_callback,
|
|
174
|
+
n_predict=1024,
|
|
175
|
+
rag_hop_query_generation_temperature=0.1, # Focused query gen
|
|
176
|
+
rag_hop_summary_temperature=0.2 # Focused summary
|
|
177
|
+
)
|
|
178
|
+
print("\n--- End of Multi-Hop RAG (1 hop) ---")
|
|
179
|
+
ASCIIColors.magenta("\nMulti-Hop RAG (1 hop) Final Output:")
|
|
180
|
+
print(json.dumps(multihop_rag_result_1, indent=2))
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
# --- Test Case 3: Multi-Hop RAG (max_rag_hops = 2) - LLM might decide it has enough earlier ---
|
|
184
|
+
ASCIIColors.cyan("\n\n--- Test Case 3: Multi-Hop RAG (max_rag_hops = 2) ---")
|
|
185
|
+
multihop_prompt_2 = "Explain Retrieval Augmented Generation (RAG) and its relation to Machine Learning."
|
|
186
|
+
ASCIIColors.blue(f"User Prompt: {multihop_prompt_2}")
|
|
187
|
+
|
|
188
|
+
multihop_rag_result_2 = lc.generate_text_with_rag(
|
|
189
|
+
prompt=multihop_prompt_2,
|
|
190
|
+
rag_query_function=mock_rag_query_function,
|
|
191
|
+
max_rag_hops=2, # Allow up to two refinement hops
|
|
192
|
+
rag_top_k=1, # Get only the best chunk per hop to force more specific queries
|
|
193
|
+
rag_min_similarity_percent=50.0,
|
|
194
|
+
streaming_callback=rag_streaming_callback,
|
|
195
|
+
n_predict=300
|
|
196
|
+
)
|
|
197
|
+
print("\n--- End of Multi-Hop RAG (up to 2 hops) ---")
|
|
198
|
+
ASCIIColors.magenta("\nMulti-Hop RAG (up to 2 hops) Final Output:")
|
|
199
|
+
print(json.dumps(multihop_rag_result_2, indent=2))
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
except ValueError as ve:
|
|
203
|
+
ASCIIColors.error(f"Initialization or RAG parameter error: {ve}")
|
|
204
|
+
trace_exception(ve)
|
|
205
|
+
except ConnectionRefusedError:
|
|
206
|
+
ASCIIColors.error(f"Connection refused. Is the Ollama server ({LLM_BINDING_NAME}) running?")
|
|
207
|
+
except Exception as e:
|
|
208
|
+
ASCIIColors.error(f"An unexpected error occurred: {e}")
|
|
209
|
+
trace_exception(e)
|
|
210
|
+
|
|
211
|
+
ASCIIColors.red("\n--- Multi-Hop RAG Example Finished ---")
|