Skip to content

Commit

Permalink
Move cancel function implementation from promptcontext to globals (#696)
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan authored Sep 7, 2024
1 parent 6b95752 commit ba1d047
Show file tree
Hide file tree
Showing 17 changed files with 5 additions and 35 deletions.
1 change: 0 additions & 1 deletion docs/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/core/src/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/core/src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "./frontmatter"
import { JSONLStringify, JSONLTryParse } from "./jsonl"
import { HTMLTablesToJSON, HTMLToMarkdown, HTMLToText } from "./html"
import { CancelError } from "./error"

export function resolveGlobal(): any {
if (typeof window !== "undefined")
Expand Down Expand Up @@ -62,4 +63,7 @@ export function installGlobals() {
convertToMarkdown: HTMLToMarkdown,
convertToText: HTMLToText,
})
glb.cancel = (reason?: string) => {
throw new CancelError(reason || "user cancelled")
}
}
21 changes: 1 addition & 20 deletions packages/core/src/promptcontext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
} from "./util"
import { runtimeHost } from "./host"
import { MarkdownTrace } from "./trace"
import { YAMLParse, YAMLStringify } from "./yaml"
import { createParsers } from "./parsers"
import { readText } from "./fs"
import {
Expand All @@ -30,22 +29,13 @@ import {
RunPromptContextNode,
createChatGenerationContext,
} from "./runpromptcontext"
import { CSVParse, CSVToMarkdown } from "./csv"
import { INIParse, INIStringify } from "./ini"
import {
CancelError,
isCancelError,
NotSupportedError,
serializeError,
} from "./error"
import { isCancelError, NotSupportedError, serializeError } from "./error"
import { createFetch } from "./fetch"
import { XMLParse } from "./xml"
import { GenerationOptions } from "./generation"
import { fuzzSearch } from "./fuzzsearch"
import { parseModelIdentifier } from "./models"
import { renderAICI } from "./aici"
import { MODEL_PROVIDER_AICI, SYSTEM_FENCE } from "./constants"
import { JSONLStringify, JSONLTryParse } from "./jsonl"
import { grepSearch } from "./grep"
import { resolveFileContents, toWorkspaceFile } from "./file"
import { vectorSearch } from "./vectorsearch"
Expand All @@ -57,12 +47,6 @@ import { resolveModelConnectionInfo } from "./models"
import { resolveLanguageModel } from "./lm"
import { callExpander } from "./expander"
import { Project } from "./ast"
import {
frontmatterTryParse,
splitMarkdown,
updateFrontmatter,
} from "./frontmatter"
import { url } from "node:inspector"

export async function createPromptContext(
prj: Project,
Expand Down Expand Up @@ -237,9 +221,6 @@ export async function createPromptContext(
defFileMerge: (fn) => {
appendPromptChild(createFileMerge(fn))
},
cancel: (reason?: string) => {
throw new CancelError(reason || "user cancelled")
},
runPrompt: async (generator, runOptions): Promise<RunPromptResult> => {
try {
const { label, system = [] } = runOptions || {}
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/types/prompt_template.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2276,7 +2276,6 @@ interface PromptContext extends ChatGenerationContext {
text?: string
file?: WorkspaceFile
}>
cancel(reason?: string): void
env: ExpansionVariables
path: Path
parsers: Parsers
Expand Down
1 change: 0 additions & 1 deletion packages/sample/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/sample/genaisrc/node/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/sample/genaisrc/python/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/sample/genaisrc/style/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/sample/src/aici/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/sample/src/errors/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/sample/src/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/sample/src/makecode/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/sample/src/tla/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/sample/src/vision/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion slides/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ba1d047

Please sign in to comment.