Skip to content

Commit

Permalink
Move cancel function implementation from promptcontext to globals
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Sep 7, 2024
1 parent 6b95752 commit 8dbbe90
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")
}

Check failure on line 68 in packages/core/src/globals.ts

View workflow job for this annotation

GitHub Actions / build

You are throwing a new `CancelError` in the `cancel` function but it's not being caught anywhere. This could lead to an unhandled promise rejection. Please make sure to catch this error where the `cancel` function is being called. 🚀
}
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> => {

Check failure on line 224 in packages/core/src/promptcontext.ts

View workflow job for this annotation

GitHub Actions / build

The `cancel` function has been removed from the `PromptContext`. If this function was being used elsewhere in the code, it could lead to a `TypeError` of `cancel` is not a function. Please ensure that the `cancel` function is not being used elsewhere in the code or provide an alternative implementation. 🧐
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

Check failure on line 2276 in packages/core/src/types/prompt_template.d.ts

View workflow job for this annotation

GitHub Actions / build

The `cancel` method has been removed from the `PromptContext` interface. This change could break existing implementations that rely on this method. Please ensure that this change is intentional and that all implementations of this interface have been updated accordingly. 🕵️‍♀️
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 8dbbe90

Please sign in to comment.