Skip to content

Commit

Permalink
handle errors in agent
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Dec 22, 2024
1 parent 482f484 commit 52ab19d
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 23 deletions.
6 changes: 3 additions & 3 deletions docs/src/content/docs/reference/scripts/system.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,7 @@ system({
lineNumbers: true,
})

Check warning on line 425 in docs/src/content/docs/reference/scripts/system.mdx

View workflow job for this annotation

GitHub Actions / build

Missing header for section "Annotations Format". Consider adding a brief description or introduction to the section.

$`## Annotation Format
$`## Annotations Format
Use the following format to report **file annotations** (same as GitHub Actions workflow).
::(notice|warning|error) file=<filename>,line=<start line>,endLine=<end line>,code=<error_id>::<message>
Expand Down Expand Up @@ -552,7 +551,8 @@ system({
title: "Generate diagrams"
})

$`Use mermaid syntax if you need to generate state diagrams, class inheritance diagrams, relationships.`
$`## Diagrams Format
Use mermaid syntax if you need to generate state diagrams, class inheritance diagrams, relationships.`
`````


Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/nodehost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ export class NodeHost implements RuntimeHost {
if (typeof value === "string") value = { model: value, source }
const aliases = this._modelAliases[source]
const c = aliases[id] || (aliases[id] = { source })
if (value.model !== undefined) (c as any).model = value.model
if (value.model !== undefined && value.model !== id)
(c as any).model = value.model
if (!isNaN(value.temperature))
(c as any).temperature = value.temperature
}
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/genaisrc/system.annotations.genai.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ system({
lineNumbers: true,
})

$`## Annotation Format
$`## Annotations Format
Use the following format to report **file annotations** (same as GitHub Actions workflow).
::(notice|warning|error) file=<filename>,line=<start line>,endLine=<end line>,code=<error_id>::<message>
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/genaisrc/system.diagrams.genai.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ system({
title: "Generate diagrams"
})

$`Use mermaid syntax if you need to generate state diagrams, class inheritance diagrams, relationships.`
$`## Diagrams Format
Use mermaid syntax if you need to generate state diagrams, class inheritance diagrams, relationships.`
16 changes: 14 additions & 2 deletions packages/core/src/llms.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Model } from "@anthropic-ai/sdk/resources/index.mjs"
import { LARGE_MODEL_ID, SMALL_MODEL_ID, VISION_MODEL_ID } from "./constants"
import { ModelConfiguration, ModelConfigurations } from "./host"
import LLMS from "./llms.json"
Expand All @@ -14,8 +15,19 @@ export function defaultModelConfigurations(): ModelConfigurations {
]
const res = {
...(Object.fromEntries(
aliases.map((alias) => [alias, readModelAlias(alias)])
aliases.map<[string, ModelConfiguration]>((alias) => [
alias,
readModelAlias(alias),
])
) as ModelConfigurations),
...Object.fromEntries(
Object.entries(LLMS.aliases).map<[string, ModelConfiguration]>(
([id, model]) => [
id,
{ model, source: "default" } satisfies ModelConfiguration,
]
)
),
}
return structuredClone(res)

Expand All @@ -30,6 +42,6 @@ export function defaultModelConfigurations(): ModelConfigurations {
model: candidates[0],
candidates,
source: "default",
})
} satisfies ModelConfiguration)
}
}
2 changes: 1 addition & 1 deletion packages/core/src/promptdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ function renderDefNode(def: PromptDefNode): string {

let res: string
if (name && fenceFormat === "xml") {
res = `\n<${name}${dtype ? ` lang="${dtype}"` : ""}${filename ? ` file="${filename}"` : ""}${schema ? ` schema=${schema}` : ""}${diffFormat}>\n${body}</${name}>\n`
res = `\n<${name}${dtype ? ` lang="${dtype}"` : ""}${filename ? ` file="${filename}"` : ""}${schema ? ` schema=${schema}` : ""}${diffFormat}>\n${body}<${name}>\n`
} else if (fenceFormat === "none") {
res = `\n${name ? name + ":\n" : ""}${body}\n`
} else {
Expand Down
11 changes: 9 additions & 2 deletions packages/core/src/runpromptcontext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ import {
} from "./parameters"
import { consoleLogFormat, stdout } from "./logging"
import { isGlobMatch } from "./glob"
import { arrayify, logError, logVerbose, logWarn } from "./util"
import {
arrayify,
deleteEmptyValues,
logError,
logVerbose,
logWarn,
} from "./util"
import { renderShellOutput } from "./chatrender"
import { jinjaRender } from "./jinja"
import { mustacheRender } from "./mustache"
Expand Down Expand Up @@ -503,7 +509,8 @@ export function createChatGenerationContext(
...rest,
}
)
return res
if (res.error) throw res.error
return deleteEmptyValues(res)
}
)
}
Expand Down
24 changes: 13 additions & 11 deletions packages/core/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,23 @@ export function parseBoolean(s: string) {
}

export function deleteUndefinedValues<T extends Record<string, any>>(o: T): T {
for (const k in o) if (o[k] === undefined) delete o[k]
if (typeof o === "object")
for (const k in o) if (o[k] === undefined) delete o[k]
return o
}

export function deleteEmptyValues<T extends Record<string, any>>(o: T): T {
for (const k in o) {
const v = o[k]
if (
v === undefined ||
v === null ||
v === "" ||
(Array.isArray(v) && !v.length)
)
delete o[k]
}
if (typeof o === "object")
for (const k in o) {
const v = o[k]
if (
v === undefined ||
v === null ||
v === "" ||
(Array.isArray(v) && !v.length)
)
delete o[k]
}
return o
}

Expand Down

0 comments on commit 52ab19d

Please sign in to comment.