@garrix82/reactgenie-dsl 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +436 -0
- package/dist/__test__/dsl-descriptor.test.d.ts +1 -0
- package/dist/__test__/dsl-descriptor.test.js +27 -0
- package/dist/__test__/dsl-descriptor.test.js.map +1 -0
- package/dist/__test__/example_descriptor.d.ts +125 -0
- package/dist/__test__/example_descriptor.js +607 -0
- package/dist/__test__/example_descriptor.js.map +1 -0
- package/dist/__test__/food_descriptor.state.json +1 -0
- package/dist/__test__/food_descriptor.test.d.ts +74 -0
- package/dist/__test__/food_descriptor.test.js +205 -0
- package/dist/__test__/food_descriptor.test.js.map +1 -0
- package/dist/__test__/nl-interpreter-provider-selection.test.d.ts +1 -0
- package/dist/__test__/nl-interpreter-provider-selection.test.js +73 -0
- package/dist/__test__/nl-interpreter-provider-selection.test.js.map +1 -0
- package/dist/__test__/nl-interpreter.test.d.ts +1 -0
- package/dist/__test__/nl-interpreter.test.js +86 -0
- package/dist/__test__/nl-interpreter.test.js.map +1 -0
- package/dist/decorators/__test__/decorators.test.d.ts +1 -0
- package/dist/decorators/__test__/decorators.test.js +182 -0
- package/dist/decorators/__test__/decorators.test.js.map +1 -0
- package/dist/decorators/__test__/inheritance-descriptor.test.d.ts +1 -0
- package/dist/decorators/__test__/inheritance-descriptor.test.js +107 -0
- package/dist/decorators/__test__/inheritance-descriptor.test.js.map +1 -0
- package/dist/decorators/decorators.d.ts +20 -0
- package/dist/decorators/decorators.js +520 -0
- package/dist/decorators/decorators.js.map +1 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.js +19 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/store.d.ts +12 -0
- package/dist/decorators/store.js +43 -0
- package/dist/decorators/store.js.map +1 -0
- package/dist/dsl/__test__/dsl-interpreter.test.d.ts +1 -0
- package/dist/dsl/__test__/dsl-interpreter.test.js +334 -0
- package/dist/dsl/__test__/dsl-interpreter.test.js.map +1 -0
- package/dist/dsl/__test__/parser.gen.test.d.ts +1 -0
- package/dist/dsl/__test__/parser.gen.test.js +283 -0
- package/dist/dsl/__test__/parser.gen.test.js.map +1 -0
- package/dist/dsl/dsl-interpreter.d.ts +66 -0
- package/dist/dsl/dsl-interpreter.js +767 -0
- package/dist/dsl/dsl-interpreter.js.map +1 -0
- package/dist/dsl/index.d.ts +1 -0
- package/dist/dsl/index.js +18 -0
- package/dist/dsl/index.js.map +1 -0
- package/dist/dsl/parser.gen.d.ts +10 -0
- package/dist/dsl/parser.gen.js +1524 -0
- package/dist/dsl/parser.gen.js.map +1 -0
- package/dist/dsl-descriptor.d.ts +75 -0
- package/dist/dsl-descriptor.js +151 -0
- package/dist/dsl-descriptor.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/nl/__test__/context-aware-prompt.test.d.ts +1 -0
- package/dist/nl/__test__/context-aware-prompt.test.js +247 -0
- package/dist/nl/__test__/context-aware-prompt.test.js.map +1 -0
- package/dist/nl/__test__/context-selector.test.d.ts +1 -0
- package/dist/nl/__test__/context-selector.test.js +20 -0
- package/dist/nl/__test__/context-selector.test.js.map +1 -0
- package/dist/nl/__test__/nl-parser-groq-transport.test.d.ts +1 -0
- package/dist/nl/__test__/nl-parser-groq-transport.test.js +87 -0
- package/dist/nl/__test__/nl-parser-groq-transport.test.js.map +1 -0
- package/dist/nl/__test__/nl-parser-openai-parity.test.d.ts +1 -0
- package/dist/nl/__test__/nl-parser-openai-parity.test.js +206 -0
- package/dist/nl/__test__/nl-parser-openai-parity.test.js.map +1 -0
- package/dist/nl/__test__/nl-parser-openai-sampling.test.d.ts +1 -0
- package/dist/nl/__test__/nl-parser-openai-sampling.test.js +44 -0
- package/dist/nl/__test__/nl-parser-openai-sampling.test.js.map +1 -0
- package/dist/nl/__test__/nl-parser-openai-transport.test.d.ts +1 -0
- package/dist/nl/__test__/nl-parser-openai-transport.test.js +55 -0
- package/dist/nl/__test__/nl-parser-openai-transport.test.js.map +1 -0
- package/dist/nl/__test__/nl-parser-utils.test.d.ts +1 -0
- package/dist/nl/__test__/nl-parser-utils.test.js +70 -0
- package/dist/nl/__test__/nl-parser-utils.test.js.map +1 -0
- package/dist/nl/__test__/nl-parser.test.d.ts +1 -0
- package/dist/nl/__test__/nl-parser.test.js +64 -0
- package/dist/nl/__test__/nl-parser.test.js.map +1 -0
- package/dist/nl/__test__/parameter-tuning.test.d.ts +1 -0
- package/dist/nl/__test__/parameter-tuning.test.js +95 -0
- package/dist/nl/__test__/parameter-tuning.test.js.map +1 -0
- package/dist/nl/__test__/semantic-parsing-experiment.test.d.ts +1 -0
- package/dist/nl/__test__/semantic-parsing-experiment.test.js +178 -0
- package/dist/nl/__test__/semantic-parsing-experiment.test.js.map +1 -0
- package/dist/nl/context-selector.d.ts +17 -0
- package/dist/nl/context-selector.js +99 -0
- package/dist/nl/context-selector.js.map +1 -0
- package/dist/nl/index.d.ts +6 -0
- package/dist/nl/index.js +15 -0
- package/dist/nl/index.js.map +1 -0
- package/dist/nl/llm-monitoring.d.ts +49 -0
- package/dist/nl/llm-monitoring.js +243 -0
- package/dist/nl/llm-monitoring.js.map +1 -0
- package/dist/nl/llm-monitoring.test.d.ts +5 -0
- package/dist/nl/llm-monitoring.test.js +101 -0
- package/dist/nl/llm-monitoring.test.js.map +1 -0
- package/dist/nl/nl-parser-groq.d.ts +21 -0
- package/dist/nl/nl-parser-groq.js +357 -0
- package/dist/nl/nl-parser-groq.js.map +1 -0
- package/dist/nl/nl-parser-utils.d.ts +101 -0
- package/dist/nl/nl-parser-utils.js +255 -0
- package/dist/nl/nl-parser-utils.js.map +1 -0
- package/dist/nl/nl-parser.d.ts +30 -0
- package/dist/nl/nl-parser.js +433 -0
- package/dist/nl/nl-parser.js.map +1 -0
- package/dist/nl/prompt-gen.d.ts +93 -0
- package/dist/nl/prompt-gen.js +369 -0
- package/dist/nl/prompt-gen.js.map +1 -0
- package/dist/nl/prompt-res.d.ts +16 -0
- package/dist/nl/prompt-res.js +190 -0
- package/dist/nl/prompt-res.js.map +1 -0
- package/dist/nl-interpreter.d.ts +48 -0
- package/dist/nl-interpreter.js +155 -0
- package/dist/nl-interpreter.js.map +1 -0
- package/lib/__test__/dsl-descriptor.test.ts +27 -0
- package/lib/__test__/example_descriptor.ts +762 -0
- package/lib/__test__/food_descriptor.state.json +1 -0
- package/lib/__test__/food_descriptor.test.ts +331 -0
- package/lib/__test__/nl-interpreter-provider-selection.test.ts +126 -0
- package/lib/__test__/nl-interpreter.test.ts +129 -0
- package/lib/decorators/__test__/decorators.test.ts +177 -0
- package/lib/decorators/__test__/inheritance-descriptor.test.ts +92 -0
- package/lib/decorators/decorators.ts +754 -0
- package/lib/decorators/index.ts +2 -0
- package/lib/decorators/store.ts +47 -0
- package/lib/dsl/__test__/dsl-interpreter.test.ts +453 -0
- package/lib/dsl/__test__/parser.gen.test.ts +296 -0
- package/lib/dsl/dsl-interpreter.ts +974 -0
- package/lib/dsl/index.ts +1 -0
- package/lib/dsl/parser.gen.js +1479 -0
- package/lib/dsl/parser.pegjs +130 -0
- package/lib/dsl-descriptor.ts +241 -0
- package/lib/index.ts +5 -0
- package/lib/nl/__test__/context-aware-prompt.test.ts +372 -0
- package/lib/nl/__test__/context-selector.test.ts +27 -0
- package/lib/nl/__test__/nl-parser-groq-transport.test.ts +139 -0
- package/lib/nl/__test__/nl-parser-openai-parity.test.ts +381 -0
- package/lib/nl/__test__/nl-parser-openai-sampling.test.ts +73 -0
- package/lib/nl/__test__/nl-parser-openai-transport.test.ts +79 -0
- package/lib/nl/__test__/nl-parser-utils.test.ts +98 -0
- package/lib/nl/__test__/nl-parser.test.ts +119 -0
- package/lib/nl/__test__/parameter-tuning.test.ts +137 -0
- package/lib/nl/__test__/semantic-parsing-experiment.test.ts +260 -0
- package/lib/nl/context-selector.ts +123 -0
- package/lib/nl/index.ts +19 -0
- package/lib/nl/llm-monitoring.test.ts +136 -0
- package/lib/nl/llm-monitoring.ts +339 -0
- package/lib/nl/nl-parser-groq.ts +510 -0
- package/lib/nl/nl-parser-utils.ts +310 -0
- package/lib/nl/nl-parser.ts +616 -0
- package/lib/nl/prompt-gen.ts +607 -0
- package/lib/nl/prompt-res.ts +207 -0
- package/lib/nl-interpreter.ts +262 -0
- package/package.json +58 -0
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NlParserGroq = void 0;
|
|
4
|
+
const llm_monitoring_1 = require("./llm-monitoring");
|
|
5
|
+
const nl_parser_utils_1 = require("./nl-parser-utils");
|
|
6
|
+
function buildChatCompletionsEndpoint(baseUrl) {
|
|
7
|
+
const resolvedBase = (0, nl_parser_utils_1.normalizeBaseUrl)(baseUrl && baseUrl.trim().length > 0
|
|
8
|
+
? baseUrl
|
|
9
|
+
: "https://api.groq.com/openai/v1");
|
|
10
|
+
if (resolvedBase.endsWith("/chat/completions")) {
|
|
11
|
+
return resolvedBase;
|
|
12
|
+
}
|
|
13
|
+
if (resolvedBase.endsWith("/openai/v1") || resolvedBase.endsWith("/v1")) {
|
|
14
|
+
return `${resolvedBase}/chat/completions`;
|
|
15
|
+
}
|
|
16
|
+
return `${resolvedBase}/openai/v1/chat/completions`;
|
|
17
|
+
}
|
|
18
|
+
function asFiniteNumber(value) {
|
|
19
|
+
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
20
|
+
}
|
|
21
|
+
function extractCostMetrics(response) {
|
|
22
|
+
const usage = response?.usage ?? response?.usage_metadata ?? {};
|
|
23
|
+
const inputCost = asFiniteNumber(usage?.input_cost) ??
|
|
24
|
+
asFiniteNumber(usage?.prompt_cost) ??
|
|
25
|
+
asFiniteNumber(usage?.prompt_cost_usd);
|
|
26
|
+
const outputCost = asFiniteNumber(usage?.output_cost) ??
|
|
27
|
+
asFiniteNumber(usage?.completion_cost) ??
|
|
28
|
+
asFiniteNumber(usage?.completion_cost_usd);
|
|
29
|
+
const totalCost = asFiniteNumber(usage?.total_cost) ??
|
|
30
|
+
asFiniteNumber(usage?.cost) ??
|
|
31
|
+
asFiniteNumber(usage?.total_cost_usd) ??
|
|
32
|
+
(typeof inputCost === "number" && typeof outputCost === "number"
|
|
33
|
+
? inputCost + outputCost
|
|
34
|
+
: undefined);
|
|
35
|
+
return {
|
|
36
|
+
...(typeof inputCost === "number" ? { inputCost } : {}),
|
|
37
|
+
...(typeof outputCost === "number" ? { outputCost } : {}),
|
|
38
|
+
...(typeof totalCost === "number" ? { totalCost } : {}),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
class NlParserGroq {
|
|
42
|
+
constructor(prompt, apiKey, model = process.env.SEMANTIC_MODEL || "llama-3.3-70b-versatile", samplingParams, baseURL, langsmithApiKey, langsmithProject, langsmithEndpoint, validateCommand) {
|
|
43
|
+
this.prompt = prompt;
|
|
44
|
+
this.apiKey = apiKey;
|
|
45
|
+
this.model = model;
|
|
46
|
+
this.baseURL = baseURL;
|
|
47
|
+
this.validateCommand = validateCommand;
|
|
48
|
+
this.chatCompletionsEndpoint = buildChatCompletionsEndpoint(this.baseURL);
|
|
49
|
+
this.llmMonitor = (0, llm_monitoring_1.getLLMMonitor)({
|
|
50
|
+
apiKey: langsmithApiKey,
|
|
51
|
+
project: langsmithProject,
|
|
52
|
+
endpoint: langsmithEndpoint,
|
|
53
|
+
});
|
|
54
|
+
this.samplingParams = {
|
|
55
|
+
...nl_parser_utils_1.DEFAULT_SEMANTIC_PARSER_SAMPLING,
|
|
56
|
+
...samplingParams,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async createChatCompletion(body) {
|
|
60
|
+
return (0, nl_parser_utils_1.createJsonChatCompletion)({
|
|
61
|
+
endpoint: this.chatCompletionsEndpoint,
|
|
62
|
+
apiKey: this.apiKey,
|
|
63
|
+
body,
|
|
64
|
+
provider: "groq",
|
|
65
|
+
requestLabel: "LLM proxy request failed",
|
|
66
|
+
invalidPayloadLabel: "LLM proxy returned an invalid JSON payload",
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async oldParse(nl) {
|
|
70
|
+
const promptText = this.prompt.prompt(nl);
|
|
71
|
+
const startTime = Date.now();
|
|
72
|
+
try {
|
|
73
|
+
const response = await this.llmMonitor.traceCall("oldParse", { model: this.model, provider: "groq" }, async () => {
|
|
74
|
+
return await this.runStructuredCommandMessages([
|
|
75
|
+
{
|
|
76
|
+
role: "user",
|
|
77
|
+
content: promptText,
|
|
78
|
+
},
|
|
79
|
+
], false);
|
|
80
|
+
});
|
|
81
|
+
const completion = await this.validateOrRepairCommand("oldParse", "legacy_prompt", promptText, response.command, promptText);
|
|
82
|
+
await this.llmMonitor.logCall({
|
|
83
|
+
model: this.model,
|
|
84
|
+
provider: "groq",
|
|
85
|
+
promptTokens: response.response.usage?.prompt_tokens,
|
|
86
|
+
completionTokens: response.response.usage?.completion_tokens,
|
|
87
|
+
totalTokens: response.response.usage?.total_tokens,
|
|
88
|
+
...extractCostMetrics(response.response),
|
|
89
|
+
prompt: promptText,
|
|
90
|
+
completion,
|
|
91
|
+
latency: Date.now() - startTime,
|
|
92
|
+
timestamp: new Date(),
|
|
93
|
+
});
|
|
94
|
+
return completion;
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
await this.llmMonitor.logCall({
|
|
98
|
+
model: this.model,
|
|
99
|
+
provider: "groq",
|
|
100
|
+
prompt: promptText,
|
|
101
|
+
completion: null,
|
|
102
|
+
latency: Date.now() - startTime,
|
|
103
|
+
timestamp: new Date(),
|
|
104
|
+
error: error instanceof Error ? error.message : String(error),
|
|
105
|
+
});
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async parse(nl) {
|
|
110
|
+
const startTime = Date.now();
|
|
111
|
+
const promptVariants = [];
|
|
112
|
+
const defaultPrompt = this.prompt.zero_shot_prompt(nl);
|
|
113
|
+
promptVariants.push({ label: "filtered", text: defaultPrompt });
|
|
114
|
+
let usedPromptText = defaultPrompt;
|
|
115
|
+
let completion = null;
|
|
116
|
+
let response;
|
|
117
|
+
let lastError;
|
|
118
|
+
try {
|
|
119
|
+
const runParse = async (strict, promptText) => {
|
|
120
|
+
return this.runStructuredCommandMessages([
|
|
121
|
+
{
|
|
122
|
+
role: "user",
|
|
123
|
+
content: promptText,
|
|
124
|
+
},
|
|
125
|
+
], strict);
|
|
126
|
+
};
|
|
127
|
+
for (const promptVariant of promptVariants) {
|
|
128
|
+
usedPromptText = promptVariant.text;
|
|
129
|
+
try {
|
|
130
|
+
const result = await this.llmMonitor.traceCall(`parse_${promptVariant.label}`, { model: this.model, provider: "groq" }, async () => runParse(false, promptVariant.text));
|
|
131
|
+
response = result.response;
|
|
132
|
+
completion = await this.validateOrRepairCommand("parse", promptVariant.label, nl, result.command, usedPromptText);
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
try {
|
|
137
|
+
const result = await this.llmMonitor.traceCall(`parse_${promptVariant.label}`, { model: this.model, provider: "groq" }, async () => runParse(true, promptVariant.text));
|
|
138
|
+
response = result.response;
|
|
139
|
+
completion = await this.validateOrRepairCommand("parse", promptVariant.label, nl, result.command, usedPromptText);
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
catch (strictError) {
|
|
143
|
+
lastError = strictError;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (!completion || !response) {
|
|
148
|
+
throw (lastError instanceof Error
|
|
149
|
+
? lastError
|
|
150
|
+
: new Error("Groq parse failed for filtered prompt"));
|
|
151
|
+
}
|
|
152
|
+
await this.llmMonitor.logCall({
|
|
153
|
+
model: this.model,
|
|
154
|
+
provider: "groq",
|
|
155
|
+
promptTokens: response.usage?.prompt_tokens,
|
|
156
|
+
completionTokens: response.usage?.completion_tokens,
|
|
157
|
+
totalTokens: response.usage?.total_tokens,
|
|
158
|
+
...extractCostMetrics(response),
|
|
159
|
+
prompt: usedPromptText,
|
|
160
|
+
completion,
|
|
161
|
+
latency: Date.now() - startTime,
|
|
162
|
+
timestamp: new Date(),
|
|
163
|
+
});
|
|
164
|
+
return completion;
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
await this.llmMonitor.logCall({
|
|
168
|
+
model: this.model,
|
|
169
|
+
provider: "groq",
|
|
170
|
+
prompt: usedPromptText,
|
|
171
|
+
completion: null,
|
|
172
|
+
latency: Date.now() - startTime,
|
|
173
|
+
timestamp: new Date(),
|
|
174
|
+
error: error instanceof Error ? error.message : String(error),
|
|
175
|
+
});
|
|
176
|
+
throw error;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async parseGpt4(nl) {
|
|
180
|
+
const promptText = this.prompt.prompt(nl);
|
|
181
|
+
const startTime = Date.now();
|
|
182
|
+
try {
|
|
183
|
+
const runParse = async (strict) => {
|
|
184
|
+
return this.runStructuredCommandMessages([
|
|
185
|
+
{
|
|
186
|
+
role: "system",
|
|
187
|
+
content: "only generate one line of code",
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
role: "user",
|
|
191
|
+
content: promptText,
|
|
192
|
+
},
|
|
193
|
+
], strict);
|
|
194
|
+
};
|
|
195
|
+
let response;
|
|
196
|
+
let completion = null;
|
|
197
|
+
try {
|
|
198
|
+
const result = await this.llmMonitor.traceCall("parseGpt4", { model: this.model, provider: "groq" }, async () => runParse(false));
|
|
199
|
+
response = result.response;
|
|
200
|
+
completion = result.command;
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
const result = await this.llmMonitor.traceCall("parseGpt4", { model: this.model, provider: "groq" }, async () => runParse(true));
|
|
204
|
+
response = result.response;
|
|
205
|
+
completion = result.command;
|
|
206
|
+
}
|
|
207
|
+
const validatedCompletion = completion
|
|
208
|
+
? await this.validateOrRepairCommand("parseGpt4", "legacy_prompt", nl, completion, promptText)
|
|
209
|
+
: completion;
|
|
210
|
+
await this.llmMonitor.logCall({
|
|
211
|
+
model: this.model,
|
|
212
|
+
provider: "groq",
|
|
213
|
+
promptTokens: response.usage?.prompt_tokens,
|
|
214
|
+
completionTokens: response.usage?.completion_tokens,
|
|
215
|
+
totalTokens: response.usage?.total_tokens,
|
|
216
|
+
...extractCostMetrics(response),
|
|
217
|
+
prompt: promptText,
|
|
218
|
+
completion: validatedCompletion,
|
|
219
|
+
latency: Date.now() - startTime,
|
|
220
|
+
timestamp: new Date(),
|
|
221
|
+
});
|
|
222
|
+
return validatedCompletion;
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
await this.llmMonitor.logCall({
|
|
226
|
+
model: this.model,
|
|
227
|
+
provider: "groq",
|
|
228
|
+
prompt: promptText,
|
|
229
|
+
completion: null,
|
|
230
|
+
latency: Date.now() - startTime,
|
|
231
|
+
timestamp: new Date(),
|
|
232
|
+
error: error instanceof Error ? error.message : String(error),
|
|
233
|
+
});
|
|
234
|
+
throw error;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
async respond(nl, parsed, result) {
|
|
238
|
+
const promptText = this.prompt.response_prompt(nl, parsed, result);
|
|
239
|
+
const startTime = Date.now();
|
|
240
|
+
try {
|
|
241
|
+
const runRespond = async (strict) => {
|
|
242
|
+
const response = await this.createChatCompletion({
|
|
243
|
+
model: this.model,
|
|
244
|
+
messages: [
|
|
245
|
+
{
|
|
246
|
+
role: "system",
|
|
247
|
+
content: "Return only a strict JSON object for agent_response_json.",
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
role: "user",
|
|
251
|
+
content: promptText,
|
|
252
|
+
},
|
|
253
|
+
],
|
|
254
|
+
temperature: this.samplingParams.temperature,
|
|
255
|
+
max_tokens: 256,
|
|
256
|
+
top_p: this.samplingParams.top_p,
|
|
257
|
+
frequency_penalty: this.samplingParams.frequency_penalty,
|
|
258
|
+
presence_penalty: this.samplingParams.presence_penalty,
|
|
259
|
+
response_format: (0, nl_parser_utils_1.getStructuredAgentResponseFormat)(strict),
|
|
260
|
+
});
|
|
261
|
+
const raw = response.choices[0]?.message?.content ?? null;
|
|
262
|
+
const payload = (0, nl_parser_utils_1.extractStructuredAgentResponse)(raw);
|
|
263
|
+
if (!payload) {
|
|
264
|
+
throw new Error("Groq structured output missing agent response payload");
|
|
265
|
+
}
|
|
266
|
+
return { response, payload };
|
|
267
|
+
};
|
|
268
|
+
let response;
|
|
269
|
+
let completion = null;
|
|
270
|
+
try {
|
|
271
|
+
const result = await this.llmMonitor.traceCall("respond", { model: this.model, provider: "groq" }, async () => runRespond(false));
|
|
272
|
+
response = result.response;
|
|
273
|
+
completion = result.payload;
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
const result = await this.llmMonitor.traceCall("respond", { model: this.model, provider: "groq" }, async () => runRespond(true));
|
|
277
|
+
response = result.response;
|
|
278
|
+
completion = result.payload;
|
|
279
|
+
}
|
|
280
|
+
const normalizedCompletion = completion
|
|
281
|
+
? (0, nl_parser_utils_1.normalizeAgentResponse)(completion)
|
|
282
|
+
: (0, nl_parser_utils_1.buildFallbackAgentResponse)(parsed, result);
|
|
283
|
+
await this.llmMonitor.logCall({
|
|
284
|
+
model: this.model,
|
|
285
|
+
provider: "groq",
|
|
286
|
+
promptTokens: response.usage?.prompt_tokens,
|
|
287
|
+
completionTokens: response.usage?.completion_tokens,
|
|
288
|
+
totalTokens: response.usage?.total_tokens,
|
|
289
|
+
...extractCostMetrics(response),
|
|
290
|
+
prompt: promptText,
|
|
291
|
+
completion: JSON.stringify(normalizedCompletion),
|
|
292
|
+
latency: Date.now() - startTime,
|
|
293
|
+
timestamp: new Date(),
|
|
294
|
+
});
|
|
295
|
+
return normalizedCompletion;
|
|
296
|
+
}
|
|
297
|
+
catch (error) {
|
|
298
|
+
const fallbackResponse = (0, nl_parser_utils_1.buildFallbackAgentResponse)(parsed, result);
|
|
299
|
+
await this.llmMonitor.logCall({
|
|
300
|
+
model: this.model,
|
|
301
|
+
provider: "groq",
|
|
302
|
+
prompt: promptText,
|
|
303
|
+
completion: JSON.stringify(fallbackResponse),
|
|
304
|
+
latency: Date.now() - startTime,
|
|
305
|
+
timestamp: new Date(),
|
|
306
|
+
error: error instanceof Error ? error.message : String(error),
|
|
307
|
+
});
|
|
308
|
+
return fallbackResponse;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
async runStructuredCommandMessages(messages, strict) {
|
|
312
|
+
const response = await this.createChatCompletion({
|
|
313
|
+
model: this.model,
|
|
314
|
+
messages: [...messages],
|
|
315
|
+
temperature: this.samplingParams.temperature,
|
|
316
|
+
max_tokens: 256,
|
|
317
|
+
top_p: this.samplingParams.top_p,
|
|
318
|
+
frequency_penalty: this.samplingParams.frequency_penalty,
|
|
319
|
+
presence_penalty: this.samplingParams.presence_penalty,
|
|
320
|
+
response_format: (0, nl_parser_utils_1.getStructuredResponseFormat)(strict),
|
|
321
|
+
});
|
|
322
|
+
const raw = response.choices[0]?.message?.content ?? null;
|
|
323
|
+
const command = (0, nl_parser_utils_1.extractStructuredCommand)(raw);
|
|
324
|
+
if (!command) {
|
|
325
|
+
throw new Error("Groq structured output missing command");
|
|
326
|
+
}
|
|
327
|
+
return { response, command };
|
|
328
|
+
}
|
|
329
|
+
async validateOrRepairCommand(traceName, promptLabel, userUtterance, command, lastUsedPrompt) {
|
|
330
|
+
if (!this.validateCommand) {
|
|
331
|
+
return command;
|
|
332
|
+
}
|
|
333
|
+
try {
|
|
334
|
+
await this.validateCommand(command);
|
|
335
|
+
return command;
|
|
336
|
+
}
|
|
337
|
+
catch (validationError) {
|
|
338
|
+
const messages = (0, nl_parser_utils_1.buildCommandRepairMessages)(userUtterance, command, validationError instanceof Error ? validationError.message : String(validationError), lastUsedPrompt);
|
|
339
|
+
let lastError = validationError;
|
|
340
|
+
for (const strict of [false, true]) {
|
|
341
|
+
try {
|
|
342
|
+
const repaired = await this.llmMonitor.traceCall(`${traceName}_${promptLabel}_repair_${strict ? "strict" : "lenient"}`, { model: this.model, provider: "groq" }, async () => this.runStructuredCommandMessages(messages, strict));
|
|
343
|
+
await this.validateCommand(repaired.command);
|
|
344
|
+
return repaired.command;
|
|
345
|
+
}
|
|
346
|
+
catch (repairError) {
|
|
347
|
+
lastError = repairError;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
throw (lastError instanceof Error
|
|
351
|
+
? lastError
|
|
352
|
+
: new Error("Groq repair failed after semantic validation"));
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
exports.NlParserGroq = NlParserGroq;
|
|
357
|
+
//# sourceMappingURL=nl-parser-groq.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nl-parser-groq.js","sourceRoot":"","sources":["../../lib/nl/nl-parser-groq.ts"],"names":[],"mappings":";;;AACA,qDAAkE;AAClE,uDAa2B;AAG3B,SAAS,4BAA4B,CAAC,OAAgB;IACpD,MAAM,YAAY,GAChB,IAAA,kCAAgB,EAAC,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;QACnD,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,gCAAgC,CAAC,CAAC;IAExC,IAAI,YAAY,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC;QAC/C,OAAO,YAAY,CAAC;IACtB,CAAC;IACD,IAAI,YAAY,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACxE,OAAO,GAAG,YAAY,mBAAmB,CAAC;IAC5C,CAAC;IACD,OAAO,GAAG,YAAY,6BAA6B,CAAC;AACtD,CAAC;AAED,SAAS,cAAc,CAAC,KAAc;IACpC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACjF,CAAC;AAED,SAAS,kBAA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AS,GAAY,eAAe,CAAC;YACzC,KAAK,MAAM,MAAM,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC;gBACnC,IAAI,CAAC;oBACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAC9C,GAAG,SAAS,IAAI,WAAW,WAAW,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,EAAE,EACrE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,EACvC,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,4BAA4B,CAAC,QAAQ,EAAE,MAAM,CAAC,CAChE,CAAC;oBACF,MAAM,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;oBAC7C,OAAO,QAAQ,CAAC,OAAO,CAAC;gBAC1B,CAAC;gBAAC,OAAO,WAAW,EAAE,CAAC;oBACrB,SAAS,GAAG,WAAW,CAAC;gBAC1B,CAAC;YACH,CAAC;YAED,MAAM,CACJ,SAAS,YAAY,KAAK;gBACxB,CAAC,CAAC,SAAS;gBACX,CAAC,CAAC,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAC9D,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AA3bD,oCA2bC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { AgentResponsePayload, PromptGen } from "./prompt-gen";
|
|
2
|
+
export interface PromptWithBroadFallback extends PromptGen {
|
|
3
|
+
zero_shot_prompt_broad?: (user_utterance: string) => string;
|
|
4
|
+
}
|
|
5
|
+
export type CommandValidator = (command: string) => Promise<void>;
|
|
6
|
+
export interface SamplingParams {
|
|
7
|
+
temperature?: number;
|
|
8
|
+
top_p?: number;
|
|
9
|
+
frequency_penalty?: number;
|
|
10
|
+
presence_penalty?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const DEFAULT_SEMANTIC_PARSER_SAMPLING: Required<SamplingParams>;
|
|
13
|
+
export declare function getStructuredResponseFormat(strict: boolean): {
|
|
14
|
+
readonly type: "json_schema";
|
|
15
|
+
readonly json_schema: {
|
|
16
|
+
readonly name: "dsl_command";
|
|
17
|
+
readonly strict: boolean;
|
|
18
|
+
readonly schema: {
|
|
19
|
+
readonly type: "object";
|
|
20
|
+
readonly properties: {
|
|
21
|
+
readonly command: {
|
|
22
|
+
readonly type: "string";
|
|
23
|
+
readonly description: "Single DSL command string to execute.";
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
readonly required: readonly ["command"];
|
|
27
|
+
readonly additionalProperties: false;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export declare function getStructuredResponseTextFormat(strict: boolean): {
|
|
32
|
+
readonly type: "json_schema";
|
|
33
|
+
readonly name: "dsl_command";
|
|
34
|
+
readonly strict: boolean;
|
|
35
|
+
readonly schema: {
|
|
36
|
+
readonly type: "object";
|
|
37
|
+
readonly properties: {
|
|
38
|
+
readonly command: {
|
|
39
|
+
readonly type: "string";
|
|
40
|
+
readonly description: "Single DSL command string to execute.";
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
readonly required: readonly ["command"];
|
|
44
|
+
readonly additionalProperties: false;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export declare function getStructuredAgentResponseFormat(strict: boolean): {
|
|
48
|
+
readonly type: "json_schema";
|
|
49
|
+
readonly json_schema: {
|
|
50
|
+
readonly name: "agent_response";
|
|
51
|
+
readonly strict: boolean;
|
|
52
|
+
readonly schema: {
|
|
53
|
+
readonly type: "object";
|
|
54
|
+
readonly properties: {
|
|
55
|
+
readonly minimalText: {
|
|
56
|
+
readonly type: "string";
|
|
57
|
+
readonly description: "Short, speech-friendly response.";
|
|
58
|
+
};
|
|
59
|
+
readonly fullText: {
|
|
60
|
+
readonly type: "string";
|
|
61
|
+
readonly description: "More informative response for on-screen UI.";
|
|
62
|
+
};
|
|
63
|
+
readonly type: {
|
|
64
|
+
readonly type: "string";
|
|
65
|
+
readonly enum: readonly ["info", "error", "success", "warning"];
|
|
66
|
+
};
|
|
67
|
+
readonly shouldSpeak: {
|
|
68
|
+
readonly type: "boolean";
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
readonly required: readonly ["minimalText", "fullText", "type", "shouldSpeak"];
|
|
72
|
+
readonly additionalProperties: false;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
export declare function extractStructuredCommand(raw?: string | null): string | null;
|
|
77
|
+
export declare function extractResponseOutputText(response: any): string | null;
|
|
78
|
+
export declare function truncateText(value: string, maxLength: number): string;
|
|
79
|
+
export declare function normalizeAgentResponse(payload: Partial<AgentResponsePayload>): AgentResponsePayload;
|
|
80
|
+
export declare function extractStructuredAgentResponse(raw?: string | null): AgentResponsePayload | null;
|
|
81
|
+
export declare function buildFallbackAgentResponse(parsedDsl: string, resultContext: string): AgentResponsePayload;
|
|
82
|
+
export declare function buildCommandRepairMessages(userUtterance: string, invalidCommand: string, validationError: string, lastUsedPrompt?: string): readonly [{
|
|
83
|
+
readonly role: "user";
|
|
84
|
+
readonly content: string;
|
|
85
|
+
}, {
|
|
86
|
+
readonly role: "assistant";
|
|
87
|
+
readonly content: string;
|
|
88
|
+
}, {
|
|
89
|
+
readonly role: "user";
|
|
90
|
+
readonly content: string;
|
|
91
|
+
}];
|
|
92
|
+
export declare function buildCommandRepairInputText(userUtterance: string, invalidCommand: string, validationError: string): string;
|
|
93
|
+
export declare function normalizeBaseUrl(baseUrl: string): string;
|
|
94
|
+
export declare function createJsonChatCompletion(params: {
|
|
95
|
+
endpoint: string;
|
|
96
|
+
apiKey: string;
|
|
97
|
+
body: Record<string, unknown>;
|
|
98
|
+
provider?: "openai" | "groq";
|
|
99
|
+
requestLabel: string;
|
|
100
|
+
invalidPayloadLabel: string;
|
|
101
|
+
}): Promise<any>;
|