@saplingai/sapling-js 1.0.39 → 1.0.52
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 +152 -1
- package/package.json +2 -2
- package/sapling/client.d.ts +405 -2
- package/sapling/client.js +1059 -4
package/README.md
CHANGED
|
@@ -76,6 +76,56 @@ You should see something like the following output:
|
|
|
76
76
|
}
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
+
If you only need to apply the corrections, pass `includeErrorCategories: false`. The API then
|
|
80
|
+
skips error classification (faster and lighter), and each edit comes back without
|
|
81
|
+
`error_type`, `general_error_type` or classifier-generated descriptions:
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
client.edits('I have a apple!', undefined, { includeErrorCategories: false, autoApply: true })
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Text classification
|
|
88
|
+
|
|
89
|
+
Zero-shot classification with your own labels (plain names or `{ name, description }` objects, 2–20):
|
|
90
|
+
|
|
91
|
+
```javascript
|
|
92
|
+
client
|
|
93
|
+
.classify(
|
|
94
|
+
'I was charged twice and the app crashes on launch.',
|
|
95
|
+
['billing', { name: 'technical issue', description: 'Bugs, crashes, errors.' }, 'other'],
|
|
96
|
+
{ multiLabel: true, threshold: 0.5, context: 'Support tickets for a SaaS billing product' },
|
|
97
|
+
)
|
|
98
|
+
.then(function (response) {
|
|
99
|
+
console.log(response.data);
|
|
100
|
+
// { label: 'billing', labels: ['billing', 'technical issue'],
|
|
101
|
+
// scores: [{ label: 'billing', score: 0.92 }, ...], rationale: '...', multi_label: true }
|
|
102
|
+
})
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Style-guide rulesets
|
|
106
|
+
|
|
107
|
+
Check text against style rules inline, or save a named ruleset once (owned by
|
|
108
|
+
your API key's account — its team, for team-scoped keys) and check against it
|
|
109
|
+
by name:
|
|
110
|
+
|
|
111
|
+
```javascript
|
|
112
|
+
// Define the house style once…
|
|
113
|
+
await client.saveStyleguideRuleset('House Style', [
|
|
114
|
+
'no exclamation marks',
|
|
115
|
+
{ name: 'no jargon', description: 'No corporate buzzwords or filler.' },
|
|
116
|
+
]);
|
|
117
|
+
|
|
118
|
+
// …then check against it by name (names match case-insensitively).
|
|
119
|
+
const response = await client.styleguide('Our synergy-driven solution!!', 'House Style');
|
|
120
|
+
console.log(response.data);
|
|
121
|
+
// { violations: [{ rule: 'no jargon', text: 'synergy-driven solution', ... }],
|
|
122
|
+
// rules: ['no exclamation marks', 'no jargon'], compliant: false }
|
|
123
|
+
|
|
124
|
+
// List and delete:
|
|
125
|
+
await client.styleguideRulesets(); // { rulesets: [{ name, rules, ... }] }
|
|
126
|
+
await client.deleteStyleguideRuleset('House Style');
|
|
127
|
+
```
|
|
128
|
+
|
|
79
129
|
## Frontend Quickstart
|
|
80
130
|
|
|
81
131
|
The SDK provides a way to automatically apply edit suggestions to any HTML contenteditable and textarea elements.
|
|
@@ -108,8 +158,109 @@ function App() {
|
|
|
108
158
|
}
|
|
109
159
|
```
|
|
110
160
|
|
|
161
|
+
## Structured Data Extraction
|
|
162
|
+
|
|
163
|
+
Pull caller-named fields out of unstructured text — invoices, emails, resumes, support tickets.
|
|
164
|
+
Pass 1–20 fields (plain names, or `{ name, type, description, required }` objects):
|
|
165
|
+
|
|
166
|
+
```javascript
|
|
167
|
+
client
|
|
168
|
+
.extract(
|
|
169
|
+
'Invoice INV-1042 for Acme Corp, total $1,299.00, due March 5, 2026.',
|
|
170
|
+
[
|
|
171
|
+
'invoice_number',
|
|
172
|
+
{ name: 'total', type: 'number', description: 'Amount due', required: true },
|
|
173
|
+
{ name: 'due_date', type: 'date' },
|
|
174
|
+
'purchase_order',
|
|
175
|
+
],
|
|
176
|
+
{ context: 'A vendor invoice' },
|
|
177
|
+
)
|
|
178
|
+
.then(function (response) {
|
|
179
|
+
console.log(response.data);
|
|
180
|
+
// { data: { invoice_number: 'INV-1042', total: 1299.0, due_date: '2026-03-05', purchase_order: null },
|
|
181
|
+
// fields: [{ name: 'invoice_number', type: 'string', value: 'INV-1042',
|
|
182
|
+
// evidence: 'Invoice INV-1042', found: true }, ...],
|
|
183
|
+
// missing: ['purchase_order'] }
|
|
184
|
+
})
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
`data` always contains every field you asked for, `null` where the text didn't state it, and each
|
|
188
|
+
entry in `fields` carries the verbatim `evidence` span its value came from. Values are coerced to
|
|
189
|
+
the declared `type` (`'string'` (default), `'number'`, `'integer'`, `'boolean'`, `'date'` returned
|
|
190
|
+
as `YYYY-MM-DD`, or `'list'`), and every value must be grounded in a quote from the text — this is
|
|
191
|
+
extraction, not inference, so a value that isn't stated is reported in `missing` rather than
|
|
192
|
+
guessed.
|
|
193
|
+
|
|
194
|
+
## Translation
|
|
195
|
+
|
|
196
|
+
Translate text into a target language, named by ISO 639 code (`'fr'`, `'zh-TW'`) or English
|
|
197
|
+
name (`'French'`). Line breaks and markup are preserved, and the detected source language is
|
|
198
|
+
reported alongside the translation:
|
|
199
|
+
|
|
200
|
+
```javascript
|
|
201
|
+
client
|
|
202
|
+
.translate('Hello world.\nSee you at 5pm.', 'fr', { formality: 'formal' })
|
|
203
|
+
.then(function (response) {
|
|
204
|
+
console.log(response.data);
|
|
205
|
+
// { translation: 'Bonjour le monde.\nÀ 17h.',
|
|
206
|
+
// source_lang: 'en', source_lang_name: 'English',
|
|
207
|
+
// target_lang: 'fr', target_lang_name: 'French' }
|
|
208
|
+
})
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Region variants `zh-CN`/`zh-TW`/`zh-HK`, `pt-BR`/`pt-PT`, `en-GB`/`en-US`, `fr-CA` and
|
|
212
|
+
`es-419` are supported as targets; the optional `source_lang` hint never overrides what the
|
|
213
|
+
text actually is, and `formality` (`'formal'`/`'informal'`) picks the register where the
|
|
214
|
+
target language distinguishes them.
|
|
215
|
+
|
|
111
216
|
## Further Documentation
|
|
112
217
|
|
|
113
218
|
- Full Sapling HTTP API and SDK [documentation](https://sapling.ai/docs).
|
|
114
219
|
- Create a key by following [these instructions](https://sapling.ai/docs/api/api-access).
|
|
115
|
-
- JavaScript, HTML, and Python [starter code](https://github.com/saplingai/sapling-samples).
|
|
220
|
+
- JavaScript, HTML, and Python [starter code](https://github.com/saplingai/sapling-samples).
|
|
221
|
+
|
|
222
|
+
## Error handling
|
|
223
|
+
|
|
224
|
+
Every client method returns the axios promise, so API errors (a `400` for
|
|
225
|
+
over-limit input, `401` for a bad key, `429` for rate limits, network errors and
|
|
226
|
+
timeouts) **reject** with the [axios error](https://axios-http.com/docs/handling_errors);
|
|
227
|
+
inspect `error.response.status` / `error.response.data`:
|
|
228
|
+
|
|
229
|
+
```javascript
|
|
230
|
+
try {
|
|
231
|
+
const response = await client.edits(text);
|
|
232
|
+
} catch (error) {
|
|
233
|
+
console.error(error.response?.status, error.response?.data ?? error.message);
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
API error bodies are JSON objects with a human-readable `msg`, for example
|
|
238
|
+
`{ msg: 'Invalid API key.' }`. The one exception is the 4MB `413`, which uses
|
|
239
|
+
`message`/`result` keys. When a `402` or `429` body has a numeric `retry_after`,
|
|
240
|
+
the request can succeed after waiting that many seconds. Without it, retrying
|
|
241
|
+
unchanged won't help. See
|
|
242
|
+
[Rate Limits & Errors](https://sapling.ai/docs/rate_limits/).
|
|
243
|
+
|
|
244
|
+
To find out why a key is blocked, and for how long, call `accountStatus()`. It
|
|
245
|
+
is unbilled and works while the key is blocked. It reports account-wide blocks:
|
|
246
|
+
an expired key or subscription, depleted credits, a billing limit, the trial
|
|
247
|
+
daily allowance or the monthly quota. It does not report a single endpoint's
|
|
248
|
+
short-term rate limit, because each endpoint has its own allowance. For a
|
|
249
|
+
`Capacity used.` 429, use that response's `retry_after` instead:
|
|
250
|
+
|
|
251
|
+
```javascript
|
|
252
|
+
const { data } = await client.accountStatus();
|
|
253
|
+
if (!data.api_access) {
|
|
254
|
+
// blocked_reason: key_expired | subscription_expired | credits_depleted |
|
|
255
|
+
// monthly_billing_limit | trial_daily_limit | monthly_quota_exhausted
|
|
256
|
+
const retry = data.retry_after ? `, retry in ${data.retry_after}s` : '';
|
|
257
|
+
console.log(`${data.blocked_reason}: ${data.message}${retry}`);
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Every response includes `api_access`, `blocked_reason`, `message` and
|
|
262
|
+
`usage.monthly_quota_chars`. Keys that aren't team-scoped also get the
|
|
263
|
+
account's `subscription`, prepaid `credits`, `usage.chars_this_month` and, on a
|
|
264
|
+
free trial, `trial`. See [Account Status](https://sapling.ai/docs/api/account-status/).
|
|
265
|
+
Each call counts as 2,000 characters against the endpoint's own rate-limit
|
|
266
|
+
bucket, so call it when something fails rather than before every request.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saplingai/sapling-js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.52",
|
|
4
4
|
"description": "JavaScript library for using the Sapling.ai API.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./sapling/client.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"LICENSE"
|
|
30
30
|
],
|
|
31
31
|
"scripts": {
|
|
32
|
-
"test": "node --test test/client.test.js test/pack.test.js",
|
|
32
|
+
"test": "node --test test/client.test.js test/errors.test.js test/pack.test.js",
|
|
33
33
|
"prepublishOnly": "npm test"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
package/sapling/client.d.ts
CHANGED
|
@@ -32,17 +32,321 @@ export type EditOptions = {
|
|
|
32
32
|
lang?: string,
|
|
33
33
|
medical?: boolean,
|
|
34
34
|
advancedEdits?: AdvancedEditOptions,
|
|
35
|
+
/** Defaults to true. false skips error classification: edits omit error_type,
|
|
36
|
+
* general_error_type and classifier-generated descriptions. */
|
|
37
|
+
includeErrorCategories?: boolean,
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
export type AIDetectOptions = {
|
|
38
41
|
sent_scores?: boolean,
|
|
39
42
|
}
|
|
40
43
|
|
|
44
|
+
export type StyleguideRule = string | { name: string; description?: string };
|
|
45
|
+
|
|
46
|
+
export type StyleguideViolation = {
|
|
47
|
+
rule: string;
|
|
48
|
+
text: string;
|
|
49
|
+
start: number | null;
|
|
50
|
+
end: number | null;
|
|
51
|
+
note: string;
|
|
52
|
+
suggestion: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type StyleguideResponse = {
|
|
56
|
+
violations: StyleguideViolation[];
|
|
57
|
+
rules: string[];
|
|
58
|
+
compliant: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type StyleguideBatchResponse = {
|
|
62
|
+
results: StyleguideResponse[];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type StyleguideRuleset = {
|
|
66
|
+
name: string;
|
|
67
|
+
rules: { name: string; description: string }[];
|
|
68
|
+
created_at: string | null;
|
|
69
|
+
updated_at: string | null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type StyleguideRulesetsResponse = {
|
|
73
|
+
rulesets: StyleguideRuleset[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type SaveStyleguideRulesetResponse = {
|
|
77
|
+
ruleset: StyleguideRuleset;
|
|
78
|
+
created: boolean;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export type DeleteStyleguideRulesetResponse = {
|
|
82
|
+
deleted: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type AccountBlockedReason =
|
|
86
|
+
| 'key_expired'
|
|
87
|
+
| 'subscription_expired'
|
|
88
|
+
| 'credits_depleted'
|
|
89
|
+
| 'monthly_billing_limit'
|
|
90
|
+
| 'trial_daily_limit'
|
|
91
|
+
| 'monthly_quota_exhausted';
|
|
92
|
+
|
|
93
|
+
export type AccountCreditSummary = {
|
|
94
|
+
enabled: boolean;
|
|
95
|
+
currency: string;
|
|
96
|
+
alert_threshold_percent: number;
|
|
97
|
+
// Present only when `enabled` is true.
|
|
98
|
+
balance_credits?: number;
|
|
99
|
+
purchased_credits?: number;
|
|
100
|
+
consumed_credits?: number;
|
|
101
|
+
consumed_percent?: number;
|
|
102
|
+
low_balance?: boolean;
|
|
103
|
+
depleted?: boolean;
|
|
104
|
+
billing_mode?: string;
|
|
105
|
+
billing_mode_effective_at?: string | null;
|
|
106
|
+
metered_fallback_available?: boolean;
|
|
107
|
+
stops_when_depleted?: boolean;
|
|
108
|
+
billing_started_at?: string;
|
|
109
|
+
auto_topup?: { enabled: boolean; [field: string]: unknown };
|
|
110
|
+
[field: string]: unknown;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export type AccountStatusResponse = {
|
|
114
|
+
api_access: boolean;
|
|
115
|
+
blocked_reason: AccountBlockedReason | null;
|
|
116
|
+
message: string | null;
|
|
117
|
+
// Seconds until the block may clear; present only when blocked.
|
|
118
|
+
retry_after?: number;
|
|
119
|
+
usage: {
|
|
120
|
+
monthly_quota_chars: number | null;
|
|
121
|
+
// Omitted for team-scoped keys, like `subscription`, `credits` and `trial`.
|
|
122
|
+
month_start?: string;
|
|
123
|
+
chars_this_month?: number;
|
|
124
|
+
};
|
|
125
|
+
subscription?: {
|
|
126
|
+
active: boolean;
|
|
127
|
+
trial_only: boolean;
|
|
128
|
+
key_expired: boolean;
|
|
129
|
+
};
|
|
130
|
+
credits?: AccountCreditSummary;
|
|
131
|
+
// Present only for free-trial accounts.
|
|
132
|
+
trial?: {
|
|
133
|
+
daily_limit_chars: number | null;
|
|
134
|
+
chars_used_today: number;
|
|
135
|
+
resets_at: 'utc_midnight';
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export type SimplifyReadingLevel = 'plain' | 'elementary' | 'middle_school' | 'high_school';
|
|
140
|
+
|
|
141
|
+
export type SimplifyOptions = {
|
|
142
|
+
reading_level?: SimplifyReadingLevel,
|
|
143
|
+
preserve_terms?: string[],
|
|
144
|
+
lang?: string,
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export type SimplifyReadabilityScores = {
|
|
148
|
+
grade: number;
|
|
149
|
+
ease: number;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export type SimplifyResponse = {
|
|
153
|
+
simplified: string;
|
|
154
|
+
reading_level: SimplifyReadingLevel;
|
|
155
|
+
lang: string;
|
|
156
|
+
readability?: {
|
|
157
|
+
before: SimplifyReadabilityScores;
|
|
158
|
+
after: SimplifyReadabilityScores;
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export type SimplifyBatchResponse = {
|
|
163
|
+
results: SimplifyResponse[];
|
|
164
|
+
}
|
|
165
|
+
|
|
41
166
|
export type LangdetectOptions = {
|
|
42
167
|
top_k?: number,
|
|
43
168
|
segments?: boolean,
|
|
44
169
|
}
|
|
45
170
|
|
|
171
|
+
export type ClassifyLabel = string | { name: string; description?: string };
|
|
172
|
+
|
|
173
|
+
export type ClassifyOptions = {
|
|
174
|
+
multiLabel?: boolean,
|
|
175
|
+
threshold?: number,
|
|
176
|
+
context?: string,
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export type ClassifyResponse = {
|
|
180
|
+
label: string;
|
|
181
|
+
labels: string[];
|
|
182
|
+
scores: { label: string; score: number }[];
|
|
183
|
+
rationale: string;
|
|
184
|
+
multi_label: boolean;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export type ClassifyBatchResponse = {
|
|
188
|
+
results: ClassifyResponse[];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export type SeoOptions = {
|
|
192
|
+
keywords?: string[],
|
|
193
|
+
suggestions?: boolean,
|
|
194
|
+
lang?: string,
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export type SeoStats = {
|
|
198
|
+
chars: number;
|
|
199
|
+
words: number;
|
|
200
|
+
sentences: number;
|
|
201
|
+
paragraphs: number;
|
|
202
|
+
reading_time_min: number;
|
|
203
|
+
flesch_reading_ease: number | null;
|
|
204
|
+
flesch_kincaid_grade: number | null;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export type SeoKeyword = {
|
|
208
|
+
keyword: string;
|
|
209
|
+
count: number;
|
|
210
|
+
density: number;
|
|
211
|
+
in_first_100_words: boolean;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export type SeoTopTerm = {
|
|
215
|
+
term: string;
|
|
216
|
+
count: number;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export type SeoSuggestions = {
|
|
220
|
+
titles: string[];
|
|
221
|
+
meta_descriptions: string[];
|
|
222
|
+
slug: string | null;
|
|
223
|
+
keywords: string[];
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export type SeoResponse = {
|
|
227
|
+
stats: SeoStats;
|
|
228
|
+
keywords: SeoKeyword[];
|
|
229
|
+
top_terms: SeoTopTerm[];
|
|
230
|
+
suggestions?: SeoSuggestions;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export type QualityOptions = {
|
|
234
|
+
sentence_scores?: boolean,
|
|
235
|
+
rubric?: boolean,
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export type QualitySentenceScore = {
|
|
239
|
+
start: number;
|
|
240
|
+
end: number;
|
|
241
|
+
text: string;
|
|
242
|
+
score: number;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export type QualityRubricIssue = {
|
|
246
|
+
quote: string;
|
|
247
|
+
dimension: string;
|
|
248
|
+
note: string;
|
|
249
|
+
suggestion: string;
|
|
250
|
+
start: number;
|
|
251
|
+
end: number;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export type QualityRubric = {
|
|
255
|
+
overall: number;
|
|
256
|
+
dimensions: {
|
|
257
|
+
clarity: number;
|
|
258
|
+
coherence: number;
|
|
259
|
+
correctness: number;
|
|
260
|
+
concision: number;
|
|
261
|
+
};
|
|
262
|
+
summary: string;
|
|
263
|
+
issues: QualityRubricIssue[];
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export type QualityResponse = {
|
|
267
|
+
score: number;
|
|
268
|
+
sentences?: QualitySentenceScore[];
|
|
269
|
+
truncated?: boolean;
|
|
270
|
+
rubric?: QualityRubric;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export type QualityBatchResponse = {
|
|
274
|
+
results: QualityResponse[];
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export type PIIType = 'email' | 'phone' | 'ssn' | 'credit_card' | 'ip_address' | 'iban' | 'us_bank_routing';
|
|
278
|
+
|
|
279
|
+
export type PIIOptions = {
|
|
280
|
+
types?: PIIType[],
|
|
281
|
+
redact?: boolean,
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export type PIIEntity = {
|
|
285
|
+
type: PIIType;
|
|
286
|
+
text: string;
|
|
287
|
+
start: number;
|
|
288
|
+
end: number;
|
|
289
|
+
replacement: string;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export type PIIResponse = {
|
|
293
|
+
entities: PIIEntity[];
|
|
294
|
+
flagged: boolean;
|
|
295
|
+
types: PIIType[];
|
|
296
|
+
redacted_text?: string;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export type NERType = 'person' | 'organization' | 'location' | 'date' | 'time' |
|
|
300
|
+
'money' | 'percent' | 'quantity' | 'product' | 'event';
|
|
301
|
+
|
|
302
|
+
export type NEROptions = {
|
|
303
|
+
types?: NERType[],
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export type NEREntity = {
|
|
307
|
+
text: string;
|
|
308
|
+
type: NERType;
|
|
309
|
+
start: number;
|
|
310
|
+
end: number;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export type NERResponse = {
|
|
314
|
+
entities: NEREntity[];
|
|
315
|
+
types: NERType[];
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export type NERBatchResponse = {
|
|
319
|
+
results: NERResponse[];
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export type SafetyCategory = 'toxicity' | 'profanity' | 'harassment' | 'hate_speech' |
|
|
323
|
+
'self_harm' | 'sexual' | 'violence';
|
|
324
|
+
|
|
325
|
+
export type SafetySpan = {
|
|
326
|
+
text: string;
|
|
327
|
+
start: number | null;
|
|
328
|
+
end: number | null;
|
|
329
|
+
scores: Partial<Record<SafetyCategory, number>>;
|
|
330
|
+
flagged_categories: SafetyCategory[];
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export type SafetyResponse = {
|
|
334
|
+
scores: Record<SafetyCategory, number>;
|
|
335
|
+
flagged: boolean;
|
|
336
|
+
flagged_categories: SafetyCategory[];
|
|
337
|
+
threshold: number;
|
|
338
|
+
spans?: SafetySpan[];
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export type SafetyBatchResponse = {
|
|
342
|
+
results: SafetyResponse[];
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export type SafetyOptions = {
|
|
346
|
+
threshold?: number,
|
|
347
|
+
spans?: boolean,
|
|
348
|
+
}
|
|
349
|
+
|
|
46
350
|
export type SpellcheckOptions = {
|
|
47
351
|
minLength?: number,
|
|
48
352
|
multipleEdits?: boolean,
|
|
@@ -52,6 +356,72 @@ export type SpellcheckOptions = {
|
|
|
52
356
|
userData?: any,
|
|
53
357
|
}
|
|
54
358
|
|
|
359
|
+
export type ExtractFieldType = 'string' | 'number' | 'integer' | 'boolean' | 'date' | 'list';
|
|
360
|
+
|
|
361
|
+
export type ExtractField = string | {
|
|
362
|
+
name: string,
|
|
363
|
+
type?: ExtractFieldType,
|
|
364
|
+
description?: string,
|
|
365
|
+
required?: boolean,
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export type ExtractOptions = {
|
|
369
|
+
context?: string,
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export type ExtractedValue = string | number | boolean | string[] | null;
|
|
373
|
+
|
|
374
|
+
export type ExtractedField = {
|
|
375
|
+
name: string,
|
|
376
|
+
type: ExtractFieldType,
|
|
377
|
+
value: ExtractedValue,
|
|
378
|
+
evidence: string,
|
|
379
|
+
found: boolean,
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export type ExtractResponse = {
|
|
383
|
+
data: Record<string, ExtractedValue>,
|
|
384
|
+
fields: ExtractedField[],
|
|
385
|
+
missing: string[],
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
export type ExtractBatchResponse = {
|
|
389
|
+
results: ExtractResponse[];
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
export type TranslateOptions = {
|
|
393
|
+
source_lang?: string,
|
|
394
|
+
formality?: 'formal' | 'informal',
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export type TranslateResponse = {
|
|
398
|
+
translation: string,
|
|
399
|
+
source_lang: string,
|
|
400
|
+
source_lang_name: string | null,
|
|
401
|
+
target_lang: string,
|
|
402
|
+
target_lang_name: string,
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export type TranslateBatchResponse = {
|
|
406
|
+
results: TranslateResponse[];
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export type SummarizeOptions = {
|
|
410
|
+
length?: 'short' | 'medium' | 'long',
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
export type SummarizeResponse = {
|
|
414
|
+
/** Mirrors `summary` — the endpoint's original response key. */
|
|
415
|
+
result: string,
|
|
416
|
+
summary: string,
|
|
417
|
+
key_points: string[],
|
|
418
|
+
length: 'short' | 'medium' | 'long',
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
export type SummarizeBatchResponse = {
|
|
422
|
+
results: SummarizeResponse[];
|
|
423
|
+
}
|
|
424
|
+
|
|
55
425
|
export type UserDetails = {
|
|
56
426
|
userId?: string,
|
|
57
427
|
anonUser?: boolean,
|
|
@@ -69,7 +439,40 @@ export declare class Client {
|
|
|
69
439
|
complete(query: string, sessionId?: string): Promise<AxiosResponse>;
|
|
70
440
|
acceptComplete(completeUUID: string, query: string, completion: string, sessionId?: string): Promise<AxiosResponse>;
|
|
71
441
|
tone(text: string): Promise<AxiosResponse>;
|
|
442
|
+
extract(text: string, fields: ExtractField[], options?: ExtractOptions): Promise<AxiosResponse<ExtractResponse>>;
|
|
443
|
+
extract(texts: string[], fields: ExtractField[], options?: ExtractOptions): Promise<AxiosResponse<ExtractBatchResponse>>;
|
|
444
|
+
extract(text: string | string[], fields: ExtractField[], options?: ExtractOptions): Promise<AxiosResponse<ExtractResponse | ExtractBatchResponse>>;
|
|
445
|
+
translate(text: string, targetLang: string, options?: TranslateOptions): Promise<AxiosResponse<TranslateResponse>>;
|
|
446
|
+
translate(texts: string[], targetLang: string, options?: TranslateOptions): Promise<AxiosResponse<TranslateBatchResponse>>;
|
|
447
|
+
translate(text: string | string[], targetLang: string, options?: TranslateOptions): Promise<AxiosResponse<TranslateResponse | TranslateBatchResponse>>;
|
|
448
|
+
summarize(text: string, options?: SummarizeOptions): Promise<AxiosResponse<SummarizeResponse>>;
|
|
449
|
+
summarize(texts: string[], options?: SummarizeOptions): Promise<AxiosResponse<SummarizeBatchResponse>>;
|
|
450
|
+
summarize(text: string | string[], options?: SummarizeOptions): Promise<AxiosResponse<SummarizeResponse | SummarizeBatchResponse>>;
|
|
72
451
|
|
|
73
|
-
aidetect(text: string, options?: AIDetectOptions): Promise<AxiosResponse>;
|
|
74
|
-
|
|
452
|
+
aidetect(text: string | string[], options?: AIDetectOptions): Promise<AxiosResponse>;
|
|
453
|
+
styleguide(text: string, rules: StyleguideRule[] | string): Promise<AxiosResponse<StyleguideResponse>>;
|
|
454
|
+
styleguide(texts: string[], rules: StyleguideRule[] | string): Promise<AxiosResponse<StyleguideBatchResponse>>;
|
|
455
|
+
styleguide(text: string | string[], rules: StyleguideRule[] | string): Promise<AxiosResponse<StyleguideResponse | StyleguideBatchResponse>>;
|
|
456
|
+
styleguideRulesets(): Promise<AxiosResponse<StyleguideRulesetsResponse>>;
|
|
457
|
+
saveStyleguideRuleset(name: string, rules: StyleguideRule[]): Promise<AxiosResponse<SaveStyleguideRulesetResponse>>;
|
|
458
|
+
deleteStyleguideRuleset(name: string): Promise<AxiosResponse<DeleteStyleguideRulesetResponse>>;
|
|
459
|
+
simplify(text: string, options?: SimplifyOptions): Promise<AxiosResponse<SimplifyResponse>>;
|
|
460
|
+
simplify(texts: string[], options?: SimplifyOptions): Promise<AxiosResponse<SimplifyBatchResponse>>;
|
|
461
|
+
simplify(text: string | string[], options?: SimplifyOptions): Promise<AxiosResponse<SimplifyResponse | SimplifyBatchResponse>>;
|
|
462
|
+
langdetect(text: string | string[], options?: LangdetectOptions): Promise<AxiosResponse>;
|
|
463
|
+
quality(text: string, options?: QualityOptions): Promise<AxiosResponse<QualityResponse>>;
|
|
464
|
+
quality(texts: string[], options?: QualityOptions): Promise<AxiosResponse<QualityBatchResponse>>;
|
|
465
|
+
quality(text: string | string[], options?: QualityOptions): Promise<AxiosResponse<QualityResponse | QualityBatchResponse>>;
|
|
466
|
+
pii(text: string, options?: PIIOptions): Promise<AxiosResponse<PIIResponse>>;
|
|
467
|
+
ner(text: string, options?: NEROptions): Promise<AxiosResponse<NERResponse>>;
|
|
468
|
+
ner(texts: string[], options?: NEROptions): Promise<AxiosResponse<NERBatchResponse>>;
|
|
469
|
+
ner(text: string | string[], options?: NEROptions): Promise<AxiosResponse<NERResponse | NERBatchResponse>>;
|
|
470
|
+
safety(text: string, options?: SafetyOptions): Promise<AxiosResponse<SafetyResponse>>;
|
|
471
|
+
safety(texts: string[], options?: SafetyOptions): Promise<AxiosResponse<SafetyBatchResponse>>;
|
|
472
|
+
safety(text: string | string[], options?: SafetyOptions): Promise<AxiosResponse<SafetyResponse | SafetyBatchResponse>>;
|
|
473
|
+
classify(text: string, labels: ClassifyLabel[], options?: ClassifyOptions): Promise<AxiosResponse<ClassifyResponse>>;
|
|
474
|
+
classify(texts: string[], labels: ClassifyLabel[], options?: ClassifyOptions): Promise<AxiosResponse<ClassifyBatchResponse>>;
|
|
475
|
+
classify(text: string | string[], labels: ClassifyLabel[], options?: ClassifyOptions): Promise<AxiosResponse<ClassifyResponse | ClassifyBatchResponse>>;
|
|
476
|
+
seo(text: string, options?: SeoOptions): Promise<AxiosResponse<SeoResponse>>;
|
|
477
|
+
accountStatus(): Promise<AxiosResponse<AccountStatusResponse>>;
|
|
75
478
|
}
|