langchain-lowrefusal 0.1.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.
- langchain_lowrefusal-0.1.0/LICENSE +21 -0
- langchain_lowrefusal-0.1.0/PKG-INFO +61 -0
- langchain_lowrefusal-0.1.0/README.md +42 -0
- langchain_lowrefusal-0.1.0/pyproject.toml +31 -0
- langchain_lowrefusal-0.1.0/src/langchain_lowrefusal/__init__.py +5 -0
- langchain_lowrefusal-0.1.0/src/langchain_lowrefusal/chat_models.py +49 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 LowRefusal
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: langchain-lowrefusal
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: LowRefusal chat models for LangChain
|
|
5
|
+
Project-URL: Homepage, https://lowrefusal.com/
|
|
6
|
+
Project-URL: Documentation, https://github.com/Chang-Hai/lowrefusal-integrations/tree/main/langchain
|
|
7
|
+
Project-URL: Source, https://github.com/Chang-Hai/lowrefusal-integrations
|
|
8
|
+
Author-email: LowRefusal <support@lowrefusal.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Python: >=3.11
|
|
12
|
+
Requires-Dist: langchain-core<2,>=1
|
|
13
|
+
Requires-Dist: langchain-openai<2,>=1.8.7
|
|
14
|
+
Requires-Dist: pydantic<3,>=2.7
|
|
15
|
+
Provides-Extra: test
|
|
16
|
+
Requires-Dist: httpx<1,>=0.28; extra == 'test'
|
|
17
|
+
Requires-Dist: pytest<10,>=8; extra == 'test'
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# LowRefusal for LangChain
|
|
21
|
+
|
|
22
|
+
`ChatLowRefusal` connects LangChain applications to the LowRefusal Chat Completions API. It supports sync and async chat, streaming, token usage metadata, and tool calling on supported models.
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
python -m pip install langchain-lowrefusal
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The package requires Python 3.11 or later. To install from a checkout, run `python -m pip install ./langchain` from the repository root.
|
|
31
|
+
|
|
32
|
+
## Get a key and send a request
|
|
33
|
+
|
|
34
|
+
Create a key under **Dashboard → API Keys**. Set `LOWREFUSAL_API_KEY` in your shell or secret manager. Live requests use your LowRefusal API credits. [Create a key](https://lowrefusal.com/dashboard/keys) · [Models and prices](https://lowrefusal.com/pricing)
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from langchain_lowrefusal import ChatLowRefusal
|
|
38
|
+
|
|
39
|
+
chat = ChatLowRefusal(model="lowrefusal/deepseek-v4.1-flash", max_tokens=120)
|
|
40
|
+
reply = chat.invoke("List three checks before sending a sales report.")
|
|
41
|
+
print(reply.content)
|
|
42
|
+
print(reply.usage_metadata)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Use `chat.stream(...)` for incremental output, or `ainvoke` and `astream` from async code.
|
|
46
|
+
|
|
47
|
+
## Bind a tool
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
def calculate_total(quantity: int, unit_price_cents: int) -> int:
|
|
51
|
+
"""Calculate a line total in cents."""
|
|
52
|
+
return quantity * unit_price_cents
|
|
53
|
+
|
|
54
|
+
with_tools = chat.bind_tools([calculate_total])
|
|
55
|
+
reply = with_tools.invoke("Use the tool to calculate the total for 3 items at 499 cents each.")
|
|
56
|
+
print(reply.tool_calls)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
This returns tool calls to the application. Your application decides when to execute each tool and can send the result back as a LangChain `ToolMessage`.
|
|
60
|
+
|
|
61
|
+
The integration sends the key, chat messages and any selected tool definitions and results to `https://lowrefusal.com/v1`. [LowRefusal API documentation](https://lowrefusal.com/docs) · [Privacy policy](https://lowrefusal.com/legal/privacy)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# LowRefusal for LangChain
|
|
2
|
+
|
|
3
|
+
`ChatLowRefusal` connects LangChain applications to the LowRefusal Chat Completions API. It supports sync and async chat, streaming, token usage metadata, and tool calling on supported models.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
python -m pip install langchain-lowrefusal
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The package requires Python 3.11 or later. To install from a checkout, run `python -m pip install ./langchain` from the repository root.
|
|
12
|
+
|
|
13
|
+
## Get a key and send a request
|
|
14
|
+
|
|
15
|
+
Create a key under **Dashboard → API Keys**. Set `LOWREFUSAL_API_KEY` in your shell or secret manager. Live requests use your LowRefusal API credits. [Create a key](https://lowrefusal.com/dashboard/keys) · [Models and prices](https://lowrefusal.com/pricing)
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from langchain_lowrefusal import ChatLowRefusal
|
|
19
|
+
|
|
20
|
+
chat = ChatLowRefusal(model="lowrefusal/deepseek-v4.1-flash", max_tokens=120)
|
|
21
|
+
reply = chat.invoke("List three checks before sending a sales report.")
|
|
22
|
+
print(reply.content)
|
|
23
|
+
print(reply.usage_metadata)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Use `chat.stream(...)` for incremental output, or `ainvoke` and `astream` from async code.
|
|
27
|
+
|
|
28
|
+
## Bind a tool
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
def calculate_total(quantity: int, unit_price_cents: int) -> int:
|
|
32
|
+
"""Calculate a line total in cents."""
|
|
33
|
+
return quantity * unit_price_cents
|
|
34
|
+
|
|
35
|
+
with_tools = chat.bind_tools([calculate_total])
|
|
36
|
+
reply = with_tools.invoke("Use the tool to calculate the total for 3 items at 499 cents each.")
|
|
37
|
+
print(reply.tool_calls)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
This returns tool calls to the application. Your application decides when to execute each tool and can send the result back as a LangChain `ToolMessage`.
|
|
41
|
+
|
|
42
|
+
The integration sends the key, chat messages and any selected tool definitions and results to `https://lowrefusal.com/v1`. [LowRefusal API documentation](https://lowrefusal.com/docs) · [Privacy policy](https://lowrefusal.com/legal/privacy)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27,<2"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "langchain-lowrefusal"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "LowRefusal chat models for LangChain"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [{name = "LowRefusal", email = "support@lowrefusal.com"}]
|
|
13
|
+
dependencies = [
|
|
14
|
+
"langchain-core>=1,<2",
|
|
15
|
+
"langchain-openai>=1.8.7,<2",
|
|
16
|
+
"pydantic>=2.7,<3",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.optional-dependencies]
|
|
20
|
+
test = ["httpx>=0.28,<1", "pytest>=8,<10"]
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Homepage = "https://lowrefusal.com/"
|
|
24
|
+
Documentation = "https://github.com/Chang-Hai/lowrefusal-integrations/tree/main/langchain"
|
|
25
|
+
Source = "https://github.com/Chang-Hai/lowrefusal-integrations"
|
|
26
|
+
|
|
27
|
+
[tool.hatch.build.targets.wheel]
|
|
28
|
+
packages = ["src/langchain_lowrefusal"]
|
|
29
|
+
|
|
30
|
+
[tool.hatch.build.targets.sdist]
|
|
31
|
+
include = ["/LICENSE", "/README.md", "/pyproject.toml", "/src"]
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""Chat Completions for LowRefusal's hosted models."""
|
|
2
|
+
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
from langchain_core.utils import secret_from_env
|
|
6
|
+
from langchain_openai import ChatOpenAI
|
|
7
|
+
from pydantic import Field, SecretStr, field_validator
|
|
8
|
+
|
|
9
|
+
LOWREFUSAL_API_BASE = "https://lowrefusal.com/v1"
|
|
10
|
+
DEFAULT_MODEL = "lowrefusal/deepseek-v4.1-flash"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ChatLowRefusal(ChatOpenAI):
|
|
14
|
+
"""Use LowRefusal with invoke, stream, and LangChain tool calling."""
|
|
15
|
+
|
|
16
|
+
model_name: str = Field(default=DEFAULT_MODEL, alias="model")
|
|
17
|
+
openai_api_base: Literal["https://lowrefusal.com/v1"] = Field(
|
|
18
|
+
default=LOWREFUSAL_API_BASE, alias="base_url"
|
|
19
|
+
)
|
|
20
|
+
openai_api_key: SecretStr = Field(
|
|
21
|
+
alias="api_key",
|
|
22
|
+
default_factory=secret_from_env(
|
|
23
|
+
"LOWREFUSAL_API_KEY",
|
|
24
|
+
error_message="Set LOWREFUSAL_API_KEY or pass api_key to ChatLowRefusal.",
|
|
25
|
+
),
|
|
26
|
+
validate_default=True,
|
|
27
|
+
)
|
|
28
|
+
use_responses_api: Literal[False] = False
|
|
29
|
+
stream_usage: bool = True
|
|
30
|
+
|
|
31
|
+
@field_validator("openai_api_key")
|
|
32
|
+
@classmethod
|
|
33
|
+
def check_api_key(cls, key: SecretStr) -> SecretStr:
|
|
34
|
+
value = key.get_secret_value().strip()
|
|
35
|
+
if not value or any(character.isspace() for character in value):
|
|
36
|
+
raise ValueError("Provide a non-empty LowRefusal API key without internal whitespace.")
|
|
37
|
+
return SecretStr(value)
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def lc_secrets(self) -> dict[str, str]:
|
|
41
|
+
return {"openai_api_key": "LOWREFUSAL_API_KEY"}
|
|
42
|
+
|
|
43
|
+
@classmethod
|
|
44
|
+
def is_lc_serializable(cls) -> bool:
|
|
45
|
+
return False
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def _llm_type(self) -> str:
|
|
49
|
+
return "lowrefusal-chat"
|