-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclassify.go
More file actions
343 lines (321 loc) · 9.67 KB
/
Copy pathclassify.go
File metadata and controls
343 lines (321 loc) · 9.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package cmd
import (
"context"
"fmt"
"github.com/run-llama/llama-parse-cli/internal/apiquery"
"github.com/run-llama/llama-parse-cli/internal/requestflag"
"github.com/run-llama/llama-parse-go"
"github.com/run-llama/llama-parse-go/option"
"github.com/tidwall/gjson"
"github.com/urfave/cli/v3"
)
var classifyCreate = requestflag.WithInnerFlags(cli.Command{
Name: "create",
Usage: "Create a classify job.",
Suggest: true,
Flags: []cli.Flag{
&requestflag.Flag[*string]{
Name: "organization-id",
QueryPath: "organization_id",
},
&requestflag.Flag[*string]{
Name: "project-id",
QueryPath: "project_id",
},
&requestflag.Flag[map[string]any]{
Name: "configuration",
Usage: "Configuration for a classify job.",
BodyPath: "configuration",
},
&requestflag.Flag[*string]{
Name: "configuration-id",
Usage: "Saved configuration ID",
BodyPath: "configuration_id",
},
&requestflag.Flag[*string]{
Name: "file-id",
Usage: "Deprecated: use file_input instead",
BodyPath: "file_id",
},
&requestflag.Flag[*string]{
Name: "file-input",
Usage: "File ID or parse job ID to classify",
BodyPath: "file_input",
},
&requestflag.Flag[*string]{
Name: "parse-job-id",
Usage: "Deprecated: use file_input instead",
BodyPath: "parse_job_id",
},
&requestflag.Flag[*string]{
Name: "transaction-id",
Usage: "Idempotency key scoped to the project",
BodyPath: "transaction_id",
},
&requestflag.Flag[any]{
Name: "webhook-configuration",
Usage: "Outbound webhook endpoints to notify on job status changes",
BodyPath: "webhook_configurations",
},
},
Action: handleClassifyCreate,
HideHelpCommand: true,
}, map[string][]requestflag.HasOuterFlag{
"configuration": {
&requestflag.InnerFlag[[]map[string]any]{
Name: "configuration.rules",
Usage: "Classify rules to evaluate against the document (at least one required)",
InnerField: "rules",
},
&requestflag.InnerFlag[string]{
Name: "configuration.mode",
Usage: "Classify execution mode",
InnerField: "mode",
},
&requestflag.InnerFlag[map[string]any]{
Name: "configuration.parsing-configuration",
Usage: "Parsing configuration for classify jobs.",
InnerField: "parsing_configuration",
},
},
"webhook-configuration": {
&requestflag.InnerFlag[any]{
Name: "webhook-configuration.webhook-events",
Usage: "Events to subscribe to (e.g. 'parse.success', 'extract.error'). If null, all events are delivered.",
InnerField: "webhook_events",
OuterIsArrayOfObjects: true,
},
&requestflag.InnerFlag[map[string]any]{
Name: "webhook-configuration.webhook-headers",
Usage: "Custom HTTP headers sent with each webhook request (e.g. auth tokens)",
InnerField: "webhook_headers",
OuterIsArrayOfObjects: true,
},
&requestflag.InnerFlag[*string]{
Name: "webhook-configuration.webhook-output-format",
Usage: "Response format sent to the webhook: 'string' (default) or 'json'",
InnerField: "webhook_output_format",
OuterIsArrayOfObjects: true,
},
&requestflag.InnerFlag[*string]{
Name: "webhook-configuration.webhook-signing-secret",
Usage: "Shared signing secret used to sign webhook deliveries. When set, each request includes an HMAC-SHA256 signature of the request body in the 'LC-Signature' header (value 'sha256=<hex>'). Recompute the HMAC over the raw request body with this secret to verify the delivery is authentic.",
InnerField: "webhook_signing_secret",
OuterIsArrayOfObjects: true,
},
&requestflag.InnerFlag[*string]{
Name: "webhook-configuration.webhook-url",
Usage: "URL to receive webhook POST notifications",
InnerField: "webhook_url",
OuterIsArrayOfObjects: true,
},
},
})
var classifyList = cli.Command{
Name: "list",
Usage: "List classify jobs with optional filtering and pagination.",
Suggest: true,
Flags: []cli.Flag{
&requestflag.Flag[*string]{
Name: "configuration-id",
Usage: "Filter by configuration ID",
QueryPath: "configuration_id",
},
&requestflag.Flag[any]{
Name: "created-at-on-or-after",
Usage: "Include items created at or after this timestamp (inclusive)",
QueryPath: "created_at_on_or_after",
},
&requestflag.Flag[any]{
Name: "created-at-on-or-before",
Usage: "Include items created at or before this timestamp (inclusive)",
QueryPath: "created_at_on_or_before",
},
&requestflag.Flag[any]{
Name: "job-id",
Usage: "Filter by specific job IDs",
QueryPath: "job_ids",
},
&requestflag.Flag[*string]{
Name: "organization-id",
QueryPath: "organization_id",
},
&requestflag.Flag[*int64]{
Name: "page-size",
Usage: "Number of items per page",
QueryPath: "page_size",
},
&requestflag.Flag[*string]{
Name: "page-token",
Usage: "Token for pagination",
QueryPath: "page_token",
},
&requestflag.Flag[*string]{
Name: "project-id",
QueryPath: "project_id",
},
&requestflag.Flag[*string]{
Name: "status",
Usage: "Filter by job status",
QueryPath: "status",
},
&requestflag.Flag[int64]{
Name: "max-items",
Usage: "The maximum number of items to return (use -1 for unlimited).",
},
},
Action: handleClassifyList,
HideHelpCommand: true,
}
var classifyGet = cli.Command{
Name: "get",
Usage: "Get a classify job by ID.",
Suggest: true,
Flags: []cli.Flag{
&requestflag.Flag[string]{
Name: "job-id",
Required: true,
PathParam: "job_id",
},
&requestflag.Flag[*string]{
Name: "organization-id",
QueryPath: "organization_id",
},
&requestflag.Flag[*string]{
Name: "project-id",
QueryPath: "project_id",
},
},
Action: handleClassifyGet,
HideHelpCommand: true,
}
func handleClassifyCreate(ctx context.Context, cmd *cli.Command) error {
client := llamacloud.NewClient(getDefaultRequestOptions(cmd)...)
unusedArgs := cmd.Args().Slice()
if len(unusedArgs) > 0 {
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
}
options, err := flagOptions(
cmd,
apiquery.NestedQueryFormatBrackets,
apiquery.ArrayQueryFormatRepeat,
ApplicationJSON,
false,
)
if err != nil {
return err
}
params := llamacloud.ClassifyNewParams{}
var res []byte
options = append(options, option.WithResponseBodyInto(&res))
_, err = client.Classify.New(ctx, params, options...)
if err != nil {
return err
}
obj := gjson.ParseBytes(res)
format := cmd.Root().String("format")
explicitFormat := cmd.Root().IsSet("format")
transform := cmd.Root().String("transform")
return ShowJSON(obj, ShowJSONOpts{
ExplicitFormat: explicitFormat,
Format: format,
RawOutput: cmd.Root().Bool("raw-output"),
Title: "classify create",
Transform: transform,
})
}
func handleClassifyList(ctx context.Context, cmd *cli.Command) error {
client := llamacloud.NewClient(getDefaultRequestOptions(cmd)...)
unusedArgs := cmd.Args().Slice()
if len(unusedArgs) > 0 {
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
}
options, err := flagOptions(
cmd,
apiquery.NestedQueryFormatBrackets,
apiquery.ArrayQueryFormatRepeat,
EmptyBody,
false,
)
if err != nil {
return err
}
params := llamacloud.ClassifyListParams{}
format := cmd.Root().String("format")
explicitFormat := cmd.Root().IsSet("format")
transform := cmd.Root().String("transform")
if format == "raw" {
var res []byte
options = append(options, option.WithResponseBodyInto(&res))
_, err = client.Classify.List(ctx, params, options...)
if err != nil {
return err
}
obj := gjson.ParseBytes(res)
return ShowJSON(obj, ShowJSONOpts{
ExplicitFormat: explicitFormat,
Format: format,
RawOutput: cmd.Root().Bool("raw-output"),
Title: "classify list",
Transform: transform,
})
} else {
iter := client.Classify.ListAutoPaging(ctx, params, options...)
maxItems := int64(-1)
if cmd.IsSet("max-items") {
maxItems = cmd.Value("max-items").(int64)
}
return ShowJSONIterator(iter, maxItems, ShowJSONOpts{
ExplicitFormat: explicitFormat,
Format: format,
RawOutput: cmd.Root().Bool("raw-output"),
Title: "classify list",
Transform: transform,
})
}
}
func handleClassifyGet(ctx context.Context, cmd *cli.Command) error {
client := llamacloud.NewClient(getDefaultRequestOptions(cmd)...)
unusedArgs := cmd.Args().Slice()
if !cmd.IsSet("job-id") && len(unusedArgs) > 0 {
cmd.Set("job-id", unusedArgs[0])
unusedArgs = unusedArgs[1:]
}
if len(unusedArgs) > 0 {
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
}
options, err := flagOptions(
cmd,
apiquery.NestedQueryFormatBrackets,
apiquery.ArrayQueryFormatRepeat,
EmptyBody,
false,
)
if err != nil {
return err
}
params := llamacloud.ClassifyGetParams{}
var res []byte
options = append(options, option.WithResponseBodyInto(&res))
_, err = client.Classify.Get(
ctx,
cmd.Value("job-id").(string),
params,
options...,
)
if err != nil {
return err
}
obj := gjson.ParseBytes(res)
format := cmd.Root().String("format")
explicitFormat := cmd.Root().IsSet("format")
transform := cmd.Root().String("transform")
return ShowJSON(obj, ShowJSONOpts{
ExplicitFormat: explicitFormat,
Format: format,
RawOutput: cmd.Root().Bool("raw-output"),
Title: "classify get",
Transform: transform,
})
}