langchain-duel 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_duel-0.1.0/.gitignore +11 -0
- langchain_duel-0.1.0/LICENSE +21 -0
- langchain_duel-0.1.0/PKG-INFO +74 -0
- langchain_duel-0.1.0/README.md +53 -0
- langchain_duel-0.1.0/langchain_duel/__init__.py +11 -0
- langchain_duel-0.1.0/langchain_duel/chat_models.py +83 -0
- langchain_duel-0.1.0/pyproject.toml +39 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aaron Shaw
|
|
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,74 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: langchain-duel
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: An integration package connecting Duel Agents and LangChain
|
|
5
|
+
Project-URL: Homepage, https://duelagents.com
|
|
6
|
+
Project-URL: Source Code, https://github.com/2aronS/Duel-Agents/tree/main/python/langchain-duel
|
|
7
|
+
Project-URL: Release Notes, https://github.com/2aronS/Duel-Agents/releases
|
|
8
|
+
Project-URL: Repository, https://github.com/2aronS/Duel-Agents
|
|
9
|
+
Author: Aaron Shaw
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: duel-agents,langchain,llm,model-routing,openai
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Requires-Dist: langchain-core<0.4,>=0.3.15
|
|
15
|
+
Requires-Dist: langchain-openai<0.4,>=0.2
|
|
16
|
+
Provides-Extra: test
|
|
17
|
+
Requires-Dist: langchain-tests<0.4,>=0.3.5; extra == 'test'
|
|
18
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'test'
|
|
19
|
+
Requires-Dist: pytest>=7.4; extra == 'test'
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# langchain-duel
|
|
23
|
+
|
|
24
|
+
This package connects [Duel Agents](https://duelagents.com) to LangChain.
|
|
25
|
+
|
|
26
|
+
Duel Agents routes each prompt against multiple models and bills the cheapest
|
|
27
|
+
answer that still wins. The proxy is OpenAI wire compatible, so `ChatDuel`
|
|
28
|
+
builds on `langchain-openai` and just points at the Duel proxy with sensible
|
|
29
|
+
defaults.
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install -U langchain-duel
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Set your Duel API key (create one at
|
|
38
|
+
[duelagents.com/dashboard/settings](https://duelagents.com/dashboard/settings)):
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
export DUEL_API_KEY="duel_<prefix>_<secret>"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Chat models
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from langchain_duel import ChatDuel
|
|
48
|
+
|
|
49
|
+
llm = ChatDuel(model="duel-auto", temperature=0)
|
|
50
|
+
print(llm.invoke("Explain concurrent agents in one sentence.").content)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`duel-auto` lets the router pick the model. You can also pass a specific model
|
|
54
|
+
name (for example `gpt-4o-mini` or `claude-3-5-haiku-latest`) and Duel will
|
|
55
|
+
route to that provider.
|
|
56
|
+
|
|
57
|
+
### Streaming
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
for chunk in llm.stream("Write a haiku about routing."):
|
|
61
|
+
print(chunk.content, end="", flush=True)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Configuration
|
|
65
|
+
|
|
66
|
+
| Argument | Env var | Default |
|
|
67
|
+
|----------|---------|---------|
|
|
68
|
+
| `api_key` | `DUEL_API_KEY` | required |
|
|
69
|
+
| `base_url` | `DUEL_PROXY_URL` | `https://duelagents.com/v1` |
|
|
70
|
+
| `model` | - | `duel-auto` |
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
MIT
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# langchain-duel
|
|
2
|
+
|
|
3
|
+
This package connects [Duel Agents](https://duelagents.com) to LangChain.
|
|
4
|
+
|
|
5
|
+
Duel Agents routes each prompt against multiple models and bills the cheapest
|
|
6
|
+
answer that still wins. The proxy is OpenAI wire compatible, so `ChatDuel`
|
|
7
|
+
builds on `langchain-openai` and just points at the Duel proxy with sensible
|
|
8
|
+
defaults.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install -U langchain-duel
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Set your Duel API key (create one at
|
|
17
|
+
[duelagents.com/dashboard/settings](https://duelagents.com/dashboard/settings)):
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
export DUEL_API_KEY="duel_<prefix>_<secret>"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Chat models
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from langchain_duel import ChatDuel
|
|
27
|
+
|
|
28
|
+
llm = ChatDuel(model="duel-auto", temperature=0)
|
|
29
|
+
print(llm.invoke("Explain concurrent agents in one sentence.").content)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`duel-auto` lets the router pick the model. You can also pass a specific model
|
|
33
|
+
name (for example `gpt-4o-mini` or `claude-3-5-haiku-latest`) and Duel will
|
|
34
|
+
route to that provider.
|
|
35
|
+
|
|
36
|
+
### Streaming
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
for chunk in llm.stream("Write a haiku about routing."):
|
|
40
|
+
print(chunk.content, end="", flush=True)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Configuration
|
|
44
|
+
|
|
45
|
+
| Argument | Env var | Default |
|
|
46
|
+
|----------|---------|---------|
|
|
47
|
+
| `api_key` | `DUEL_API_KEY` | required |
|
|
48
|
+
| `base_url` | `DUEL_PROXY_URL` | `https://duelagents.com/v1` |
|
|
49
|
+
| `model` | - | `duel-auto` |
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
MIT
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""Duel Agents chat model for LangChain."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from langchain_openai import ChatOpenAI
|
|
9
|
+
from pydantic import model_validator
|
|
10
|
+
|
|
11
|
+
DUEL_API_BASE = "https://duelagents.com/v1"
|
|
12
|
+
DEFAULT_MODEL = "duel-auto"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ChatDuel(ChatOpenAI):
|
|
16
|
+
"""Duel Agents chat model.
|
|
17
|
+
|
|
18
|
+
Routes prompts through the Duel Agents proxy, which runs the request against
|
|
19
|
+
multiple models and bills the cheapest answer that still wins. The proxy is
|
|
20
|
+
wire compatible with the OpenAI chat completions API, so this class builds on
|
|
21
|
+
:class:`~langchain_openai.ChatOpenAI` and only changes the defaults.
|
|
22
|
+
|
|
23
|
+
Setup:
|
|
24
|
+
Install ``langchain-duel`` and set ``DUEL_API_KEY`` (create a key at
|
|
25
|
+
https://duelagents.com/dashboard/settings).
|
|
26
|
+
|
|
27
|
+
.. code-block:: bash
|
|
28
|
+
|
|
29
|
+
pip install -U langchain-duel
|
|
30
|
+
export DUEL_API_KEY="duel_<prefix>_<secret>"
|
|
31
|
+
|
|
32
|
+
Key init args:
|
|
33
|
+
model: str
|
|
34
|
+
Model routed by Duel. Defaults to ``"duel-auto"`` (auto routing).
|
|
35
|
+
api_key: Optional[str]
|
|
36
|
+
Duel API key. Falls back to the ``DUEL_API_KEY`` env var.
|
|
37
|
+
base_url: Optional[str]
|
|
38
|
+
Proxy URL. Falls back to ``DUEL_PROXY_URL`` then the public proxy.
|
|
39
|
+
|
|
40
|
+
Example:
|
|
41
|
+
.. code-block:: python
|
|
42
|
+
|
|
43
|
+
from langchain_duel import ChatDuel
|
|
44
|
+
|
|
45
|
+
llm = ChatDuel(model="duel-auto", temperature=0)
|
|
46
|
+
llm.invoke("Explain concurrent agents in one sentence.")
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def lc_secrets(self) -> dict[str, str]:
|
|
51
|
+
return {"openai_api_key": "DUEL_API_KEY"}
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def _llm_type(self) -> str:
|
|
55
|
+
return "duel-chat"
|
|
56
|
+
|
|
57
|
+
@classmethod
|
|
58
|
+
def is_lc_serializable(cls) -> bool:
|
|
59
|
+
# Third-party namespaces are not registered with the LangChain loader,
|
|
60
|
+
# so the model is not round-trip serializable.
|
|
61
|
+
return False
|
|
62
|
+
|
|
63
|
+
@model_validator(mode="before")
|
|
64
|
+
@classmethod
|
|
65
|
+
def _set_duel_defaults(cls, values: Any) -> Any:
|
|
66
|
+
if not isinstance(values, dict):
|
|
67
|
+
return values
|
|
68
|
+
|
|
69
|
+
values.setdefault("model", DEFAULT_MODEL)
|
|
70
|
+
values.setdefault(
|
|
71
|
+
"base_url", os.getenv("DUEL_PROXY_URL", DUEL_API_BASE)
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
has_key = any(
|
|
75
|
+
values.get(field)
|
|
76
|
+
for field in ("api_key", "openai_api_key")
|
|
77
|
+
)
|
|
78
|
+
if not has_key:
|
|
79
|
+
env_key = os.getenv("DUEL_API_KEY")
|
|
80
|
+
if env_key:
|
|
81
|
+
values["api_key"] = env_key
|
|
82
|
+
|
|
83
|
+
return values
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "langchain-duel"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "An integration package connecting Duel Agents and LangChain"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
authors = [{ name = "Aaron Shaw" }]
|
|
13
|
+
keywords = ["langchain", "duel-agents", "llm", "openai", "model-routing"]
|
|
14
|
+
dependencies = [
|
|
15
|
+
"langchain-core>=0.3.15,<0.4",
|
|
16
|
+
"langchain-openai>=0.2,<0.4",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Homepage = "https://duelagents.com"
|
|
21
|
+
"Source Code" = "https://github.com/2aronS/Duel-Agents/tree/main/python/langchain-duel"
|
|
22
|
+
"Release Notes" = "https://github.com/2aronS/Duel-Agents/releases"
|
|
23
|
+
Repository = "https://github.com/2aronS/Duel-Agents"
|
|
24
|
+
|
|
25
|
+
[project.optional-dependencies]
|
|
26
|
+
test = [
|
|
27
|
+
"pytest>=7.4",
|
|
28
|
+
"pytest-asyncio>=0.23",
|
|
29
|
+
"langchain-tests>=0.3.5,<0.4",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[tool.hatch.build.targets.wheel]
|
|
33
|
+
packages = ["langchain_duel"]
|
|
34
|
+
|
|
35
|
+
[tool.hatch.build.targets.sdist]
|
|
36
|
+
include = ["langchain_duel", "README.md", "LICENSE"]
|
|
37
|
+
|
|
38
|
+
[tool.pytest.ini_options]
|
|
39
|
+
asyncio_mode = "auto"
|