Skip to content

Commit 2f718fa

Browse files
committed
refactor: update trace handling in context creation and expand functions
1 parent b805713 commit 2f718fa

5 files changed

Lines changed: 12 additions & 14 deletions

File tree

packages/core/src/expander.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ export async function callExpander(
5252
prj: Project,
5353
r: PromptScript,
5454
ev: ExpansionVariables,
55-
trace: MarkdownTrace,
5655
options: GenerationOptions,
5756
installGlobally: boolean,
5857
) {
5958
mark("prompt.expand.main");
6059
assert(!!options.model);
60+
const trace = options.trace;
6161
const modelId = r.model ?? options.model;
62-
const ctx = await createPromptContext(prj, ev, trace, options, modelId);
62+
const ctx = await createPromptContext(prj, ev, options, modelId);
6363
if (installGlobally) installGlobalPromptContext(ctx);
6464

6565
let status: GenerationStatus = undefined;
@@ -268,9 +268,9 @@ export async function expandTemplate(
268268
prj,
269269
template,
270270
env,
271-
trace,
272271
{
273272
...options,
273+
trace,
274274
maxTokens,
275275
maxToolCalls,
276276
flexTokens,
@@ -356,8 +356,7 @@ export async function expandTemplate(
356356
prj,
357357
system,
358358
mergeEnvVarsWithSystem(env, systemId),
359-
trace,
360-
options,
359+
{ ...options, trace },
361360
false,
362361
);
363362

packages/core/src/promptcontext.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,10 @@ const dbg = genaiscriptDebug("ctx");
5454
export async function createPromptContext(
5555
prj: Project,
5656
ev: ExpansionVariables,
57-
trace: MarkdownTrace,
5857
options: GenerationOptions,
5958
model: string,
6059
) {
61-
const { cancellationToken } = options;
60+
const { trace, cancellationToken } = options;
6261
const { generator, vars, dbg, output, ...varsNoGenerator } = ev;
6362

6463
dbg(`create`);

packages/core/src/runpromptcontext.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,6 @@ export function createChatGenerationContext(
894894
prj,
895895
system,
896896
mergeEnvVarsWithSystem(env, systemId),
897-
runTrace,
898897
genOptions,
899898
false,
900899
);

packages/runtime-sample/src/poem-js.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import "@genaiscript/runtime";
1+
import { config } from "@genaiscript/runtime";
2+
3+
await config();
24

35
const d = YAML`foo: bar`;
46

packages/runtime/src/runtime.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ import {
3636
generateId,
3737
getRunDir,
3838
installGlobalPromptContext,
39-
installGlobals,
4039
genaiscriptDebug,
4140
LARGE_MODEL_ID,
41+
MarkdownTrace,
4242
} from "@genaiscript/core";
4343
import { NodeHost } from "./nodehost.js";
4444
import debug from "debug";
@@ -124,6 +124,7 @@ export async function config(
124124
const prj = await buildProject();
125125
const runId = generateId();
126126
const runDir = getRunDir("runtime", runId);
127+
const output = new MarkdownTrace();
127128
const env: ExpansionVariables = {
128129
runId,
129130
runDir,
@@ -135,21 +136,19 @@ export async function config(
135136
id: "",
136137
},
137138
generator: undefined,
138-
output: undefined,
139+
output,
139140
dbg: debug(DEBUG_SCRIPT_CATEGORY),
140141
};
141142
const ctx = await createPromptContext(
142143
prj,
143144
env,
144-
undefined,
145145
{
146146
inner: false,
147147
stats: undefined,
148-
trace: undefined,
149148
model: LARGE_MODEL_ID,
150149
userState: {},
151150
},
152-
undefined,
151+
LARGE_MODEL_ID,
153152
);
154153
installGlobalPromptContext(ctx);
155154
}

0 commit comments

Comments
 (0)