langchain-converter-studio 1.0.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_converter_studio-1.0.0/.gitignore +12 -0
- langchain_converter_studio-1.0.0/CHANGELOG.md +19 -0
- langchain_converter_studio-1.0.0/LICENSE +21 -0
- langchain_converter_studio-1.0.0/PKG-INFO +252 -0
- langchain_converter_studio-1.0.0/README.md +217 -0
- langchain_converter_studio-1.0.0/langchain_converter_studio/__init__.py +34 -0
- langchain_converter_studio-1.0.0/langchain_converter_studio/_client.py +281 -0
- langchain_converter_studio-1.0.0/langchain_converter_studio/_version.py +3 -0
- langchain_converter_studio-1.0.0/langchain_converter_studio/py.typed +0 -0
- langchain_converter_studio-1.0.0/langchain_converter_studio/toolkits.py +95 -0
- langchain_converter_studio-1.0.0/langchain_converter_studio/tools.py +641 -0
- langchain_converter_studio-1.0.0/pyproject.toml +121 -0
- langchain_converter_studio-1.0.0/tests/__init__.py +0 -0
- langchain_converter_studio-1.0.0/tests/integration_tests/__init__.py +0 -0
- langchain_converter_studio-1.0.0/tests/integration_tests/data/report.docx +0 -0
- langchain_converter_studio-1.0.0/tests/integration_tests/data/scan.pdf +0 -0
- langchain_converter_studio-1.0.0/tests/integration_tests/test_standard.py +90 -0
- langchain_converter_studio-1.0.0/tests/unit_tests/__init__.py +0 -0
- langchain_converter_studio-1.0.0/tests/unit_tests/conftest.py +48 -0
- langchain_converter_studio-1.0.0/tests/unit_tests/fake_api.py +212 -0
- langchain_converter_studio-1.0.0/tests/unit_tests/test_agent.py +105 -0
- langchain_converter_studio-1.0.0/tests/unit_tests/test_standard.py +90 -0
- langchain_converter_studio-1.0.0/tests/unit_tests/test_toolkit.py +90 -0
- langchain_converter_studio-1.0.0/tests/unit_tests/test_tools.py +505 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this package are listed here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the package uses
|
|
5
|
+
[semantic versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## 1.0.0 - 2026-11-23
|
|
8
|
+
|
|
9
|
+
The first release.
|
|
10
|
+
|
|
11
|
+
- Four tools for LangChain agents, sync and async: `ConverterStudioConvert` (a file or a link to
|
|
12
|
+
another format, with the API's conversion settings), `ConverterStudioExtractText` (the text of
|
|
13
|
+
a scanned PDF or a picture, with OCR), `ConverterStudioCompressPdf` and
|
|
14
|
+
`ConverterStudioListFormats` (free, no key), and `ConverterStudioToolkit` with all four.
|
|
15
|
+
- A working directory (`root_dir`): local files are read only from inside it and results are
|
|
16
|
+
saved to it, never replacing a file; without it the tools take links only.
|
|
17
|
+
- `max_credits` (20 by default) caps what one conversion may cost; errors go back to the model
|
|
18
|
+
as the tool's answer; the conversion's details come back as the tool message's artifact.
|
|
19
|
+
- LangChain's standard unit and integration tests for tools (`langchain-tests` 1.1.9).
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Converter Studio
|
|
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,252 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: langchain-converter-studio
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: LangChain tools for Converter Studio: convert files and links to other formats, read scanned PDFs and images with OCR, and compress PDFs.
|
|
5
|
+
Project-URL: Homepage, https://converter.studio
|
|
6
|
+
Project-URL: Documentation, https://converter.studio/developers
|
|
7
|
+
Project-URL: Source, https://github.com/tariksucu/langchain-converter-studio
|
|
8
|
+
Project-URL: Issues, https://github.com/tariksucu/langchain-converter-studio/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/tariksucu/langchain-converter-studio/blob/main/CHANGELOG.md
|
|
10
|
+
Author-email: Converter Studio <support@converter.studio>
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: agents,converter-studio,file-conversion,langchain,langchain-tools,ocr,pdf
|
|
14
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
15
|
+
Classifier: Framework :: AsyncIO
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
24
|
+
Classifier: Topic :: Multimedia :: Graphics :: Graphics Conversion
|
|
25
|
+
Classifier: Topic :: Office/Business
|
|
26
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
27
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
28
|
+
Classifier: Typing :: Typed
|
|
29
|
+
Requires-Python: <4.0,>=3.11
|
|
30
|
+
Requires-Dist: converter-studio<2,>=1.0
|
|
31
|
+
Requires-Dist: httpx<1,>=0.27
|
|
32
|
+
Requires-Dist: langchain-core<2,>=1.4
|
|
33
|
+
Requires-Dist: pydantic<3,>=2.7.4
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# langchain-converter-studio
|
|
37
|
+
|
|
38
|
+
LangChain tools for [Converter Studio](https://converter.studio): an agent can convert files and
|
|
39
|
+
links to other formats, read the text of scanned PDFs and photos with OCR, make PDFs smaller and
|
|
40
|
+
look up what a file can become. The work runs on Converter Studio's servers through its
|
|
41
|
+
[API](https://converter.studio/developers), so there is nothing else to install: no LibreOffice,
|
|
42
|
+
no FFmpeg, no Tesseract.
|
|
43
|
+
|
|
44
|
+
| Tool | Name | What the agent gets back |
|
|
45
|
+
| ---------------------------- | ------------------------------- | --------------------------------------------------------------------------- |
|
|
46
|
+
| `ConverterStudioConvert` | `converter_studio_convert` | the new file's download link, and the file in the working directory |
|
|
47
|
+
| `ConverterStudioExtractText` | `converter_studio_extract_text` | the recognised text of a scanned PDF or a picture (JPG, PNG, WebP, HEIC...) |
|
|
48
|
+
| `ConverterStudioCompressPdf` | `converter_studio_compress_pdf` | the sizes before and after, the smaller PDF's link and file |
|
|
49
|
+
| `ConverterStudioListFormats` | `converter_studio_list_formats` | what a format, extension or file name can become (free, no key) |
|
|
50
|
+
|
|
51
|
+
`ConverterStudioToolkit` gives an agent all four, with one set of settings.
|
|
52
|
+
|
|
53
|
+
Converter Studio reads documents (Word, PDF, ODT, RTF, Markdown, HTML), spreadsheets,
|
|
54
|
+
presentations, images and iPhone photos (HEIC, camera RAW, WebP, AVIF), video, audio, e-books,
|
|
55
|
+
subtitles, fonts, data files and archives: 67 formats.
|
|
56
|
+
|
|
57
|
+
## Installation
|
|
58
|
+
|
|
59
|
+
```console
|
|
60
|
+
$ pip install -U langchain-converter-studio
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Python 3.11 or later and `langchain-core` 1.4 or later. The package uses the official
|
|
64
|
+
[Converter Studio Python client](https://github.com/tariksucu/converter-studio-python)
|
|
65
|
+
(`converter-studio`), which pip installs with it.
|
|
66
|
+
|
|
67
|
+
Create an API key on your [account page](https://converter.studio/account#api-keys) (keys start
|
|
68
|
+
with `cvs_live_`; a free account works) and put it in the environment:
|
|
69
|
+
|
|
70
|
+
```console
|
|
71
|
+
$ export CONVERTER_STUDIO_API_KEY=cvs_live_...
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Every conversion uses the account's credits, the same as on the website: free accounts get
|
|
75
|
+
credits every day, Pro and Premium their monthly credits. Most files cost 1 credit; text
|
|
76
|
+
recognition costs a credit for every ten PDF pages started; audio and video are priced by their
|
|
77
|
+
length (video also by its frame size and the format made). See
|
|
78
|
+
[pricing](https://converter.studio/pricing). Listing formats is free.
|
|
79
|
+
|
|
80
|
+
## Quick start
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from langchain_converter_studio import ConverterStudioConvert
|
|
84
|
+
|
|
85
|
+
tool = ConverterStudioConvert(root_dir="documents")
|
|
86
|
+
print(tool.invoke({"source": "report.docx", "to": "pdf"}))
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
```text
|
|
90
|
+
Converted report.docx (DOCX) to PDF: report.pdf, 52.1 KB, 1 credit.
|
|
91
|
+
Saved in the working directory as report.pdf.
|
|
92
|
+
Download link (anyone with it can download the file until 2026-11-23 08:00 UTC): https://converter.studio/api/jobs/...
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Use it in an agent
|
|
96
|
+
|
|
97
|
+
The toolkit gives the agent all four tools. This example runs as it is, without a model provider's
|
|
98
|
+
key: `ScriptedModel` plays back the tool calls a model would make. It needs `pip install langchain`
|
|
99
|
+
for `create_agent`, a `documents` folder with a `report.docx` in it, and your Converter Studio key
|
|
100
|
+
in `CONVERTER_STUDIO_API_KEY`.
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from langchain.agents import create_agent
|
|
104
|
+
from langchain_core.language_models.fake_chat_models import GenericFakeChatModel
|
|
105
|
+
from langchain_core.messages import AIMessage
|
|
106
|
+
|
|
107
|
+
from langchain_converter_studio import ConverterStudioToolkit
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
class ScriptedModel(GenericFakeChatModel):
|
|
111
|
+
"""Plays back the messages below instead of calling a model."""
|
|
112
|
+
|
|
113
|
+
def bind_tools(self, tools, **kwargs):
|
|
114
|
+
return self
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def tool_call(call_id, name, **args):
|
|
118
|
+
return AIMessage("", tool_calls=[{"id": call_id, "name": name, "args": args}])
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
model = ScriptedModel(
|
|
122
|
+
messages=iter(
|
|
123
|
+
[
|
|
124
|
+
tool_call("1", "converter_studio_list_formats", file_format="report.docx"),
|
|
125
|
+
tool_call("2", "converter_studio_convert", source="report.docx", to="pdf"),
|
|
126
|
+
AIMessage("report.pdf is in the documents folder."),
|
|
127
|
+
]
|
|
128
|
+
)
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
toolkit = ConverterStudioToolkit(root_dir="documents", max_credits=5)
|
|
132
|
+
agent = create_agent(model, tools=toolkit.get_tools())
|
|
133
|
+
|
|
134
|
+
result = agent.invoke({"messages": [{"role": "user", "content": "Make a PDF of report.docx"}]})
|
|
135
|
+
for message in result["messages"]:
|
|
136
|
+
message.pretty_print()
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
With a real model, pass any chat model that supports tool calling instead of `model`, for example
|
|
140
|
+
`create_agent("<provider>:<model>", tools=toolkit.get_tools())`. The tools' descriptions and
|
|
141
|
+
argument schemas tell the model what each one does.
|
|
142
|
+
|
|
143
|
+
## The working directory
|
|
144
|
+
|
|
145
|
+
`root_dir` is the folder the tools work in:
|
|
146
|
+
|
|
147
|
+
- **With it**, the agent can name local files by their path inside that folder
|
|
148
|
+
(`"report.docx"`, `"scans/invoice.pdf"`), and every result is saved there under its own name.
|
|
149
|
+
A result never replaces a file: it gets `-1`, `-2`... before its extension. Paths that lead out
|
|
150
|
+
of the folder (`../`, absolute paths elsewhere, symbolic links pointing outside) are refused, so
|
|
151
|
+
a model's argument never sends other files on the machine to Converter Studio.
|
|
152
|
+
- **Without it**, the tools read no local files: they take `http://` and `https://` links only
|
|
153
|
+
(direct links and Google Drive, Dropbox or OneDrive share links), and give back download links.
|
|
154
|
+
|
|
155
|
+
## Settings
|
|
156
|
+
|
|
157
|
+
The toolkit takes all of these keyword arguments, and each tool the ones that apply to it:
|
|
158
|
+
|
|
159
|
+
| Setting | Default | What it does |
|
|
160
|
+
| ------------------- | ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
|
|
161
|
+
| `api_key` | `CONVERTER_STUDIO_API_KEY` | the account's API key (not needed by `ConverterStudioListFormats`) |
|
|
162
|
+
| `root_dir` | none | the working directory (above) |
|
|
163
|
+
| `max_credits` | `20` | the most one conversion may cost; a dearer one is refused and costs nothing. The model cannot change it |
|
|
164
|
+
| `timeout` | `600` | seconds to wait for a conversion to finish |
|
|
165
|
+
| `max_characters` | `20000` | the most characters of recognised text returned to the model (`ConverterStudioExtractText`) |
|
|
166
|
+
| `base_url` | `CONVERTER_STUDIO_BASE_URL` or `https://converter.studio/api` | another address of the API |
|
|
167
|
+
| `handle_tool_error` | `True` | tools only: errors go back to the model as the tool's answer; `False` raises `ToolException` |
|
|
168
|
+
|
|
169
|
+
## What the tools return
|
|
170
|
+
|
|
171
|
+
Called with a model's tool call (as an agent calls them), the conversion tools return a
|
|
172
|
+
`ToolMessage` whose `content` is the text above and whose `artifact` holds the conversion as a
|
|
173
|
+
dict, for your own code:
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
message = tool.invoke(
|
|
177
|
+
{
|
|
178
|
+
"args": {"source": "report.docx", "to": "pdf"},
|
|
179
|
+
"id": "1",
|
|
180
|
+
"name": tool.name,
|
|
181
|
+
"type": "tool_call",
|
|
182
|
+
}
|
|
183
|
+
)
|
|
184
|
+
message.artifact["download_url"], message.artifact["saved_path"], message.artifact["credits"]
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
The artifact has `conversion_id`, `status`, `from_format`, `to_format`, `input_name`,
|
|
188
|
+
`input_size`, `output_name`, `output_size`, `credits`, `download_url`, `expires_at` and
|
|
189
|
+
`saved_path`; `ConverterStudioExtractText` adds `text`, the whole text even when the message shows
|
|
190
|
+
only its start.
|
|
191
|
+
|
|
192
|
+
The conversion tool's arguments are `source`, `to` (`pdf`, `docx`, `jpg`, `mp4`, `mp3`...) and
|
|
193
|
+
optional `options`: the API's conversion settings, such as `{"quality": "high"}`,
|
|
194
|
+
`{"height": "720"}` for video, `{"maxKb": 200}` for a JPG under a size, `{"pageRange": "1-3"}`,
|
|
195
|
+
`{"pdfA": true}` or `{"keepMetadata": true}`. The full list is on the
|
|
196
|
+
[API page](https://converter.studio/developers); settings that do not apply are ignored.
|
|
197
|
+
`ConverterStudioExtractText` takes `source`, `language` (`auto`, `en`, `de`, `fr`, `es`, `tr`,
|
|
198
|
+
`zh`, `ja`... 19 languages) and `page_range`; `ConverterStudioCompressPdf` takes `source` and
|
|
199
|
+
`level` (`light`, `balanced`, `strong`).
|
|
200
|
+
|
|
201
|
+
## Errors
|
|
202
|
+
|
|
203
|
+
Errors come back to the model as the tool's answer (`status="error"`), in words it can act on or
|
|
204
|
+
pass on: the API's own message for a key that does not work, a lack of credits, a file that
|
|
205
|
+
cannot be converted ("Your credits were given back") or a format that cannot become another, and
|
|
206
|
+
the tool's message for a price over `max_credits`, a conversion that took longer than `timeout`, a
|
|
207
|
+
path outside the working directory or a setting with the wrong type. The API key is never part of
|
|
208
|
+
an answer.
|
|
209
|
+
|
|
210
|
+
## Async
|
|
211
|
+
|
|
212
|
+
Every tool works with `ainvoke` and in async agents (`agent.ainvoke(...)`), with the client's
|
|
213
|
+
asynchronous version underneath.
|
|
214
|
+
|
|
215
|
+
## Limits
|
|
216
|
+
|
|
217
|
+
- The largest file and the longest audio or video depend on the plan. Results are kept for 6
|
|
218
|
+
hours, then deleted.
|
|
219
|
+
- One file in, one file out: no merging or splitting of PDFs.
|
|
220
|
+
- Anyone with a download link can download the result until it expires. When an agent run is
|
|
221
|
+
traced (LangSmith, logs), the links in the tools' answers are traced with it.
|
|
222
|
+
|
|
223
|
+
## Privacy
|
|
224
|
+
|
|
225
|
+
The files the tools are given are sent to Converter Studio (converter.studio) to be converted.
|
|
226
|
+
Uploaded files are deleted as soon as they are converted, and results 6 hours later. Each request
|
|
227
|
+
also says which integration sent it (`X-Converter-Studio-Client: langchain/<version>`), for usage
|
|
228
|
+
statistics only. See the [privacy policy](https://converter.studio/privacy) and the
|
|
229
|
+
[terms](https://converter.studio/terms).
|
|
230
|
+
|
|
231
|
+
## Development
|
|
232
|
+
|
|
233
|
+
```console
|
|
234
|
+
$ pip install -e . --group dev
|
|
235
|
+
$ pytest --disable-socket --allow-unix-socket tests/unit_tests
|
|
236
|
+
$ CONVERTER_STUDIO_API_KEY=cvs_live_... pytest tests/integration_tests
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
The unit tests run LangChain's standard tool tests (`langchain-tests`) and the tools inside
|
|
240
|
+
`create_agent` against a fake API, without network. The integration tests run LangChain's
|
|
241
|
+
standard integration tests against the real API and use 12 credits.
|
|
242
|
+
|
|
243
|
+
## Links
|
|
244
|
+
|
|
245
|
+
- Converter Studio: <https://converter.studio>
|
|
246
|
+
- API documentation: <https://converter.studio/developers>
|
|
247
|
+
- Pricing: <https://converter.studio/pricing>
|
|
248
|
+
- Source code and issues: <https://github.com/tariksucu/langchain-converter-studio>
|
|
249
|
+
- Changelog: <https://github.com/tariksucu/langchain-converter-studio/blob/main/CHANGELOG.md>
|
|
250
|
+
- Support: <support@converter.studio>
|
|
251
|
+
|
|
252
|
+
MIT licensed. © Converter Studio.
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# langchain-converter-studio
|
|
2
|
+
|
|
3
|
+
LangChain tools for [Converter Studio](https://converter.studio): an agent can convert files and
|
|
4
|
+
links to other formats, read the text of scanned PDFs and photos with OCR, make PDFs smaller and
|
|
5
|
+
look up what a file can become. The work runs on Converter Studio's servers through its
|
|
6
|
+
[API](https://converter.studio/developers), so there is nothing else to install: no LibreOffice,
|
|
7
|
+
no FFmpeg, no Tesseract.
|
|
8
|
+
|
|
9
|
+
| Tool | Name | What the agent gets back |
|
|
10
|
+
| ---------------------------- | ------------------------------- | --------------------------------------------------------------------------- |
|
|
11
|
+
| `ConverterStudioConvert` | `converter_studio_convert` | the new file's download link, and the file in the working directory |
|
|
12
|
+
| `ConverterStudioExtractText` | `converter_studio_extract_text` | the recognised text of a scanned PDF or a picture (JPG, PNG, WebP, HEIC...) |
|
|
13
|
+
| `ConverterStudioCompressPdf` | `converter_studio_compress_pdf` | the sizes before and after, the smaller PDF's link and file |
|
|
14
|
+
| `ConverterStudioListFormats` | `converter_studio_list_formats` | what a format, extension or file name can become (free, no key) |
|
|
15
|
+
|
|
16
|
+
`ConverterStudioToolkit` gives an agent all four, with one set of settings.
|
|
17
|
+
|
|
18
|
+
Converter Studio reads documents (Word, PDF, ODT, RTF, Markdown, HTML), spreadsheets,
|
|
19
|
+
presentations, images and iPhone photos (HEIC, camera RAW, WebP, AVIF), video, audio, e-books,
|
|
20
|
+
subtitles, fonts, data files and archives: 67 formats.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```console
|
|
25
|
+
$ pip install -U langchain-converter-studio
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Python 3.11 or later and `langchain-core` 1.4 or later. The package uses the official
|
|
29
|
+
[Converter Studio Python client](https://github.com/tariksucu/converter-studio-python)
|
|
30
|
+
(`converter-studio`), which pip installs with it.
|
|
31
|
+
|
|
32
|
+
Create an API key on your [account page](https://converter.studio/account#api-keys) (keys start
|
|
33
|
+
with `cvs_live_`; a free account works) and put it in the environment:
|
|
34
|
+
|
|
35
|
+
```console
|
|
36
|
+
$ export CONVERTER_STUDIO_API_KEY=cvs_live_...
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Every conversion uses the account's credits, the same as on the website: free accounts get
|
|
40
|
+
credits every day, Pro and Premium their monthly credits. Most files cost 1 credit; text
|
|
41
|
+
recognition costs a credit for every ten PDF pages started; audio and video are priced by their
|
|
42
|
+
length (video also by its frame size and the format made). See
|
|
43
|
+
[pricing](https://converter.studio/pricing). Listing formats is free.
|
|
44
|
+
|
|
45
|
+
## Quick start
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from langchain_converter_studio import ConverterStudioConvert
|
|
49
|
+
|
|
50
|
+
tool = ConverterStudioConvert(root_dir="documents")
|
|
51
|
+
print(tool.invoke({"source": "report.docx", "to": "pdf"}))
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```text
|
|
55
|
+
Converted report.docx (DOCX) to PDF: report.pdf, 52.1 KB, 1 credit.
|
|
56
|
+
Saved in the working directory as report.pdf.
|
|
57
|
+
Download link (anyone with it can download the file until 2026-11-23 08:00 UTC): https://converter.studio/api/jobs/...
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Use it in an agent
|
|
61
|
+
|
|
62
|
+
The toolkit gives the agent all four tools. This example runs as it is, without a model provider's
|
|
63
|
+
key: `ScriptedModel` plays back the tool calls a model would make. It needs `pip install langchain`
|
|
64
|
+
for `create_agent`, a `documents` folder with a `report.docx` in it, and your Converter Studio key
|
|
65
|
+
in `CONVERTER_STUDIO_API_KEY`.
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from langchain.agents import create_agent
|
|
69
|
+
from langchain_core.language_models.fake_chat_models import GenericFakeChatModel
|
|
70
|
+
from langchain_core.messages import AIMessage
|
|
71
|
+
|
|
72
|
+
from langchain_converter_studio import ConverterStudioToolkit
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class ScriptedModel(GenericFakeChatModel):
|
|
76
|
+
"""Plays back the messages below instead of calling a model."""
|
|
77
|
+
|
|
78
|
+
def bind_tools(self, tools, **kwargs):
|
|
79
|
+
return self
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def tool_call(call_id, name, **args):
|
|
83
|
+
return AIMessage("", tool_calls=[{"id": call_id, "name": name, "args": args}])
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
model = ScriptedModel(
|
|
87
|
+
messages=iter(
|
|
88
|
+
[
|
|
89
|
+
tool_call("1", "converter_studio_list_formats", file_format="report.docx"),
|
|
90
|
+
tool_call("2", "converter_studio_convert", source="report.docx", to="pdf"),
|
|
91
|
+
AIMessage("report.pdf is in the documents folder."),
|
|
92
|
+
]
|
|
93
|
+
)
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
toolkit = ConverterStudioToolkit(root_dir="documents", max_credits=5)
|
|
97
|
+
agent = create_agent(model, tools=toolkit.get_tools())
|
|
98
|
+
|
|
99
|
+
result = agent.invoke({"messages": [{"role": "user", "content": "Make a PDF of report.docx"}]})
|
|
100
|
+
for message in result["messages"]:
|
|
101
|
+
message.pretty_print()
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
With a real model, pass any chat model that supports tool calling instead of `model`, for example
|
|
105
|
+
`create_agent("<provider>:<model>", tools=toolkit.get_tools())`. The tools' descriptions and
|
|
106
|
+
argument schemas tell the model what each one does.
|
|
107
|
+
|
|
108
|
+
## The working directory
|
|
109
|
+
|
|
110
|
+
`root_dir` is the folder the tools work in:
|
|
111
|
+
|
|
112
|
+
- **With it**, the agent can name local files by their path inside that folder
|
|
113
|
+
(`"report.docx"`, `"scans/invoice.pdf"`), and every result is saved there under its own name.
|
|
114
|
+
A result never replaces a file: it gets `-1`, `-2`... before its extension. Paths that lead out
|
|
115
|
+
of the folder (`../`, absolute paths elsewhere, symbolic links pointing outside) are refused, so
|
|
116
|
+
a model's argument never sends other files on the machine to Converter Studio.
|
|
117
|
+
- **Without it**, the tools read no local files: they take `http://` and `https://` links only
|
|
118
|
+
(direct links and Google Drive, Dropbox or OneDrive share links), and give back download links.
|
|
119
|
+
|
|
120
|
+
## Settings
|
|
121
|
+
|
|
122
|
+
The toolkit takes all of these keyword arguments, and each tool the ones that apply to it:
|
|
123
|
+
|
|
124
|
+
| Setting | Default | What it does |
|
|
125
|
+
| ------------------- | ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
|
|
126
|
+
| `api_key` | `CONVERTER_STUDIO_API_KEY` | the account's API key (not needed by `ConverterStudioListFormats`) |
|
|
127
|
+
| `root_dir` | none | the working directory (above) |
|
|
128
|
+
| `max_credits` | `20` | the most one conversion may cost; a dearer one is refused and costs nothing. The model cannot change it |
|
|
129
|
+
| `timeout` | `600` | seconds to wait for a conversion to finish |
|
|
130
|
+
| `max_characters` | `20000` | the most characters of recognised text returned to the model (`ConverterStudioExtractText`) |
|
|
131
|
+
| `base_url` | `CONVERTER_STUDIO_BASE_URL` or `https://converter.studio/api` | another address of the API |
|
|
132
|
+
| `handle_tool_error` | `True` | tools only: errors go back to the model as the tool's answer; `False` raises `ToolException` |
|
|
133
|
+
|
|
134
|
+
## What the tools return
|
|
135
|
+
|
|
136
|
+
Called with a model's tool call (as an agent calls them), the conversion tools return a
|
|
137
|
+
`ToolMessage` whose `content` is the text above and whose `artifact` holds the conversion as a
|
|
138
|
+
dict, for your own code:
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
message = tool.invoke(
|
|
142
|
+
{
|
|
143
|
+
"args": {"source": "report.docx", "to": "pdf"},
|
|
144
|
+
"id": "1",
|
|
145
|
+
"name": tool.name,
|
|
146
|
+
"type": "tool_call",
|
|
147
|
+
}
|
|
148
|
+
)
|
|
149
|
+
message.artifact["download_url"], message.artifact["saved_path"], message.artifact["credits"]
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
The artifact has `conversion_id`, `status`, `from_format`, `to_format`, `input_name`,
|
|
153
|
+
`input_size`, `output_name`, `output_size`, `credits`, `download_url`, `expires_at` and
|
|
154
|
+
`saved_path`; `ConverterStudioExtractText` adds `text`, the whole text even when the message shows
|
|
155
|
+
only its start.
|
|
156
|
+
|
|
157
|
+
The conversion tool's arguments are `source`, `to` (`pdf`, `docx`, `jpg`, `mp4`, `mp3`...) and
|
|
158
|
+
optional `options`: the API's conversion settings, such as `{"quality": "high"}`,
|
|
159
|
+
`{"height": "720"}` for video, `{"maxKb": 200}` for a JPG under a size, `{"pageRange": "1-3"}`,
|
|
160
|
+
`{"pdfA": true}` or `{"keepMetadata": true}`. The full list is on the
|
|
161
|
+
[API page](https://converter.studio/developers); settings that do not apply are ignored.
|
|
162
|
+
`ConverterStudioExtractText` takes `source`, `language` (`auto`, `en`, `de`, `fr`, `es`, `tr`,
|
|
163
|
+
`zh`, `ja`... 19 languages) and `page_range`; `ConverterStudioCompressPdf` takes `source` and
|
|
164
|
+
`level` (`light`, `balanced`, `strong`).
|
|
165
|
+
|
|
166
|
+
## Errors
|
|
167
|
+
|
|
168
|
+
Errors come back to the model as the tool's answer (`status="error"`), in words it can act on or
|
|
169
|
+
pass on: the API's own message for a key that does not work, a lack of credits, a file that
|
|
170
|
+
cannot be converted ("Your credits were given back") or a format that cannot become another, and
|
|
171
|
+
the tool's message for a price over `max_credits`, a conversion that took longer than `timeout`, a
|
|
172
|
+
path outside the working directory or a setting with the wrong type. The API key is never part of
|
|
173
|
+
an answer.
|
|
174
|
+
|
|
175
|
+
## Async
|
|
176
|
+
|
|
177
|
+
Every tool works with `ainvoke` and in async agents (`agent.ainvoke(...)`), with the client's
|
|
178
|
+
asynchronous version underneath.
|
|
179
|
+
|
|
180
|
+
## Limits
|
|
181
|
+
|
|
182
|
+
- The largest file and the longest audio or video depend on the plan. Results are kept for 6
|
|
183
|
+
hours, then deleted.
|
|
184
|
+
- One file in, one file out: no merging or splitting of PDFs.
|
|
185
|
+
- Anyone with a download link can download the result until it expires. When an agent run is
|
|
186
|
+
traced (LangSmith, logs), the links in the tools' answers are traced with it.
|
|
187
|
+
|
|
188
|
+
## Privacy
|
|
189
|
+
|
|
190
|
+
The files the tools are given are sent to Converter Studio (converter.studio) to be converted.
|
|
191
|
+
Uploaded files are deleted as soon as they are converted, and results 6 hours later. Each request
|
|
192
|
+
also says which integration sent it (`X-Converter-Studio-Client: langchain/<version>`), for usage
|
|
193
|
+
statistics only. See the [privacy policy](https://converter.studio/privacy) and the
|
|
194
|
+
[terms](https://converter.studio/terms).
|
|
195
|
+
|
|
196
|
+
## Development
|
|
197
|
+
|
|
198
|
+
```console
|
|
199
|
+
$ pip install -e . --group dev
|
|
200
|
+
$ pytest --disable-socket --allow-unix-socket tests/unit_tests
|
|
201
|
+
$ CONVERTER_STUDIO_API_KEY=cvs_live_... pytest tests/integration_tests
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
The unit tests run LangChain's standard tool tests (`langchain-tests`) and the tools inside
|
|
205
|
+
`create_agent` against a fake API, without network. The integration tests run LangChain's
|
|
206
|
+
standard integration tests against the real API and use 12 credits.
|
|
207
|
+
|
|
208
|
+
## Links
|
|
209
|
+
|
|
210
|
+
- Converter Studio: <https://converter.studio>
|
|
211
|
+
- API documentation: <https://converter.studio/developers>
|
|
212
|
+
- Pricing: <https://converter.studio/pricing>
|
|
213
|
+
- Source code and issues: <https://github.com/tariksucu/langchain-converter-studio>
|
|
214
|
+
- Changelog: <https://github.com/tariksucu/langchain-converter-studio/blob/main/CHANGELOG.md>
|
|
215
|
+
- Support: <support@converter.studio>
|
|
216
|
+
|
|
217
|
+
MIT licensed. © Converter Studio.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""LangChain tools for Converter Studio (https://converter.studio).
|
|
2
|
+
|
|
3
|
+
>>> from langchain_converter_studio import ConverterStudioToolkit
|
|
4
|
+
>>> tools = ConverterStudioToolkit(root_dir="documents").get_tools()
|
|
5
|
+
|
|
6
|
+
The API key comes from ``CONVERTER_STUDIO_API_KEY``. Documentation:
|
|
7
|
+
https://github.com/tariksucu/langchain-converter-studio and https://converter.studio/developers
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from langchain_converter_studio._version import __version__
|
|
11
|
+
from langchain_converter_studio.toolkits import ConverterStudioToolkit
|
|
12
|
+
from langchain_converter_studio.tools import (
|
|
13
|
+
CompressPdfInput,
|
|
14
|
+
ConverterStudioCompressPdf,
|
|
15
|
+
ConverterStudioConvert,
|
|
16
|
+
ConverterStudioExtractText,
|
|
17
|
+
ConverterStudioListFormats,
|
|
18
|
+
ConvertInput,
|
|
19
|
+
ExtractTextInput,
|
|
20
|
+
ListFormatsInput,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
"CompressPdfInput",
|
|
25
|
+
"ConvertInput",
|
|
26
|
+
"ConverterStudioCompressPdf",
|
|
27
|
+
"ConverterStudioConvert",
|
|
28
|
+
"ConverterStudioExtractText",
|
|
29
|
+
"ConverterStudioListFormats",
|
|
30
|
+
"ConverterStudioToolkit",
|
|
31
|
+
"ExtractTextInput",
|
|
32
|
+
"ListFormatsInput",
|
|
33
|
+
"__version__",
|
|
34
|
+
]
|