repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
genaiscript
github_2023
microsoft
typescript
BrowserManager.browse
async browse( url: string, options?: BrowseSessionOptions & TraceOptions ): Promise<BrowserPage> { const { trace, incognito, timeout, recordVideo, ...rest } = options || {} logVerbose(`browsing ${ellipseUri(url)}`) const browser = await this.launchBrowser(options...
/** * Opens a URL in a new browser page with optional tracing and session options. * @param url The URL to browse. * @param options Optional settings for the browsing session and trace options. * @returns A promise that resolves to a Page object. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/cli/src/playwright.ts#L134-L181
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
cancelAll
const cancelAll = () => { for (const [runId, run] of Object.entries(runs)) { logVerbose(`abort run ${runId}`) run.canceller.abort("closing") delete runs[runId] } for (const [chatId, chat] of Object.entries(chats)) { logVerbose(`abort chat ${chat}`)...
// Cancels all active runs and chats.
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/cli/src/server.ts#L137-L157
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
handleChunk
const handleChunk = async (chunk: ChatChunk) => { const handler = chats[chunk.chatId] if (handler) { if (chunk.finishReason) delete chats[chunk.chatId] await handler(chunk) } }
// Handles incoming chat chunks and calls the appropriate handler.
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/cli/src/server.ts#L160-L166
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
parseModelSpec
function parseModelSpec(m: string): ModelOptions & ModelAliasesOptions { const values = m .split(/&/g) .map((kv) => kv.split("=", 2)) .reduce( (acc, [key, value]) => { acc[key] = decodeURIComponent(value) return acc }, {} as...
/** * Parses model specifications from a string and returns a ModelOptions object. * @param m - The string representation of the model specification. * @returns A ModelOptions object with model, temperature, and topP fields if applicable. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/cli/src/test.ts#L65-L86
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
createEnv
function createEnv() { const env = process.env return { ...process.env, PROMPTFOO_CACHE_PATH: env.PROMPTFOO_CACHE_PATH ?? PROMPTFOO_CACHE_PATH, PROMPTFOO_CONFIG_DIR: env.PROMPTFOO_CONFIG_DIR ?? PROMPTFOO_CONFIG_DIR, PROMPTFOO_DISABLE_TELEMETRY: env.PROMPTFOO_DISABLE_TELEMETRY ?? ...
/** * Creates an environment object for execution with defaults and optional overrides. * @returns An environment object with necessary configurations. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/cli/src/test.ts#L92-L103
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
listTests
async function listTests(options: { ids?: string[] groups?: string[] redteam?: boolean }) { const prj = await buildProject() const scripts = filterScripts(prj.scripts, { ...(options || {}), test: options.redteam ? undefined : true, redteam: options.redteam, }) return ...
/* * Lists test scripts based on given options, filtering by IDs and groups. * @param options - Options to filter the test scripts by IDs or groups. * @returns A Promise resolving to an array of filtered scripts. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/cli/src/test.ts#L361-L373
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
renderAICINode
function renderAICINode(node: AICINode) { const { name } = node switch (name) { case "gen": // Extract options and build arguments for 'gen' const { regex, ...rest } = (node as AICIGenNode).options const args = Object.entries(rest).map( ([k, v]) => `${...
/** * Renders an AICI node into a string representation. * Handles different node types and constructs appropriate string output. * @param node - The AICI node to render. * @returns The string representation of the node. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/aici.ts#L36-L50
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
escapeJavascriptString
function escapeJavascriptString(s: string) { return s.replace(/`/g, "\\`") }
/** * Escapes backticks in a JavaScript string for template literals. * Used to handle strings in template literals. * @param s - The string to escape. * @returns The escaped string. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/aici.ts#L58-L60
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
AICIChatCompletion
const AICIChatCompletion: ChatCompletionHandler = async ( req, connection, options, trace ) => { const { messages, response_format, tools } = req const { requestOptions, partialCb, cancellationToken, inner } = options const { headers, ...rest } = requestOptions || {} // Check for unsupp...
/** * Handles the completion of chat requests. * Processes incoming chat messages and constructs AICI script. * @param req - The chat request object. * @param connection - The connection details. * @param options - Options for processing the request. * @param trace - Tracing information for debugging. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/aici.ts#L203-L410
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
doChunk
function doChunk(chunk: string) { chunk = pref + chunk const ch0 = chatResp chunk = chunk.replace(/^data:\s*(.*)[\r\n]+/gm, (_, json) => { if (json == "[DONE]") { seenDone = true return "" } if (seenDone) { logEr...
/** * Processes a chunk of data from the response. * @param value - The chunk of data to process. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/aici.ts#L352-L409
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
listModels
const listModels: ListModelsFunction = async (cfg, options) => { try { const { token, base } = cfg const url = `${base}/proxy/info` const fetch = await createFetch() const res = await fetch(url, { method: "GET", headers: { "api-key": token, ...
/** * Lists available models based on configuration. * Fetches model information from the server. * @param cfg - The configuration for the language model. * @returns A list of language model information. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/aici.ts#L418-L447
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
addAnnotation
const addAnnotation = (m: RegExpMatchArray) => { const { file, line, endLine, severity, code, message } = m.groups const annotation: Diagnostic = { severity: SEV_MAP[severity?.toLowerCase()] ?? "info", // Default to "info" if severity is missing filename: file, range:...
// Helper function to add an annotation to the set.
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/annotations.ts#L49-L62
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
createAzureToken
async function createAzureToken( scopes: readonly string[], credentialsType: AzureCredentialsType, cancellationToken?: CancellationToken ): Promise<AuthenticationToken> { // Dynamically import DefaultAzureCredential from the Azure SDK const { DefaultAzureCredential, EnvironmentCreden...
/** * This module provides functions to handle Azure authentication tokens, * including checking expiration and creating new tokens using Azure Identity SDK. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/azuretoken.ts#L32-L89
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
MemoryCache.constructor
protected constructor(public readonly name: string) { super() // Initialize EventTarget }
// Constructor is private to enforce the use of byName factory method
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/cache.ts#L30-L32
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
MemoryCache.byName
static byName<K, V>( name: string, options?: { lookupOnly?: boolean } ): MemoryCache<K, V> { name = name.replace(/[^a-z0-9_]/gi, "_") // Sanitize name const key = "memorycache." + name if (host.userState[key]) return host.userState[key] // Return if exists if (options...
/** * Factory method to create or retrieve an existing cache by name. * Sanitizes the name to ensure it is a valid identifier. * @param name - The name of the cache * @returns An instance of JSONLineCache */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/cache.ts#L40-L51
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
MemoryCache.keys
async keys(): Promise<K[]> { await this.initialize() return Object.values(this._entries).map((kv) => kv.key) }
/** * Retrieve all keys from the cache. * @returns A promise resolving to an array of keys */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/cache.ts#L63-L66
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
MemoryCache.values
async values(): Promise<V[]> { await this.initialize() return Object.values(this._entries).map((kv) => kv.val) }
/** * Retrieve all values from the cache. * @returns */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/cache.ts#L72-L75
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
MemoryCache.entries
async entries(): Promise<CacheEntry<K, V>[]> { await this.initialize() return Object.values(this._entries).map((e) => ({ ...e })) }
/** * Retrieve all entries from the cache. * @returns A promise resolving to an array of cache entries */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/cache.ts#L81-L84
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
MemoryCache.getEntryBySha
async getEntryBySha(sha: string) { await this.initialize() return this._entries[sha] }
/** * Retrieve a specific entry by its SHA identifier. * @param sha - The SHA identifier of the entry * @returns A promise resolving to the cache entry */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/cache.ts#L91-L94
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
MemoryCache.get
async get(key: K): Promise<V> { if (key === undefined) return undefined // Handle undefined key await this.initialize() const sha = await keySHA(key) return this._entries[sha]?.val }
/** * Get the value associated with a specific key. * @param key - The key of the entry * @returns A promise resolving to the value */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/cache.ts#L101-L106
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
MemoryCache.set
async set(key: K, val: V) { await this.initialize() const sha = await keySHA(key) const ent = { sha, key, val } const ex = this._entries[sha] if (ex && JSON.stringify(ex) == JSON.stringify(ent)) return // No change this._entries[sha] = ent await this.appendEntry(e...
/** * Set a key-value pair in the cache, triggering a change event. * @param key - The key to set * @param val - The value to set * @param options - Optional trace options */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/cache.ts#L139-L148
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
MemoryCache.getKeySHA
async getKeySHA(key: K) { const sha = await keySHA(key) return sha }
/** * Compute SHA for a given key. * @param key - The key to compute SHA for * @returns A promise resolving to the SHA string */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/cache.ts#L155-L158
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
JSONLineCache.constructor
protected constructor(public readonly name: string) { super(name) // Initialize EventTarget }
// Constructor is private to enforce the use of byName factory method
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/cache.ts#L169-L171
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
JSONLineCache.byName
static byName<K, V>(name: string): JSONLineCache<K, V> { if (!name) return undefined name = name.replace(/[^a-z0-9_]/gi, "_") // Sanitize name const key = "workspacecache." + name if (host.userState[key]) return host.userState[key] // Return if exists const r = new JSONLineCache<...
/** * Factory method to create or retrieve an existing cache by name. * Sanitizes the name to ensure it is a valid identifier. * @param name - The name of the cache * @returns An instance of JSONLineCache */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/cache.ts#L179-L187
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
JSONLineCache.folder
private folder() { return dotGenaiscriptPath("cache", this.name) }
// Get the folder path for the cache storage
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/cache.ts#L190-L192
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
JSONLineCache.path
private path() { return host.resolvePath(this.folder(), "db.jsonl") }
// Get the full path to the cache file
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/cache.ts#L195-L197
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
JSONLineCache.initialize
override async initialize() { if (this._entries) return if (this._initializePromise) return await this._initializePromise this._initializePromise = (async () => { await host.createDirectory(this.folder()) // Ensure directory exists const content = await tryReadText(this....
/** * Initialize the cache by loading entries from the file. * Identifies duplicate entries and rewrites the file if necessary. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/cache.ts#L204-L232
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
keySHA
async function keySHA(key: any) { return await hash(key, { algorithm: "sha-256", version: true }) // Compute SHA256 hash }
/** * Compute the hash of a key for uniqueness. * Normalizes the key by converting it to a string and appending the core version. * @param key - The key to hash * @returns A promise resolving to the SHA256 hash string */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/cache.ts#L245-L247
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
AbortSignalCancellationToken.constructor
constructor(private readonly signal: AbortSignal) {}
// Constructor takes an AbortSignal to track cancellation
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/cancellation.ts#L26-L26
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
AbortSignalCancellationToken.isCancellationRequested
get isCancellationRequested() { return this.signal.aborted }
// Accessor for checking if the cancellation has been requested
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/cancellation.ts#L29-L31
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
AbortSignalCancellationController.constructor
constructor() { this.controller = new AbortController() this.token = new AbortSignalCancellationToken(this.controller.signal) }
// Initializes the controller and creates a token with the associated signal
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/cancellation.ts#L54-L57
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
AbortSignalCancellationController.abort
abort(reason?: any) { this.controller.abort(reason) }
/** * Aborts the ongoing operation with an optional reason. * This triggers the cancellation state in the associated token. * * @param reason - Optional reason for aborting the operation. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/cancellation.ts#L65-L67
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
parseChange
function parseChange(): ChangeLogChange { // Parse OriginalCode block let m = /^OriginalCode@(?<start>\d+)-(?<end>\d+):$/i.exec(lines[0]) if (!m) return undefined lines.shift() const original = parseChunk(m) // Parse ChangedCode block m = /^ChangedCode@(?<start>...
// Parses a single change within the changelog.
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/changelog.ts#L95-L112
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
parseChunk
function parseChunk(m: RegExpExecArray): ChangeLogChunk { const start = parseInt(m.groups.start) const end = parseInt(m.groups.end) const chunk: ChangeLogChunk = { start, end, lines: [], } while (lines.length) { m = /^\[(?<index>\d+...
// Parses a chunk of code from the changelog.
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/changelog.ts#L115-L138
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
renderToolArguments
function renderToolArguments(args: string) { const js = JSONLLMTryParse(args) // Convert arguments to YAML if possible, otherwise keep as JSON. if (js) return fenceMD(YAMLStringify(js), "yaml") else return fenceMD(args, "json") }
/** * Parses and renders tool arguments into formatted YAML or JSON. * @param args - The tool arguments as a string. * @returns A formatted string in YAML or JSON. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/chatrender.ts#L205-L210
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
promptPath
function promptPath(id: string) { const prompts = host.resolvePath(host.projectFolder(), GENAI_SRC) // Resolve base prompt directory if (id === null) return prompts // Return base path if id is not provided return host.resolvePath(prompts, id + GENAI_MJS_EXT) // Construct full path if id is provided }
/** * Constructs the path to a prompt file. * If `id` is null, returns the base prompt directory path. * Otherwise, appends the `id` with a specific file extension to the path. * * @param id - Identifier for the prompt script * @returns The file path as a string */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/copy.ts#L17-L21
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
findChunk
function findChunk(lines: string[], chunk: Chunk, startLine: number): number { const chunkLines = chunk.lines if (chunkLines.length === 0) return startLine const chunkStart = chunkLines[0].trim() let linei = startLine while (linei < lines.length) { const line = lines[linei].trim() if...
/** * Finds the starting position of a chunk in the given lines. * @param lines - The array of lines to search through. * @param chunk - The chunk to find. * @param startLine - The line to start the search from. * @returns The index of the starting line of the chunk, or -1 if not found. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/diff.ts#L143-L169
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
startFence
function startFence(text: string) { const m = promptFenceStartRx.exec(text) const groups: Record<string, string> = m?.groups || {} return { fence: groups.fence, language: unquote(groups.language), args: parseKeyValuePairs(groups.args), } }
/** * Start parsing a fence from a given text line. * @param text - The text line to parse. * @returns An object containing the fence, language, and arguments. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/fence.ts#L18-L26
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
normalize
function normalize(label: string, text: string) { // remove extra line numbers text = removeLineNumbers(text) /** handles situations like this: ````` file=problem1.py ```python import re ... */ if (/file=\w+\.\w+/.test(label)) { const...
/** * Normalize content by removing unnecessary code fences. * @param label - The label of the content. * @param text - The content text. * @returns The normalized text. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/fence.ts#L151-L168
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
getFileEdit
const getFileEdit = async (fn: string) => { fn = relativePath(projFolder, fn) let fileEdit: FileUpdate = fileEdits[fn] if (!fileEdit) { let before: string = null let after: string = undefined if (await fileExists(fn)) before = await readText(fn) el...
// Helper function to get or create file edit object
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/fileedits.ts#L37-L48
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
validateFileOutputs
function validateFileOutputs( fileOutputs: FileOutput[], trace: MarkdownTrace, fileEdits: Record<string, FileUpdate>, schemas: Record<string, JSONSchema> ) { if (fileOutputs?.length && Object.keys(fileEdits || {}).length) { trace.startDetails("🗂 file outputs") try { for ...
// Validate file outputs against specified schemas and patterns
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/fileedits.ts#L220-L278
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
GitClient.constructor
constructor(cwd: string) { this.cwd = cwd }
// Stores the current branch name
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/git.ts#L36-L38
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
GitClient.defaultBranch
async defaultBranch(): Promise<string> { if (!this._defaultBranch) { const res = await this.exec(["remote", "show", "origin"], {}) this._defaultBranch = /^\s*HEAD branch:\s+(?<name>.+)\s*$/m.exec( res )?.groups?.name } return this._defaultBranc...
/** * Retrieves the default branch name. * If not already set, it fetches from the Git remote. * @returns {Promise<string>} The default branch name. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/git.ts#L58-L66
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
GitClient.branch
async branch(): Promise<string> { if (!this._branch) { const res = await this.exec(["branch", "--show-current"]) this._branch = res.trim() } return this._branch }
/** * Gets the current branch * @returns */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/git.ts#L72-L78
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
GitClient.exec
async exec( args: string | string[], options?: { label?: string } ): Promise<string> { const opts = { ...(options || {}), cwd: this.cwd, } const res = await runtimeHost.exec( undefined, this.git, Array.isArray(args) ...
/** * Executes a Git command with given arguments. * @param args Git command arguments. * @param options Optional command options with a label. * @returns {Promise<string>} The standard output from the command. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/git.ts#L94-L110
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
GitClient.listFiles
async listFiles( scope: "modified-base" | "staged" | "modified", options?: { base?: string paths?: ElementOrArray<string> excludedPaths?: ElementOrArray<string> askStageOnEmpty?: boolean } ): Promise<WorkspaceFile[]> { const { askStageO...
/** * Finds modified files in the Git repository based on the specified scope. * @param scope The scope of modifications to find: "modified-base", "staged", or "modified". * @param options Optional settings such as base branch, paths, and exclusions. * @returns {Promise<WorkspaceFile[]>} List of mod...
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/git.ts#L118-L175
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
GitClient.addFileFilters
private static addFileFilters( paths: string[], excludedPaths: string[], args: string[] ) { if (paths.length > 0 || excludedPaths.length > 0) { args.push("--") if (!paths.length) args.push(".") else args.push(...paths) args.push( ...
/** * Adds file path filters to Git command arguments. * @param paths Paths to include. * @param excludedPaths Paths to exclude. * @param args Git command arguments. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/git.ts#L183-L196
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
GitClient.diff
async diff(options?: { staged?: boolean askStageOnEmpty?: boolean base?: string head?: string paths?: ElementOrArray<string> excludedPaths?: ElementOrArray<string> unified?: number nameOnly?: boolean llmify?: boolean algorithm?: "patience" ...
/** * Generates a diff of changes based on provided options. * @param options Options such as staged flag, base, head, paths, and exclusions. * @returns {Promise<string>} The diff output. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/git.ts#L274-L348
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
GitClient.shallowClone
async shallowClone( repository: string, options?: { /** * Brnach to clone */ branch?: string /** * Do not reuse previous clone */ force?: boolean /** * Runs install command afte...
/** * Create a shallow git clone * @param repository URL of the remote repository * @param options various clone options */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/git.ts#L355-L417
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
GitHubClient.downloadWorkflowJobLog
async downloadWorkflowJobLog( job_id: number, options?: { llmify?: boolean } ): Promise<string> { const { client, owner, repo } = await this.api() const { url: logs_url } = await client.rest.actions.downloadJobLogsForWorkflowRun({ owner, re...
/** * Downloads a GitHub Action workflow run log * @param jobId */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/github.ts#L851-L865
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
cleanMarkdown
function cleanMarkdown(res: string): string { return res?.replace(/(\r?\n){3,}/g, "\n\n") }
/** * Cleans markdown by reducing multiple consecutive newlines to two. * @param res - The string to be cleaned. * @returns The cleaned string. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/markdown.ts#L28-L30
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
listModels
const listModels: ListModelsFunction = async (cfg, options) => { try { // Create a fetch instance to make HTTP requests const fetch = await createFetch({ retries: 0, ...options }) // Fetch the list of models from the remote API const res = await fetch(cfg.base.replace("/v1", "/api/ta...
/** * Lists available models for the Ollama language model configuration. * Fetches model data from a remote endpoint and formats it into a LanguageModelInfo array. * * @param cfg - The configuration for the language model. * @returns A promise that resolves to an array of LanguageModelInfo objects. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/ollama.ts#L18-L57
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
templKey
function templKey(t: PromptScript) { const pref = t.unlisted ? "Z" : t.filename ? "A" : "B" // Determine prefix for sorting return pref + t.title + t.id // Concatenate for final sorting key }
/** * Generates a sorting key for a PromptScript * Determines priority based on whether a script is unlisted or has a filename. * @param t - The PromptScript to generate the key for. * @returns string - The sorting key. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/parser.ts#L60-L63
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
tryImportPdfjs
async function tryImportPdfjs(options?: TraceOptions) { const { trace } = options || {} installPromiseWithResolversShim() // Ensure Promise.withResolvers is available const pdfjs = await import("pdfjs-dist") let workerSrc = require.resolve("pdfjs-dist/build/pdf.worker.min.mjs") // Adjust worker sou...
/** * Attempts to import pdfjs and configure worker source * based on the operating system. * @param options - Optional tracing options * @returns A promise resolving to the pdfjs module */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/pdf.ts#L27-L44
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
CanvasFactory._createCanvas
_createCanvas(width: number, height: number) { return CanvasFactory.createCanvas(width, height) }
/** * @ignore */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/pdf.ts#L91-L93
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
installPromiseWithResolversShim
function installPromiseWithResolversShim() { ;(Promise as any).withResolvers || ((Promise as any).withResolvers = function () { let rs, rj, pm = new this((resolve: any, reject: any) => { rs = resolve rj = reject ...
/** * Installs a shim for Promise.withResolvers if not available. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/pdf.ts#L119-L134
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
PDFTryParse
async function PDFTryParse( fileOrUrl: string, content?: Uint8Array, options?: ParsePDFOptions & TraceOptions & CancellationOptions ) { const { cancellationToken, disableCleanup, trace, renderAsImage, scale = PDF_SCALE, cache, } = options || {} co...
/** * Parses PDF files using pdfjs-dist. * @param fileOrUrl - The file path or URL of the PDF * @param content - Optional PDF content as a Uint8Array * @param options - Options including disableCleanup and tracing * @returns An object indicating success or failure and the parsed pages */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/pdf.ts#L165-L392
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
PDFPagesToString
function PDFPagesToString(pages: PDFPage[]) { return pages ?.map((p) => `-------- Page ${p.index} --------\n\n${p.content}`) .join("\n\n") }
/** * Joins pages into a single string with page breaks. * @param pages - Array of page content strings * @returns A single string representing the entire document */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/pdf.ts#L399-L403
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
parsePageItems
function parsePageItems(pdfItems: TextItem[]) { const lineData: { [y: number]: TextItem[] } = {} // Group text items by their vertical position (y-coordinate) for (let i = 0; i < pdfItems.length; i++) { const item = pdfItems[i] const y = item?.transform[5] if (!lineData.hasOwnProper...
/** * Parses text items from a PDF page into lines. * @param pdfItems - Array of text items * @returns An object containing parsed lines */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/pdf.ts#L439-L529
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
renderDefNode
function renderDefNode(def: PromptDefNode): string { const { name, resolved, language, lineNumbers, schema, prediction } = def const { filename, content = "" } = resolved let fenceFormat = def.fenceFormat const norm = (s: string, lang: string) => { s = (s || "").replace(/\n*$/, "") if (...
// Function to render a definition node to a string.
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/promptdom.ts#L272-L332
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
haveSameKeysAndSimpleValues
function haveSameKeysAndSimpleValues(data: object[]): boolean { if (data.length === 0) return true const headers = Object.entries(data[0]) return data.slice(1).every((obj) => { const keys = Object.entries(obj) return ( headers.length === keys.length && headers.every( ...
// Function to check if data objects have the same keys and simple values.
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/promptdom.ts#L512-L528
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
resolvePromptNode
async function resolvePromptNode( encoder: TokenEncoder, root: PromptNode, options: TraceOptions ): Promise<{ errors: number }> { const { trace } = options || {} let err = 0 const names = new Set<string>() const uniqueName = (n_: string) => { let i = 1 let n = n_ whil...
// Function to resolve a prompt node.
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/promptdom.ts#L655-L855
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
truncatePromptNode
async function truncatePromptNode( encoder: TokenEncoder, node: PromptNode, options?: TraceOptions ): Promise<boolean> { const { trace } = options || {} let truncated = false const cap = (n: { error?: unknown resolved?: string tokens?: number maxTokens?: number ...
// Function to handle truncation of prompt nodes based on token limits.
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/promptdom.ts#L896-L961
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
flexPromptNode
async function flexPromptNode( root: PromptNode, options?: { flexTokens: number } & TraceOptions ): Promise<void> { const PRIORITY_DEFAULT = 0 const { trace, flexTokens } = options || {} let log = "" // Collect all nodes const nodes: PromptNode[] = [] await visitNode(root, { no...
// Function to adjust token limits for nodes with flexibility.
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/promptdom.ts#L964-L1020
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
tracePromptNode
async function tracePromptNode( trace: MarkdownTrace, root: PromptNode, options?: { label: string } ) { if (!trace || !root.children?.length) return await visitNode(root, { node: (n) => { const error = errorMessage(n.error) let title = toStringList( n...
// Function to trace the prompt node structure for debugging.
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/promptdom.ts#L1023-L1056
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
resolveTestProvider
function resolveTestProvider( info: ModelConnectionInfo, modelType: "chat" | "embedding" ): { id: string config?: { apiHost: string } } { if (!info) return undefined const { base } = info const { provider, model } = parseModelIdentifier(info.model) const apiHost = base .replace(...
/** * Convert GenAIScript connection info into prompt foo configuration * @param info */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/promptfoo.ts#L31-L69
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
resolveExpansionVars
async function resolveExpansionVars( project: Project, trace: MarkdownTrace, template: PromptScript, fragment: Fragment, output: OutputTrace, options: GenerationOptions ): Promise<ExpansionVariables> { const { vars, runDir } = options const root = runtimeHost.projectFolder() assert(...
// Asynchronously resolve expansion variables needed for a template
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/promptrunner.ts#L34-L107
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
defOutputProcessor
const defOutputProcessor = (fn: PromptOutputProcessorHandler) => { checkCancelled(cancellationToken) if (fn) appendChild(node, createOutputProcessor(fn)) }
// Default output processor for the prompt
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/runpromptcontext.ts#L336-L339
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
append
function append(line: string) { if (/=$/.test(lines[lines.length - 1])) lines[lines.length - 1] = lines[lines.length - 1] + " " + line else if (/[<}]$/.test(lines[lines.length - 1])) lines[lines.length - 1] = lines[lines.length - 1] + line else lines.push(" ".repeat(inde...
// Append a line to the TypeScript definition
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/schema.ts#L71-L77
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
appendJsDoc
function appendJsDoc(...parts: string[]) { const text = parts?.filter((d) => d).join("\n") if (!text) return if (text.indexOf("\n") > -1) append( `/* ${text.split(/\n/g).join("\n" + " ".repeat(indent))} */` ) else append(`// ${text}`) }
// Append JSDoc comments
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/schema.ts#L80-L88
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
stringifyNode
function stringifyNode(node: JSONSchemaType): string { if (node === undefined) return "any" else if ((node as JSONSchemaAnyOf).anyOf) { const n = node as JSONSchemaAnyOf return n.anyOf .map((x) => { const v = stringifyNode(x) ...
// Convert a JSON Schema node to TypeScript
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/schema.ts#L91-L116
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
stringifyNodeDoc
function stringifyNodeDoc(node: JSONSchemaType): string { const n = node as JSONSchemaSimpleType const doc = [n?.title, n?.description] switch (n.type) { case "number": case "integer": { if (n.minimum !== undefined) doc.push(`minimum: ${n.minimum}`) ...
// Extract documentation for a node
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/schema.ts#L119-L139
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
stringifyObject
function stringifyObject(object: JSONSchemaObject): void { const { required, properties, additionalProperties } = object append(`{`) indent++ if (additionalProperties) append(`[key: string]: any,`) if (properties) Object.keys(properties).forEach((key) => { ...
// Convert a JSON Schema object to TypeScript
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/schema.ts#L142-L161
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
stringifyArray
function stringifyArray(array: JSONSchemaArray): void { append(`Array<`) indent++ const v = stringifyNode(array.items) indent-- if (v) lines[lines.length - 1] = lines[lines.length - 1] + v + ">" else append(`>`) }
// Convert a JSON Schema array to TypeScript
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/schema.ts#L164-L171
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
visit
function visit(node: JSONSchemaType): void { const n = node as JSONSchemaSimpleType switch (n.type) { case "string": { delete n.uiType break } case "object": { if (n.additionalProperties) throw new Er...
// Recursive function to make the schema strict
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/schema.ts#L318-L352
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
resolveSystemFromTools
function resolveSystemFromTools(prj: Project, tool: string): string[] { const system = prj.scripts.filter( (t) => t.isSystem && t.defTools?.find((to) => to.id.startsWith(tool)) ) const res = system.map(({ id }) => id) return res }
/** * Helper function to resolve tools in the project and return their system IDs. * Finds systems in the project associated with a specific tool. * * @param prj - The project object containing templates and other project-related data. * @param tool - The tool ID to resolve systems for. * @returns An array of sys...
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/systems.ts#L147-L154
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
microsoftTeamsChannelUploadFile
async function microsoftTeamsChannelUploadFile( token: string, channelUrl: string, file: string | WorkspaceFileWithDescription, options?: { folder?: string; disclaimer?: string } & TraceOptions & CancellationOptions ): Promise<MicrosoftTeamsEntity> { const { disclaimer } = options || {} ...
/** * Uploads a file to the files storage of a Microsoft Teams channel. * @param channelUrl Shared channel link in the format https://teams.microsoft.com/l/channel/<channelId>/<channelName>?groupId=<teamId> * @param filename * @returns */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/teams.ts#L69-L152
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
MicrosoftTeamsChannelClient.postMessage
async postMessage( message: string, options?: { /** * File attachments that will be added in the channel folder */ files?: string[] /** * Sets to false to remove AI generated disclaimer */ disclaimer?: bo...
/** * Posts a message with attachments to the channel * @param message * @param options */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/teams.ts#L260-L283
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
templateIdFromFileName
function templateIdFromFileName(filename: string) { return filename .replace(/\.(mjs|ts|js|mts|prompty)$/i, "") .replace(/\.genai$/i, "") .replace(/.*[\/\\]/, "") }
/** * Extracts a template ID from the given filename by removing specific extensions * and directories. * * @param filename - The filename to extract the template ID from. * @returns The extracted template ID. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/template.ts#L23-L28
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
parsePromptTemplateCore
async function parsePromptTemplateCore( filename: string, content: string, prj: Project ) { const r = { id: templateIdFromFileName(filename), title: humanize( host.path.basename(filename).replace(GENAI_ANY_REGEX, "") ), jsSource: content, } as PromptScript...
/** * Core function to parse a prompt template and validate its contents. * * @param filename - The filename of the template. * @param content - The content of the template. * @param prj - The Project object containing diagnostics and other data. * @param finalizer - Finalizer function to perform additional valid...
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/template.ts#L79-L96
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
TestHost.install
static install() { setRuntimeHost(new TestHost()) }
// Static method to set this class as the runtime host
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/testhost.ts#L71-L73
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
TestHost.createUTF8Decoder
createUTF8Decoder(): UTF8Decoder { return new TextDecoder("utf-8") }
// Method to create a UTF-8 decoder
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/testhost.ts#L108-L110
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
TestHost.createUTF8Encoder
createUTF8Encoder(): UTF8Encoder { return new TextEncoder() }
// Method to create a UTF-8 encoder
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/testhost.ts#L113-L115
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
TestHost.projectFolder
projectFolder(): string { return resolve(".") }
// Method to get the current project folder path
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/testhost.ts#L118-L120
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
TestHost.installFolder
installFolder(): string { throw new Error("Method not implemented.") }
// Placeholder for the method to get the installation folder path
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/testhost.ts#L123-L125
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
TestHost.resolvePath
resolvePath(...segments: string[]): string { return this.path.resolve(...segments) }
// Placeholder for path resolution method
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/testhost.ts#L128-L130
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
TestHost.readSecret
readSecret(name: string): Promise<string> { throw new Error("Method not implemented.") }
// Placeholder for reading a secret value
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/testhost.ts#L133-L135
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
TestHost.browse
browse(url: string, options?: BrowseSessionOptions): Promise<BrowserPage> { throw new Error("Method not implemented.") }
// Placeholder for browsing a URL
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/testhost.ts#L138-L140
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
TestHost.getLanguageModelConfiguration
getLanguageModelConfiguration( modelId: string ): Promise<LanguageModelConfiguration> { throw new Error("Method not implemented.") }
// Placeholder for getting language model configuration
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/testhost.ts#L143-L147
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
TestHost.log
log(level: LogLevel, msg: string): void { console[level](msg) }
// Placeholder for logging functionality
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/testhost.ts#L153-L155
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
TestHost.readFile
async readFile(name: string): Promise<Uint8Array> { return new Uint8Array(await readFile(resolve(name))) }
// Method to read a file and return its content as a Uint8Array
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/testhost.ts#L158-L160
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
TestHost.writeFile
async writeFile(name: string, content: Uint8Array): Promise<void> { await writeFile(resolve(name), content) }
// Method to write content to a file
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/testhost.ts#L170-L172
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
TestHost.deleteFile
deleteFile(name: string): Promise<void> { throw new Error("Method not implemented.") }
// Placeholder for file deletion functionality
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/testhost.ts#L175-L177
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
TestHost.findFiles
findFiles(glob: string, options?: {}): Promise<string[]> { throw new Error("Method not implemented.") }
// Placeholder for finding files with a glob pattern
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/testhost.ts#L180-L182
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
TestHost.createDirectory
async createDirectory(name: string): Promise<void> { await ensureDir(name) }
// Placeholder for creating a directory
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/testhost.ts#L185-L187
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
TestHost.deleteDirectory
deleteDirectory(name: string): Promise<void> { throw new Error("Method not implemented.") }
// Placeholder for deleting a directory
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/testhost.ts#L190-L192
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
TestHost.exec
exec( containerId: string, command: string, args: string[], options: ShellOptions ): Promise<ShellOutput> { throw new Error("Method not implemented.") }
// Placeholder for executing a shell command in a container
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/testhost.ts#L195-L202
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
TestHost.container
container( options: ContainerOptions & TraceOptions ): Promise<ContainerHost> { throw new Error("Method not implemented.") }
// Placeholder for creating a container host
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/testhost.ts#L205-L209
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
TestHost.python
python(options?: PythonRuntimeOptions): Promise<PythonRuntime> { throw new Error("python") }
/** * Instantiates a python evaluation environment */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/testhost.ts#L214-L216
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
TestHost.removeContainers
async removeContainers(): Promise<void> {}
// Async method to remove containers
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/core/src/testhost.ts#L219-L219
fde9f9a763333bd67ede17209c4b32ba17df94f2