dirac-lang 0.1.8 → 0.1.9
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/dist/{chunk-JRNIX6BA.js → chunk-VHP3G4BF.js} +1 -1
- package/dist/{chunk-NIODUB7M.js → chunk-X3LQ626H.js} +14 -15
- package/dist/cli.js +3 -3
- package/dist/index.js +2 -2
- package/dist/{interpreter-22UMBAZX.js → interpreter-46CAOCAZ.js} +1 -1
- package/examples/llm-basic.di +3 -3
- package/examples/llm-command.di +0 -7
- package/examples/llm-simple-test.di +12 -0
- package/package.json +1 -1
- package/src/tags/llm.ts +4 -5
|
@@ -370,12 +370,12 @@ async function executeIf(session, element) {
|
|
|
370
370
|
const condition = await evaluatePredicate(session, conditionElement);
|
|
371
371
|
if (condition) {
|
|
372
372
|
if (thenElement) {
|
|
373
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
373
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-46CAOCAZ.js");
|
|
374
374
|
await integrateChildren2(session, thenElement);
|
|
375
375
|
}
|
|
376
376
|
} else {
|
|
377
377
|
if (elseElement) {
|
|
378
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
378
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-46CAOCAZ.js");
|
|
379
379
|
await integrateChildren2(session, elseElement);
|
|
380
380
|
}
|
|
381
381
|
}
|
|
@@ -388,7 +388,7 @@ async function evaluatePredicate(session, predicateElement) {
|
|
|
388
388
|
return await evaluateCondition(session, predicateElement);
|
|
389
389
|
}
|
|
390
390
|
const outputLengthBefore = session.output.length;
|
|
391
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
391
|
+
const { integrate: integrate2 } = await import("./interpreter-46CAOCAZ.js");
|
|
392
392
|
await integrate2(session, predicateElement);
|
|
393
393
|
const newOutputChunks = session.output.slice(outputLengthBefore);
|
|
394
394
|
const result = newOutputChunks.join("").trim();
|
|
@@ -411,11 +411,11 @@ async function evaluateCondition(session, condElement) {
|
|
|
411
411
|
}
|
|
412
412
|
const outputLengthBefore = session.output.length;
|
|
413
413
|
const args = [];
|
|
414
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
414
|
+
const { integrate: integrate2 } = await import("./interpreter-46CAOCAZ.js");
|
|
415
415
|
for (const child of condElement.children) {
|
|
416
416
|
if (child.tag.toLowerCase() === "arg") {
|
|
417
417
|
const argOutputStart = session.output.length;
|
|
418
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
418
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-46CAOCAZ.js");
|
|
419
419
|
await integrateChildren2(session, child);
|
|
420
420
|
const newChunks = session.output.slice(argOutputStart);
|
|
421
421
|
const argValue = newChunks.join("");
|
|
@@ -616,10 +616,10 @@ async function executeLLM(session, element) {
|
|
|
616
616
|
await integrate(session, child);
|
|
617
617
|
}
|
|
618
618
|
const childOutput = session.output.slice(beforeOutput);
|
|
619
|
-
userPrompt = childOutput.join("");
|
|
619
|
+
userPrompt = childOutput.join("").trim();
|
|
620
620
|
session.output = session.output.slice(0, beforeOutput);
|
|
621
621
|
} else if (element.text) {
|
|
622
|
-
userPrompt = substituteVariables(session, element.text);
|
|
622
|
+
userPrompt = substituteVariables(session, element.text).trim();
|
|
623
623
|
} else {
|
|
624
624
|
throw new Error("<LLM> requires prompt content");
|
|
625
625
|
}
|
|
@@ -682,11 +682,10 @@ then you call it like
|
|
|
682
682
|
console.error("[LLM] Full prompt sent to LLM:\n" + prompt + "\n");
|
|
683
683
|
}
|
|
684
684
|
}
|
|
685
|
-
|
|
686
|
-
dialogHistory.push({ role: "user", content: noExtra ? userPrompt : prompt });
|
|
687
|
-
}
|
|
685
|
+
dialogHistory.push({ role: "user", content: noExtra ? userPrompt : prompt });
|
|
688
686
|
if (session.debug) {
|
|
689
687
|
console.error(`[LLM] Calling ${model} with prompt length: ${prompt.length}`);
|
|
688
|
+
console.error(`[LLM] Dialog history length: ${dialogHistory.length} messages`);
|
|
690
689
|
}
|
|
691
690
|
try {
|
|
692
691
|
let result;
|
|
@@ -1163,7 +1162,7 @@ async function executeTagCheck(session, element) {
|
|
|
1163
1162
|
const executeTag = correctedTag || tagName;
|
|
1164
1163
|
console.error(`[tag-check] Executing <${executeTag}/> as all checks passed and execute=true.`);
|
|
1165
1164
|
const elementToExecute = correctedTag ? { ...child, tag: correctedTag } : child;
|
|
1166
|
-
const { integrate: integrate2 } = await import("./interpreter-
|
|
1165
|
+
const { integrate: integrate2 } = await import("./interpreter-46CAOCAZ.js");
|
|
1167
1166
|
await integrate2(session, elementToExecute);
|
|
1168
1167
|
}
|
|
1169
1168
|
}
|
|
@@ -1172,7 +1171,7 @@ async function executeTagCheck(session, element) {
|
|
|
1172
1171
|
// src/tags/throw.ts
|
|
1173
1172
|
async function executeThrow(session, element) {
|
|
1174
1173
|
const exceptionName = element.attributes?.name || "exception";
|
|
1175
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1174
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-46CAOCAZ.js");
|
|
1176
1175
|
const exceptionDom = {
|
|
1177
1176
|
tag: "exception-content",
|
|
1178
1177
|
attributes: { name: exceptionName },
|
|
@@ -1185,7 +1184,7 @@ async function executeThrow(session, element) {
|
|
|
1185
1184
|
// src/tags/try.ts
|
|
1186
1185
|
async function executeTry(session, element) {
|
|
1187
1186
|
setExceptionBoundary(session);
|
|
1188
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1187
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-46CAOCAZ.js");
|
|
1189
1188
|
await integrateChildren2(session, element);
|
|
1190
1189
|
unsetExceptionBoundary(session);
|
|
1191
1190
|
}
|
|
@@ -1195,7 +1194,7 @@ async function executeCatch(session, element) {
|
|
|
1195
1194
|
const exceptionName = element.attributes?.name || "exception";
|
|
1196
1195
|
const caughtCount = lookupException(session, exceptionName);
|
|
1197
1196
|
if (caughtCount > 0) {
|
|
1198
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1197
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-46CAOCAZ.js");
|
|
1199
1198
|
await integrateChildren2(session, element);
|
|
1200
1199
|
}
|
|
1201
1200
|
flushCurrentException(session);
|
|
@@ -1204,7 +1203,7 @@ async function executeCatch(session, element) {
|
|
|
1204
1203
|
// src/tags/exception.ts
|
|
1205
1204
|
async function executeException(session, element) {
|
|
1206
1205
|
const exceptions = getCurrentExceptions(session);
|
|
1207
|
-
const { integrateChildren: integrateChildren2 } = await import("./interpreter-
|
|
1206
|
+
const { integrateChildren: integrateChildren2 } = await import("./interpreter-46CAOCAZ.js");
|
|
1208
1207
|
for (const exceptionDom of exceptions) {
|
|
1209
1208
|
await integrateChildren2(session, exceptionDom);
|
|
1210
1209
|
}
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
execute
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-VHP3G4BF.js";
|
|
5
|
+
import "./chunk-X3LQ626H.js";
|
|
6
6
|
import "./chunk-E7IWGUE6.js";
|
|
7
7
|
|
|
8
8
|
// src/cli.ts
|
|
@@ -11,7 +11,7 @@ import "dotenv/config";
|
|
|
11
11
|
// package.json
|
|
12
12
|
var package_default = {
|
|
13
13
|
name: "dirac-lang",
|
|
14
|
-
version: "0.1.
|
|
14
|
+
version: "0.1.9",
|
|
15
15
|
description: "LLM-Augmented Declarative Execution",
|
|
16
16
|
type: "module",
|
|
17
17
|
main: "dist/index.js",
|
package/dist/index.js
CHANGED
|
@@ -2,11 +2,11 @@ import {
|
|
|
2
2
|
createLLMAdapter,
|
|
3
3
|
execute,
|
|
4
4
|
executeUserCommand
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-VHP3G4BF.js";
|
|
6
6
|
import {
|
|
7
7
|
DiracParser,
|
|
8
8
|
integrate
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-X3LQ626H.js";
|
|
10
10
|
import {
|
|
11
11
|
createSession,
|
|
12
12
|
getAvailableSubroutines,
|
package/examples/llm-basic.di
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
<dirac>
|
|
3
3
|
<defvar name="topic" value="quantum computing" />
|
|
4
4
|
|
|
5
|
-
<output>Asking LLM about
|
|
5
|
+
<output>Asking LLM about <variable name="topic" />... </output>
|
|
6
6
|
|
|
7
7
|
<LLM output="response" maxTokens="200">
|
|
8
|
-
Explain
|
|
8
|
+
Explain <variable name="topic" /> in one sentence.
|
|
9
9
|
</LLM>
|
|
10
10
|
|
|
11
|
-
<output>Response:
|
|
11
|
+
<output>Response: <variable name="response" /> </output>
|
|
12
12
|
</dirac>
|
package/examples/llm-command.di
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
<dirac>
|
|
2
|
-
|
|
3
2
|
<subroutine name="background" description="set the background color." param-color="string:required:color name" >
|
|
4
|
-
<parameters select="@color"/>
|
|
5
|
-
<output>
|
|
6
3
|
this is my color: <variable name="color" />
|
|
7
|
-
</output>
|
|
8
4
|
</subroutine>
|
|
9
|
-
|
|
10
5
|
<llm execute="true">set the background color to red</llm>
|
|
11
|
-
|
|
12
|
-
|
|
13
6
|
</dirac>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<dirac>
|
|
2
|
+
<defvar name="topic" value="test" />
|
|
3
|
+
<output>Topic is: <variable name="topic" /></output>
|
|
4
|
+
<output> </output>
|
|
5
|
+
|
|
6
|
+
<LLM output="response" maxTokens="50" noextra="true">
|
|
7
|
+
Say hello
|
|
8
|
+
</LLM>
|
|
9
|
+
|
|
10
|
+
<output>Response: <variable name="response" /></output>
|
|
11
|
+
<output> </output>
|
|
12
|
+
</dirac>
|
package/package.json
CHANGED
package/src/tags/llm.ts
CHANGED
|
@@ -50,11 +50,11 @@ export async function executeLLM(session: DiracSession, element: DiracElement):
|
|
|
50
50
|
}
|
|
51
51
|
// Collect output from children
|
|
52
52
|
const childOutput = session.output.slice(beforeOutput);
|
|
53
|
-
userPrompt = childOutput.join('');
|
|
53
|
+
userPrompt = childOutput.join('').trim();
|
|
54
54
|
// Remove child output from main output
|
|
55
55
|
session.output = session.output.slice(0, beforeOutput);
|
|
56
56
|
} else if (element.text) {
|
|
57
|
-
userPrompt = substituteVariables(session, element.text);
|
|
57
|
+
userPrompt = substituteVariables(session, element.text).trim();
|
|
58
58
|
} else {
|
|
59
59
|
throw new Error('<LLM> requires prompt content');
|
|
60
60
|
}
|
|
@@ -121,12 +121,11 @@ for (const sub of subroutines) {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
// Add the full prompt as a user message to dialogHistory
|
|
124
|
-
|
|
125
|
-
dialogHistory.push({ role: 'user', content: noExtra ? userPrompt : prompt });
|
|
126
|
-
}
|
|
124
|
+
dialogHistory.push({ role: 'user', content: noExtra ? userPrompt : prompt });
|
|
127
125
|
|
|
128
126
|
if (session.debug) {
|
|
129
127
|
console.error(`[LLM] Calling ${model} with prompt length: ${prompt.length}`);
|
|
128
|
+
console.error(`[LLM] Dialog history length: ${dialogHistory.length} messages`);
|
|
130
129
|
}
|
|
131
130
|
|
|
132
131
|
try {
|