lollms-client 0.20.6__py3-none-any.whl → 0.20.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of lollms-client might be problematic. Click here for more details.
- lollms_client/__init__.py +1 -1
- lollms_client/lollms_core.py +679 -416
- lollms_client/lollms_discussion.py +254 -341
- lollms_client/lollms_types.py +3 -3
- lollms_client/lollms_utilities.py +97 -0
- lollms_client/mcp_bindings/remote_mcp/__init__.py +2 -0
- {lollms_client-0.20.6.dist-info → lollms_client-0.20.8.dist-info}/METADATA +1 -1
- {lollms_client-0.20.6.dist-info → lollms_client-0.20.8.dist-info}/RECORD +11 -11
- {lollms_client-0.20.6.dist-info → lollms_client-0.20.8.dist-info}/WHEEL +0 -0
- {lollms_client-0.20.6.dist-info → lollms_client-0.20.8.dist-info}/licenses/LICENSE +0 -0
- {lollms_client-0.20.6.dist-info → lollms_client-0.20.8.dist-info}/top_level.txt +0 -0
lollms_client/lollms_types.py
CHANGED
|
@@ -2,9 +2,9 @@ from enum import Enum
|
|
|
2
2
|
class MSG_TYPE(Enum):
|
|
3
3
|
# Messaging
|
|
4
4
|
MSG_TYPE_CHUNK = 0 # A chunk of a message (used for classical chat)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
MSG_TYPE_CONTENT = 1 # A full message (for some personality the answer is sent in bulk)
|
|
6
|
+
MSG_TYPE_CONTENT_INVISIBLE_TO_AI = 2 # A full message (for some personality the answer is sent in bulk)
|
|
7
|
+
MSG_TYPE_CONTENT_INVISIBLE_TO_USER = 3 # A full message (for some personality the answer is sent in bulk)
|
|
8
8
|
|
|
9
9
|
# Conditionning
|
|
10
10
|
# Informations
|
|
@@ -7,6 +7,103 @@ import io
|
|
|
7
7
|
import base64
|
|
8
8
|
import re
|
|
9
9
|
import numpy as np
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import re
|
|
13
|
+
from ascii_colors import ASCIIColors, trace_exception
|
|
14
|
+
def robust_json_parser(json_string: str) -> dict:
|
|
15
|
+
"""
|
|
16
|
+
Parses a JSON string that may be malformed by an LLM by applying a series of cleaning strategies.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
json_string: The string that is expected to contain a JSON object.
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
A dictionary parsed from the JSON string.
|
|
23
|
+
|
|
24
|
+
Raises:
|
|
25
|
+
ValueError: If the string cannot be parsed after all cleaning attempts.
|
|
26
|
+
|
|
27
|
+
Strategies Applied in Order:
|
|
28
|
+
1. Tries to parse the string directly.
|
|
29
|
+
2. If that fails, it extracts the main JSON object or array from the string.
|
|
30
|
+
3. Applies a series of fixes:
|
|
31
|
+
a. Replaces Python/JS boolean/null values with JSON-compliant ones.
|
|
32
|
+
b. Removes single-line and multi-line comments.
|
|
33
|
+
c. Fixes improperly escaped characters (e.g., \_).
|
|
34
|
+
d. Removes trailing commas from objects and arrays.
|
|
35
|
+
e. Escapes unescaped newline characters within strings.
|
|
36
|
+
4. Tries to parse the cleaned string.
|
|
37
|
+
"""
|
|
38
|
+
# 1. First attempt: Standard parsing
|
|
39
|
+
try:
|
|
40
|
+
return json.loads(json_string)
|
|
41
|
+
except json.JSONDecodeError:
|
|
42
|
+
pass # Will proceed to cleaning steps
|
|
43
|
+
|
|
44
|
+
# 2. Second attempt: Find a JSON object or array within a larger string
|
|
45
|
+
# This is useful if the LLM adds text like "Here is the JSON: {..}"
|
|
46
|
+
# Regex to find a JSON object `{...}` or array `[...]`
|
|
47
|
+
json_match = re.search(r'(\{[\s\S]*\}|\[[\s\S]*\])', json_string)
|
|
48
|
+
if json_match:
|
|
49
|
+
json_substring = json_match.group(0)
|
|
50
|
+
else:
|
|
51
|
+
# If no object or array is found, we work with the original string
|
|
52
|
+
json_substring = json_string
|
|
53
|
+
|
|
54
|
+
# Store the potentially cleaned string
|
|
55
|
+
cleaned_string = json_substring
|
|
56
|
+
|
|
57
|
+
# 3. Third attempt: Apply a series of cleaning functions
|
|
58
|
+
try:
|
|
59
|
+
# a. Fix boolean and null values
|
|
60
|
+
cleaned_string = re.sub(r'\bTrue\b', 'true', cleaned_string)
|
|
61
|
+
cleaned_string = re.sub(r'\bFalse\b', 'false', cleaned_string)
|
|
62
|
+
cleaned_string = re.sub(r'\bNone\b', 'null', cleaned_string)
|
|
63
|
+
|
|
64
|
+
# b. Remove comments
|
|
65
|
+
# Remove // comments
|
|
66
|
+
cleaned_string = re.sub(r'//.*', '', cleaned_string)
|
|
67
|
+
# Remove /* ... */ comments
|
|
68
|
+
cleaned_string = re.sub(r'/\*[\s\S]*?\*/', '', cleaned_string)
|
|
69
|
+
|
|
70
|
+
# c. Un-escape characters that are not valid JSON escape sequences
|
|
71
|
+
# e.g., \_ , \- , \* etc. that LLMs sometimes add.
|
|
72
|
+
cleaned_string = re.sub(r'\\([_`*#-])', r'\1', cleaned_string)
|
|
73
|
+
|
|
74
|
+
# d. Remove trailing commas
|
|
75
|
+
cleaned_string = re.sub(r',\s*(\}|\])', r'\1', cleaned_string)
|
|
76
|
+
|
|
77
|
+
# e. Fix unescaped newlines within strings. This is the most complex part.
|
|
78
|
+
# We iterate through the string and escape newlines only when inside a string literal.
|
|
79
|
+
in_string = False
|
|
80
|
+
escaped_string = []
|
|
81
|
+
for i, char in enumerate(cleaned_string):
|
|
82
|
+
if char == '"' and (i == 0 or cleaned_string[i-1] != '\\'):
|
|
83
|
+
in_string = not in_string
|
|
84
|
+
|
|
85
|
+
if in_string and char == '\n':
|
|
86
|
+
escaped_string.append('\\n')
|
|
87
|
+
else:
|
|
88
|
+
escaped_string.append(char)
|
|
89
|
+
|
|
90
|
+
cleaned_string = "".join(escaped_string)
|
|
91
|
+
|
|
92
|
+
return json.loads(cleaned_string)
|
|
93
|
+
|
|
94
|
+
except json.JSONDecodeError as e:
|
|
95
|
+
# If all else fails, raise the final error with context
|
|
96
|
+
ASCIIColors.error("Failed to parse JSON after all cleaning attempts. See details below.")
|
|
97
|
+
print("\n--- JSONDecodeError ---")
|
|
98
|
+
trace_exception(e)
|
|
99
|
+
print("\n--- Original String ---")
|
|
100
|
+
print(json_string)
|
|
101
|
+
print("\n--- Final Cleaned String Attempted ---")
|
|
102
|
+
print(cleaned_string)
|
|
103
|
+
raise ValueError(f"Failed to parse JSON. Final error: {e}") from e
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
10
107
|
class PromptReshaper:
|
|
11
108
|
def __init__(self, template:str):
|
|
12
109
|
self.template = template
|
|
@@ -5,8 +5,10 @@ from lollms_client.lollms_mcp_binding import LollmsMCPBinding
|
|
|
5
5
|
from ascii_colors import ASCIIColors, trace_exception
|
|
6
6
|
import threading
|
|
7
7
|
import json
|
|
8
|
+
import pipmaster as pm
|
|
8
9
|
|
|
9
10
|
try:
|
|
11
|
+
pm.ensure_packages(["mcp"])
|
|
10
12
|
from mcp import ClientSession, types
|
|
11
13
|
from mcp.client.streamable_http import streamablehttp_client
|
|
12
14
|
MCP_LIBRARY_AVAILABLE = True
|
|
@@ -25,10 +25,10 @@ examples/personality_test/chat_test.py,sha256=o2jlpoddFc-T592iqAiA29xk3x27KsdK5D
|
|
|
25
25
|
examples/personality_test/chat_with_aristotle.py,sha256=4X_fwubMpd0Eq2rCReS2bgVlUoAqJprjkLXk2Jz6pXU,1774
|
|
26
26
|
examples/personality_test/tesks_test.py,sha256=7LIiwrEbva9WWZOLi34fsmCBN__RZbPpxoUOKA_AtYk,1924
|
|
27
27
|
examples/test_local_models/local_chat.py,sha256=slakja2zaHOEAUsn2tn_VmI4kLx6luLBrPqAeaNsix8,456
|
|
28
|
-
lollms_client/__init__.py,sha256=
|
|
28
|
+
lollms_client/__init__.py,sha256=BgDFjiLC2bGnZJ3-9qq2QfP8qYOSPvFoTcHsxpXgJi8,912
|
|
29
29
|
lollms_client/lollms_config.py,sha256=goEseDwDxYJf3WkYJ4IrLXwg3Tfw73CXV2Avg45M_hE,21876
|
|
30
|
-
lollms_client/lollms_core.py,sha256=
|
|
31
|
-
lollms_client/lollms_discussion.py,sha256=
|
|
30
|
+
lollms_client/lollms_core.py,sha256=kIiRskIE7w7S104SUBXDEtauGY2nt6ljMDTtc8O7pzg,133572
|
|
31
|
+
lollms_client/lollms_discussion.py,sha256=d_RA4wIbg9NSpK367q8ZD5sb8vLnxzSxDpDpe7ZfLiM,19242
|
|
32
32
|
lollms_client/lollms_js_analyzer.py,sha256=01zUvuO2F_lnUe_0NLxe1MF5aHE1hO8RZi48mNPv-aw,8361
|
|
33
33
|
lollms_client/lollms_llm_binding.py,sha256=E81g4yBlQn76WTSLicnTETJuQhf_WZUMZaxotgRnOcA,12096
|
|
34
34
|
lollms_client/lollms_mcp_binding.py,sha256=0rK9HQCBEGryNc8ApBmtOlhKE1Yfn7X7xIQssXxS2Zc,8933
|
|
@@ -38,8 +38,8 @@ lollms_client/lollms_tti_binding.py,sha256=afO0-d-Kqsmh8UHTijTvy6dZAt-XDB6R-IHmd
|
|
|
38
38
|
lollms_client/lollms_ttm_binding.py,sha256=FjVVSNXOZXK1qvcKEfxdiX6l2b4XdGOSNnZ0utAsbDg,4167
|
|
39
39
|
lollms_client/lollms_tts_binding.py,sha256=5cJYECj8PYLJAyB6SEH7_fhHYK3Om-Y3arkygCnZ24o,4342
|
|
40
40
|
lollms_client/lollms_ttv_binding.py,sha256=KkTaHLBhEEdt4sSVBlbwr5i_g_TlhcrwrT-7DjOsjWQ,4131
|
|
41
|
-
lollms_client/lollms_types.py,sha256=
|
|
42
|
-
lollms_client/lollms_utilities.py,sha256=
|
|
41
|
+
lollms_client/lollms_types.py,sha256=6x9EIoHVK37UKBX9MD8S7usfzvTisNPlDXqysIrJzpI,2872
|
|
42
|
+
lollms_client/lollms_utilities.py,sha256=IyeZZcoKzera4I4Vjk7IIUJXT8uQ45FU2ZjTvaeKFjM,10944
|
|
43
43
|
lollms_client/llm_bindings/__init__.py,sha256=9sWGpmWSSj6KQ8H4lKGCjpLYwhnVdL_2N7gXCphPqh4,14
|
|
44
44
|
lollms_client/llm_bindings/llamacpp/__init__.py,sha256=Qj5RvsgPeHGNfb5AEwZSzFwAp4BOWjyxmm9qBNtstrc,63716
|
|
45
45
|
lollms_client/llm_bindings/lollms/__init__.py,sha256=17TwGMDJMxRPjZjZZSysR8AwjMXZeRfDBy8RqWWuaIY,17769
|
|
@@ -55,7 +55,7 @@ lollms_client/mcp_bindings/local_mcp/default_tools/file_writer/file_writer.py,sh
|
|
|
55
55
|
lollms_client/mcp_bindings/local_mcp/default_tools/generate_image_from_prompt/generate_image_from_prompt.py,sha256=THtZsMxNnXZiBdkwoBlfbWY2C5hhDdmPtnM-8cSKN6s,9488
|
|
56
56
|
lollms_client/mcp_bindings/local_mcp/default_tools/internet_search/internet_search.py,sha256=PLC31-D04QKTOTb1uuCHnrAlpysQjsk89yIJngK0VGc,4586
|
|
57
57
|
lollms_client/mcp_bindings/local_mcp/default_tools/python_interpreter/python_interpreter.py,sha256=McDCBVoVrMDYgU7EYtyOY7mCk1uEeTea0PSD69QqDsQ,6228
|
|
58
|
-
lollms_client/mcp_bindings/remote_mcp/__init__.py,sha256=
|
|
58
|
+
lollms_client/mcp_bindings/remote_mcp/__init__.py,sha256=VsM7SX23sCZa2NDMad4fYAxm_2oJzMdIc8ZiiI6LJp8,16539
|
|
59
59
|
lollms_client/mcp_bindings/standard_mcp/__init__.py,sha256=zpF4h8cTUxoERI-xcVjmS_V772LK0V4jegjz2k1PK98,31658
|
|
60
60
|
lollms_client/stt_bindings/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
61
61
|
lollms_client/stt_bindings/lollms/__init__.py,sha256=jBz3285atdPRqQe9ZRrb-AvjqKRB4f8tjLXjma0DLfE,6082
|
|
@@ -77,8 +77,8 @@ lollms_client/tts_bindings/piper_tts/__init__.py,sha256=0IEWG4zH3_sOkSb9WbZzkeV5
|
|
|
77
77
|
lollms_client/tts_bindings/xtts/__init__.py,sha256=FgcdUH06X6ZR806WQe5ixaYx0QoxtAcOgYo87a2qxYc,18266
|
|
78
78
|
lollms_client/ttv_bindings/__init__.py,sha256=UZ8o2izQOJLQgtZ1D1cXoNST7rzqW22rL2Vufc7ddRc,3141
|
|
79
79
|
lollms_client/ttv_bindings/lollms/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
80
|
-
lollms_client-0.20.
|
|
81
|
-
lollms_client-0.20.
|
|
82
|
-
lollms_client-0.20.
|
|
83
|
-
lollms_client-0.20.
|
|
84
|
-
lollms_client-0.20.
|
|
80
|
+
lollms_client-0.20.8.dist-info/licenses/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
|
|
81
|
+
lollms_client-0.20.8.dist-info/METADATA,sha256=CWTfUNMbBklC5rr7WI06zba9JPaE_DS0vUT1kI87gAI,13374
|
|
82
|
+
lollms_client-0.20.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
83
|
+
lollms_client-0.20.8.dist-info/top_level.txt,sha256=NI_W8S4OYZvJjb0QWMZMSIpOrYzpqwPGYaklhyWKH2w,23
|
|
84
|
+
lollms_client-0.20.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|