@graphext/cuery 0.4.0 → 0.5.2
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/esm/browser.d.ts +1 -1
- package/esm/browser.d.ts.map +1 -1
- package/esm/browser.js +1 -1
- package/esm/mod.d.ts +5 -2
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +7 -2
- package/esm/src/api.d.ts +36 -5
- package/esm/src/api.d.ts.map +1 -1
- package/esm/src/api.js +84 -37
- package/esm/src/apis/chatgptScraper/brightdata.js +1 -1
- package/esm/src/apis/chatgptScraper/oxy.js +1 -1
- package/esm/src/apis/chatgptScraper/scraper.js +2 -2
- package/esm/src/apis/hasdata/aim.js +1 -1
- package/esm/src/apis/hasdata/aio.js +1 -1
- package/esm/src/apis/hasdata/helpers.d.ts +1 -1
- package/esm/src/apis/hasdata/helpers.d.ts.map +1 -1
- package/esm/src/apis/hasdata/helpers.js +2 -2
- package/esm/src/assets/models.d.ts +60725 -0
- package/esm/src/assets/models.d.ts.map +1 -0
- package/esm/src/assets/models.js +71915 -0
- package/esm/src/helpers/async.d.ts.map +1 -0
- package/esm/src/{async.js → helpers/async.js} +1 -1
- package/esm/src/helpers/seedKeywords.d.ts.map +1 -0
- package/esm/src/helpers/urls.d.ts.map +1 -0
- package/esm/src/helpers/utils.d.ts.map +1 -0
- package/esm/src/llm.d.ts +35 -0
- package/esm/src/llm.d.ts.map +1 -0
- package/esm/src/llm.js +59 -0
- package/esm/src/providers/google.d.ts +12 -0
- package/esm/src/providers/google.d.ts.map +1 -0
- package/esm/src/providers/google.js +111 -0
- package/esm/src/providers/index.d.ts +13 -0
- package/esm/src/providers/index.d.ts.map +1 -0
- package/esm/src/providers/index.js +14 -0
- package/esm/src/providers/openai.d.ts +12 -0
- package/esm/src/providers/openai.d.ts.map +1 -0
- package/esm/src/providers/openai.js +141 -0
- package/esm/src/providers/pricing.d.ts +72 -0
- package/esm/src/providers/pricing.d.ts.map +1 -0
- package/esm/src/providers/pricing.js +88 -0
- package/esm/src/providers/registry.d.ts +20 -0
- package/esm/src/providers/registry.d.ts.map +1 -0
- package/esm/src/providers/registry.js +35 -0
- package/esm/src/providers/types.d.ts +49 -0
- package/esm/src/providers/types.d.ts.map +1 -0
- package/esm/src/providers/types.js +7 -0
- package/esm/src/response.d.ts +74 -0
- package/esm/src/response.d.ts.map +1 -0
- package/esm/src/response.js +110 -0
- package/esm/src/tool.d.ts +58 -0
- package/esm/src/tool.d.ts.map +1 -0
- package/esm/src/tool.js +91 -0
- package/esm/src/tools/brands.js +6 -6
- package/esm/src/tools/classifier.d.ts +80 -17
- package/esm/src/tools/classifier.d.ts.map +1 -1
- package/esm/src/tools/classifier.js +68 -80
- package/esm/src/tools/entities.d.ts +23 -12
- package/esm/src/tools/entities.d.ts.map +1 -1
- package/esm/src/tools/entities.js +27 -47
- package/esm/src/tools/funnel.js +7 -7
- package/esm/src/tools/generic.d.ts +17 -4
- package/esm/src/tools/generic.d.ts.map +1 -1
- package/esm/src/tools/generic.js +39 -14
- package/esm/src/tools/keywords.js +5 -5
- package/esm/src/tools/personas.d.ts +49 -2
- package/esm/src/tools/personas.d.ts.map +1 -1
- package/esm/src/tools/personas.js +59 -35
- package/esm/src/tools/scorer.d.ts +24 -6
- package/esm/src/tools/scorer.d.ts.map +1 -1
- package/esm/src/tools/scorer.js +27 -22
- package/esm/src/tools/search.d.ts.map +1 -1
- package/esm/src/tools/search.js +33 -9
- package/esm/src/tools/sentiment.d.ts +30 -8
- package/esm/src/tools/sentiment.d.ts.map +1 -1
- package/esm/src/tools/sentiment.js +33 -28
- package/esm/src/tools/sources.d.ts +5 -5
- package/esm/src/tools/sources.d.ts.map +1 -1
- package/esm/src/tools/sources.js +5 -6
- package/esm/src/tools/topics.d.ts +44 -16
- package/esm/src/tools/topics.d.ts.map +1 -1
- package/esm/src/tools/topics.js +77 -68
- package/esm/src/tools/translate.d.ts +22 -31
- package/esm/src/tools/translate.d.ts.map +1 -1
- package/esm/src/tools/translate.js +40 -36
- package/package.json +2 -1
- package/script/browser.d.ts +1 -1
- package/script/browser.d.ts.map +1 -1
- package/script/browser.js +1 -1
- package/script/mod.d.ts +5 -2
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +14 -2
- package/script/src/api.d.ts +36 -5
- package/script/src/api.d.ts.map +1 -1
- package/script/src/api.js +84 -35
- package/script/src/apis/chatgptScraper/brightdata.js +1 -1
- package/script/src/apis/chatgptScraper/oxy.js +1 -1
- package/script/src/apis/chatgptScraper/scraper.js +2 -2
- package/script/src/apis/hasdata/aim.js +1 -1
- package/script/src/apis/hasdata/aio.js +1 -1
- package/script/src/apis/hasdata/helpers.d.ts +1 -1
- package/script/src/apis/hasdata/helpers.d.ts.map +1 -1
- package/script/src/apis/hasdata/helpers.js +2 -2
- package/script/src/assets/models.d.ts +60725 -0
- package/script/src/assets/models.d.ts.map +1 -0
- package/script/src/assets/models.js +71917 -0
- package/script/src/helpers/async.d.ts.map +1 -0
- package/script/src/{async.js → helpers/async.js} +1 -1
- package/script/src/helpers/seedKeywords.d.ts.map +1 -0
- package/script/src/helpers/urls.d.ts.map +1 -0
- package/script/src/helpers/utils.d.ts.map +1 -0
- package/script/src/llm.d.ts +35 -0
- package/script/src/llm.d.ts.map +1 -0
- package/script/src/llm.js +65 -0
- package/script/src/providers/google.d.ts +12 -0
- package/script/src/providers/google.d.ts.map +1 -0
- package/script/src/providers/google.js +148 -0
- package/script/src/providers/index.d.ts +13 -0
- package/script/src/providers/index.d.ts.map +1 -0
- package/script/src/providers/index.js +24 -0
- package/script/src/providers/openai.d.ts +12 -0
- package/script/src/providers/openai.d.ts.map +1 -0
- package/script/src/providers/openai.js +181 -0
- package/script/src/providers/pricing.d.ts +72 -0
- package/script/src/providers/pricing.d.ts.map +1 -0
- package/script/src/providers/pricing.js +97 -0
- package/script/src/providers/registry.d.ts +20 -0
- package/script/src/providers/registry.d.ts.map +1 -0
- package/script/src/providers/registry.js +39 -0
- package/script/src/providers/types.d.ts +49 -0
- package/script/src/providers/types.d.ts.map +1 -0
- package/script/src/providers/types.js +8 -0
- package/script/src/response.d.ts +74 -0
- package/script/src/response.d.ts.map +1 -0
- package/script/src/response.js +114 -0
- package/script/src/tool.d.ts +58 -0
- package/script/src/tool.d.ts.map +1 -0
- package/script/src/tool.js +95 -0
- package/script/src/tools/brands.js +6 -6
- package/script/src/tools/classifier.d.ts +80 -17
- package/script/src/tools/classifier.d.ts.map +1 -1
- package/script/src/tools/classifier.js +72 -85
- package/script/src/tools/entities.d.ts +23 -12
- package/script/src/tools/entities.d.ts.map +1 -1
- package/script/src/tools/entities.js +29 -51
- package/script/src/tools/funnel.js +7 -7
- package/script/src/tools/generic.d.ts +17 -4
- package/script/src/tools/generic.d.ts.map +1 -1
- package/script/src/tools/generic.js +39 -14
- package/script/src/tools/keywords.js +5 -5
- package/script/src/tools/personas.d.ts +49 -2
- package/script/src/tools/personas.d.ts.map +1 -1
- package/script/src/tools/personas.js +63 -36
- package/script/src/tools/scorer.d.ts +24 -6
- package/script/src/tools/scorer.d.ts.map +1 -1
- package/script/src/tools/scorer.js +28 -24
- package/script/src/tools/search.d.ts.map +1 -1
- package/script/src/tools/search.js +69 -9
- package/script/src/tools/sentiment.d.ts +30 -8
- package/script/src/tools/sentiment.d.ts.map +1 -1
- package/script/src/tools/sentiment.js +37 -30
- package/script/src/tools/sources.d.ts +5 -5
- package/script/src/tools/sources.d.ts.map +1 -1
- package/script/src/tools/sources.js +4 -5
- package/script/src/tools/topics.d.ts +44 -16
- package/script/src/tools/topics.d.ts.map +1 -1
- package/script/src/tools/topics.js +80 -72
- package/script/src/tools/translate.d.ts +22 -31
- package/script/src/tools/translate.d.ts.map +1 -1
- package/script/src/tools/translate.js +43 -40
- package/esm/src/async.d.ts.map +0 -1
- package/esm/src/models.d.ts +0 -18
- package/esm/src/models.d.ts.map +0 -1
- package/esm/src/models.js +0 -48
- package/esm/src/openai.d.ts +0 -17
- package/esm/src/openai.d.ts.map +0 -1
- package/esm/src/openai.js +0 -136
- package/esm/src/tools/seedKeywords.d.ts.map +0 -1
- package/esm/src/urls.d.ts.map +0 -1
- package/esm/src/utils.d.ts.map +0 -1
- package/script/src/async.d.ts.map +0 -1
- package/script/src/models.d.ts +0 -18
- package/script/src/models.d.ts.map +0 -1
- package/script/src/models.js +0 -52
- package/script/src/openai.d.ts +0 -17
- package/script/src/openai.d.ts.map +0 -1
- package/script/src/openai.js +0 -175
- package/script/src/tools/seedKeywords.d.ts.map +0 -1
- package/script/src/urls.d.ts.map +0 -1
- package/script/src/utils.d.ts.map +0 -1
- /package/esm/src/{async.d.ts → helpers/async.d.ts} +0 -0
- /package/esm/src/{tools → helpers}/seedKeywords.d.ts +0 -0
- /package/esm/src/{tools → helpers}/seedKeywords.js +0 -0
- /package/esm/src/{urls.d.ts → helpers/urls.d.ts} +0 -0
- /package/esm/src/{urls.js → helpers/urls.js} +0 -0
- /package/esm/src/{utils.d.ts → helpers/utils.d.ts} +0 -0
- /package/esm/src/{utils.js → helpers/utils.js} +0 -0
- /package/script/src/{async.d.ts → helpers/async.d.ts} +0 -0
- /package/script/src/{tools → helpers}/seedKeywords.d.ts +0 -0
- /package/script/src/{tools → helpers}/seedKeywords.js +0 -0
- /package/script/src/{urls.d.ts → helpers/urls.d.ts} +0 -0
- /package/script/src/{urls.js → helpers/urls.js} +0 -0
- /package/script/src/{utils.d.ts → helpers/utils.d.ts} +0 -0
- /package/script/src/{utils.js → helpers/utils.js} +0 -0
|
@@ -1,34 +1,97 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z } from '../../deps/jsr.io/@zod/zod/4.3.6/src/index.js';
|
|
2
|
+
import { Tool, type ModelConfig } from '../tool.js';
|
|
3
|
+
interface ClassifierConfig {
|
|
4
|
+
/** Map of label names to descriptions */
|
|
5
|
+
labels: Record<string, string>;
|
|
6
|
+
/** Additional instructions for the classifier */
|
|
7
|
+
instructions?: string;
|
|
8
|
+
}
|
|
2
9
|
/**
|
|
3
|
-
*
|
|
10
|
+
* A tool that classifies records into one of the provided categories.
|
|
4
11
|
*/
|
|
5
|
-
export declare
|
|
12
|
+
export declare class Classifier extends Tool<Record<string, unknown> | null, {
|
|
13
|
+
label: string;
|
|
14
|
+
}, string> {
|
|
15
|
+
private readonly labelSchema;
|
|
16
|
+
private readonly promptTemplate;
|
|
17
|
+
constructor(config: ClassifierConfig, modelConfig: ModelConfig);
|
|
18
|
+
protected schema(): z.ZodObject<{
|
|
19
|
+
label: z.ZodLiteral<string>;
|
|
20
|
+
}, z.core.$strip> | z.ZodObject<{
|
|
21
|
+
label: z.ZodUnion<[z.ZodLiteral<string>, z.ZodLiteral<string>, ...z.ZodLiteral<string>[]]>;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
protected prompt(record: Record<string, unknown> | null): string;
|
|
24
|
+
protected extractResult(parsed: {
|
|
25
|
+
label: string;
|
|
26
|
+
}): string;
|
|
27
|
+
}
|
|
6
28
|
/**
|
|
7
|
-
*
|
|
29
|
+
* Configuration for the Labeler tool.
|
|
8
30
|
*/
|
|
9
|
-
export
|
|
31
|
+
export interface LabelerConfig {
|
|
32
|
+
/** Map of label names to descriptions */
|
|
33
|
+
labels: Record<string, string>;
|
|
34
|
+
/** Additional instructions for the labeler */
|
|
35
|
+
instructions?: string;
|
|
36
|
+
}
|
|
10
37
|
/**
|
|
11
|
-
*
|
|
38
|
+
* A tool that assigns one or more labels to records from provided options.
|
|
12
39
|
*/
|
|
13
|
-
export declare
|
|
40
|
+
export declare class Labeler extends Tool<Record<string, unknown> | null, {
|
|
41
|
+
labels: Array<string>;
|
|
42
|
+
}, Array<string>> {
|
|
43
|
+
private readonly multiLabelSchema;
|
|
44
|
+
private readonly promptTemplate;
|
|
45
|
+
constructor(config: LabelerConfig, modelConfig: ModelConfig);
|
|
46
|
+
protected schema(): z.ZodObject<{
|
|
47
|
+
labels: z.ZodArray<z.ZodLiteral<string> | z.ZodUnion<[z.ZodLiteral<string>, z.ZodLiteral<string>, ...z.ZodLiteral<string>[]]>>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
protected prompt(record: Record<string, unknown> | null): string;
|
|
50
|
+
protected extractResult(parsed: {
|
|
51
|
+
labels: Array<string>;
|
|
52
|
+
}): string[];
|
|
53
|
+
}
|
|
14
54
|
/**
|
|
15
|
-
*
|
|
55
|
+
* Configuration for the LabelExtractor tool.
|
|
16
56
|
*/
|
|
17
|
-
export
|
|
18
|
-
|
|
19
|
-
records: Array<Record<string, unknown>>;
|
|
57
|
+
export interface LabelExtractorConfig {
|
|
58
|
+
/** Maximum number of labels to extract (default: 10) */
|
|
20
59
|
nLabels?: number;
|
|
60
|
+
/** Additional instructions for label extraction */
|
|
21
61
|
instructions?: string;
|
|
62
|
+
/** Maximum number of records to sample (default: 500) */
|
|
22
63
|
maxSamples?: number;
|
|
23
|
-
|
|
24
|
-
modelParams?: AIParams;
|
|
25
|
-
maxRetries?: number;
|
|
64
|
+
/** Language for labels and descriptions (default: same as records) */
|
|
26
65
|
language?: string;
|
|
27
66
|
}
|
|
28
67
|
/**
|
|
29
|
-
*
|
|
68
|
+
* A tool that extracts classification labels from a set of records.
|
|
30
69
|
* Returns a Record<string, string> mapping label names to descriptions,
|
|
31
|
-
* which can be used directly with
|
|
70
|
+
* which can be used directly with Classifier and Labeler.
|
|
32
71
|
*/
|
|
33
|
-
export declare
|
|
72
|
+
export declare class LabelExtractor extends Tool<Array<Record<string, unknown>>, {
|
|
73
|
+
labels: Array<{
|
|
74
|
+
name: string;
|
|
75
|
+
description: string;
|
|
76
|
+
}>;
|
|
77
|
+
}, Record<string, string>> {
|
|
78
|
+
private readonly maxSamples;
|
|
79
|
+
private readonly promptTemplate;
|
|
80
|
+
constructor(config: LabelExtractorConfig | undefined, modelConfig: ModelConfig);
|
|
81
|
+
protected schema(): z.ZodObject<{
|
|
82
|
+
labels: z.ZodArray<z.ZodObject<{
|
|
83
|
+
name: z.ZodString;
|
|
84
|
+
description: z.ZodString;
|
|
85
|
+
}, z.core.$strip>>;
|
|
86
|
+
}, z.core.$strip>;
|
|
87
|
+
protected prompt(records: Array<Record<string, unknown>>): string;
|
|
88
|
+
protected isEmpty(records: Array<Record<string, unknown>>): boolean;
|
|
89
|
+
protected extractResult(parsed: {
|
|
90
|
+
labels: Array<{
|
|
91
|
+
name: string;
|
|
92
|
+
description: string;
|
|
93
|
+
}>;
|
|
94
|
+
}): Record<string, string>;
|
|
95
|
+
}
|
|
96
|
+
export {};
|
|
34
97
|
//# sourceMappingURL=classifier.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"classifier.d.ts","sourceRoot":"","sources":["../../../src/src/tools/classifier.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"classifier.d.ts","sourceRoot":"","sources":["../../../src/src/tools/classifier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,+CAA+C,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAmGpD,UAAU,gBAAgB;IACzB,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,iDAAiD;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,MAAM,CAAC;IAC9F,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAuC;IACnE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;gBAE5B,MAAM,EAAE,gBAAgB,EAAE,WAAW,EAAE,WAAW;cAS3C,MAAM;;;;;IAIzB,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;cAIpC,aAAa,CAAC,MAAM,EAAE;QAAE,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,CAAC,MAAM,EAAE,MAAM,CAAC,CACtB;IACA,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;gBAE5B,MAAM,EAAE,oBAAoB,YAAK,EAAE,WAAW,EAAE,WAAW;cAgBpD,MAAM;;;;;;IAIzB,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;cAQrC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,OAAO;cAIzD,aAAa,CAC/B,MAAM,EAAE;QAAE,MAAM,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,WAAW,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE,GAC9D,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;CAGzB"}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.classifyBatch = classifyBatch;
|
|
5
|
-
exports.label = label;
|
|
6
|
-
exports.labelBatch = labelBatch;
|
|
7
|
-
exports.extractLabels = extractLabels;
|
|
3
|
+
exports.LabelExtractor = exports.Labeler = exports.Classifier = void 0;
|
|
8
4
|
const index_js_1 = require("../../deps/jsr.io/@zod/zod/4.3.6/src/index.js");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const utils_js_1 = require("../utils.js");
|
|
5
|
+
const tool_js_1 = require("../tool.js");
|
|
6
|
+
const utils_js_1 = require("../helpers/utils.js");
|
|
12
7
|
const PROMPT_TEMPLATE = (0, utils_js_1.dedent)(`
|
|
13
8
|
# Instructions
|
|
14
9
|
|
|
@@ -43,7 +38,6 @@ if it matches multiple categories. Assign all relevant labels that apply to the
|
|
|
43
38
|
`);
|
|
44
39
|
/**
|
|
45
40
|
* Formats a record object into a human-readable text representation.
|
|
46
|
-
* Similar to the record_to_text.jinja template in Python.
|
|
47
41
|
*/
|
|
48
42
|
function formatRecord(record) {
|
|
49
43
|
return Object.entries(record)
|
|
@@ -60,7 +54,6 @@ function formatLabels(labels) {
|
|
|
60
54
|
}
|
|
61
55
|
/**
|
|
62
56
|
* Creates a dynamic Category schema based on provided labels.
|
|
63
|
-
* Each category literal includes its description, which helps the LLM understand the classification.
|
|
64
57
|
*/
|
|
65
58
|
function createLabelSchema(labels) {
|
|
66
59
|
const entries = Object.entries(labels);
|
|
@@ -73,7 +66,6 @@ function createLabelSchema(labels) {
|
|
|
73
66
|
label: index_js_1.z.literal(label).describe(description)
|
|
74
67
|
});
|
|
75
68
|
}
|
|
76
|
-
// TypeScript now knows entries.length >= 2
|
|
77
69
|
const literals = entries.map(([label, description]) => index_js_1.z.literal(label).describe(description));
|
|
78
70
|
return index_js_1.z.object({
|
|
79
71
|
label: index_js_1.z.union(literals)
|
|
@@ -81,7 +73,6 @@ function createLabelSchema(labels) {
|
|
|
81
73
|
}
|
|
82
74
|
/**
|
|
83
75
|
* Creates a dynamic multi-label schema based on provided labels.
|
|
84
|
-
* Returns a schema that accepts an array of labels, reusing the single label schema.
|
|
85
76
|
*/
|
|
86
77
|
function createMultiLabelSchema(labels) {
|
|
87
78
|
const singleLabelSchema = createLabelSchema(labels);
|
|
@@ -93,55 +84,57 @@ function createMultiLabelSchema(labels) {
|
|
|
93
84
|
});
|
|
94
85
|
}
|
|
95
86
|
/**
|
|
96
|
-
*
|
|
87
|
+
* A tool that classifies records into one of the provided categories.
|
|
97
88
|
*/
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
89
|
+
class Classifier extends tool_js_1.Tool {
|
|
90
|
+
labelSchema;
|
|
91
|
+
promptTemplate;
|
|
92
|
+
constructor(config, modelConfig) {
|
|
93
|
+
super(modelConfig);
|
|
94
|
+
const { labels, instructions = '' } = config;
|
|
95
|
+
this.labelSchema = createLabelSchema(labels);
|
|
96
|
+
this.promptTemplate = PROMPT_TEMPLATE
|
|
97
|
+
.replace('{labels}', formatLabels(labels))
|
|
98
|
+
.replace('{instructions}', instructions);
|
|
101
99
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
.replace('{labels}', formatLabels(labels))
|
|
105
|
-
.replace('{instructions}', instructions)
|
|
106
|
-
.replace('{record}', formatRecord(record));
|
|
107
|
-
const { parsed } = await (0, openai_js_1.askOpenAISafe)(prompt, model, categorySchema);
|
|
108
|
-
if (!parsed) {
|
|
109
|
-
throw new Error('Failed to parse response from OpenAI');
|
|
100
|
+
schema() {
|
|
101
|
+
return this.labelSchema;
|
|
110
102
|
}
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Classifies multiple data records concurrently while preserving order.
|
|
115
|
-
*/
|
|
116
|
-
function classifyBatch(records, labels, instructions = '', model = 'gpt-4.1-mini', maxConcurrency = 100) {
|
|
117
|
-
return (0, async_js_1.mapParallel)(records, maxConcurrency, record => classify(record, labels, instructions, model));
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Assigns one or more labels to a single data record using an LLM call.
|
|
121
|
-
*/
|
|
122
|
-
async function label(record, labels, instructions = '', model = 'gpt-4.1-mini') {
|
|
123
|
-
if (record == null || Object.keys(record).length === 0) {
|
|
124
|
-
return null;
|
|
103
|
+
prompt(record) {
|
|
104
|
+
return this.promptTemplate.replace('{record}', formatRecord(record));
|
|
125
105
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
.replace('{labels}', formatLabels(labels))
|
|
129
|
-
.replace('{instructions}', instructions)
|
|
130
|
-
.replace('{record}', formatRecord(record));
|
|
131
|
-
const { parsed } = await (0, openai_js_1.askOpenAISafe)(prompt, model, multiLabelSchema);
|
|
132
|
-
if (!parsed) {
|
|
133
|
-
throw new Error('Failed to parse response from OpenAI');
|
|
106
|
+
extractResult(parsed) {
|
|
107
|
+
return parsed.label;
|
|
134
108
|
}
|
|
135
|
-
return parsed.labels;
|
|
136
109
|
}
|
|
110
|
+
exports.Classifier = Classifier;
|
|
137
111
|
/**
|
|
138
|
-
*
|
|
112
|
+
* A tool that assigns one or more labels to records from provided options.
|
|
139
113
|
*/
|
|
140
|
-
|
|
141
|
-
|
|
114
|
+
class Labeler extends tool_js_1.Tool {
|
|
115
|
+
multiLabelSchema;
|
|
116
|
+
promptTemplate;
|
|
117
|
+
constructor(config, modelConfig) {
|
|
118
|
+
super(modelConfig);
|
|
119
|
+
const { labels, instructions = '' } = config;
|
|
120
|
+
this.multiLabelSchema = createMultiLabelSchema(labels);
|
|
121
|
+
this.promptTemplate = MULTI_LABEL_PROMPT_TEMPLATE
|
|
122
|
+
.replace('{labels}', formatLabels(labels))
|
|
123
|
+
.replace('{instructions}', instructions);
|
|
124
|
+
}
|
|
125
|
+
schema() {
|
|
126
|
+
return this.multiLabelSchema;
|
|
127
|
+
}
|
|
128
|
+
prompt(record) {
|
|
129
|
+
return this.promptTemplate.replace('{record}', formatRecord(record));
|
|
130
|
+
}
|
|
131
|
+
extractResult(parsed) {
|
|
132
|
+
return parsed.labels;
|
|
133
|
+
}
|
|
142
134
|
}
|
|
135
|
+
exports.Labeler = Labeler;
|
|
143
136
|
// =============================================================================
|
|
144
|
-
//
|
|
137
|
+
// LabelExtractor (extract classification labels from records)
|
|
145
138
|
// =============================================================================
|
|
146
139
|
const EXTRACT_LABELS_PROMPT = (0, utils_js_1.dedent)(`
|
|
147
140
|
# Instructions
|
|
@@ -169,10 +162,6 @@ unless the user provides different instructions below.
|
|
|
169
162
|
|
|
170
163
|
{records}
|
|
171
164
|
`);
|
|
172
|
-
/**
|
|
173
|
-
* Schema for extracted labels - an array of label objects.
|
|
174
|
-
* Uses array format instead of record because OpenAI doesn't support propertyNames in JSON schema.
|
|
175
|
-
*/
|
|
176
165
|
const ExtractedLabelsSchema = index_js_1.z.object({
|
|
177
166
|
labels: index_js_1.z.array(index_js_1.z.object({
|
|
178
167
|
name: index_js_1.z.string(),
|
|
@@ -180,39 +169,37 @@ const ExtractedLabelsSchema = index_js_1.z.object({
|
|
|
180
169
|
}))
|
|
181
170
|
});
|
|
182
171
|
/**
|
|
183
|
-
*
|
|
172
|
+
* A tool that extracts classification labels from a set of records.
|
|
184
173
|
* Returns a Record<string, string> mapping label names to descriptions,
|
|
185
|
-
* which can be used directly with
|
|
174
|
+
* which can be used directly with Classifier and Labeler.
|
|
186
175
|
*/
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
176
|
+
class LabelExtractor extends tool_js_1.Tool {
|
|
177
|
+
maxSamples;
|
|
178
|
+
promptTemplate;
|
|
179
|
+
constructor(config = {}, modelConfig) {
|
|
180
|
+
super(modelConfig);
|
|
181
|
+
const { nLabels = 10, instructions = '', maxSamples = 500, language = 'The same language as the records' } = config;
|
|
182
|
+
this.maxSamples = maxSamples;
|
|
183
|
+
this.promptTemplate = EXTRACT_LABELS_PROMPT
|
|
184
|
+
.replace('{n_labels}', String(nLabels))
|
|
185
|
+
.replace('{instructions}', instructions)
|
|
186
|
+
.replace('{language}', language);
|
|
187
|
+
}
|
|
188
|
+
schema() {
|
|
189
|
+
return ExtractedLabelsSchema;
|
|
190
|
+
}
|
|
191
|
+
prompt(records) {
|
|
192
|
+
const sampledRecords = records.length > this.maxSamples
|
|
193
|
+
? records.slice(0, this.maxSamples)
|
|
194
|
+
: records;
|
|
195
|
+
const formattedRecords = (0, utils_js_1.formatRecordsAttrWise)(sampledRecords);
|
|
196
|
+
return this.promptTemplate.replace('{records}', formattedRecords);
|
|
190
197
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
: records;
|
|
194
|
-
const formattedRecords = (0, utils_js_1.formatRecordsAttrWise)(sampledRecords);
|
|
195
|
-
const prompt = EXTRACT_LABELS_PROMPT
|
|
196
|
-
.replace('{n_labels}', String(nLabels))
|
|
197
|
-
.replace('{instructions}', instructions)
|
|
198
|
-
.replace('{records}', formattedRecords)
|
|
199
|
-
.replace('{language}', language);
|
|
200
|
-
const { parsed, output_text, error } = await (0, openai_js_1.askOpenAISafe)(prompt, model, ExtractedLabelsSchema, modelParams, maxRetries, 'return');
|
|
201
|
-
if (error != null) {
|
|
202
|
-
if (output_text == null) {
|
|
203
|
-
throw new Error('Failed to get response from OpenAI');
|
|
204
|
-
}
|
|
205
|
-
try {
|
|
206
|
-
const extracted = JSON.parse(output_text);
|
|
207
|
-
const { labels } = ExtractedLabelsSchema.parse(extracted);
|
|
208
|
-
return Object.fromEntries(labels.map(l => [l.name, l.description]));
|
|
209
|
-
}
|
|
210
|
-
catch (parseError) {
|
|
211
|
-
throw new Error(`Failed to parse response: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
|
|
212
|
-
}
|
|
198
|
+
isEmpty(records) {
|
|
199
|
+
return !records || records.length === 0;
|
|
213
200
|
}
|
|
214
|
-
|
|
215
|
-
|
|
201
|
+
extractResult(parsed) {
|
|
202
|
+
return Object.fromEntries(parsed.labels.map(l => [l.name, l.description]));
|
|
216
203
|
}
|
|
217
|
-
return Object.fromEntries(parsed.labels.map(l => [l.name, l.description]));
|
|
218
204
|
}
|
|
205
|
+
exports.LabelExtractor = LabelExtractor;
|
|
@@ -1,19 +1,30 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type Entity } from '../schemas/entity.schema.js';
|
|
3
|
-
export declare const PROMPT: string;
|
|
1
|
+
import { Tool, type ModelConfig } from '../tool.js';
|
|
2
|
+
import { type Entity, type Entities } from '../schemas/entity.schema.js';
|
|
4
3
|
/**
|
|
5
|
-
*
|
|
6
|
-
* Extracts free-form entities from the given text (without enforced entity types).
|
|
4
|
+
* Configuration for the EntityExtractor tool.
|
|
7
5
|
*/
|
|
8
|
-
export
|
|
6
|
+
export interface EntityExtractorConfig {
|
|
7
|
+
/** Entity type definitions (string or map of type to description) */
|
|
8
|
+
entityDefinitions?: string | Record<string, string>;
|
|
9
|
+
/** Additional instructions */
|
|
10
|
+
instructions?: string;
|
|
11
|
+
}
|
|
9
12
|
/**
|
|
10
|
-
*
|
|
13
|
+
* A tool that extracts entities from text.
|
|
11
14
|
*/
|
|
12
|
-
export declare
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
export declare class EntityExtractor extends Tool<string | null, Entities, Array<Entity>> {
|
|
16
|
+
private readonly promptTemplate;
|
|
17
|
+
constructor(config: EntityExtractorConfig | undefined, modelConfig: ModelConfig);
|
|
18
|
+
protected schema(): import("../../deps/jsr.io/@zod/zod/4.3.6/src/index.js").ZodObject<{
|
|
19
|
+
entities: import("../../deps/jsr.io/@zod/zod/4.3.6/src/index.js").ZodArray<import("../../deps/jsr.io/@zod/zod/4.3.6/src/index.js").ZodObject<{
|
|
20
|
+
name: import("../../deps/jsr.io/@zod/zod/4.3.6/src/index.js").ZodString;
|
|
21
|
+
type: import("../../deps/jsr.io/@zod/zod/4.3.6/src/index.js").ZodString;
|
|
22
|
+
}, import("../../deps/jsr.io/@zod/zod/4.3.6/src/v4/core/schemas.js").$strip>>;
|
|
23
|
+
}, import("../../deps/jsr.io/@zod/zod/4.3.6/src/v4/core/schemas.js").$strip>;
|
|
24
|
+
protected prompt(text: string | null): string;
|
|
25
|
+
protected isEmpty(text: string | null): boolean;
|
|
26
|
+
protected extractResult(parsed: Entities): Array<Entity>;
|
|
27
|
+
}
|
|
17
28
|
export type { Entity, Entities } from '../schemas/entity.schema.js';
|
|
18
29
|
export { EntitySchema, EntitiesSchema } from '../schemas/entity.schema.js';
|
|
19
30
|
//# sourceMappingURL=entities.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../../../src/src/tools/entities.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../../../src/src/tools/entities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAkB,KAAK,MAAM,EAAE,KAAK,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAkCzF;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACrC,qEAAqE;IACrE,iBAAiB,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpD,8BAA8B;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,IAAI,CAAC,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAChF,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;gBAE5B,MAAM,EAAE,qBAAqB,YAAK,EAAE,WAAW,EAAE,WAAW;cAgBrD,MAAM;;;;;;IAIzB,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;cAIjB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;cAIrC,aAAa,CAAC,MAAM,EAAE,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC;CAGjE;AAGD,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC"}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EntitiesSchema = exports.EntitySchema = exports.
|
|
4
|
-
|
|
5
|
-
exports.extractEntitiesFromText = extractEntitiesFromText;
|
|
6
|
-
exports.extractEntitiesBatch = extractEntitiesBatch;
|
|
7
|
-
const async_js_1 = require("../async.js");
|
|
8
|
-
const openai_js_1 = require("../openai.js");
|
|
3
|
+
exports.EntitiesSchema = exports.EntitySchema = exports.EntityExtractor = void 0;
|
|
4
|
+
const tool_js_1 = require("../tool.js");
|
|
9
5
|
const entity_schema_js_1 = require("../schemas/entity.schema.js");
|
|
10
|
-
const utils_js_1 = require("../utils.js");
|
|
11
|
-
|
|
6
|
+
const utils_js_1 = require("../helpers/utils.js");
|
|
7
|
+
const PROMPT = (0, utils_js_1.dedent)(`
|
|
12
8
|
# Instructions
|
|
13
9
|
|
|
14
10
|
From the Data Record section below extract entities in the following categories:
|
|
@@ -35,54 +31,36 @@ definitions include a "brand" category and a "product" category, the expected ou
|
|
|
35
31
|
{text}
|
|
36
32
|
`);
|
|
37
33
|
/**
|
|
38
|
-
*
|
|
39
|
-
* Extracts free-form entities from the given text (without enforced entity types).
|
|
34
|
+
* A tool that extracts entities from text.
|
|
40
35
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
class EntityExtractor extends tool_js_1.Tool {
|
|
37
|
+
promptTemplate;
|
|
38
|
+
constructor(config = {}, modelConfig) {
|
|
39
|
+
super(modelConfig);
|
|
40
|
+
const { entityDefinitions = '', instructions = '' } = config;
|
|
41
|
+
const definitionsText = typeof entityDefinitions === 'string'
|
|
42
|
+
? entityDefinitions
|
|
43
|
+
: Object.entries(entityDefinitions)
|
|
44
|
+
.map(([type, description]) => `- ${type}: ${description}`)
|
|
45
|
+
.join('\n');
|
|
46
|
+
this.promptTemplate = PROMPT
|
|
47
|
+
.replace('{definitions}', definitionsText)
|
|
48
|
+
.replace('{instructions}', instructions);
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Extracts entities in pre-specified categories from a single text.
|
|
54
|
-
*/
|
|
55
|
-
async function extractEntitiesFromText(text, entityDefinitions, instructions = '', model = 'gpt-4.1-mini', modelParams = {}) {
|
|
56
|
-
if (text === null) {
|
|
57
|
-
return [];
|
|
50
|
+
schema() {
|
|
51
|
+
return entity_schema_js_1.EntitiesSchema;
|
|
58
52
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
.
|
|
67
|
-
.replace('{instructions}', instructions);
|
|
68
|
-
const { parsed } = await (0, openai_js_1.askOpenAISafe)(prompt, model, entity_schema_js_1.EntitiesSchema, modelParams);
|
|
69
|
-
if (!parsed) {
|
|
70
|
-
throw new Error('Failed to parse response from OpenAI');
|
|
53
|
+
prompt(text) {
|
|
54
|
+
return this.promptTemplate.replace('{text}', text ?? '');
|
|
55
|
+
}
|
|
56
|
+
isEmpty(text) {
|
|
57
|
+
return text == null || text.trim() === '';
|
|
58
|
+
}
|
|
59
|
+
extractResult(parsed) {
|
|
60
|
+
return parsed.entities;
|
|
71
61
|
}
|
|
72
|
-
return parsed.entities;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Extracts entities from a batch of texts.
|
|
76
|
-
*/
|
|
77
|
-
async function extractEntitiesBatch(texts, entityDefinitions, instructions = '', model = 'gpt-4.1-mini', maxConcurrency = 100, modelParams = {}) {
|
|
78
|
-
// Do this once outside the loop
|
|
79
|
-
const definitions = typeof entityDefinitions === 'string'
|
|
80
|
-
? entityDefinitions
|
|
81
|
-
: Object.entries(entityDefinitions)
|
|
82
|
-
.map(([type, description]) => `- ${type}: ${description}`)
|
|
83
|
-
.join('\n');
|
|
84
|
-
return (0, async_js_1.mapParallel)(texts, maxConcurrency, (text) => extractEntitiesFromText(text, definitions, instructions, model, modelParams));
|
|
85
62
|
}
|
|
63
|
+
exports.EntityExtractor = EntityExtractor;
|
|
86
64
|
var entity_schema_js_2 = require("../schemas/entity.schema.js");
|
|
87
65
|
Object.defineProperty(exports, "EntitySchema", { enumerable: true, get: function () { return entity_schema_js_2.EntitySchema; } });
|
|
88
66
|
Object.defineProperty(exports, "EntitiesSchema", { enumerable: true, get: function () { return entity_schema_js_2.EntitiesSchema; } });
|
|
@@ -7,11 +7,11 @@ exports.customizeFunnel = customizeFunnel;
|
|
|
7
7
|
exports.generateSeedKeywords = generateSeedKeywords;
|
|
8
8
|
exports.reseedFunnel = reseedFunnel;
|
|
9
9
|
exports.generateFunnel = generateFunnel;
|
|
10
|
-
const async_js_1 = require("../async.js");
|
|
11
|
-
const
|
|
10
|
+
const async_js_1 = require("../helpers/async.js");
|
|
11
|
+
const llm_js_1 = require("../llm.js");
|
|
12
12
|
const funnel_schema_js_1 = require("../schemas/funnel.schema.js");
|
|
13
13
|
Object.defineProperty(exports, "FunnelWithExplanationSchema", { enumerable: true, get: function () { return funnel_schema_js_1.FunnelWithExplanationSchema; } });
|
|
14
|
-
const utils_js_1 = require("../utils.js");
|
|
14
|
+
const utils_js_1 = require("../helpers/utils.js");
|
|
15
15
|
/**
|
|
16
16
|
* Iterates over all categories in a funnel, yielding references to stage info and category objects.
|
|
17
17
|
* This allows in-place modifications of categories within the funnel structure.
|
|
@@ -303,9 +303,9 @@ async function customizeFunnel(sector, language, userLanguage = null, country =
|
|
|
303
303
|
.replace('{language}', language)
|
|
304
304
|
.replace('{userLanguage}', userLanguage ?? language)
|
|
305
305
|
.replace('{funnel}', JSON.stringify(funnelData, null, 2));
|
|
306
|
-
const { parsed } = await (0,
|
|
306
|
+
const { parsed } = await (0, llm_js_1.askLLMSafe)({ prompt, model, schema: funnel_schema_js_1.FunnelWithExplanationSchema });
|
|
307
307
|
if (!parsed) {
|
|
308
|
-
throw new Error('Failed to parse response from
|
|
308
|
+
throw new Error('Failed to parse response from LLM');
|
|
309
309
|
}
|
|
310
310
|
return parsed;
|
|
311
311
|
}
|
|
@@ -346,9 +346,9 @@ async function generateSeedKeywords(stage, goal, category, sector, language, cou
|
|
|
346
346
|
.replace('{sector}', sector)
|
|
347
347
|
.replace('{market}', country)
|
|
348
348
|
.replace('{language}', language);
|
|
349
|
-
const { parsed } = await (0,
|
|
349
|
+
const { parsed } = await (0, llm_js_1.askLLMSafe)({ prompt, model, schema: funnel_schema_js_1.SeedsSchema });
|
|
350
350
|
if (!parsed) {
|
|
351
|
-
throw new Error('Failed to parse seed keywords from
|
|
351
|
+
throw new Error('Failed to parse seed keywords from LLM');
|
|
352
352
|
}
|
|
353
353
|
return parsed.seeds;
|
|
354
354
|
}
|
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
* is either provided directly or inferred from the user's instructions using an LLM.
|
|
6
6
|
*/
|
|
7
7
|
import { z } from '../../deps/jsr.io/@zod/zod/4.3.6/src/index.js';
|
|
8
|
-
import { type
|
|
8
|
+
import { type LLMResponse, type ProviderParams } from '../llm.js';
|
|
9
|
+
import { BatchResponse } from '../response.js';
|
|
10
|
+
export type AIParams = ProviderParams;
|
|
9
11
|
/**
|
|
10
12
|
* Schema for the schema generation response.
|
|
11
13
|
*/
|
|
@@ -42,15 +44,18 @@ export interface GenericBatchOptions extends BaseLLMOptions {
|
|
|
42
44
|
records: Array<Record<string, unknown> | null>;
|
|
43
45
|
schema: Record<string, unknown>;
|
|
44
46
|
maxConcurrency?: number;
|
|
47
|
+
trackCost?: boolean;
|
|
45
48
|
}
|
|
46
49
|
/**
|
|
47
50
|
* Processes a single record using an LLM with a provided JSON schema.
|
|
51
|
+
* Returns both the result and usage information.
|
|
48
52
|
*/
|
|
49
|
-
export declare function generic<T = Record<string, unknown>>({ record, instructions, schema, model, modelParams, maxRetries }: GenericOptions): Promise<T | null
|
|
53
|
+
export declare function generic<T = Record<string, unknown>>({ record, instructions, schema, model, modelParams, maxRetries }: GenericOptions): Promise<LLMResponse<T | null>>;
|
|
50
54
|
/**
|
|
51
55
|
* Processes multiple records using an LLM with a provided JSON schema.
|
|
56
|
+
* Returns a BatchResponse with usage tracking.
|
|
52
57
|
*/
|
|
53
|
-
export declare function genericBatch<T = Record<string, unknown>>({ records, instructions, schema, model, modelParams, maxRetries, maxConcurrency }: GenericBatchOptions): Promise<
|
|
58
|
+
export declare function genericBatch<T = Record<string, unknown>>({ records, instructions, schema, model, modelParams, maxRetries, maxConcurrency, trackCost, }: GenericBatchOptions): Promise<BatchResponse<T | null>>;
|
|
54
59
|
/** Common options for auto functions */
|
|
55
60
|
interface BaseAutoOptions extends BaseLLMOptions {
|
|
56
61
|
schemaOrInstructions?: string | Record<string, unknown> | null;
|
|
@@ -78,11 +83,19 @@ export interface AutoResult<T> {
|
|
|
78
83
|
* 3. Processes the record using the generated schema
|
|
79
84
|
*/
|
|
80
85
|
export declare function auto<T = Record<string, unknown>>({ record, instructions, schemaOrInstructions, model, schemaModel, modelParams, maxRetries }: AutoOptions): Promise<AutoResult<T | null>>;
|
|
86
|
+
/**
|
|
87
|
+
* Result from autoBatch includes schema info and BatchResponse.
|
|
88
|
+
*/
|
|
89
|
+
export interface AutoBatchResult<T> {
|
|
90
|
+
data: BatchResponse<T | null>;
|
|
91
|
+
schema: Record<string, unknown>;
|
|
92
|
+
schemaReasoning: string;
|
|
93
|
+
}
|
|
81
94
|
/**
|
|
82
95
|
* Automatically generates a response schema and processes multiple records.
|
|
83
96
|
*
|
|
84
97
|
* The schema is generated once from the instructions, then used to process all records.
|
|
85
98
|
*/
|
|
86
|
-
export declare function autoBatch<T = Record<string, unknown>>({ records, instructions, schemaOrInstructions, model, schemaModel, modelParams, maxRetries, maxConcurrency }: AutoBatchOptions): Promise<
|
|
99
|
+
export declare function autoBatch<T = Record<string, unknown>>({ records, instructions, schemaOrInstructions, model, schemaModel, modelParams, maxRetries, maxConcurrency }: AutoBatchOptions): Promise<AutoBatchResult<T>>;
|
|
87
100
|
export {};
|
|
88
101
|
//# sourceMappingURL=generic.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../../src/src/tools/generic.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,+CAA+C,CAAC;AAElE,OAAO,
|
|
1
|
+
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../../src/src/tools/generic.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MA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