lightmodel 0.1.0__tar.gz → 0.1.2__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.
- {lightmodel-0.1.0 → lightmodel-0.1.2}/LICENSE +1 -1
- lightmodel-0.1.2/PKG-INFO +126 -0
- lightmodel-0.1.2/README.md +106 -0
- {lightmodel-0.1.0 → lightmodel-0.1.2}/pyproject.toml +4 -3
- lightmodel-0.1.2/src/lightmodel/__init__.py +6 -0
- {lightmodel-0.1.0 → lightmodel-0.1.2}/src/lightmodel/model.py +11 -5
- lightmodel-0.1.2/src/lightmodel/tools.py +39 -0
- lightmodel-0.1.2/src/lightmodel.egg-info/PKG-INFO +126 -0
- {lightmodel-0.1.0 → lightmodel-0.1.2}/src/lightmodel.egg-info/SOURCES.txt +3 -1
- {lightmodel-0.1.0 → lightmodel-0.1.2}/src/lightmodel.egg-info/requires.txt +3 -0
- {lightmodel-0.1.0 → lightmodel-0.1.2}/tests/test_model.py +3 -3
- lightmodel-0.1.2/tests/test_tools.py +29 -0
- lightmodel-0.1.0/PKG-INFO +0 -45
- lightmodel-0.1.0/README.md +0 -27
- lightmodel-0.1.0/src/lightmodel/__init__.py +0 -5
- lightmodel-0.1.0/src/lightmodel.egg-info/PKG-INFO +0 -45
- {lightmodel-0.1.0 → lightmodel-0.1.2}/setup.cfg +0 -0
- {lightmodel-0.1.0 → lightmodel-0.1.2}/src/lightmodel.egg-info/dependency_links.txt +0 -0
- {lightmodel-0.1.0 → lightmodel-0.1.2}/src/lightmodel.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lightmodel
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Ultra-light Model adapter and web search tool for smolagents - works with any OpenAI-compatible API
|
|
5
|
+
Author-email: PlimbAi <plimb.ai.contact@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: smolagents,llm,ai,agent,openai,nvidia-nim,duckduckgo,web-search
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: requests>=2.28
|
|
15
|
+
Provides-Extra: smolagents
|
|
16
|
+
Requires-Dist: smolagents>=1.0; extra == "smolagents"
|
|
17
|
+
Provides-Extra: search
|
|
18
|
+
Requires-Dist: beautifulsoup4>=4.12; extra == "search"
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# LightModel
|
|
22
|
+
|
|
23
|
+
Ultra-light **Model adapter** and **web search tool** for [smolagents](https://github.com/huggingface/smolagents).
|
|
24
|
+
|
|
25
|
+
Works with **any** OpenAI-compatible API: NVIDIA NIM, Ollama, vLLM, LM Studio,
|
|
26
|
+
Groq, OpenRouter, Together, DeepSeek, or any custom URL. No heavy dependencies,
|
|
27
|
+
no Rust compilation, runs everywhere (including Termux on Android).
|
|
28
|
+
|
|
29
|
+
## Features
|
|
30
|
+
|
|
31
|
+
- `LightModel`: a drop-in `Model` adapter for smolagents using only `requests`.
|
|
32
|
+
- `SimpleDuckDuckGoSearchTool`: a lightweight web search tool that scrapes
|
|
33
|
+
DuckDuckGo HTML and does not require `ddgs`, `primp`, or Rust toolchain.
|
|
34
|
+
- Zero heavy dependencies: only `requests` (and `beautifulsoup4` for search).
|
|
35
|
+
- Works with any endpoint exposing an OpenAI-compatible `/chat/completions` API.
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
pip install lightmodel
|
|
40
|
+
pip install lightmodel[smolagents] # with smolagents
|
|
41
|
+
pip install lightmodel[search] # with beautifulsoup4 for web search
|
|
42
|
+
|
|
43
|
+
On Termux or restricted environments, install `smolagents` without its heavy
|
|
44
|
+
dependencies:
|
|
45
|
+
|
|
46
|
+
export HF_HUB_DISABLE_XET=1
|
|
47
|
+
pip install --no-deps smolagents
|
|
48
|
+
pip install --no-deps "huggingface-hub==0.31.2"
|
|
49
|
+
pip install rich jinja2 pillow python-dotenv requests beautifulsoup4
|
|
50
|
+
pip install lightmodel
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
### Model only
|
|
55
|
+
|
|
56
|
+
from smolagents import CodeAgent
|
|
57
|
+
from lightmodel import LightModel
|
|
58
|
+
|
|
59
|
+
model = LightModel(
|
|
60
|
+
model_id="meta/llama3-70b-instruct",
|
|
61
|
+
api_base="https://integrate.api.nvidia.com/v1",
|
|
62
|
+
api_key="your_nvidia_key",
|
|
63
|
+
)
|
|
64
|
+
agent = CodeAgent(tools=[], model=model)
|
|
65
|
+
agent.run("Explain quantum entanglement in one sentence.")
|
|
66
|
+
|
|
67
|
+
### Model + web search
|
|
68
|
+
|
|
69
|
+
from smolagents import CodeAgent
|
|
70
|
+
from lightmodel import LightModel, SimpleDuckDuckGoSearchTool
|
|
71
|
+
|
|
72
|
+
model = LightModel(
|
|
73
|
+
model_id="meta/llama3-70b-instruct",
|
|
74
|
+
api_base="https://integrate.api.nvidia.com/v1",
|
|
75
|
+
api_key="your_nvidia_key",
|
|
76
|
+
)
|
|
77
|
+
agent = CodeAgent(
|
|
78
|
+
tools=[SimpleDuckDuckGoSearchTool()],
|
|
79
|
+
model=model,
|
|
80
|
+
)
|
|
81
|
+
agent.run("What are the latest AI news in 2026?")
|
|
82
|
+
|
|
83
|
+
### With Ollama (local)
|
|
84
|
+
|
|
85
|
+
model = LightModel(
|
|
86
|
+
model_id="llama3",
|
|
87
|
+
api_base="http://localhost:11434/v1",
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
### With any custom URL
|
|
91
|
+
|
|
92
|
+
model = LightModel(
|
|
93
|
+
model_id="my-model",
|
|
94
|
+
api_base="https://my-server.example.com/v1",
|
|
95
|
+
api_key="my-key",
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
## API reference
|
|
99
|
+
|
|
100
|
+
### `LightModel`
|
|
101
|
+
|
|
102
|
+
LightModel(
|
|
103
|
+
model_id: str,
|
|
104
|
+
api_base: str,
|
|
105
|
+
api_key: str = "not-needed",
|
|
106
|
+
temperature: float = 0.7,
|
|
107
|
+
max_tokens: int = 2048,
|
|
108
|
+
timeout: int = 120,
|
|
109
|
+
extra: dict | None = None,
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
- `model_id`: model name sent to the API.
|
|
113
|
+
- `api_base`: base URL. `/chat/completions` is appended automatically.
|
|
114
|
+
- `api_key`: bearer token (optional for local servers).
|
|
115
|
+
- `extra`: extra JSON fields merged into the request payload.
|
|
116
|
+
|
|
117
|
+
### `SimpleDuckDuckGoSearchTool`
|
|
118
|
+
|
|
119
|
+
SimpleDuckDuckGoSearchTool()
|
|
120
|
+
|
|
121
|
+
Scrapes DuckDuckGo HTML results and returns the top 5 as formatted text.
|
|
122
|
+
No API key required. No Rust dependency.
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
MIT
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# LightModel
|
|
2
|
+
|
|
3
|
+
Ultra-light **Model adapter** and **web search tool** for [smolagents](https://github.com/huggingface/smolagents).
|
|
4
|
+
|
|
5
|
+
Works with **any** OpenAI-compatible API: NVIDIA NIM, Ollama, vLLM, LM Studio,
|
|
6
|
+
Groq, OpenRouter, Together, DeepSeek, or any custom URL. No heavy dependencies,
|
|
7
|
+
no Rust compilation, runs everywhere (including Termux on Android).
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- `LightModel`: a drop-in `Model` adapter for smolagents using only `requests`.
|
|
12
|
+
- `SimpleDuckDuckGoSearchTool`: a lightweight web search tool that scrapes
|
|
13
|
+
DuckDuckGo HTML and does not require `ddgs`, `primp`, or Rust toolchain.
|
|
14
|
+
- Zero heavy dependencies: only `requests` (and `beautifulsoup4` for search).
|
|
15
|
+
- Works with any endpoint exposing an OpenAI-compatible `/chat/completions` API.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
pip install lightmodel
|
|
20
|
+
pip install lightmodel[smolagents] # with smolagents
|
|
21
|
+
pip install lightmodel[search] # with beautifulsoup4 for web search
|
|
22
|
+
|
|
23
|
+
On Termux or restricted environments, install `smolagents` without its heavy
|
|
24
|
+
dependencies:
|
|
25
|
+
|
|
26
|
+
export HF_HUB_DISABLE_XET=1
|
|
27
|
+
pip install --no-deps smolagents
|
|
28
|
+
pip install --no-deps "huggingface-hub==0.31.2"
|
|
29
|
+
pip install rich jinja2 pillow python-dotenv requests beautifulsoup4
|
|
30
|
+
pip install lightmodel
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
### Model only
|
|
35
|
+
|
|
36
|
+
from smolagents import CodeAgent
|
|
37
|
+
from lightmodel import LightModel
|
|
38
|
+
|
|
39
|
+
model = LightModel(
|
|
40
|
+
model_id="meta/llama3-70b-instruct",
|
|
41
|
+
api_base="https://integrate.api.nvidia.com/v1",
|
|
42
|
+
api_key="your_nvidia_key",
|
|
43
|
+
)
|
|
44
|
+
agent = CodeAgent(tools=[], model=model)
|
|
45
|
+
agent.run("Explain quantum entanglement in one sentence.")
|
|
46
|
+
|
|
47
|
+
### Model + web search
|
|
48
|
+
|
|
49
|
+
from smolagents import CodeAgent
|
|
50
|
+
from lightmodel import LightModel, SimpleDuckDuckGoSearchTool
|
|
51
|
+
|
|
52
|
+
model = LightModel(
|
|
53
|
+
model_id="meta/llama3-70b-instruct",
|
|
54
|
+
api_base="https://integrate.api.nvidia.com/v1",
|
|
55
|
+
api_key="your_nvidia_key",
|
|
56
|
+
)
|
|
57
|
+
agent = CodeAgent(
|
|
58
|
+
tools=[SimpleDuckDuckGoSearchTool()],
|
|
59
|
+
model=model,
|
|
60
|
+
)
|
|
61
|
+
agent.run("What are the latest AI news in 2026?")
|
|
62
|
+
|
|
63
|
+
### With Ollama (local)
|
|
64
|
+
|
|
65
|
+
model = LightModel(
|
|
66
|
+
model_id="llama3",
|
|
67
|
+
api_base="http://localhost:11434/v1",
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
### With any custom URL
|
|
71
|
+
|
|
72
|
+
model = LightModel(
|
|
73
|
+
model_id="my-model",
|
|
74
|
+
api_base="https://my-server.example.com/v1",
|
|
75
|
+
api_key="my-key",
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
## API reference
|
|
79
|
+
|
|
80
|
+
### `LightModel`
|
|
81
|
+
|
|
82
|
+
LightModel(
|
|
83
|
+
model_id: str,
|
|
84
|
+
api_base: str,
|
|
85
|
+
api_key: str = "not-needed",
|
|
86
|
+
temperature: float = 0.7,
|
|
87
|
+
max_tokens: int = 2048,
|
|
88
|
+
timeout: int = 120,
|
|
89
|
+
extra: dict | None = None,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
- `model_id`: model name sent to the API.
|
|
93
|
+
- `api_base`: base URL. `/chat/completions` is appended automatically.
|
|
94
|
+
- `api_key`: bearer token (optional for local servers).
|
|
95
|
+
- `extra`: extra JSON fields merged into the request payload.
|
|
96
|
+
|
|
97
|
+
### `SimpleDuckDuckGoSearchTool`
|
|
98
|
+
|
|
99
|
+
SimpleDuckDuckGoSearchTool()
|
|
100
|
+
|
|
101
|
+
Scrapes DuckDuckGo HTML results and returns the top 5 as formatted text.
|
|
102
|
+
No API key required. No Rust dependency.
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
MIT
|
|
@@ -4,13 +4,13 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "lightmodel"
|
|
7
|
-
version = "0.1.
|
|
8
|
-
description = "Ultra-light Model adapter for smolagents - works with any OpenAI-compatible API"
|
|
7
|
+
version = "0.1.2"
|
|
8
|
+
description = "Ultra-light Model adapter and web search tool for smolagents - works with any OpenAI-compatible API"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
11
11
|
license = {text = "MIT"}
|
|
12
12
|
authors = [{name = "PlimbAi", email = "plimb.ai.contact@gmail.com"}]
|
|
13
|
-
keywords = ["smolagents", "llm", "ai", "agent", "openai", "nvidia-nim"]
|
|
13
|
+
keywords = ["smolagents", "llm", "ai", "agent", "openai", "nvidia-nim", "duckduckgo", "web-search"]
|
|
14
14
|
classifiers = [
|
|
15
15
|
"Programming Language :: Python :: 3",
|
|
16
16
|
"License :: OSI Approved :: MIT License",
|
|
@@ -20,6 +20,7 @@ dependencies = ["requests>=2.28"]
|
|
|
20
20
|
|
|
21
21
|
[project.optional-dependencies]
|
|
22
22
|
smolagents = ["smolagents>=1.0"]
|
|
23
|
+
search = ["beautifulsoup4>=4.12"]
|
|
23
24
|
|
|
24
25
|
[tool.setuptools.packages.find]
|
|
25
26
|
where = ["src"]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""LightModel - Model adapter
|
|
1
|
+
"""LightModel - lightweight Model adapter for smolagents."""
|
|
2
2
|
import requests
|
|
3
3
|
|
|
4
4
|
from smolagents import Model
|
|
@@ -12,7 +12,7 @@ except ImportError:
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
class LightModel(Model):
|
|
15
|
-
"""
|
|
15
|
+
"""Universal adapter for any OpenAI-compatible API."""
|
|
16
16
|
|
|
17
17
|
def __init__(self, model_id, api_base, api_key="not-needed",
|
|
18
18
|
temperature=0.7, max_tokens=2048, timeout=120, extra=None):
|
|
@@ -47,15 +47,20 @@ class LightModel(Model):
|
|
|
47
47
|
r = requests.post(self.api_url, json=payload, headers=headers,
|
|
48
48
|
timeout=self.timeout)
|
|
49
49
|
if r.status_code >= 400:
|
|
50
|
-
raise RuntimeError(f"API {r.status_code}
|
|
50
|
+
raise RuntimeError(f"API {r.status_code}: {r.text[:300]}")
|
|
51
51
|
try:
|
|
52
52
|
text = r.json()["choices"][0]["message"]["content"] or ""
|
|
53
53
|
except (KeyError, IndexError):
|
|
54
|
-
raise RuntimeError(f"
|
|
54
|
+
raise RuntimeError(f"Invalid response: {r.text[:300]}")
|
|
55
55
|
return ChatMessage(role=ROLE_ASSISTANT, content=text)
|
|
56
56
|
|
|
57
57
|
@staticmethod
|
|
58
58
|
def _to_openai(messages):
|
|
59
|
+
ROLE_MAP = {
|
|
60
|
+
"tool-call": "assistant",
|
|
61
|
+
"tool-response": "tool",
|
|
62
|
+
"tool": "tool",
|
|
63
|
+
}
|
|
59
64
|
out = []
|
|
60
65
|
for m in messages:
|
|
61
66
|
if isinstance(m, dict):
|
|
@@ -65,5 +70,6 @@ class LightModel(Model):
|
|
|
65
70
|
content = getattr(m, "content", "")
|
|
66
71
|
if hasattr(role, "value"):
|
|
67
72
|
role = role.value
|
|
68
|
-
|
|
73
|
+
role = ROLE_MAP.get(str(role), str(role))
|
|
74
|
+
out.append({"role": role, "content": str(content)})
|
|
69
75
|
return out
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""Lightweight tools for smolagents."""
|
|
2
|
+
import requests
|
|
3
|
+
from bs4 import BeautifulSoup
|
|
4
|
+
from smolagents import Tool
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class SimpleDuckDuckGoSearchTool(Tool):
|
|
8
|
+
"""Lightweight DuckDuckGo web search tool (HTML scraping, no Rust)."""
|
|
9
|
+
|
|
10
|
+
name = "web_search"
|
|
11
|
+
description = "Search the web for information via DuckDuckGo."
|
|
12
|
+
inputs = {
|
|
13
|
+
"query": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"description": "The search query.",
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
output_type = "string"
|
|
19
|
+
|
|
20
|
+
def forward(self, query: str) -> str:
|
|
21
|
+
url = "https://html.duckduckgo.com/html/"
|
|
22
|
+
headers = {"User-Agent": "Mozilla/5.0"}
|
|
23
|
+
params = {"q": query}
|
|
24
|
+
try:
|
|
25
|
+
response = requests.post(url, data=params, headers=headers, timeout=10)
|
|
26
|
+
response.raise_for_status()
|
|
27
|
+
soup = BeautifulSoup(response.text, "html.parser")
|
|
28
|
+
results = []
|
|
29
|
+
for result in soup.select(".result")[:5]:
|
|
30
|
+
title_tag = result.select_one(".result__a")
|
|
31
|
+
snippet_tag = result.select_one(".result__snippet")
|
|
32
|
+
if title_tag and snippet_tag:
|
|
33
|
+
title = title_tag.get_text(strip=True)
|
|
34
|
+
link = title_tag["href"]
|
|
35
|
+
snippet = snippet_tag.get_text(strip=True)
|
|
36
|
+
results.append(f"- {title}\n {link}\n {snippet}")
|
|
37
|
+
return "\n\n".join(results) if results else "No results found."
|
|
38
|
+
except Exception as e:
|
|
39
|
+
return f"Search error: {e}"
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lightmodel
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Ultra-light Model adapter and web search tool for smolagents - works with any OpenAI-compatible API
|
|
5
|
+
Author-email: PlimbAi <plimb.ai.contact@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: smolagents,llm,ai,agent,openai,nvidia-nim,duckduckgo,web-search
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: requests>=2.28
|
|
15
|
+
Provides-Extra: smolagents
|
|
16
|
+
Requires-Dist: smolagents>=1.0; extra == "smolagents"
|
|
17
|
+
Provides-Extra: search
|
|
18
|
+
Requires-Dist: beautifulsoup4>=4.12; extra == "search"
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# LightModel
|
|
22
|
+
|
|
23
|
+
Ultra-light **Model adapter** and **web search tool** for [smolagents](https://github.com/huggingface/smolagents).
|
|
24
|
+
|
|
25
|
+
Works with **any** OpenAI-compatible API: NVIDIA NIM, Ollama, vLLM, LM Studio,
|
|
26
|
+
Groq, OpenRouter, Together, DeepSeek, or any custom URL. No heavy dependencies,
|
|
27
|
+
no Rust compilation, runs everywhere (including Termux on Android).
|
|
28
|
+
|
|
29
|
+
## Features
|
|
30
|
+
|
|
31
|
+
- `LightModel`: a drop-in `Model` adapter for smolagents using only `requests`.
|
|
32
|
+
- `SimpleDuckDuckGoSearchTool`: a lightweight web search tool that scrapes
|
|
33
|
+
DuckDuckGo HTML and does not require `ddgs`, `primp`, or Rust toolchain.
|
|
34
|
+
- Zero heavy dependencies: only `requests` (and `beautifulsoup4` for search).
|
|
35
|
+
- Works with any endpoint exposing an OpenAI-compatible `/chat/completions` API.
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
pip install lightmodel
|
|
40
|
+
pip install lightmodel[smolagents] # with smolagents
|
|
41
|
+
pip install lightmodel[search] # with beautifulsoup4 for web search
|
|
42
|
+
|
|
43
|
+
On Termux or restricted environments, install `smolagents` without its heavy
|
|
44
|
+
dependencies:
|
|
45
|
+
|
|
46
|
+
export HF_HUB_DISABLE_XET=1
|
|
47
|
+
pip install --no-deps smolagents
|
|
48
|
+
pip install --no-deps "huggingface-hub==0.31.2"
|
|
49
|
+
pip install rich jinja2 pillow python-dotenv requests beautifulsoup4
|
|
50
|
+
pip install lightmodel
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
### Model only
|
|
55
|
+
|
|
56
|
+
from smolagents import CodeAgent
|
|
57
|
+
from lightmodel import LightModel
|
|
58
|
+
|
|
59
|
+
model = LightModel(
|
|
60
|
+
model_id="meta/llama3-70b-instruct",
|
|
61
|
+
api_base="https://integrate.api.nvidia.com/v1",
|
|
62
|
+
api_key="your_nvidia_key",
|
|
63
|
+
)
|
|
64
|
+
agent = CodeAgent(tools=[], model=model)
|
|
65
|
+
agent.run("Explain quantum entanglement in one sentence.")
|
|
66
|
+
|
|
67
|
+
### Model + web search
|
|
68
|
+
|
|
69
|
+
from smolagents import CodeAgent
|
|
70
|
+
from lightmodel import LightModel, SimpleDuckDuckGoSearchTool
|
|
71
|
+
|
|
72
|
+
model = LightModel(
|
|
73
|
+
model_id="meta/llama3-70b-instruct",
|
|
74
|
+
api_base="https://integrate.api.nvidia.com/v1",
|
|
75
|
+
api_key="your_nvidia_key",
|
|
76
|
+
)
|
|
77
|
+
agent = CodeAgent(
|
|
78
|
+
tools=[SimpleDuckDuckGoSearchTool()],
|
|
79
|
+
model=model,
|
|
80
|
+
)
|
|
81
|
+
agent.run("What are the latest AI news in 2026?")
|
|
82
|
+
|
|
83
|
+
### With Ollama (local)
|
|
84
|
+
|
|
85
|
+
model = LightModel(
|
|
86
|
+
model_id="llama3",
|
|
87
|
+
api_base="http://localhost:11434/v1",
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
### With any custom URL
|
|
91
|
+
|
|
92
|
+
model = LightModel(
|
|
93
|
+
model_id="my-model",
|
|
94
|
+
api_base="https://my-server.example.com/v1",
|
|
95
|
+
api_key="my-key",
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
## API reference
|
|
99
|
+
|
|
100
|
+
### `LightModel`
|
|
101
|
+
|
|
102
|
+
LightModel(
|
|
103
|
+
model_id: str,
|
|
104
|
+
api_base: str,
|
|
105
|
+
api_key: str = "not-needed",
|
|
106
|
+
temperature: float = 0.7,
|
|
107
|
+
max_tokens: int = 2048,
|
|
108
|
+
timeout: int = 120,
|
|
109
|
+
extra: dict | None = None,
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
- `model_id`: model name sent to the API.
|
|
113
|
+
- `api_base`: base URL. `/chat/completions` is appended automatically.
|
|
114
|
+
- `api_key`: bearer token (optional for local servers).
|
|
115
|
+
- `extra`: extra JSON fields merged into the request payload.
|
|
116
|
+
|
|
117
|
+
### `SimpleDuckDuckGoSearchTool`
|
|
118
|
+
|
|
119
|
+
SimpleDuckDuckGoSearchTool()
|
|
120
|
+
|
|
121
|
+
Scrapes DuckDuckGo HTML results and returns the top 5 as formatted text.
|
|
122
|
+
No API key required. No Rust dependency.
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
MIT
|
|
@@ -3,9 +3,11 @@ README.md
|
|
|
3
3
|
pyproject.toml
|
|
4
4
|
src/lightmodel/__init__.py
|
|
5
5
|
src/lightmodel/model.py
|
|
6
|
+
src/lightmodel/tools.py
|
|
6
7
|
src/lightmodel.egg-info/PKG-INFO
|
|
7
8
|
src/lightmodel.egg-info/SOURCES.txt
|
|
8
9
|
src/lightmodel.egg-info/dependency_links.txt
|
|
9
10
|
src/lightmodel.egg-info/requires.txt
|
|
10
11
|
src/lightmodel.egg-info/top_level.txt
|
|
11
|
-
tests/test_model.py
|
|
12
|
+
tests/test_model.py
|
|
13
|
+
tests/test_tools.py
|
|
@@ -16,10 +16,10 @@ def test_generate_parses_response():
|
|
|
16
16
|
m = LightModel("m", "https://api.example.com/v1", api_key="k")
|
|
17
17
|
fake = MagicMock()
|
|
18
18
|
fake.status_code = 200
|
|
19
|
-
fake.json.return_value = {"choices": [{"message": {"content": "
|
|
19
|
+
fake.json.return_value = {"choices": [{"message": {"content": "Hello"}}]}
|
|
20
20
|
with patch("lightmodel.model.requests.post", return_value=fake):
|
|
21
|
-
resp = m.generate([{"role": "user", "content": "
|
|
22
|
-
assert resp.content == "
|
|
21
|
+
resp = m.generate([{"role": "user", "content": "hi"}])
|
|
22
|
+
assert resp.content == "Hello"
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
def test_generate_raises_on_error():
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from unittest.mock import patch, MagicMock
|
|
2
|
+
from lightmodel import SimpleDuckDuckGoSearchTool
|
|
3
|
+
|
|
4
|
+
SAMPLE_HTML = """
|
|
5
|
+
<html><body>
|
|
6
|
+
<div class="result">
|
|
7
|
+
<a class="result__a" href="https://example.com">Example</a>
|
|
8
|
+
<a class="result__snippet">An example snippet.</a>
|
|
9
|
+
</div>
|
|
10
|
+
</body></html>
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_search_returns_results():
|
|
15
|
+
tool = SimpleDuckDuckGoSearchTool()
|
|
16
|
+
fake = MagicMock()
|
|
17
|
+
fake.text = SAMPLE_HTML
|
|
18
|
+
fake.raise_for_status = lambda: None
|
|
19
|
+
with patch("lightmodel.tools.requests.post", return_value=fake):
|
|
20
|
+
out = tool.forward("test")
|
|
21
|
+
assert "Example" in out
|
|
22
|
+
assert "https://example.com" in out
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_search_handles_error():
|
|
26
|
+
tool = SimpleDuckDuckGoSearchTool()
|
|
27
|
+
with patch("lightmodel.tools.requests.post", side_effect=Exception("net down")):
|
|
28
|
+
out = tool.forward("test")
|
|
29
|
+
assert "Search error" in out
|
lightmodel-0.1.0/PKG-INFO
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: lightmodel
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: Ultra-light Model adapter for smolagents - works with any OpenAI-compatible API
|
|
5
|
-
Author-email: PlimbAi <plimb.ai.contact@gmail.com>
|
|
6
|
-
License: MIT
|
|
7
|
-
Keywords: smolagents,llm,ai,agent,openai,nvidia-nim
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
-
Classifier: Operating System :: OS Independent
|
|
11
|
-
Requires-Python: >=3.9
|
|
12
|
-
Description-Content-Type: text/markdown
|
|
13
|
-
License-File: LICENSE
|
|
14
|
-
Requires-Dist: requests>=2.28
|
|
15
|
-
Provides-Extra: smolagents
|
|
16
|
-
Requires-Dist: smolagents>=1.0; extra == "smolagents"
|
|
17
|
-
Dynamic: license-file
|
|
18
|
-
|
|
19
|
-
# LightModel
|
|
20
|
-
|
|
21
|
-
Ultra-light Model adapter for [smolagents](https://github.com/huggingface/smolagents).
|
|
22
|
-
Works with **any** OpenAI-compatible API : NVIDIA NIM, Ollama, vLLM, LM Studio,
|
|
23
|
-
Groq, OpenRouter, Together, DeepSeek, URL personnalisée...
|
|
24
|
-
|
|
25
|
-
## Installation
|
|
26
|
-
|
|
27
|
-
pip install lightmodel
|
|
28
|
-
pip install lightmodel[smolagents] # avec smolagents
|
|
29
|
-
|
|
30
|
-
## Usage
|
|
31
|
-
|
|
32
|
-
from smolagents import CodeAgent, DuckDuckGoSearchTool
|
|
33
|
-
from lightmodel import LightModel
|
|
34
|
-
|
|
35
|
-
model = LightModel(
|
|
36
|
-
model_id="meta/llama3-70b-instruct",
|
|
37
|
-
api_base="https://integrate.api.nvidia.com/v1",
|
|
38
|
-
api_key="votre_cle_nvidia",
|
|
39
|
-
)
|
|
40
|
-
agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)
|
|
41
|
-
agent.run("Quelles sont les dernières actualités sur l'IA ?")
|
|
42
|
-
|
|
43
|
-
## License
|
|
44
|
-
|
|
45
|
-
MIT
|
lightmodel-0.1.0/README.md
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# LightModel
|
|
2
|
-
|
|
3
|
-
Ultra-light Model adapter for [smolagents](https://github.com/huggingface/smolagents).
|
|
4
|
-
Works with **any** OpenAI-compatible API : NVIDIA NIM, Ollama, vLLM, LM Studio,
|
|
5
|
-
Groq, OpenRouter, Together, DeepSeek, URL personnalisée...
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
pip install lightmodel
|
|
10
|
-
pip install lightmodel[smolagents] # avec smolagents
|
|
11
|
-
|
|
12
|
-
## Usage
|
|
13
|
-
|
|
14
|
-
from smolagents import CodeAgent, DuckDuckGoSearchTool
|
|
15
|
-
from lightmodel import LightModel
|
|
16
|
-
|
|
17
|
-
model = LightModel(
|
|
18
|
-
model_id="meta/llama3-70b-instruct",
|
|
19
|
-
api_base="https://integrate.api.nvidia.com/v1",
|
|
20
|
-
api_key="votre_cle_nvidia",
|
|
21
|
-
)
|
|
22
|
-
agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)
|
|
23
|
-
agent.run("Quelles sont les dernières actualités sur l'IA ?")
|
|
24
|
-
|
|
25
|
-
## License
|
|
26
|
-
|
|
27
|
-
MIT
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: lightmodel
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: Ultra-light Model adapter for smolagents - works with any OpenAI-compatible API
|
|
5
|
-
Author-email: PlimbAi <plimb.ai.contact@gmail.com>
|
|
6
|
-
License: MIT
|
|
7
|
-
Keywords: smolagents,llm,ai,agent,openai,nvidia-nim
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
-
Classifier: Operating System :: OS Independent
|
|
11
|
-
Requires-Python: >=3.9
|
|
12
|
-
Description-Content-Type: text/markdown
|
|
13
|
-
License-File: LICENSE
|
|
14
|
-
Requires-Dist: requests>=2.28
|
|
15
|
-
Provides-Extra: smolagents
|
|
16
|
-
Requires-Dist: smolagents>=1.0; extra == "smolagents"
|
|
17
|
-
Dynamic: license-file
|
|
18
|
-
|
|
19
|
-
# LightModel
|
|
20
|
-
|
|
21
|
-
Ultra-light Model adapter for [smolagents](https://github.com/huggingface/smolagents).
|
|
22
|
-
Works with **any** OpenAI-compatible API : NVIDIA NIM, Ollama, vLLM, LM Studio,
|
|
23
|
-
Groq, OpenRouter, Together, DeepSeek, URL personnalisée...
|
|
24
|
-
|
|
25
|
-
## Installation
|
|
26
|
-
|
|
27
|
-
pip install lightmodel
|
|
28
|
-
pip install lightmodel[smolagents] # avec smolagents
|
|
29
|
-
|
|
30
|
-
## Usage
|
|
31
|
-
|
|
32
|
-
from smolagents import CodeAgent, DuckDuckGoSearchTool
|
|
33
|
-
from lightmodel import LightModel
|
|
34
|
-
|
|
35
|
-
model = LightModel(
|
|
36
|
-
model_id="meta/llama3-70b-instruct",
|
|
37
|
-
api_base="https://integrate.api.nvidia.com/v1",
|
|
38
|
-
api_key="votre_cle_nvidia",
|
|
39
|
-
)
|
|
40
|
-
agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)
|
|
41
|
-
agent.run("Quelles sont les dernières actualités sur l'IA ?")
|
|
42
|
-
|
|
43
|
-
## License
|
|
44
|
-
|
|
45
|
-
MIT
|
|
File without changes
|
|
File without changes
|
|
File without changes
|