LLMlight 1.2.0__tar.gz → 1.2.1__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.
@@ -244,13 +244,16 @@ class LLMlight:
244
244
  self.store_path = self._resolve_file_path(file_path)
245
245
  self.modelinfo = {}
246
246
 
247
- # Get the max context length
247
+ # Auto-detect context window when the user did not supply one (or
248
+ # supplied an unrealistically small value). Same source as the
249
+ # coding benchmark: LM Studio model card → max_context_length.
248
250
  if self.model is not None and (n_ctx is None or n_ctx < 512):
249
- # Store modelinfo
250
251
  self.modelinfo = self.get_model_info(model=model)
251
- # self.n_ctx = modelinfo.get('max_context_length') or 8192
252
- loaded = self.modelinfo.get("loaded_instances") or []
253
- self.n_ctx = (loaded[0].get("config", {}).get("context_length", 16384) if loaded else 16384)
252
+ self.n_ctx = utils.resolve_max_context(self.modelinfo, fallback=N_CTX)
253
+ if n_ctx is None:
254
+ logger.info(f'n_ctx not set → using model max context length: {self.n_ctx:,}')
255
+ else:
256
+ logger.info(f'n_ctx={n_ctx} too small → using model max context length: {self.n_ctx:,}')
254
257
 
255
258
  # When no model is given, report available models and return early.
256
259
  # All attributes above are already set so tests can inspect them.
@@ -258,10 +261,7 @@ class LLMlight:
258
261
  models = self.get_available_models(validate=False)
259
262
  if models is not None:
260
263
  logger.info(f'Available models: {models}')
261
- logger.info(
262
- f'Set model before proceeding: '
263
- f'Example: client = LLMlight(model="{models[0]}", endpoint="{endpoint}").'
264
- )
264
+ logger.info(f'Set model before proceeding: Example: client = LLMlight(model="{models[0]}", endpoint="{endpoint}").')
265
265
  self.models = models
266
266
  return
267
267
 
@@ -2244,13 +2244,13 @@ def convert_messages_to_model(messages, model='llama', add_assistant_start=True)
2244
2244
 
2245
2245
 
2246
2246
 
2247
- def load_local_gguf_model(model_path: str, n_ctx: int=4096, n_threads: int=8, n_gpu_layers: int=0) -> Llama:
2247
+ def load_local_gguf_model(model_path: str, n_ctx: int=32768, n_threads: int=8, n_gpu_layers: int=0) -> Llama:
2248
2248
  """
2249
2249
  Loads a local GGUF model using llama-cpp-python.
2250
2250
 
2251
2251
  Args:
2252
2252
  model_path (str): Path to the .gguf model file.
2253
- n_ctx (int): Maximum context length. Default is 4096.
2253
+ n_ctx (int): Maximum context length. Default is 32768
2254
2254
  n_threads (int): Number of CPU threads to use. Default is 8.
2255
2255
  n_gpu_layers (int): Number of layers to offload to GPU (if available). Default is 20.
2256
2256
 
@@ -2291,7 +2291,7 @@ def load_local_gguf_model(model_path: str, n_ctx: int=4096, n_threads: int=8, n_
2291
2291
  return llm
2292
2292
 
2293
2293
 
2294
- def compute_tokens(text: str, n_ctx: int = 16384, chars_per_token=3, task: str = "max"):
2294
+ def compute_tokens(text: str, n_ctx: int = 32768, chars_per_token=3, task: str = "max"):
2295
2295
  """
2296
2296
  Estimate token usage using a model-agnostic approximation.
2297
2297
 
@@ -2305,7 +2305,7 @@ def compute_tokens(text: str, n_ctx: int = 16384, chars_per_token=3, task: str =
2305
2305
  ----------
2306
2306
  text : str
2307
2307
  Prompt text.
2308
- n_ctx : int, default=16384
2308
+ n_ctx : int, default=N_CTX
2309
2309
  Model context window.
2310
2310
  chars_per_token : float, default=305
2311
2311
  3: for coding
@@ -2326,7 +2326,7 @@ def compute_tokens(text: str, n_ctx: int = 16384, chars_per_token=3, task: str =
2326
2326
 
2327
2327
  # Fall back to the function default when no context window is known
2328
2328
  if n_ctx is None:
2329
- n_ctx = 16384
2329
+ n_ctx = 32768
2330
2330
 
2331
2331
  if used_tokens >= n_ctx:
2332
2332
  logger.warning(f"Prompt length ({used_tokens:,} estimated tokens) exceeds context window ({n_ctx:,}). Input will likely be truncated.")
@@ -2338,7 +2338,7 @@ def compute_tokens(text: str, n_ctx: int = 16384, chars_per_token=3, task: str =
2338
2338
  return used_tokens, max_tokens
2339
2339
 
2340
2340
 
2341
- def compute_max_tokens(used_tokens: int, n_ctx: int = 4096, task: str = "max"):
2341
+ def compute_max_tokens(used_tokens: int, n_ctx: int = 32768, task: str = "max"):
2342
2342
  """
2343
2343
  Compute a safe generation budget.
2344
2344
 
@@ -2347,7 +2347,7 @@ def compute_max_tokens(used_tokens: int, n_ctx: int = 4096, task: str = "max"):
2347
2347
  """
2348
2348
 
2349
2349
  if n_ctx is None:
2350
- n_ctx = 4096
2350
+ n_ctx = 32768
2351
2351
 
2352
2352
  available = max(n_ctx - used_tokens, 1)
2353
2353
 
@@ -18,7 +18,7 @@ from LLMlight.LLMlight import (
18
18
 
19
19
  __author__ = 'Erdogan Tasksen'
20
20
  __email__ = 'erdogant@gmail.com'
21
- __version__ = '1.2.0'
21
+ __version__ = '1.2.1'
22
22
 
23
23
  # Setup root logger
24
24
  # Setup package-level logger
@@ -17,6 +17,14 @@ result = client.extract(
17
17
 
18
18
  html = client.visualize_extractions(result, output_html="visualization.html")
19
19
 
20
+ #
21
+ # import webbrowser
22
+ webbrowser.open(html)
23
+ outfile = Path("index.html")
24
+ outfile.write_text(html, encoding="utf-8")
25
+ webbrowser.open(outfile.resolve().as_uri())
26
+
27
+
20
28
  # %%
21
29
  from LLMlight import LLMlight
22
30
 
@@ -249,3 +249,39 @@ def count_words(string):
249
249
  words = [word.strip() for word in words if word.strip() and not word.strip().isdigit()]
250
250
  logger.info(f"Word count: {len(words)}, Number of characters: {len(string)}")
251
251
  return len(words)
252
+
253
+
254
+ def resolve_max_context(modelinfo: dict, fallback: int = 32768) -> int:
255
+ """
256
+ Determine the model's maximum context length from LM Studio model info.
257
+
258
+ Priority (same idea as llm_coding_benchmark.determine_model_contexts):
259
+ 1. ``max_context_length`` on the model card (trained / architecture max)
260
+ 2. ``context_length`` of an already-loaded instance
261
+ 3. ``fallback`` (module default ``N_CTX``)
262
+ """
263
+ if not modelinfo:
264
+ logger.warning(
265
+ f'No model info available; falling back to N_CTX={fallback:,}'
266
+ )
267
+ return int(fallback)
268
+
269
+ max_ctx = modelinfo.get("max_context_length")
270
+ if max_ctx is not None:
271
+ return int(max_ctx)
272
+
273
+ loaded = modelinfo.get("loaded_instances") or []
274
+ if loaded:
275
+ ctx = loaded[0].get("config", {}).get("context_length")
276
+ if ctx is not None:
277
+ logger.info(
278
+ f'max_context_length missing; using loaded instance '
279
+ f'context_length={int(ctx):,}'
280
+ )
281
+ return int(ctx)
282
+
283
+ logger.warning(
284
+ f'Could not read max_context_length from model info; '
285
+ f'falling back to N_CTX={fallback:,}'
286
+ )
287
+ return int(fallback)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: LLMlight
3
- Version: 1.2.0
3
+ Version: 1.2.1
4
4
  Summary: LLMlight is a Python library for ...
5
5
  Author-email: Erdogan Taskesen <erdogant@gmail.com>
6
6
  License-Expression: MIT
@@ -33,7 +33,7 @@ Provides-Extra: llamacpp
33
33
  Requires-Dist: llama-cpp-python; extra == "llamacpp"
34
34
  Dynamic: license-file
35
35
 
36
- # LLMlight
36
+ # LLMLight - Lightweight and Flexible Agentic Framework
37
37
 
38
38
  [![Python](https://img.shields.io/pypi/pyversions/LLMlight)](https://img.shields.io/pypi/pyversions/LLMlight)
39
39
  [![Pypi](https://img.shields.io/pypi/v/LLMlight)](https://pypi.org/project/LLMlight/)
@@ -49,7 +49,7 @@ Dynamic: license-file
49
49
  [![Donate](https://img.shields.io/badge/Support%20this%20project-grey.svg?logo=github%20sponsors)](https://erdogant.github.io/LLMlight/pages/html/Documentation.html#)
50
50
 
51
51
  <div>
52
- LLMlight is a Python package for running Large Language Models (LLMs) locally with minimal dependencies. It provides a simple interface to interact with various LLM models, including support for GGUF models and local API endpoints. ⭐️Star it if you like it⭐️
52
+ LLMLight is a Python package for running Large Language Models (LLMs) locally with minimal dependencies. It provides a simple interface to interact with various LLM models, including support for GGUF models and local API endpoints. ⭐️Star it if you like it⭐️
53
53
  </div>
54
54
 
55
55
  ---
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: LLMlight
3
- Version: 1.2.0
3
+ Version: 1.2.1
4
4
  Summary: LLMlight is a Python library for ...
5
5
  Author-email: Erdogan Taskesen <erdogant@gmail.com>
6
6
  License-Expression: MIT
@@ -33,7 +33,7 @@ Provides-Extra: llamacpp
33
33
  Requires-Dist: llama-cpp-python; extra == "llamacpp"
34
34
  Dynamic: license-file
35
35
 
36
- # LLMlight
36
+ # LLMLight - Lightweight and Flexible Agentic Framework
37
37
 
38
38
  [![Python](https://img.shields.io/pypi/pyversions/LLMlight)](https://img.shields.io/pypi/pyversions/LLMlight)
39
39
  [![Pypi](https://img.shields.io/pypi/v/LLMlight)](https://pypi.org/project/LLMlight/)
@@ -49,7 +49,7 @@ Dynamic: license-file
49
49
  [![Donate](https://img.shields.io/badge/Support%20this%20project-grey.svg?logo=github%20sponsors)](https://erdogant.github.io/LLMlight/pages/html/Documentation.html#)
50
50
 
51
51
  <div>
52
- LLMlight is a Python package for running Large Language Models (LLMs) locally with minimal dependencies. It provides a simple interface to interact with various LLM models, including support for GGUF models and local API endpoints. ⭐️Star it if you like it⭐️
52
+ LLMLight is a Python package for running Large Language Models (LLMs) locally with minimal dependencies. It provides a simple interface to interact with various LLM models, including support for GGUF models and local API endpoints. ⭐️Star it if you like it⭐️
53
53
  </div>
54
54
 
55
55
  ---
@@ -1,4 +1,4 @@
1
- # LLMlight
1
+ # LLMLight - Lightweight and Flexible Agentic Framework
2
2
 
3
3
  [![Python](https://img.shields.io/pypi/pyversions/LLMlight)](https://img.shields.io/pypi/pyversions/LLMlight)
4
4
  [![Pypi](https://img.shields.io/pypi/v/LLMlight)](https://pypi.org/project/LLMlight/)
@@ -14,7 +14,7 @@
14
14
  [![Donate](https://img.shields.io/badge/Support%20this%20project-grey.svg?logo=github%20sponsors)](https://erdogant.github.io/LLMlight/pages/html/Documentation.html#)
15
15
 
16
16
  <div>
17
- LLMlight is a Python package for running Large Language Models (LLMs) locally with minimal dependencies. It provides a simple interface to interact with various LLM models, including support for GGUF models and local API endpoints. ⭐️Star it if you like it⭐️
17
+ LLMLight is a Python package for running Large Language Models (LLMs) locally with minimal dependencies. It provides a simple interface to interact with various LLM models, including support for GGUF models and local API endpoints. ⭐️Star it if you like it⭐️
18
18
  </div>
19
19
 
20
20
  ---
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes