@mdgate/ai 0.6.8 → 0.6.10
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.
- package/README.md +73 -7
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,31 +1,97 @@
|
|
|
1
1
|
# @mdgate/ai
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Optional multimodal callbacks for mdgate image, audio, and video conversion.**
|
|
4
|
+
|
|
5
|
+
[`@mdgate/ai`](https://github.com/mdgate/converters/tree/main/packages/ai) talks to an OpenAI-compatible `chat/completions` endpoint. There is no default provider. You pass `baseURL`, `apiKey`, and `model`.
|
|
6
|
+
|
|
7
|
+
Works in **Node.js, Cloudflare Workers, Edge runtimes, and browsers**.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @mdgate/ai
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Why [`@mdgate/ai`](https://github.com/mdgate/converters/tree/main/packages/ai)
|
|
16
|
+
|
|
17
|
+
Raster images, audio, and video are not deterministic document formats. mdgate does not pick an OCR or speech vendor.
|
|
18
|
+
|
|
19
|
+
This package is a thin adapter so the model you already use can plug into [`@mdgate/image`](https://github.com/mdgate/converters/tree/main/packages/image), [`@mdgate/audio`](https://github.com/mdgate/converters/tree/main/packages/audio), and [`@mdgate/video`](https://github.com/mdgate/converters/tree/main/packages/video).
|
|
20
|
+
|
|
21
|
+
* **No default endpoint**
|
|
22
|
+
* **No Python runtime**
|
|
23
|
+
* **No native addons**
|
|
24
|
+
* **No WASM runtime**
|
|
25
|
+
* **The prompt is built in**
|
|
26
|
+
|
|
27
|
+
SVG still converts locally in [`@mdgate/image`](https://github.com/mdgate/converters/tree/main/packages/image). You do not need this package for SVG.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
4
32
|
|
|
5
33
|
```ts
|
|
6
34
|
import { create } from '@mdgate/core';
|
|
35
|
+
import { ai } from '@mdgate/ai';
|
|
7
36
|
import { image } from '@mdgate/image';
|
|
8
37
|
import { audio } from '@mdgate/audio';
|
|
9
38
|
import { video } from '@mdgate/video';
|
|
10
|
-
import { ai } from '@mdgate/ai';
|
|
11
39
|
import { pdf } from '@mdgate/pdf';
|
|
12
40
|
|
|
13
41
|
const media = ai({
|
|
14
42
|
baseURL: 'https://api.example.com/v1',
|
|
15
|
-
apiKey: process.env.
|
|
16
|
-
model: '
|
|
43
|
+
apiKey: process.env.API_KEY!,
|
|
44
|
+
model: 'your-model',
|
|
17
45
|
});
|
|
18
46
|
|
|
19
|
-
const
|
|
47
|
+
const read = create([
|
|
20
48
|
pdf(),
|
|
21
49
|
image(media.convertImage),
|
|
22
50
|
audio(media.convertAudio),
|
|
23
51
|
video(media.convertVideo),
|
|
24
52
|
]);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`baseURL` is the OpenAI-compatible API root (the same value the OpenAI SDK uses). Requests go to `{baseURL}/chat/completions`.
|
|
56
|
+
|
|
57
|
+
Audio and video are sent as data URLs.
|
|
25
58
|
|
|
26
|
-
|
|
59
|
+
These callbacks are not registered by `all()`. Compose them yourself.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## What it covers
|
|
64
|
+
|
|
65
|
+
Raster images: JPEG, PNG, WebP, GIF, TIFF, HEIC, BMP.
|
|
66
|
+
|
|
67
|
+
Audio: MP3, WAV, M4A, AAC, Ogg, FLAC, WebM audio.
|
|
68
|
+
|
|
69
|
+
Video: MP4, MOV, WebM, Matroska, AVI.
|
|
70
|
+
|
|
71
|
+
You can also call the helpers directly:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
await media.convertImage({ bytes, mime: 'image/png' });
|
|
27
75
|
await media.convertAudio({ bytes, mime: 'audio/mpeg' });
|
|
28
76
|
await media.convertVideo({ bytes, mime: 'video/mp4' });
|
|
29
77
|
```
|
|
30
78
|
|
|
31
|
-
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## Need a complete reader?
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
npm install @mdgate/converters
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Then add `image()`, `audio()`, and `video()` on top of `all()`.
|
|
88
|
+
|
|
89
|
+
[`@mdgate/ai`](https://github.com/mdgate/converters/tree/main/packages/ai) is part of the open-source [`mdgate/converters`](https://github.com/mdgate/converters) project.
|
|
90
|
+
|
|
91
|
+
For AI agents, the same converter architecture can be used to extend `read_file` from text files to real-world document formats.
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdgate/ai",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.10",
|
|
4
4
|
"description": "Optional AI helper for mdgate: ai({ baseURL, apiKey, model }).convertImage / convertAudio / convertVideo",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"homepage": "https://
|
|
7
|
+
"homepage": "https://convert.mdgate.dev",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "git+https://github.com/mdgate/converters.git",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"prepublishOnly": "bun run build"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@mdgate/core": "0.6.
|
|
32
|
-
"@mdgate/image": "0.6.
|
|
33
|
-
"@mdgate/video": "0.6.
|
|
31
|
+
"@mdgate/core": "0.6.10",
|
|
32
|
+
"@mdgate/image": "0.6.10",
|
|
33
|
+
"@mdgate/video": "0.6.10"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|