Skip to content

Commit

Permalink
feat: ✨ add logWarn to console methods in runpromptcontext
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Oct 23, 2024
1 parent 488ea1a commit 28e9232
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions packages/core/src/runpromptcontext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from "./parameters"
import { consoleLogFormat } from "./logging"
import { isGlobMatch } from "./glob"
import { arrayify, logError, logVerbose } from "./util"
import { arrayify, logError, logVerbose, logWarn } from "./util"
import { renderShellOutput } from "./chatrender"
import { jinjaRender } from "./jinja"
import { mustacheRender } from "./mustache"
Expand Down Expand Up @@ -73,18 +73,35 @@ export function createChatTurnGenerationContext(
): ChatTurnGenerationContext & { node: PromptNode } {
const node: PromptNode = { children: [] }

const log = (...args: any[]) => {
const line = consoleLogFormat(...args)
if (line) {
trace.log(line)
logVerbose(line)
}
}
const console = Object.freeze<PromptGenerationConsole>({
log,
debug: log,
warn: log,
error: log,
log: (...args: any[]) => {
const line = consoleLogFormat(...args)
if (line) {
trace.log(line)
process.stdout.write(line + "\n")
}
},
debug: (...args: any[]) => {
const line = consoleLogFormat(...args)
if (line) {
trace.log(line)
logVerbose(line)
}
},
warn: (...args: any[]) => {
const line = consoleLogFormat(...args)
if (line) {
trace.log(line)
logWarn(line)
}
},
error: (...args: any[]) => {
const line = consoleLogFormat(...args)
if (line) {
trace.log(line)
logError(line)
}
},
})

const ctx: ChatTurnGenerationContext & { node: PromptNode } = {
Expand Down

0 comments on commit 28e9232

Please sign in to comment.