@llamaindex/liteparse-grpc 0.1.0
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/LICENSE +21 -0
- package/README.md +154 -0
- package/dist/client.js +1674 -0
- package/dist/protogen/parser.js +1542 -0
- package/dist/server.js +6224 -0
- package/dist/types/client.d.ts +3 -0
- package/dist/types/protogen/parser.d.ts +267 -0
- package/dist/types/server.d.ts +3 -0
- package/package.json +84 -0
- package/proto/parser.proto +213 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) LlamaIndex 2026
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# @llamaindex/liteparse-grpc
|
|
2
|
+
|
|
3
|
+
A [gRPC](https://grpc.io) server (and matching client) that exposes [`@llamaindex/liteparse`](https://www.npmjs.com/package/@llamaindex/liteparse) for parsing, screenshotting, and complexity estimation of unstructured documents.
|
|
4
|
+
|
|
5
|
+
The package ships:
|
|
6
|
+
|
|
7
|
+
- A **server binary** (`liteparse-grpc-server`) that runs the gRPC service
|
|
8
|
+
- A **client binary** (`liteparse-grpc-client`) for quickly exercising the service from the command line
|
|
9
|
+
- The **generated TypeScript stubs** so you can build your own client or server against the same `.proto`
|
|
10
|
+
- The raw **`parser.proto`** file for generating stubs in other languages
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @llamaindex/liteparse-grpc
|
|
16
|
+
# or
|
|
17
|
+
pnpm add @llamaindex/liteparse-grpc
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Service definition
|
|
21
|
+
|
|
22
|
+
The service exposes three RPCs:
|
|
23
|
+
|
|
24
|
+
| RPC | Description |
|
|
25
|
+
| ------------ | ----------------------------------------------------------- |
|
|
26
|
+
| `Parse` | Parse a file into JSON pages, plain text, or markdown |
|
|
27
|
+
| `Screenshot` | Render the pages of a PDF as PNG images |
|
|
28
|
+
| `IsComplex` | Estimate the complexity of a file and whether OCR is needed |
|
|
29
|
+
|
|
30
|
+
See [`proto/parser.proto`](./proto/parser.proto) for the full schema, or import it from the package:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import protoPath from "@llamaindex/liteparse-grpc/proto";
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Running the server
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# From an install
|
|
40
|
+
npx liteparse-grpc-server
|
|
41
|
+
|
|
42
|
+
# Bind address is configurable via env var (default: 127.0.0.1:50051)
|
|
43
|
+
GRPC_BIND_ADDR=0.0.0.0:50051 npx liteparse-grpc-server
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Environment variables:
|
|
47
|
+
|
|
48
|
+
| Variable | Default | Description |
|
|
49
|
+
| ---------------- | ----------------- | --------------------------------------------- |
|
|
50
|
+
| `GRPC_BIND_ADDR` | `127.0.0.1:50051` | Address the gRPC server binds to |
|
|
51
|
+
| `LOG_LEVEL` | `info` | pino log level (`trace`/`debug`/`info`/...) |
|
|
52
|
+
| `NODE_ENV` | — | Set to `production` to disable pretty logging |
|
|
53
|
+
|
|
54
|
+
## Docker
|
|
55
|
+
|
|
56
|
+
The repo ships a [`Dockerfile`](./Dockerfile) that produces a self-contained image with all system libraries needed for full LiteParse functionality (libvips, LibreOffice, ImageMagick).
|
|
57
|
+
|
|
58
|
+
Build and run it from the **repo root** (the Dockerfile expects the workspace layout):
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# Build the image
|
|
62
|
+
docker build -f packages/liteparse-grpc/Dockerfile -t liteparse-grpc .
|
|
63
|
+
|
|
64
|
+
# Run exposing port 50051
|
|
65
|
+
docker run -p 50051:50051 liteparse-grpc
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The gRPC server is then reachable at **localhost:50051**. Override `GRPC_BIND_ADDR` or `LOG_LEVEL` with `-e` as needed.
|
|
69
|
+
|
|
70
|
+
## Using the client binary
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# Parse a file (defaults to plain text output)
|
|
74
|
+
npx liteparse-grpc-client parse ./document.pdf
|
|
75
|
+
|
|
76
|
+
# Parse as JSON pages
|
|
77
|
+
npx liteparse-grpc-client parse ./document.pdf --json
|
|
78
|
+
|
|
79
|
+
# Parse as markdown
|
|
80
|
+
npx liteparse-grpc-client parse ./document.pdf --markdown
|
|
81
|
+
|
|
82
|
+
# Estimate complexity
|
|
83
|
+
npx liteparse-grpc-client is-complex ./document.pdf
|
|
84
|
+
|
|
85
|
+
# Screenshot every page to ./imgs/
|
|
86
|
+
npx liteparse-grpc-client screenshot ./document.pdf --dest-dir ./imgs
|
|
87
|
+
|
|
88
|
+
# Provide a custom LiteParseConfig via JSON file
|
|
89
|
+
npx liteparse-grpc-client parse ./document.pdf --config-file ./my-config.json
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Run `npx liteparse-grpc-client --help` for the full option list.
|
|
93
|
+
|
|
94
|
+
## Programmatic usage
|
|
95
|
+
|
|
96
|
+
The generated stubs are re-exported from the package root, and dedicated client/server entry points are also available:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
// Generated protobuf types & service definitions
|
|
100
|
+
import {
|
|
101
|
+
ParserServiceClient,
|
|
102
|
+
ParserServiceService,
|
|
103
|
+
OutputFormat,
|
|
104
|
+
ImageMode,
|
|
105
|
+
type LiteParseConfig,
|
|
106
|
+
} from "@llamaindex/liteparse-grpc";
|
|
107
|
+
|
|
108
|
+
import * as grpc from "@grpc/grpc-js";
|
|
109
|
+
|
|
110
|
+
const client = new ParserServiceClient(
|
|
111
|
+
"127.0.0.1:50051",
|
|
112
|
+
grpc.credentials.createInsecure(),
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const file = /* Buffer of your document */;
|
|
116
|
+
const config: LiteParseConfig = {
|
|
117
|
+
ocrLanguage: "eng",
|
|
118
|
+
ocrEnabled: true,
|
|
119
|
+
outputFormat: OutputFormat.OUTPUT_FORMAT_MARKDOWN,
|
|
120
|
+
imageMode: ImageMode.IMAGE_MODE_OFF,
|
|
121
|
+
// ...see proto/parser.proto for all fields
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
client.parse({ config, file }, (err, response) => {
|
|
125
|
+
if (err) throw err;
|
|
126
|
+
console.log(response.text);
|
|
127
|
+
});
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Generating stubs in other languages
|
|
131
|
+
|
|
132
|
+
Because the `.proto` is bundled, you can point `protoc` (or your language's equivalent) at it:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
protoc \
|
|
136
|
+
--proto_path=node_modules/@llamaindex/liteparse-grpc/proto \
|
|
137
|
+
--python_out=./gen \
|
|
138
|
+
--grpc_python_out=./gen \
|
|
139
|
+
parser.proto
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Development
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
# Regenerate TS stubs from the .proto
|
|
146
|
+
pnpm run build:proto
|
|
147
|
+
|
|
148
|
+
# Build everything (proto + server + client + type declarations)
|
|
149
|
+
pnpm run build
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
MIT
|