fix webfetch

This commit is contained in:
Dax Raad
2025-06-05 15:59:09 -04:00
parent ea9dd4e9e2
commit 9147108675
3 changed files with 19 additions and 6 deletions

View File

@@ -185,7 +185,7 @@ export namespace Session {
previous.metadata.assistant.tokens.output previous.metadata.assistant.tokens.output
if ( if (
tokens > tokens >
(model.info.contextWindow - (model.info.maxOutputTokens ?? 0)) * 0.9 (model.info.limit.context - (model.info.limit.output ?? 0)) * 0.9
) { ) {
await summarize({ await summarize({
sessionID: input.sessionID, sessionID: input.sessionID,
@@ -507,6 +507,7 @@ export namespace Session {
await updateMessage(next) await updateMessage(next)
}, },
onError(input) { onError(input) {
log.error("error", input)
if (input.error instanceof Error) { if (input.error instanceof Error) {
next.metadata.error = input.error.toString() next.metadata.error = input.error.toString()
} }
@@ -520,7 +521,6 @@ export namespace Session {
}, },
toolCallStreaming: false, toolCallStreaming: false,
abortSignal: abort.signal, abortSignal: abort.signal,
maxRetries: 6,
stopWhen: stepCountIs(1000), stopWhen: stepCountIs(1000),
messages: convertToModelMessages(msgs), messages: convertToModelMessages(msgs),
temperature: 0, temperature: 0,
@@ -530,7 +530,13 @@ export namespace Session {
}, },
model: model.language, model: model.language,
}) })
await result.consumeStream() await result.consumeStream({
onError: (err) => {
log.error("error", {
err,
})
},
})
next.metadata!.time.completed = Date.now() next.metadata!.time.completed = Date.now()
await updateMessage(next) await updateMessage(next)
return next return next

View File

@@ -99,6 +99,13 @@ function extractTextFromHTML(html: string): string {
} }
function convertHTMLToMarkdown(html: string): string { function convertHTMLToMarkdown(html: string): string {
const turndownService = new TurndownService() const turndownService = new TurndownService({
headingStyle: "atx",
hr: "---",
bulletListMarker: "-",
codeBlockStyle: "fenced",
emDelimiter: "*",
})
turndownService.remove(["script", "style", "meta", "link"])
return turndownService.turndown(html) return turndownService.turndown(html)
} }

View File

@@ -51,10 +51,10 @@ export namespace Log {
write.out(build(message, extra)) write.out(build(message, extra))
}, },
error(message?: any, extra?: Record<string, any>) { error(message?: any, extra?: Record<string, any>) {
write.err(build(message, extra)) write.out(build(message, extra))
}, },
warn(message?: any, extra?: Record<string, any>) { warn(message?: any, extra?: Record<string, any>) {
write.err(build(message, extra)) write.out(build(message, extra))
}, },
tag(key: string, value: string) { tag(key: string, value: string) {
if (tags) tags[key] = value if (tags) tags[key] = value