Skip to content

Commit

Permalink
fix for def FILES is empty #832
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Nov 8, 2024
1 parent 1be9fdd commit be3498e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export const DOCS_CONFIGURATION_HUGGINGFACE_URL =
"https://microsoft.github.io/genaiscript/getting-started/configuration/#huggingface"
export const DOCS_CONFIGURATION_CONTENT_SAFETY_URL =
"https://microsoft.github.io/genaiscript/reference/scripts/content-safety"
export const DOCS_DEF_FILES_IS_EMPTY_URL = "https://microsoft.github.io/genaiscript/reference/scripts/context/#empty-files"

export const MODEL_PROVIDERS = Object.freeze([
{
Expand Down
13 changes: 10 additions & 3 deletions packages/core/src/runpromptcontext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
TOKEN_NO_ANSWER,
MODEL_PROVIDER_AICI,
SYSTEM_FENCE,
DOCS_DEF_FILES_IS_EMPTY_URL,
} from "./constants"
import { renderAICI } from "./aici"
import { resolveSystems, resolveTools } from "./systems"
Expand Down Expand Up @@ -167,15 +168,21 @@ export function createChatTurnGenerationContext(
// shortcuts
if (body === undefined || body === null) {
if (!doptions.ignoreEmpty)
throw new Error(`def ${name} is ${body}`)
throw new Error(
`def ${name} is ${body}. See ${DOCS_DEF_FILES_IS_EMPTY_URL}`
)
return undefined
} else if (Array.isArray(body)) {
if (body.length === 0 && !doptions.ignoreEmpty)
throw new Error(`def ${name} is empty`)
throw new Error(
`def ${name} is empty. See ${DOCS_DEF_FILES_IS_EMPTY_URL}`
)
body.forEach((f) => ctx.def(name, f, defOptions))
} else if (typeof body === "string") {
if (body.trim() === "" && !doptions.ignoreEmpty)
throw new Error(`def ${name} is empty`)
throw new Error(
`def ${name} is empty. See ${DOCS_DEF_FILES_IS_EMPTY_URL}`
)
appendChild(
node,
createDef(name, { filename: "", content: body }, doptions)
Expand Down

0 comments on commit be3498e

Please sign in to comment.