@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
|
@@ -12,9 +12,10 @@ exports.genericBatch = genericBatch;
|
|
|
12
12
|
exports.auto = auto;
|
|
13
13
|
exports.autoBatch = autoBatch;
|
|
14
14
|
const index_js_1 = require("../../deps/jsr.io/@zod/zod/4.3.6/src/index.js");
|
|
15
|
-
const async_js_1 = require("../async.js");
|
|
16
|
-
const
|
|
17
|
-
const
|
|
15
|
+
const async_js_1 = require("../helpers/async.js");
|
|
16
|
+
const llm_js_1 = require("../llm.js");
|
|
17
|
+
const response_js_1 = require("../response.js");
|
|
18
|
+
const utils_js_1 = require("../helpers/utils.js");
|
|
18
19
|
// ============================================================================
|
|
19
20
|
// Prompts
|
|
20
21
|
// ============================================================================
|
|
@@ -115,7 +116,14 @@ async function generateSchema({ instructions, model = 'gpt-4.1', modelParams = {
|
|
|
115
116
|
{ role: 'system', content: SCHEMA_GENERATION_SYSTEM_PROMPT },
|
|
116
117
|
{ role: 'user', content: SCHEMA_GENERATION_PROMPT.replace('{instructions}', instructions) }
|
|
117
118
|
];
|
|
118
|
-
const { parsed, error } = await (0,
|
|
119
|
+
const { parsed, error } = await (0, llm_js_1.askLLMSafe)({
|
|
120
|
+
prompt,
|
|
121
|
+
model,
|
|
122
|
+
schema: SchemaResponseSchema,
|
|
123
|
+
params: modelParams,
|
|
124
|
+
maxRetries,
|
|
125
|
+
onError: 'return',
|
|
126
|
+
});
|
|
119
127
|
if (error || !parsed) {
|
|
120
128
|
throw new Error(`Failed to generate schema: ${error?.message ?? 'Unknown error'}`);
|
|
121
129
|
}
|
|
@@ -127,7 +135,14 @@ async function generateSchema({ instructions, model = 'gpt-4.1', modelParams = {
|
|
|
127
135
|
*/
|
|
128
136
|
async function convertToSchemaInstructions(instructions, model, modelParams, maxRetries) {
|
|
129
137
|
const prompt = SCHEMA_CONVERSION_PROMPT.replace('{instructions}', instructions);
|
|
130
|
-
const { parsed, error } = await (0,
|
|
138
|
+
const { parsed, error } = await (0, llm_js_1.askLLMSafe)({
|
|
139
|
+
prompt,
|
|
140
|
+
model,
|
|
141
|
+
schema: SchemaInstructionsSchema,
|
|
142
|
+
params: modelParams,
|
|
143
|
+
maxRetries,
|
|
144
|
+
onError: 'return',
|
|
145
|
+
});
|
|
131
146
|
if (error || !parsed) {
|
|
132
147
|
throw new Error(`Failed to convert instructions: ${error?.message ?? 'Unknown error'}`);
|
|
133
148
|
}
|
|
@@ -135,26 +150,36 @@ async function convertToSchemaInstructions(instructions, model, modelParams, max
|
|
|
135
150
|
}
|
|
136
151
|
/**
|
|
137
152
|
* Processes a single record using an LLM with a provided JSON schema.
|
|
153
|
+
* Returns both the result and usage information.
|
|
138
154
|
*/
|
|
139
155
|
async function generic({ record, instructions, schema, model = 'gpt-4.1-mini', modelParams = {}, maxRetries = 3 }) {
|
|
140
156
|
if (record == null || Object.keys(record).length === 0) {
|
|
141
|
-
return null;
|
|
157
|
+
return { parsed: null, text: null, usage: null, error: null };
|
|
142
158
|
}
|
|
143
159
|
const zodSchema = index_js_1.z.fromJSONSchema(schema);
|
|
144
160
|
const prompt = GENERIC_PROMPT
|
|
145
161
|
.replace('{instructions}', instructions)
|
|
146
162
|
.replace('{record}', formatRecord(record));
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
163
|
+
const response = await (0, llm_js_1.askLLMSafe)({
|
|
164
|
+
prompt,
|
|
165
|
+
model,
|
|
166
|
+
schema: zodSchema,
|
|
167
|
+
params: modelParams,
|
|
168
|
+
maxRetries,
|
|
169
|
+
onError: 'return',
|
|
170
|
+
});
|
|
171
|
+
if (response.error || response.parsed == null) {
|
|
172
|
+
throw new Error(`Failed to process record: ${response.error?.message ?? 'Unknown error'}`);
|
|
150
173
|
}
|
|
151
|
-
return parsed;
|
|
174
|
+
return { parsed: response.parsed, text: response.text, usage: response.usage, error: null };
|
|
152
175
|
}
|
|
153
176
|
/**
|
|
154
177
|
* Processes multiple records using an LLM with a provided JSON schema.
|
|
178
|
+
* Returns a BatchResponse with usage tracking.
|
|
155
179
|
*/
|
|
156
|
-
function genericBatch({ records, instructions, schema, model = 'gpt-4.1-mini', modelParams = {}, maxRetries = 3, maxConcurrency = 100 }) {
|
|
157
|
-
|
|
180
|
+
async function genericBatch({ records, instructions, schema, model = 'gpt-4.1-mini', modelParams = {}, maxRetries = 3, maxConcurrency = 100, trackCost = false, }) {
|
|
181
|
+
const responses = await (0, async_js_1.mapParallel)(records, maxConcurrency, (record) => generic({ record, instructions, schema, model, modelParams, maxRetries }));
|
|
182
|
+
return new response_js_1.BatchResponse(responses.map(r => r.parsed), trackCost ? responses.map(r => r.usage) : undefined, trackCost ? model : undefined);
|
|
158
183
|
}
|
|
159
184
|
/**
|
|
160
185
|
* Resolves a schema from various input types:
|
|
@@ -196,7 +221,7 @@ async function resolveSchema(schemaOrInstructions, taskInstructions, model, mode
|
|
|
196
221
|
*/
|
|
197
222
|
async function auto({ record, instructions, schemaOrInstructions = null, model = 'gpt-4.1-mini', schemaModel = 'gpt-4.1', modelParams = {}, maxRetries = 3 }) {
|
|
198
223
|
const { schema, schemaReasoning } = await resolveSchema(schemaOrInstructions, instructions, schemaModel, modelParams, maxRetries);
|
|
199
|
-
const
|
|
224
|
+
const response = await generic({
|
|
200
225
|
record,
|
|
201
226
|
instructions,
|
|
202
227
|
schema,
|
|
@@ -204,7 +229,7 @@ async function auto({ record, instructions, schemaOrInstructions = null, model =
|
|
|
204
229
|
modelParams,
|
|
205
230
|
maxRetries
|
|
206
231
|
});
|
|
207
|
-
return { data, schema, schemaReasoning };
|
|
232
|
+
return { data: response.parsed, schema, schemaReasoning };
|
|
208
233
|
}
|
|
209
234
|
/**
|
|
210
235
|
* Automatically generates a response schema and processes multiple records.
|
|
@@ -16,11 +16,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.expandKeywords = expandKeywords;
|
|
18
18
|
exports.generateKeywords = generateKeywords;
|
|
19
|
-
const async_js_1 = require("../async.js");
|
|
20
|
-
const
|
|
19
|
+
const async_js_1 = require("../helpers/async.js");
|
|
20
|
+
const llm_js_1 = require("../llm.js");
|
|
21
21
|
const brands_js_1 = require("./brands.js");
|
|
22
22
|
const keyword_schema_js_1 = require("../schemas/keyword.schema.js");
|
|
23
|
-
const utils_js_1 = require("../utils.js");
|
|
23
|
+
const utils_js_1 = require("../helpers/utils.js");
|
|
24
24
|
const keywordPlanner_js_1 = require("../apis/googleAds/keywordPlanner.js");
|
|
25
25
|
async function expandKeywords({ seedKeywords, url, urlAsExpandRelevanceContext, language = 'EN', countryISOCode, generateIdeasFromSeeds = false, includeSeedKeywords = false }) {
|
|
26
26
|
url = url?.trim();
|
|
@@ -181,9 +181,9 @@ async function generateKeywords({ sector, market, brand, brandDomain, language =
|
|
|
181
181
|
.replaceAll('{brandsInfo}', brandsInfo || '')
|
|
182
182
|
.replaceAll('{personasInfo}', personasInfo || '')
|
|
183
183
|
.replaceAll('{funnelInfo}', funnelInfo || '');
|
|
184
|
-
const { parsed } = await (0,
|
|
184
|
+
const { parsed } = await (0, llm_js_1.askLLMSafe)({ prompt: content, model, schema: keyword_schema_js_1.KeywordsResponseSchema });
|
|
185
185
|
if (!parsed) {
|
|
186
|
-
throw new Error('Failed to parse response from
|
|
186
|
+
throw new Error('Failed to parse response from LLM');
|
|
187
187
|
}
|
|
188
188
|
return parsed;
|
|
189
189
|
}
|
|
@@ -1,3 +1,50 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { Tool, type ModelConfig } from '../tool.js';
|
|
2
|
+
import type { Persona, PersonasResponse } from '../schemas/persona.schema.js';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for the PersonaGenerator tool.
|
|
5
|
+
*/
|
|
6
|
+
export interface PersonaGeneratorConfig {
|
|
7
|
+
/** Industry sector the brand operates in */
|
|
8
|
+
sector: string;
|
|
9
|
+
/** Geographical market or region */
|
|
10
|
+
market: string;
|
|
11
|
+
/** Brand name */
|
|
12
|
+
brand?: string;
|
|
13
|
+
/** Brand domain */
|
|
14
|
+
brandDomain?: string;
|
|
15
|
+
/** Language for keyword seeds (default: 'english') */
|
|
16
|
+
language?: string;
|
|
17
|
+
/** Language for persona descriptions (default: same as language) */
|
|
18
|
+
userLanguage?: string | null;
|
|
19
|
+
/** Number of personas to generate (default: 5) */
|
|
20
|
+
count?: number;
|
|
21
|
+
/** Brand briefing context */
|
|
22
|
+
briefing?: string;
|
|
23
|
+
/** Additional instructions */
|
|
24
|
+
instructions?: string | null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A tool that generates customer personas for a brand.
|
|
28
|
+
*/
|
|
29
|
+
export declare class PersonaGenerator extends Tool<Array<Persona> | null, PersonasResponse, PersonasResponse> {
|
|
30
|
+
private readonly promptTemplate;
|
|
31
|
+
constructor(config: PersonaGeneratorConfig, modelConfig: ModelConfig);
|
|
32
|
+
protected schema(): import("../../deps/jsr.io/@zod/zod/4.3.6/src/index.js").ZodObject<{
|
|
33
|
+
personas: 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<{
|
|
34
|
+
name: import("../../deps/jsr.io/@zod/zod/4.3.6/src/index.js").ZodString;
|
|
35
|
+
description: import("../../deps/jsr.io/@zod/zod/4.3.6/src/index.js").ZodString;
|
|
36
|
+
keywordSeeds: 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").ZodString>;
|
|
37
|
+
}, import("../../deps/jsr.io/@zod/zod/4.3.6/src/v4/core/schemas.js").$strip>>;
|
|
38
|
+
explanation: import("../../deps/jsr.io/@zod/zod/4.3.6/src/index.js").ZodString;
|
|
39
|
+
}, import("../../deps/jsr.io/@zod/zod/4.3.6/src/v4/core/schemas.js").$strip>;
|
|
40
|
+
protected prompt(existingPersonas: Array<Persona> | null): string;
|
|
41
|
+
protected isEmpty(_input: Array<Persona> | null): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Not supported. PersonaGenerator is configured for a specific brand context
|
|
44
|
+
* and generates personas in a single call. Use invoke() instead.
|
|
45
|
+
*/
|
|
46
|
+
batch(): never;
|
|
47
|
+
}
|
|
48
|
+
export type { Persona, PersonasResponse, PersonasOptions } from '../schemas/persona.schema.js';
|
|
49
|
+
export { PersonaSchema, PersonasResponseSchema } from '../schemas/persona.schema.js';
|
|
3
50
|
//# sourceMappingURL=personas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"personas.d.ts","sourceRoot":"","sources":["../../../src/src/tools/personas.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"personas.d.ts","sourceRoot":"","sources":["../../../src/src/tools/personas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,KAAK,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAsD9E;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACtC,4CAA4C;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mBAAmB;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sDAAsD;IACtD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oEAAoE;IACpE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,kDAAkD;IAClD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6BAA6B;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8BAA8B;IAC9B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,IAAI,EAAE,gBAAgB,EAAE,gBAAgB,CAAC;IACpG,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;gBAE5B,MAAM,EAAE,sBAAsB,EAAE,WAAW,EAAE,WAAW;cAgDjD,MAAM;;;;;;;;IAIzB,SAAS,CAAC,MAAM,CAAC,gBAAgB,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,MAAM;cAW9C,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,OAAO;IAKlE;;;OAGG;IACM,KAAK,IAAI,KAAK;CAOvB;AAGD,YAAY,EAAE,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/F,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
3
|
+
exports.PersonasResponseSchema = exports.PersonaSchema = exports.PersonaGenerator = void 0;
|
|
4
|
+
const tool_js_1 = require("../tool.js");
|
|
5
5
|
const brands_js_1 = require("./brands.js");
|
|
6
6
|
const persona_schema_js_1 = require("../schemas/persona.schema.js");
|
|
7
|
-
const utils_js_1 = require("../utils.js");
|
|
7
|
+
const utils_js_1 = require("../helpers/utils.js");
|
|
8
8
|
const PROMPT = (0, utils_js_1.dedent)(`
|
|
9
9
|
You're a marketing expert identifying typical profiles/personas of people searching
|
|
10
10
|
for brands, products or services. Generate {count} detailed customer personas for a brand
|
|
@@ -49,43 +49,70 @@ from this list, you MUST return at least all the same competitors that are alrea
|
|
|
49
49
|
current data. If no modification instructions are provided, maintain the existing list and only add
|
|
50
50
|
new competitors if they are relevant.
|
|
51
51
|
`);
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
sector,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
52
|
+
/**
|
|
53
|
+
* A tool that generates customer personas for a brand.
|
|
54
|
+
*/
|
|
55
|
+
class PersonaGenerator extends tool_js_1.Tool {
|
|
56
|
+
promptTemplate;
|
|
57
|
+
constructor(config, modelConfig) {
|
|
58
|
+
super(modelConfig);
|
|
59
|
+
const { sector, market, brand, brandDomain, language = 'english', userLanguage = null, count = 5, briefing, instructions } = config;
|
|
60
|
+
if (!brand && !brandDomain) {
|
|
61
|
+
throw new Error('Either brand or brandDomain must be provided');
|
|
62
|
+
}
|
|
63
|
+
const brandContext = (0, brands_js_1.buildBrandContext)({
|
|
64
|
+
brand,
|
|
65
|
+
brandDomain,
|
|
66
|
+
sector,
|
|
67
|
+
market,
|
|
68
|
+
briefing
|
|
69
|
+
});
|
|
70
|
+
let brandExclusion;
|
|
71
|
+
if (brandDomain) {
|
|
72
|
+
if (brand) {
|
|
73
|
+
brandExclusion = ` "${brand}" or the domain`;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
brandExclusion = ' or domain';
|
|
77
|
+
}
|
|
67
78
|
}
|
|
68
79
|
else {
|
|
69
|
-
brandExclusion =
|
|
80
|
+
brandExclusion = ` "${brand}"`;
|
|
70
81
|
}
|
|
82
|
+
this.promptTemplate = PROMPT
|
|
83
|
+
.replace('{count}', count.toString())
|
|
84
|
+
.replaceAll('{sector}', sector)
|
|
85
|
+
.replaceAll('{market}', market)
|
|
86
|
+
.replaceAll('{brand_context}', brandContext)
|
|
87
|
+
.replaceAll('{brand_exclusion}', brandExclusion)
|
|
88
|
+
.replaceAll('{language}', language)
|
|
89
|
+
.replaceAll('{userLanguage}', userLanguage ?? language)
|
|
90
|
+
.replaceAll('{instructions}', instructions || '');
|
|
91
|
+
}
|
|
92
|
+
schema() {
|
|
93
|
+
return persona_schema_js_1.PersonasResponseSchema;
|
|
94
|
+
}
|
|
95
|
+
prompt(existingPersonas) {
|
|
96
|
+
const currentData = existingPersonas && existingPersonas.length > 0
|
|
97
|
+
? CURRENT_DATA_CLAUSE.replace('{currentData}', JSON.stringify({ personas: existingPersonas }, null, 2))
|
|
98
|
+
: '';
|
|
99
|
+
return this.promptTemplate.replace('{currentPersonasInfo}', currentData);
|
|
71
100
|
}
|
|
72
|
-
|
|
73
|
-
|
|
101
|
+
isEmpty(_input) {
|
|
102
|
+
// Never skip - null means generate fresh personas
|
|
103
|
+
return false;
|
|
74
104
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
.replaceAll('{userLanguage}', userLanguage ?? language)
|
|
84
|
-
.replaceAll('{instructions}', instructions || '')
|
|
85
|
-
.replaceAll('{currentPersonasInfo}', currentData || '');
|
|
86
|
-
const { parsed } = await (0, openai_js_1.askOpenAISafe)(content, model, persona_schema_js_1.PersonasResponseSchema);
|
|
87
|
-
if (!parsed) {
|
|
88
|
-
throw new Error('Failed to parse response from OpenAI');
|
|
105
|
+
/**
|
|
106
|
+
* Not supported. PersonaGenerator is configured for a specific brand context
|
|
107
|
+
* and generates personas in a single call. Use invoke() instead.
|
|
108
|
+
*/
|
|
109
|
+
batch() {
|
|
110
|
+
throw new Error('PersonaGenerator.batch() is not supported. ' +
|
|
111
|
+
'This tool generates personas for a specific brand context. ' +
|
|
112
|
+
'Use invoke() instead.');
|
|
89
113
|
}
|
|
90
|
-
return parsed;
|
|
91
114
|
}
|
|
115
|
+
exports.PersonaGenerator = PersonaGenerator;
|
|
116
|
+
var persona_schema_js_2 = require("../schemas/persona.schema.js");
|
|
117
|
+
Object.defineProperty(exports, "PersonaSchema", { enumerable: true, get: function () { return persona_schema_js_2.PersonaSchema; } });
|
|
118
|
+
Object.defineProperty(exports, "PersonasResponseSchema", { enumerable: true, get: function () { return persona_schema_js_2.PersonasResponseSchema; } });
|
|
@@ -1,14 +1,32 @@
|
|
|
1
1
|
import { z } from '../../deps/jsr.io/@zod/zod/4.3.6/src/index.js';
|
|
2
|
-
|
|
2
|
+
import { Tool, type ModelConfig } from '../tool.js';
|
|
3
|
+
type ScoreSchema = z.ZodObject<{
|
|
3
4
|
value: z.ZodNumber;
|
|
4
5
|
}>;
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
+
* Configuration for the Scorer tool.
|
|
7
8
|
*/
|
|
8
|
-
export
|
|
9
|
+
export interface ScorerConfig {
|
|
10
|
+
name: string;
|
|
11
|
+
description: string;
|
|
12
|
+
type: 'integer' | 'number';
|
|
13
|
+
min: number;
|
|
14
|
+
max: number;
|
|
15
|
+
}
|
|
9
16
|
/**
|
|
10
|
-
*
|
|
17
|
+
* A tool that scores records based on configured criteria.
|
|
11
18
|
*/
|
|
12
|
-
export declare
|
|
13
|
-
|
|
19
|
+
export declare class Scorer extends Tool<Record<string, unknown> | null, {
|
|
20
|
+
value: number;
|
|
21
|
+
}, number> {
|
|
22
|
+
private readonly scoreSchema;
|
|
23
|
+
private readonly promptTemplate;
|
|
24
|
+
constructor(config: ScorerConfig, modelConfig: ModelConfig);
|
|
25
|
+
protected schema(): ScoreSchema;
|
|
26
|
+
protected prompt(record: Record<string, unknown> | null): string;
|
|
27
|
+
protected extractResult(parsed: {
|
|
28
|
+
value: number;
|
|
29
|
+
}): number;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
14
32
|
//# sourceMappingURL=scorer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scorer.d.ts","sourceRoot":"","sources":["../../../src/src/tools/scorer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,+CAA+C,CAAC;
|
|
1
|
+
{"version":3,"file":"scorer.d.ts","sourceRoot":"","sources":["../../../src/src/tools/scorer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,+CAA+C,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAkBpD,KAAK,WAAW,GAAG,CAAC,CAAC,SAAS,CAAC;IAAE,KAAK,EAAE,CAAC,CAAC,SAAS,CAAA;CAAE,CAAC,CAAC;AAuBvD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACZ;AAED;;GAEG;AACH,qBAAa,MAAO,SAAQ,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,MAAM,CAAC;IAC1F,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAC1C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;gBAE5B,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW;cAYvC,MAAM;IAIzB,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;cAIpC,aAAa,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE;CAG1D"}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.score = score;
|
|
5
|
-
exports.scoreBatch = scoreBatch;
|
|
3
|
+
exports.Scorer = void 0;
|
|
6
4
|
const index_js_1 = require("../../deps/jsr.io/@zod/zod/4.3.6/src/index.js");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const utils_js_1 = require("../utils.js");
|
|
5
|
+
const tool_js_1 = require("../tool.js");
|
|
6
|
+
const utils_js_1 = require("../helpers/utils.js");
|
|
10
7
|
const PROMPT = (0, utils_js_1.dedent)(`
|
|
11
8
|
# Instructions
|
|
12
9
|
|
|
@@ -33,27 +30,34 @@ function makeScoreSchema(type, min, max, description) {
|
|
|
33
30
|
schema = index_js_1.z.number().min(min).max(max).describe(description);
|
|
34
31
|
}
|
|
35
32
|
return index_js_1.z.object({
|
|
36
|
-
value: schema
|
|
33
|
+
value: schema,
|
|
37
34
|
});
|
|
38
35
|
}
|
|
39
36
|
/**
|
|
40
|
-
*
|
|
37
|
+
* A tool that scores records based on configured criteria.
|
|
41
38
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
class Scorer extends tool_js_1.Tool {
|
|
40
|
+
scoreSchema;
|
|
41
|
+
promptTemplate;
|
|
42
|
+
constructor(config, modelConfig) {
|
|
43
|
+
super(modelConfig);
|
|
44
|
+
const { name, description, type, min, max } = config;
|
|
45
|
+
this.scoreSchema = makeScoreSchema(type, min, max, description);
|
|
46
|
+
this.promptTemplate = PROMPT
|
|
47
|
+
.replace('{name}', name)
|
|
48
|
+
.replace('{type}', type)
|
|
49
|
+
.replace('{min}', min.toString())
|
|
50
|
+
.replace('{max}', max.toString())
|
|
51
|
+
.replace('{description}', description);
|
|
52
|
+
}
|
|
53
|
+
schema() {
|
|
54
|
+
return this.scoreSchema;
|
|
55
|
+
}
|
|
56
|
+
prompt(record) {
|
|
57
|
+
return this.promptTemplate.replace('{record}', JSON.stringify(record, null, 2));
|
|
58
|
+
}
|
|
59
|
+
extractResult(parsed) {
|
|
60
|
+
return parsed.value;
|
|
47
61
|
}
|
|
48
|
-
return response.parsed.value;
|
|
49
|
-
}
|
|
50
|
-
async function scoreBatch(records, name, description, type, min, max, model = 'gpt-4.1-mini', maxConcurrency = 100) {
|
|
51
|
-
const schema = makeScoreSchema(type, min, max, description);
|
|
52
|
-
const prompt = PROMPT
|
|
53
|
-
.replace('{name}', name)
|
|
54
|
-
.replace('{type}', type)
|
|
55
|
-
.replace('{min}', min.toString())
|
|
56
|
-
.replace('{max}', max.toString())
|
|
57
|
-
.replace('{description}', description);
|
|
58
|
-
return (0, async_js_1.mapParallel)(records, maxConcurrency, (record) => score(record, prompt, schema, model));
|
|
59
62
|
}
|
|
63
|
+
exports.Scorer = Scorer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../../src/src/tools/search.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../../src/src/tools/search.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AA0B3H,YAAY,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,EAClC,MAAM,EACN,KAAsB,EACtB,SAAgB,EAChB,cAAqB,EACrB,WAAmB,EACnB,eAAuB,EACvB,UAAyB,EACzB,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CA4BvC;AAqED;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EAAE,EACzC,MAAM,EACN,KAAK,EACL,cAAc,EACd,SAAgB,EAChB,cAAqB,EACrB,WAAsB,EACtB,eAAuB,EACvB,EAAE,sBAAsB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CA0BxC;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,EAC3B,OAAO,EACP,KAAsB,EACtB,SAAgB,EAChB,cAAqB,EACrB,WAAsB,EACtB,eAAuB,EACvB,cAAoB,EACpB,EAAE,kBAAkB,GAAG,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAanD"}
|
|
@@ -1,12 +1,66 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
2
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
39
|
exports.searchOpenAI = searchOpenAI;
|
|
4
40
|
exports.searchWithFormat = searchWithFormat;
|
|
5
41
|
exports.searchBatch = searchBatch;
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
42
|
+
const dntShim = __importStar(require("../../_dnt.shims.js"));
|
|
43
|
+
const openai_1 = __importDefault(require("openai"));
|
|
44
|
+
const async_js_1 = require("../helpers/async.js");
|
|
45
|
+
const llm_js_1 = require("../llm.js");
|
|
46
|
+
const urls_js_1 = require("../helpers/urls.js");
|
|
47
|
+
const utils_js_1 = require("../helpers/utils.js");
|
|
48
|
+
// Lazy-initialized OpenAI client for web search functionality
|
|
49
|
+
let openaiClient = null;
|
|
50
|
+
function getOpenAIClient() {
|
|
51
|
+
if (!openaiClient) {
|
|
52
|
+
const fetchOptions = {};
|
|
53
|
+
const abortSignal = dntShim.dntGlobalThis.abortSignal;
|
|
54
|
+
if (abortSignal) {
|
|
55
|
+
fetchOptions.signal = abortSignal;
|
|
56
|
+
}
|
|
57
|
+
openaiClient = new openai_1.default({
|
|
58
|
+
apiKey: dntShim.Deno.env.get('OPENAI_API_KEY'),
|
|
59
|
+
fetchOptions,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return openaiClient;
|
|
63
|
+
}
|
|
10
64
|
/**
|
|
11
65
|
* Call OpenAI Responses API with Web Search enabled (async).
|
|
12
66
|
*
|
|
@@ -26,11 +80,17 @@ async function searchOpenAI({ prompt, model = 'gpt-4.1-mini', useSearch = true,
|
|
|
26
80
|
}];
|
|
27
81
|
params.tool_choice = 'required';
|
|
28
82
|
}
|
|
29
|
-
const
|
|
30
|
-
|
|
83
|
+
const client = getOpenAIClient();
|
|
84
|
+
const response = await client.responses.create({
|
|
85
|
+
...params,
|
|
86
|
+
model,
|
|
87
|
+
input: [{ role: 'user', content: prompt }],
|
|
88
|
+
stream: false,
|
|
89
|
+
});
|
|
90
|
+
if (!response.output) {
|
|
31
91
|
throw new Error('No output from OpenAI');
|
|
32
92
|
}
|
|
33
|
-
return validateOpenAI(output);
|
|
93
|
+
return validateOpenAI(response.output);
|
|
34
94
|
}
|
|
35
95
|
/**
|
|
36
96
|
* Convert a raw web search response into a SearchResult instance.
|
|
@@ -114,9 +174,9 @@ async function searchWithFormat({ prompt, model, responseSchema, useSearch = tru
|
|
|
114
174
|
.replace('{prompt}', prompt)
|
|
115
175
|
.replace('{answer}', searchResult.answer)
|
|
116
176
|
.replace('{sources}', sources);
|
|
117
|
-
const { parsed } = await (0,
|
|
177
|
+
const { parsed } = await (0, llm_js_1.askLLMSafe)({ prompt: formattedPrompt, model: 'gpt-4.1-mini', schema: responseSchema });
|
|
118
178
|
if (!parsed) {
|
|
119
|
-
throw new Error('Failed to parse structured response from
|
|
179
|
+
throw new Error('Failed to parse structured response from LLM');
|
|
120
180
|
}
|
|
121
181
|
return parsed;
|
|
122
182
|
}
|
|
@@ -1,11 +1,33 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import {
|
|
1
|
+
import { Tool, type ModelConfig } from '../tool.js';
|
|
2
|
+
import type { Message } from '../llm.js';
|
|
3
|
+
import type { BrandContext } from '../schemas/brand.schema.js';
|
|
4
|
+
import { type ABSentiment, type ABSentiments } from '../schemas/sentiment.schema.js';
|
|
5
|
+
export interface SentimentExtractorConfig {
|
|
6
|
+
/** Additional instructions for sentiment extraction */
|
|
7
|
+
instructions?: string;
|
|
8
|
+
/** Brand context for focused analysis */
|
|
9
|
+
brand?: BrandContext | null;
|
|
10
|
+
}
|
|
3
11
|
/**
|
|
4
|
-
*
|
|
12
|
+
* A tool that extracts aspect-based sentiments from text.
|
|
5
13
|
*/
|
|
6
|
-
export declare
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
export declare class SentimentExtractor extends Tool<string | null, ABSentiments, Array<ABSentiment>> {
|
|
15
|
+
private readonly systemPrompt;
|
|
16
|
+
constructor(config: SentimentExtractorConfig | undefined, modelConfig: ModelConfig);
|
|
17
|
+
protected schema(): import("../../deps/jsr.io/@zod/zod/4.3.6/src/index.js").ZodObject<{
|
|
18
|
+
aspects: 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<{
|
|
19
|
+
aspect: import("../../deps/jsr.io/@zod/zod/4.3.6/src/index.js").ZodString;
|
|
20
|
+
sentiment: import("../../deps/jsr.io/@zod/zod/4.3.6/src/index.js").ZodEnum<{
|
|
21
|
+
positive: "positive";
|
|
22
|
+
negative: "negative";
|
|
23
|
+
}>;
|
|
24
|
+
reason: import("../../deps/jsr.io/@zod/zod/4.3.6/src/index.js").ZodString;
|
|
25
|
+
}, import("../../deps/jsr.io/@zod/zod/4.3.6/src/v4/core/schemas.js").$strip>>;
|
|
26
|
+
}, import("../../deps/jsr.io/@zod/zod/4.3.6/src/v4/core/schemas.js").$strip>;
|
|
27
|
+
protected prompt(text: string | null): Message[];
|
|
28
|
+
protected isEmpty(text: string | null): boolean;
|
|
29
|
+
protected extractResult(parsed: ABSentiments): Array<ABSentiment>;
|
|
30
|
+
}
|
|
31
|
+
export type { ABSentiment, ABSentiments } from '../schemas/sentiment.schema.js';
|
|
32
|
+
export { ABSentimentSchema, ABSentimentsSchema } from '../schemas/sentiment.schema.js';
|
|
11
33
|
//# sourceMappingURL=sentiment.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentiment.d.ts","sourceRoot":"","sources":["../../../src/src/tools/sentiment.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sentiment.d.ts","sourceRoot":"","sources":["../../../src/src/tools/sentiment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAsB,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAwCzG,MAAM,WAAW,wBAAwB;IACxC,uDAAuD;IACvD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yCAAyC;IACzC,KAAK,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;CAC5B;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,IAAI,CAAC,MAAM,GAAG,IAAI,EAAE,YAAY,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IAC5F,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;gBAE1B,MAAM,EAAE,wBAAwB,YAAK,EAAE,WAAW,EAAE,WAAW;cAgBxD,MAAM;;;;;;;;;;IAIzB,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,EAAE;cAQ7B,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;cAIrC,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,KAAK,CAAC,WAAW,CAAC;CAG1E;AAED,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC"}
|