@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.
Files changed (203) hide show
  1. package/esm/browser.d.ts +1 -1
  2. package/esm/browser.d.ts.map +1 -1
  3. package/esm/browser.js +1 -1
  4. package/esm/mod.d.ts +5 -2
  5. package/esm/mod.d.ts.map +1 -1
  6. package/esm/mod.js +7 -2
  7. package/esm/src/api.d.ts +36 -5
  8. package/esm/src/api.d.ts.map +1 -1
  9. package/esm/src/api.js +84 -37
  10. package/esm/src/apis/chatgptScraper/brightdata.js +1 -1
  11. package/esm/src/apis/chatgptScraper/oxy.js +1 -1
  12. package/esm/src/apis/chatgptScraper/scraper.js +2 -2
  13. package/esm/src/apis/hasdata/aim.js +1 -1
  14. package/esm/src/apis/hasdata/aio.js +1 -1
  15. package/esm/src/apis/hasdata/helpers.d.ts +1 -1
  16. package/esm/src/apis/hasdata/helpers.d.ts.map +1 -1
  17. package/esm/src/apis/hasdata/helpers.js +2 -2
  18. package/esm/src/assets/models.d.ts +60725 -0
  19. package/esm/src/assets/models.d.ts.map +1 -0
  20. package/esm/src/assets/models.js +71915 -0
  21. package/esm/src/helpers/async.d.ts.map +1 -0
  22. package/esm/src/{async.js → helpers/async.js} +1 -1
  23. package/esm/src/helpers/seedKeywords.d.ts.map +1 -0
  24. package/esm/src/helpers/urls.d.ts.map +1 -0
  25. package/esm/src/helpers/utils.d.ts.map +1 -0
  26. package/esm/src/llm.d.ts +35 -0
  27. package/esm/src/llm.d.ts.map +1 -0
  28. package/esm/src/llm.js +59 -0
  29. package/esm/src/providers/google.d.ts +12 -0
  30. package/esm/src/providers/google.d.ts.map +1 -0
  31. package/esm/src/providers/google.js +111 -0
  32. package/esm/src/providers/index.d.ts +13 -0
  33. package/esm/src/providers/index.d.ts.map +1 -0
  34. package/esm/src/providers/index.js +14 -0
  35. package/esm/src/providers/openai.d.ts +12 -0
  36. package/esm/src/providers/openai.d.ts.map +1 -0
  37. package/esm/src/providers/openai.js +141 -0
  38. package/esm/src/providers/pricing.d.ts +72 -0
  39. package/esm/src/providers/pricing.d.ts.map +1 -0
  40. package/esm/src/providers/pricing.js +88 -0
  41. package/esm/src/providers/registry.d.ts +20 -0
  42. package/esm/src/providers/registry.d.ts.map +1 -0
  43. package/esm/src/providers/registry.js +35 -0
  44. package/esm/src/providers/types.d.ts +49 -0
  45. package/esm/src/providers/types.d.ts.map +1 -0
  46. package/esm/src/providers/types.js +7 -0
  47. package/esm/src/response.d.ts +74 -0
  48. package/esm/src/response.d.ts.map +1 -0
  49. package/esm/src/response.js +110 -0
  50. package/esm/src/tool.d.ts +58 -0
  51. package/esm/src/tool.d.ts.map +1 -0
  52. package/esm/src/tool.js +91 -0
  53. package/esm/src/tools/brands.js +6 -6
  54. package/esm/src/tools/classifier.d.ts +80 -17
  55. package/esm/src/tools/classifier.d.ts.map +1 -1
  56. package/esm/src/tools/classifier.js +68 -80
  57. package/esm/src/tools/entities.d.ts +23 -12
  58. package/esm/src/tools/entities.d.ts.map +1 -1
  59. package/esm/src/tools/entities.js +27 -47
  60. package/esm/src/tools/funnel.js +7 -7
  61. package/esm/src/tools/generic.d.ts +17 -4
  62. package/esm/src/tools/generic.d.ts.map +1 -1
  63. package/esm/src/tools/generic.js +39 -14
  64. package/esm/src/tools/keywords.js +5 -5
  65. package/esm/src/tools/personas.d.ts +49 -2
  66. package/esm/src/tools/personas.d.ts.map +1 -1
  67. package/esm/src/tools/personas.js +59 -35
  68. package/esm/src/tools/scorer.d.ts +24 -6
  69. package/esm/src/tools/scorer.d.ts.map +1 -1
  70. package/esm/src/tools/scorer.js +27 -22
  71. package/esm/src/tools/search.d.ts.map +1 -1
  72. package/esm/src/tools/search.js +33 -9
  73. package/esm/src/tools/sentiment.d.ts +30 -8
  74. package/esm/src/tools/sentiment.d.ts.map +1 -1
  75. package/esm/src/tools/sentiment.js +33 -28
  76. package/esm/src/tools/sources.d.ts +5 -5
  77. package/esm/src/tools/sources.d.ts.map +1 -1
  78. package/esm/src/tools/sources.js +5 -6
  79. package/esm/src/tools/topics.d.ts +44 -16
  80. package/esm/src/tools/topics.d.ts.map +1 -1
  81. package/esm/src/tools/topics.js +77 -68
  82. package/esm/src/tools/translate.d.ts +22 -31
  83. package/esm/src/tools/translate.d.ts.map +1 -1
  84. package/esm/src/tools/translate.js +40 -36
  85. package/package.json +2 -1
  86. package/script/browser.d.ts +1 -1
  87. package/script/browser.d.ts.map +1 -1
  88. package/script/browser.js +1 -1
  89. package/script/mod.d.ts +5 -2
  90. package/script/mod.d.ts.map +1 -1
  91. package/script/mod.js +14 -2
  92. package/script/src/api.d.ts +36 -5
  93. package/script/src/api.d.ts.map +1 -1
  94. package/script/src/api.js +84 -35
  95. package/script/src/apis/chatgptScraper/brightdata.js +1 -1
  96. package/script/src/apis/chatgptScraper/oxy.js +1 -1
  97. package/script/src/apis/chatgptScraper/scraper.js +2 -2
  98. package/script/src/apis/hasdata/aim.js +1 -1
  99. package/script/src/apis/hasdata/aio.js +1 -1
  100. package/script/src/apis/hasdata/helpers.d.ts +1 -1
  101. package/script/src/apis/hasdata/helpers.d.ts.map +1 -1
  102. package/script/src/apis/hasdata/helpers.js +2 -2
  103. package/script/src/assets/models.d.ts +60725 -0
  104. package/script/src/assets/models.d.ts.map +1 -0
  105. package/script/src/assets/models.js +71917 -0
  106. package/script/src/helpers/async.d.ts.map +1 -0
  107. package/script/src/{async.js → helpers/async.js} +1 -1
  108. package/script/src/helpers/seedKeywords.d.ts.map +1 -0
  109. package/script/src/helpers/urls.d.ts.map +1 -0
  110. package/script/src/helpers/utils.d.ts.map +1 -0
  111. package/script/src/llm.d.ts +35 -0
  112. package/script/src/llm.d.ts.map +1 -0
  113. package/script/src/llm.js +65 -0
  114. package/script/src/providers/google.d.ts +12 -0
  115. package/script/src/providers/google.d.ts.map +1 -0
  116. package/script/src/providers/google.js +148 -0
  117. package/script/src/providers/index.d.ts +13 -0
  118. package/script/src/providers/index.d.ts.map +1 -0
  119. package/script/src/providers/index.js +24 -0
  120. package/script/src/providers/openai.d.ts +12 -0
  121. package/script/src/providers/openai.d.ts.map +1 -0
  122. package/script/src/providers/openai.js +181 -0
  123. package/script/src/providers/pricing.d.ts +72 -0
  124. package/script/src/providers/pricing.d.ts.map +1 -0
  125. package/script/src/providers/pricing.js +97 -0
  126. package/script/src/providers/registry.d.ts +20 -0
  127. package/script/src/providers/registry.d.ts.map +1 -0
  128. package/script/src/providers/registry.js +39 -0
  129. package/script/src/providers/types.d.ts +49 -0
  130. package/script/src/providers/types.d.ts.map +1 -0
  131. package/script/src/providers/types.js +8 -0
  132. package/script/src/response.d.ts +74 -0
  133. package/script/src/response.d.ts.map +1 -0
  134. package/script/src/response.js +114 -0
  135. package/script/src/tool.d.ts +58 -0
  136. package/script/src/tool.d.ts.map +1 -0
  137. package/script/src/tool.js +95 -0
  138. package/script/src/tools/brands.js +6 -6
  139. package/script/src/tools/classifier.d.ts +80 -17
  140. package/script/src/tools/classifier.d.ts.map +1 -1
  141. package/script/src/tools/classifier.js +72 -85
  142. package/script/src/tools/entities.d.ts +23 -12
  143. package/script/src/tools/entities.d.ts.map +1 -1
  144. package/script/src/tools/entities.js +29 -51
  145. package/script/src/tools/funnel.js +7 -7
  146. package/script/src/tools/generic.d.ts +17 -4
  147. package/script/src/tools/generic.d.ts.map +1 -1
  148. package/script/src/tools/generic.js +39 -14
  149. package/script/src/tools/keywords.js +5 -5
  150. package/script/src/tools/personas.d.ts +49 -2
  151. package/script/src/tools/personas.d.ts.map +1 -1
  152. package/script/src/tools/personas.js +63 -36
  153. package/script/src/tools/scorer.d.ts +24 -6
  154. package/script/src/tools/scorer.d.ts.map +1 -1
  155. package/script/src/tools/scorer.js +28 -24
  156. package/script/src/tools/search.d.ts.map +1 -1
  157. package/script/src/tools/search.js +69 -9
  158. package/script/src/tools/sentiment.d.ts +30 -8
  159. package/script/src/tools/sentiment.d.ts.map +1 -1
  160. package/script/src/tools/sentiment.js +37 -30
  161. package/script/src/tools/sources.d.ts +5 -5
  162. package/script/src/tools/sources.d.ts.map +1 -1
  163. package/script/src/tools/sources.js +4 -5
  164. package/script/src/tools/topics.d.ts +44 -16
  165. package/script/src/tools/topics.d.ts.map +1 -1
  166. package/script/src/tools/topics.js +80 -72
  167. package/script/src/tools/translate.d.ts +22 -31
  168. package/script/src/tools/translate.d.ts.map +1 -1
  169. package/script/src/tools/translate.js +43 -40
  170. package/esm/src/async.d.ts.map +0 -1
  171. package/esm/src/models.d.ts +0 -18
  172. package/esm/src/models.d.ts.map +0 -1
  173. package/esm/src/models.js +0 -48
  174. package/esm/src/openai.d.ts +0 -17
  175. package/esm/src/openai.d.ts.map +0 -1
  176. package/esm/src/openai.js +0 -136
  177. package/esm/src/tools/seedKeywords.d.ts.map +0 -1
  178. package/esm/src/urls.d.ts.map +0 -1
  179. package/esm/src/utils.d.ts.map +0 -1
  180. package/script/src/async.d.ts.map +0 -1
  181. package/script/src/models.d.ts +0 -18
  182. package/script/src/models.d.ts.map +0 -1
  183. package/script/src/models.js +0 -52
  184. package/script/src/openai.d.ts +0 -17
  185. package/script/src/openai.d.ts.map +0 -1
  186. package/script/src/openai.js +0 -175
  187. package/script/src/tools/seedKeywords.d.ts.map +0 -1
  188. package/script/src/urls.d.ts.map +0 -1
  189. package/script/src/utils.d.ts.map +0 -1
  190. /package/esm/src/{async.d.ts → helpers/async.d.ts} +0 -0
  191. /package/esm/src/{tools → helpers}/seedKeywords.d.ts +0 -0
  192. /package/esm/src/{tools → helpers}/seedKeywords.js +0 -0
  193. /package/esm/src/{urls.d.ts → helpers/urls.d.ts} +0 -0
  194. /package/esm/src/{urls.js → helpers/urls.js} +0 -0
  195. /package/esm/src/{utils.d.ts → helpers/utils.d.ts} +0 -0
  196. /package/esm/src/{utils.js → helpers/utils.js} +0 -0
  197. /package/script/src/{async.d.ts → helpers/async.d.ts} +0 -0
  198. /package/script/src/{tools → helpers}/seedKeywords.d.ts +0 -0
  199. /package/script/src/{tools → helpers}/seedKeywords.js +0 -0
  200. /package/script/src/{urls.d.ts → helpers/urls.d.ts} +0 -0
  201. /package/script/src/{urls.js → helpers/urls.js} +0 -0
  202. /package/script/src/{utils.d.ts → helpers/utils.d.ts} +0 -0
  203. /package/script/src/{utils.js → helpers/utils.js} +0 -0
@@ -1,34 +1,97 @@
1
- import { type AIParams } from '../openai.js';
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
- * Classifies a single data record into one of the provided categories using an LLM call.
10
+ * A tool that classifies records into one of the provided categories.
4
11
  */
5
- export declare function classify(record: Record<string, unknown> | null, labels: Record<string, string>, instructions?: string, model?: string): Promise<string | null>;
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
- * Classifies multiple data records concurrently while preserving order.
29
+ * Configuration for the Labeler tool.
8
30
  */
9
- export declare function classifyBatch(records: Array<Record<string, unknown> | null>, labels: Record<string, string>, instructions?: string, model?: string, maxConcurrency?: number): Promise<Array<string | null>>;
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
- * Assigns one or more labels to a single data record using an LLM call.
38
+ * A tool that assigns one or more labels to records from provided options.
12
39
  */
13
- export declare function label(record: Record<string, unknown> | null, labels: Record<string, string>, instructions?: string, model?: string): Promise<Array<string> | null>;
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
- * Assigns labels to multiple data records concurrently while preserving order.
55
+ * Configuration for the LabelExtractor tool.
16
56
  */
17
- export declare function labelBatch(records: Array<Record<string, unknown> | null>, labels: Record<string, string>, instructions?: string, model?: string, maxConcurrency?: number): Promise<Array<Array<string> | null>>;
18
- export interface LabelExtractionOptions {
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
- model?: string;
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
- * Extracts a set of classification labels from an array of records using an LLM.
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 classify() and classifyBatch().
70
+ * which can be used directly with Classifier and Labeler.
32
71
  */
33
- export declare function extractLabels({ records, nLabels, instructions, maxSamples, model, modelParams, maxRetries, language }: LabelExtractionOptions): Promise<Record<string, string>>;
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":"AAEA,OAAO,EAAiB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAoG5D;;GAEG;AACH,wBAAsB,QAAQ,CAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,EACtC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,YAAY,GAAE,MAAW,EACzB,KAAK,GAAE,MAAuB,GAC5B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAiBxB;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC5B,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,EAC9C,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,YAAY,GAAE,MAAW,EACzB,KAAK,GAAE,MAAuB,EAC9B,cAAc,GAAE,MAAY,GAC1B,OAAO,CAAC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C/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.classify = classify;
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 async_js_1 = require("../async.js");
10
- const openai_js_1 = require("../openai.js");
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
- * Classifies a single data record into one of the provided categories using an LLM call.
87
+ * A tool that classifies records into one of the provided categories.
97
88
  */
98
- async function classify(record, labels, instructions = '', model = 'gpt-4.1-mini') {
99
- if (record == null || Object.keys(record).length === 0) {
100
- return null;
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
- const categorySchema = createLabelSchema(labels);
103
- const prompt = PROMPT_TEMPLATE
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
- return parsed.label;
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
- const multiLabelSchema = createMultiLabelSchema(labels);
127
- const prompt = MULTI_LABEL_PROMPT_TEMPLATE
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
- * Assigns labels to multiple data records concurrently while preserving order.
112
+ * A tool that assigns one or more labels to records from provided options.
139
113
  */
140
- function labelBatch(records, labels, instructions = '', model = 'gpt-4.1-mini', maxConcurrency = 100) {
141
- return (0, async_js_1.mapParallel)(records, maxConcurrency, record => label(record, labels, instructions, model));
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
- // Label Extraction
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
- * Extracts a set of classification labels from an array of records using an LLM.
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 classify() and classifyBatch().
174
+ * which can be used directly with Classifier and Labeler.
186
175
  */
187
- async function extractLabels({ records, nLabels = 10, instructions = '', maxSamples = 500, model = 'gpt-4.1', modelParams = {}, maxRetries = 8, language = 'The same language as the records' }) {
188
- if (!records || records.length === 0) {
189
- return {};
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
- const sampledRecords = records.length > maxSamples
192
- ? records.slice(0, maxSamples)
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
- if (parsed == null) {
215
- throw new Error('Failed to parse response from OpenAI');
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 AIParams } from '../openai.js';
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 declare function extractAnyEntities(body: string, instructions: string | undefined, model: string, modelParams?: AIParams): Promise<Array<Entity>>;
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
- * Extracts entities in pre-specified categories from a single text.
13
+ * A tool that extracts entities from text.
11
14
  */
12
- export declare function extractEntitiesFromText(text: string | null, entityDefinitions: string | Record<string, string>, instructions?: string, model?: string, modelParams?: AIParams): Promise<Array<Entity>>;
13
- /**
14
- * Extracts entities from a batch of texts.
15
- */
16
- export declare function extractEntitiesBatch(texts: Array<string | null>, entityDefinitions: Record<string, string> | string, instructions?: string, model?: string, maxConcurrency?: number, modelParams?: AIParams): Promise<Array<Array<Entity>>>;
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":"AACA,OAAO,EAAiB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE5D,OAAO,EAAkB,KAAK,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAG1E,eAAO,MAAM,MAAM,QAyBjB,CAAC;AAEH;;;GAGG;AACH,wBAAsB,kBAAkB,CACvC,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,YAAK,EACzB,KAAK,EAAE,MAAM,EACb,WAAW,GAAE,QAAa,GACxB,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAYxB;AAED;;GAEG;AACH,wBAAsB,uBAAu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ChF,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.PROMPT = void 0;
4
- exports.extractAnyEntities = extractAnyEntities;
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
- exports.PROMPT = (0, utils_js_1.dedent)(`
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
- async function extractAnyEntities(body, instructions = '', model, modelParams = {}) {
42
- const prompt = exports.PROMPT
43
- .replace('{definitions}', '')
44
- .replace('{text}', body)
45
- .replace('{instructions}', instructions);
46
- const { parsed } = await (0, openai_js_1.askOpenAISafe)(prompt, model, entity_schema_js_1.EntitiesSchema, modelParams);
47
- if (!parsed) {
48
- throw new Error('Failed to parse response from OpenAI');
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
- return parsed.entities;
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
- const definitionsText = typeof entityDefinitions === 'string'
60
- ? entityDefinitions
61
- : Object.entries(entityDefinitions)
62
- .map(([type, description]) => `- ${type}: ${description}`)
63
- .join('\n');
64
- const prompt = exports.PROMPT
65
- .replace('{definitions}', definitionsText)
66
- .replace('{text}', text)
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 openai_js_1 = require("../openai.js");
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, openai_js_1.askOpenAISafe)(prompt, model, funnel_schema_js_1.FunnelWithExplanationSchema);
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 OpenAI');
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, openai_js_1.askOpenAISafe)(prompt, model, funnel_schema_js_1.SeedsSchema);
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 OpenAI');
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 AIParams } from '../openai.js';
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<Array<T | null>>;
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<AutoResult<Array<T | null>>>;
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,EAAiB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AA0E5D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