langchain-aicheckerhumanizer 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_aicheckerhumanizer-0.1.0/.gitignore +10 -0
- langchain_aicheckerhumanizer-0.1.0/LICENSE +21 -0
- langchain_aicheckerhumanizer-0.1.0/Makefile +16 -0
- langchain_aicheckerhumanizer-0.1.0/PKG-INFO +94 -0
- langchain_aicheckerhumanizer-0.1.0/README.md +74 -0
- langchain_aicheckerhumanizer-0.1.0/examples/agent.py +33 -0
- langchain_aicheckerhumanizer-0.1.0/examples/detect_and_humanize.py +69 -0
- langchain_aicheckerhumanizer-0.1.0/langchain_aicheckerhumanizer/__init__.py +27 -0
- langchain_aicheckerhumanizer-0.1.0/langchain_aicheckerhumanizer/_version.py +1 -0
- langchain_aicheckerhumanizer-0.1.0/langchain_aicheckerhumanizer/api.py +415 -0
- langchain_aicheckerhumanizer-0.1.0/langchain_aicheckerhumanizer/py.typed +0 -0
- langchain_aicheckerhumanizer-0.1.0/langchain_aicheckerhumanizer/tools.py +348 -0
- langchain_aicheckerhumanizer-0.1.0/pyproject.toml +65 -0
- langchain_aicheckerhumanizer-0.1.0/tests/integration_tests/test_standard_live.py +86 -0
- langchain_aicheckerhumanizer-0.1.0/tests/unit_tests/conftest.py +21 -0
- langchain_aicheckerhumanizer-0.1.0/tests/unit_tests/test_api.py +270 -0
- langchain_aicheckerhumanizer-0.1.0/tests/unit_tests/test_standard.py +70 -0
- langchain_aicheckerhumanizer-0.1.0/tests/unit_tests/test_tools.py +815 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AI Checker Humanizer
|
|
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,16 @@
|
|
|
1
|
+
.PHONY: test integration_tests lint format
|
|
2
|
+
|
|
3
|
+
test:
|
|
4
|
+
uv run --locked pytest tests/unit_tests
|
|
5
|
+
|
|
6
|
+
integration_tests:
|
|
7
|
+
uv run --locked pytest tests/integration_tests
|
|
8
|
+
|
|
9
|
+
lint:
|
|
10
|
+
uv run --locked ruff check .
|
|
11
|
+
uv run --locked ruff format --check .
|
|
12
|
+
uv run --locked --group examples mypy --strict langchain_aicheckerhumanizer tests examples
|
|
13
|
+
|
|
14
|
+
format:
|
|
15
|
+
uv run ruff format .
|
|
16
|
+
uv run ruff check --fix .
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: langchain-aicheckerhumanizer
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: AI Checker Humanizer detection and rewriting tools for LangChain
|
|
5
|
+
Project-URL: Documentation, https://aicheckerhumanizer.com/docs/api
|
|
6
|
+
Project-URL: Repository, https://github.com/supertj/aicheckerhumanizer-mcp
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Typing :: Typed
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Requires-Dist: httpx<1,>=0.27
|
|
17
|
+
Requires-Dist: langchain-core<2,>=1.0
|
|
18
|
+
Requires-Dist: pydantic<3,>=2.7.4
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# AI Checker Humanizer for LangChain
|
|
22
|
+
|
|
23
|
+
Use the [AI detection API](https://aicheckerhumanizer.com/ai-detector-api) to score a draft and the [AI humanizer API](https://aicheckerhumanizer.com/ai-humanizer-api) to rewrite it.
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
The package requires `langchain-core` 1.x.
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install langchain-aicheckerhumanizer
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Create a key on your [account page](https://aicheckerhumanizer.com/account#api) and set `AICHECKERHUMANIZER_API_KEY` in your environment.
|
|
34
|
+
|
|
35
|
+
## Call the tools directly
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from pathlib import Path
|
|
39
|
+
|
|
40
|
+
from langchain_aicheckerhumanizer import AICheckerHumanizerToolkit
|
|
41
|
+
|
|
42
|
+
toolkit = AICheckerHumanizerToolkit()
|
|
43
|
+
detect, humanize, get_result = toolkit.get_tools()
|
|
44
|
+
text = Path("draft.txt").read_text(encoding="utf-8")
|
|
45
|
+
|
|
46
|
+
print(detect.invoke({"text": text}))
|
|
47
|
+
rewrite = humanize.invoke({"text": text, "mode": "standard", "strength": "medium"})
|
|
48
|
+
print(rewrite)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Each tool returns a JSON string on success and supports `ainvoke`. Detection accepts up to 10,000 words and can return a null score with a reason. Rewriting accepts up to 3,000 words.
|
|
52
|
+
|
|
53
|
+
- Mode can be `standard` (default), `academic`, `casual` or `concise`.
|
|
54
|
+
- Strength can be `light`, `medium` (default) or `heavy`.
|
|
55
|
+
|
|
56
|
+
By default, the rewrite tool waits up to 120 seconds after submission, including the status checks and the pauses between them. Set `humanize.max_wait_seconds` to change the limit.
|
|
57
|
+
|
|
58
|
+
If the rewrite is still pending when polling stops, you get the `taskId` and last known status. If polling stops after a temporary error such as a malformed response, the result also includes an `error` code. Check again with `get_result.invoke({"task_id": task_id})`. The result is available for about 70 minutes after submission.
|
|
59
|
+
|
|
60
|
+
When the API reports an expired result, `get_result` returns `result_expired` with `httpStatus` 410. Resubmitting with the same `idempotency_key` within 24 hours reports the same error. The response also includes `taskStatus`, `creditsCharged` and `expiredAt` when available.
|
|
61
|
+
|
|
62
|
+
`skippedWords` counts words left unchanged because their language is unsupported or the chosen mode is unavailable for that language. If a status check leaves out `skippedWords`, the rewrite tool uses the count from submission when available.
|
|
63
|
+
|
|
64
|
+
With the default error handling, a failed tool call returns a JSON string with the API's error fields and `httpStatus` if the server responded.
|
|
65
|
+
|
|
66
|
+
## Use the toolkit in an agent
|
|
67
|
+
|
|
68
|
+
Run `pip install langchain` and install the provider package for your chat model. Choose a model that supports tool calls, set `MODEL` to its `provider:model` identifier and configure the provider's credentials.
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
import os
|
|
72
|
+
|
|
73
|
+
from langchain.agents import create_agent
|
|
74
|
+
from langchain.chat_models import init_chat_model
|
|
75
|
+
|
|
76
|
+
from langchain_aicheckerhumanizer import AICheckerHumanizerToolkit
|
|
77
|
+
|
|
78
|
+
toolkit = AICheckerHumanizerToolkit()
|
|
79
|
+
agent = create_agent(init_chat_model(os.environ["MODEL"]), tools=toolkit.get_tools())
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
See `examples/agent.py` for a complete invocation.
|
|
83
|
+
|
|
84
|
+
## Credits
|
|
85
|
+
|
|
86
|
+
Detection costs 1 credit per scored word when there is a verdict. Rewriting costs 5 credits per original word in each chunk it successfully rewrites. A chunk is a paragraph or part of a long paragraph. Chunks under 10 words count as 10 for billing.
|
|
87
|
+
|
|
88
|
+
Reuse the same `idempotency_key`, text and options within 24 hours to avoid another charge for a completed check or accepted rewrite. The detect and rewrite tools generate a key when you omit it.
|
|
89
|
+
|
|
90
|
+
The server may have accepted a submission even if it times out or the connection drops. When the error JSON includes `idempotencyKey`, retry the same request with that value as `idempotency_key`. The tools also return the key after decoding errors, malformed 2xx responses, HTTP 5xx and `in_progress`.
|
|
91
|
+
|
|
92
|
+
When a rewrite has status `failed` or `cancelled`, the old key still points to that task. To start a fresh rewrite, leave `idempotency_key` out or pass a new one. This also applies to results with reason `not_humanized`, which use no credits.
|
|
93
|
+
|
|
94
|
+
See the [API documentation](https://aicheckerhumanizer.com/docs/api) for response fields, errors and service limits.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# AI Checker Humanizer for LangChain
|
|
2
|
+
|
|
3
|
+
Use the [AI detection API](https://aicheckerhumanizer.com/ai-detector-api) to score a draft and the [AI humanizer API](https://aicheckerhumanizer.com/ai-humanizer-api) to rewrite it.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
The package requires `langchain-core` 1.x.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install langchain-aicheckerhumanizer
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Create a key on your [account page](https://aicheckerhumanizer.com/account#api) and set `AICHECKERHUMANIZER_API_KEY` in your environment.
|
|
14
|
+
|
|
15
|
+
## Call the tools directly
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
from langchain_aicheckerhumanizer import AICheckerHumanizerToolkit
|
|
21
|
+
|
|
22
|
+
toolkit = AICheckerHumanizerToolkit()
|
|
23
|
+
detect, humanize, get_result = toolkit.get_tools()
|
|
24
|
+
text = Path("draft.txt").read_text(encoding="utf-8")
|
|
25
|
+
|
|
26
|
+
print(detect.invoke({"text": text}))
|
|
27
|
+
rewrite = humanize.invoke({"text": text, "mode": "standard", "strength": "medium"})
|
|
28
|
+
print(rewrite)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Each tool returns a JSON string on success and supports `ainvoke`. Detection accepts up to 10,000 words and can return a null score with a reason. Rewriting accepts up to 3,000 words.
|
|
32
|
+
|
|
33
|
+
- Mode can be `standard` (default), `academic`, `casual` or `concise`.
|
|
34
|
+
- Strength can be `light`, `medium` (default) or `heavy`.
|
|
35
|
+
|
|
36
|
+
By default, the rewrite tool waits up to 120 seconds after submission, including the status checks and the pauses between them. Set `humanize.max_wait_seconds` to change the limit.
|
|
37
|
+
|
|
38
|
+
If the rewrite is still pending when polling stops, you get the `taskId` and last known status. If polling stops after a temporary error such as a malformed response, the result also includes an `error` code. Check again with `get_result.invoke({"task_id": task_id})`. The result is available for about 70 minutes after submission.
|
|
39
|
+
|
|
40
|
+
When the API reports an expired result, `get_result` returns `result_expired` with `httpStatus` 410. Resubmitting with the same `idempotency_key` within 24 hours reports the same error. The response also includes `taskStatus`, `creditsCharged` and `expiredAt` when available.
|
|
41
|
+
|
|
42
|
+
`skippedWords` counts words left unchanged because their language is unsupported or the chosen mode is unavailable for that language. If a status check leaves out `skippedWords`, the rewrite tool uses the count from submission when available.
|
|
43
|
+
|
|
44
|
+
With the default error handling, a failed tool call returns a JSON string with the API's error fields and `httpStatus` if the server responded.
|
|
45
|
+
|
|
46
|
+
## Use the toolkit in an agent
|
|
47
|
+
|
|
48
|
+
Run `pip install langchain` and install the provider package for your chat model. Choose a model that supports tool calls, set `MODEL` to its `provider:model` identifier and configure the provider's credentials.
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
import os
|
|
52
|
+
|
|
53
|
+
from langchain.agents import create_agent
|
|
54
|
+
from langchain.chat_models import init_chat_model
|
|
55
|
+
|
|
56
|
+
from langchain_aicheckerhumanizer import AICheckerHumanizerToolkit
|
|
57
|
+
|
|
58
|
+
toolkit = AICheckerHumanizerToolkit()
|
|
59
|
+
agent = create_agent(init_chat_model(os.environ["MODEL"]), tools=toolkit.get_tools())
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
See `examples/agent.py` for a complete invocation.
|
|
63
|
+
|
|
64
|
+
## Credits
|
|
65
|
+
|
|
66
|
+
Detection costs 1 credit per scored word when there is a verdict. Rewriting costs 5 credits per original word in each chunk it successfully rewrites. A chunk is a paragraph or part of a long paragraph. Chunks under 10 words count as 10 for billing.
|
|
67
|
+
|
|
68
|
+
Reuse the same `idempotency_key`, text and options within 24 hours to avoid another charge for a completed check or accepted rewrite. The detect and rewrite tools generate a key when you omit it.
|
|
69
|
+
|
|
70
|
+
The server may have accepted a submission even if it times out or the connection drops. When the error JSON includes `idempotencyKey`, retry the same request with that value as `idempotency_key`. The tools also return the key after decoding errors, malformed 2xx responses, HTTP 5xx and `in_progress`.
|
|
71
|
+
|
|
72
|
+
When a rewrite has status `failed` or `cancelled`, the old key still points to that task. To start a fresh rewrite, leave `idempotency_key` out or pass a new one. This also applies to results with reason `not_humanized`, which use no credits.
|
|
73
|
+
|
|
74
|
+
See the [API documentation](https://aicheckerhumanizer.com/docs/api) for response fields, errors and service limits.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Give a LangChain agent the AI Checker Humanizer toolkit."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
from detect_and_humanize import SAMPLE_TEXT
|
|
6
|
+
from langchain.agents import create_agent
|
|
7
|
+
from langchain.chat_models import init_chat_model
|
|
8
|
+
|
|
9
|
+
from langchain_aicheckerhumanizer import AICheckerHumanizerToolkit
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main() -> None:
|
|
13
|
+
model = init_chat_model(os.environ["MODEL"])
|
|
14
|
+
agent = create_agent(model, tools=AICheckerHumanizerToolkit().get_tools())
|
|
15
|
+
result = agent.invoke(
|
|
16
|
+
{
|
|
17
|
+
"messages": [
|
|
18
|
+
{
|
|
19
|
+
"role": "user",
|
|
20
|
+
"content": (
|
|
21
|
+
"Check the paragraph below for AI writing. Report its score. "
|
|
22
|
+
"If the score is above 50, rewrite the paragraph and show me "
|
|
23
|
+
f"the rewritten text.\n\n{SAMPLE_TEXT}"
|
|
24
|
+
),
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
)
|
|
29
|
+
print(result["messages"][-1].content)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
if __name__ == "__main__":
|
|
33
|
+
main()
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""Check a sample, rewrite it, and check the rewrite."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from langchain_core.tools import BaseTool
|
|
7
|
+
|
|
8
|
+
from langchain_aicheckerhumanizer import (
|
|
9
|
+
AICheckerHumanizerAPIWrapper,
|
|
10
|
+
AICheckerHumanizerDetectTool,
|
|
11
|
+
AICheckerHumanizerHumanizeTool,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
SAMPLE_TEXT = (
|
|
15
|
+
"Remote work has become an increasingly common operating model for organizations "
|
|
16
|
+
"that want to recruit beyond a single city. By giving employees more control over "
|
|
17
|
+
"where they work, companies can reduce commuting time and make it easier for staff "
|
|
18
|
+
"to manage commitments outside the office. However, the success of a distributed "
|
|
19
|
+
"team depends on clear communication and deliberate coordination. Managers should "
|
|
20
|
+
"document decisions where everyone can find them and specify when colleagues can "
|
|
21
|
+
"expect a response. Meetings should have a clear purpose, especially when team "
|
|
22
|
+
"members are spread across time zones. It is also important to give new hires a "
|
|
23
|
+
"regular point of contact so questions do not pile up during their first few "
|
|
24
|
+
"weeks. "
|
|
25
|
+
"Teams can use recurring check-ins to identify obstacles early and adjust their "
|
|
26
|
+
"working agreements as needed. With these practices in place, employers can "
|
|
27
|
+
"support flexible schedules while keeping projects on track and making "
|
|
28
|
+
"responsibilities clear to everyone."
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _invoke_json(tool: BaseTool, **inputs: str) -> dict[str, Any]:
|
|
33
|
+
result: str = tool.invoke(inputs)
|
|
34
|
+
try:
|
|
35
|
+
decoded = json.loads(result)
|
|
36
|
+
except json.JSONDecodeError:
|
|
37
|
+
raise SystemExit(result) from None
|
|
38
|
+
if not isinstance(decoded, dict):
|
|
39
|
+
raise SystemExit("Expected a JSON object from the tool.")
|
|
40
|
+
return decoded
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def main() -> None:
|
|
44
|
+
api = AICheckerHumanizerAPIWrapper()
|
|
45
|
+
detect = AICheckerHumanizerDetectTool(api_wrapper=api)
|
|
46
|
+
humanize = AICheckerHumanizerHumanizeTool(api_wrapper=api)
|
|
47
|
+
|
|
48
|
+
before = _invoke_json(detect, text=SAMPLE_TEXT)
|
|
49
|
+
print("Detection result")
|
|
50
|
+
print(json.dumps(before, indent=2, ensure_ascii=False))
|
|
51
|
+
|
|
52
|
+
rewrite = _invoke_json(
|
|
53
|
+
humanize, text=SAMPLE_TEXT, mode="standard", strength="medium"
|
|
54
|
+
)
|
|
55
|
+
rewritten_text = rewrite.get("output")
|
|
56
|
+
if not rewritten_text:
|
|
57
|
+
print(json.dumps(rewrite, indent=2, ensure_ascii=False))
|
|
58
|
+
return
|
|
59
|
+
|
|
60
|
+
print("\nRewritten text")
|
|
61
|
+
print(rewritten_text)
|
|
62
|
+
|
|
63
|
+
after = _invoke_json(detect, text=rewritten_text)
|
|
64
|
+
print(f"\nOriginal score {before.get('score')}")
|
|
65
|
+
print(f"Rewrite score {after.get('score')}")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if __name__ == "__main__":
|
|
69
|
+
main()
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""AI Checker Humanizer tools for LangChain."""
|
|
2
|
+
|
|
3
|
+
from ._version import __version__
|
|
4
|
+
from .api import (
|
|
5
|
+
AICheckerHumanizerAPIWrapper,
|
|
6
|
+
AICheckerHumanizerError,
|
|
7
|
+
HumanizeMode,
|
|
8
|
+
HumanizeStrength,
|
|
9
|
+
)
|
|
10
|
+
from .tools import (
|
|
11
|
+
AICheckerHumanizerDetectTool,
|
|
12
|
+
AICheckerHumanizerGetResultTool,
|
|
13
|
+
AICheckerHumanizerHumanizeTool,
|
|
14
|
+
AICheckerHumanizerToolkit,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"AICheckerHumanizerAPIWrapper",
|
|
19
|
+
"AICheckerHumanizerDetectTool",
|
|
20
|
+
"AICheckerHumanizerError",
|
|
21
|
+
"AICheckerHumanizerGetResultTool",
|
|
22
|
+
"AICheckerHumanizerHumanizeTool",
|
|
23
|
+
"AICheckerHumanizerToolkit",
|
|
24
|
+
"HumanizeMode",
|
|
25
|
+
"HumanizeStrength",
|
|
26
|
+
"__version__",
|
|
27
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|