repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
jan
github_2023
janhq
typescript
JSONEngineManagementExtension.getLatestReleasedEngine
async getLatestReleasedEngine(name: InferenceEngine, platform?: string) { return this.queue.add(() => ky .get(`${API_URL}/v1/engines/${name}/releases/latest`) .json<EngineReleased[]>() .then((e) => platform ? e.filter((r) => r.name.includes(platform)) : e ) ) as P...
/** * @param name - Inference engine name. * @param platform - Optional to sort by operating system. macOS, linux, windows. * @returns A Promise that resolves to an array of latest released engine by version. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/engine-management-extension/src/index.ts#L114-L123
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JSONEngineManagementExtension.installEngine
async installEngine(name: string, engineConfig: EngineConfig) { return this.queue.add(() => ky .post(`${API_URL}/v1/engines/${name}/install`, { json: engineConfig }) .then((e) => e) ) as Promise<{ messages: string }> }
/** * @param name - Inference engine name. * @returns A Promise that resolves to intall of engine. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/engine-management-extension/src/index.ts#L129-L135
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JSONEngineManagementExtension.addRemoteEngine
async addRemoteEngine(engineConfig: EngineConfig) { return this.queue.add(() => ky.post(`${API_URL}/v1/engines`, { json: engineConfig }).then((e) => e) ) as Promise<{ messages: string }> }
/** * Add a new remote engine * @returns A Promise that resolves to intall of engine. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/engine-management-extension/src/index.ts#L141-L145
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JSONEngineManagementExtension.uninstallEngine
async uninstallEngine(name: InferenceEngine, engineConfig: EngineConfig) { return this.queue.add(() => ky .delete(`${API_URL}/v1/engines/${name}/install`, { json: engineConfig }) .then((e) => e) ) as Promise<{ messages: string }> }
/** * @param name - Inference engine name. * @returns A Promise that resolves to unintall of engine. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/engine-management-extension/src/index.ts#L151-L157
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JSONEngineManagementExtension.addRemoteModel
async addRemoteModel(model: Model) { return this.queue.add(() => ky.post(`${API_URL}/v1/models/add`, { json: model }).then((e) => e) ) }
/** * Add a new remote model * @param model - Remote model object. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/engine-management-extension/src/index.ts#L163-L167
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JSONEngineManagementExtension.getDefaultEngineVariant
async getDefaultEngineVariant(name: InferenceEngine) { return this.queue.add(() => ky .get(`${API_URL}/v1/engines/${name}/default`) .json<{ messages: string }>() .then((e) => e) ) as Promise<DefaultEngineVariant> }
/** * @param name - Inference engine name. * @returns A Promise that resolves to an object of default engine. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/engine-management-extension/src/index.ts#L173-L180
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JSONEngineManagementExtension.setDefaultEngineVariant
async setDefaultEngineVariant( name: InferenceEngine, engineConfig: EngineConfig ) { return this.queue.add(() => ky .post(`${API_URL}/v1/engines/${name}/default`, { json: engineConfig }) .then((e) => e) ) as Promise<{ messages: string }> }
/** * @body variant - string * @body version - string * @returns A Promise that resolves to set default engine. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/engine-management-extension/src/index.ts#L187-L196
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JSONEngineManagementExtension.updateEngine
async updateEngine(name: InferenceEngine, engineConfig?: EngineConfig) { return this.queue.add(() => ky .post(`${API_URL}/v1/engines/${name}/update`, { json: engineConfig }) .then((e) => e) ) as Promise<{ messages: string }> }
/** * @returns A Promise that resolves to update engine. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/engine-management-extension/src/index.ts#L201-L207
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JSONEngineManagementExtension.healthz
async healthz(): Promise<void> { return ky .get(`${API_URL}/healthz`, { retry: { limit: 20, delay: () => 500, methods: ['get'] }, }) .then(() => {}) }
/** * Do health check on cortex.cpp * @returns */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/engine-management-extension/src/index.ts#L213-L219
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JSONEngineManagementExtension.updateDefaultEngine
async updateDefaultEngine() { try { const variant = await this.getDefaultEngineVariant( InferenceEngine.cortex_llamacpp ) const installedEngines = await this.getInstalledEngines( InferenceEngine.cortex_llamacpp ) if ( !installedEngines.some( (e) => e.n...
/** * Update default local engine * This is to use built-in engine variant in case there is no default engine set */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/engine-management-extension/src/index.ts#L225-L261
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JSONEngineManagementExtension.populateDefaultRemoteEngines
async populateDefaultRemoteEngines() { const engines = await this.getEngines() if ( !Object.values(engines) .flat() .some((e) => e.type === 'remote') ) { await Promise.all( DEFAULT_REMOTE_ENGINES.map(async (engine) => { const { id, ...data } = engine ...
/** * This is to populate default remote engines in case there is no customized remote engine setting */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/engine-management-extension/src/index.ts#L266-L305
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
gpuRunMode
const gpuRunMode = (settings?: GpuSetting): string => { if (process.platform === 'darwin') // MacOS now has universal binaries return '' if (!settings) return '' return settings.vulkan === true || settings.run_mode === 'cpu' ? '' : 'cuda' }
/** * The GPU runMode that will be set - either 'vulkan', 'cuda', or empty for cpu. * @param settings * @returns */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/engine-management-extension/src/node/index.ts#L16-L24
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
os
const os = (): string => { return process.platform === 'win32' ? 'windows-amd64' : process.platform === 'darwin' ? process.arch === 'arm64' ? 'mac-arm64' : 'mac-amd64' : 'linux-amd64' }
/** * The OS & architecture that the current process is running on. * @returns win, mac-x64, mac-arm64, or linux */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/engine-management-extension/src/node/index.ts#L30-L38
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
cudaVersion
const cudaVersion = (settings?: GpuSetting): '11-7' | '12-0' | undefined => { const isUsingCuda = settings?.vulkan !== true && settings?.run_mode === 'gpu' && !os().includes('mac') if (!isUsingCuda) return undefined return settings?.cuda?.version === '11' ? '11-7' : '12-0' }
/** * The CUDA version that will be set - either '11-7' or '12-0'. * @param settings * @returns */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/engine-management-extension/src/node/index.ts#L45-L53
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
cpuInstructions
const cpuInstructions = async (): Promise<string> => { if (process.platform === 'darwin') return '' const child = fork(path.join(__dirname, './cpuInfo.js')) // Path to the child process file return new Promise((resolve, reject) => { child.on('message', (cpuInfo?: string) => { resolve(cpuInfo ?? 'noavx...
/** * The CPU instructions that will be set - either 'avx512', 'avx2', 'avx', or 'noavx'. * @returns */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/engine-management-extension/src/node/index.ts#L59-L82
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
engineVariant
const engineVariant = async (gpuSetting?: GpuSetting): Promise<string> => { const cpuInstruction = await cpuInstructions() log(`[CORTEX]: CPU instruction: ${cpuInstruction}`) let engineVariant = [ os(), gpuSetting?.vulkan ? 'vulkan' : gpuRunMode(gpuSetting) !== 'cuda' ? // CPU mode - s...
/** * Find which variant to run based on the current platform. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/engine-management-extension/src/node/index.ts#L87-L109
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
symlinkEngines
const symlinkEngines = async () => { const sourceEnginePath = path.join( appResourcePath(), 'shared', 'engines', 'cortex.llamacpp' ) const symlinkEnginePath = path.join( getJanDataFolderPath(), 'engines', 'cortex.llamacpp' ) const variantFolders = await readdir(sourceEnginePath) ...
/** * Create symlink to each variant for the default bundled version */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/engine-management-extension/src/node/index.ts#L114-L148
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanInferenceCortexExtension.onLoad
async onLoad() { const models = MODELS as Model[] this.registerModels(models) super.onLoad() // Register Settings this.registerSettings(SETTINGS) this.n_parallel = Number(await this.getSetting<string>(Settings.n_parallel, '4')) ?? 4 this.cont_batching = await this.getSetting<boolea...
/** * Subscribes to events emitted by the @janhq/core package. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/inference-cortex-extension/src/index.ts#L86-L123
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanInferenceCortexExtension.healthz
private async healthz(): Promise<void> { return ky .get(`${CORTEX_API_URL}/healthz`, { retry: { limit: 20, delay: () => 500, methods: ['get'], }, }) .then(() => {}) }
/** * Do health check on cortex.cpp * @returns */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/inference-cortex-extension/src/index.ts#L236-L246
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanInferenceCortexExtension.clean
private async clean(): Promise<any> { return ky .delete(`${CORTEX_API_URL}/processmanager/destroy`, { timeout: 2000, // maximum 2 seconds retry: { limit: 0, }, }) .catch(() => { // Do nothing }) }
/** * Clean cortex processes * @returns */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/inference-cortex-extension/src/index.ts#L252-L263
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanInferenceCortexExtension.subscribeToEvents
private subscribeToEvents() { this.queue.add( () => new Promise<void>((resolve) => { this.socket = new WebSocket(`${CORTEX_SOCKET_URL}/events`) this.socket.addEventListener('message', (event) => { const data = JSON.parse(event.data) const transferred = dat...
/** * Subscribe to cortex.cpp websocket events */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/inference-cortex-extension/src/index.ts#L268-L340
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
getModelFilePath
const getModelFilePath = async ( model: Model & { file_path?: string }, file: string ): Promise<string> => { // Symlink to the model file if ( !model.sources[0]?.url.startsWith('http') && (await fs.existsSync(model.sources[0].url)) ) { return model.sources[0]?.url } if (model.file_path) { ...
/// Legacy
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/inference-cortex-extension/src/index.ts#L344-L359
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
run
function run(systemInfo?: SystemInformation): Promise<any> { log(`[CORTEX]:: Spawning cortex subprocess...`) return new Promise<void>(async (resolve, reject) => { let gpuVisibleDevices = systemInfo?.gpuSetting?.gpus_in_use.join(',') ?? '' let binaryName = `cortex-server${process.platform === 'win32' ? '.ex...
/** * Spawns a Nitro subprocess. * @returns A promise that resolves when the Nitro subprocess is started. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/inference-cortex-extension/src/node/index.ts#L19-L63
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
dispose
function dispose() { watchdog?.terminate() }
/** * Every module should have a dispose function * This will be called when the extension is unloaded and should clean up any resources * Also called when app is closed */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/inference-cortex-extension/src/node/index.ts#L70-L72
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
CortexAPI.getModel
getModel(model: string): Promise<any> { return this.queue.add(() => ky .get(`${API_URL}/v1/models/${model}`) .json() .then((e) => this.transformModel(e)) ) }
/** * Fetches a model detail from cortex.cpp * @param model * @returns */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/cortex.ts#L43-L50
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
CortexAPI.getModels
getModels(): Promise<Model[]> { return this.queue .add(() => ky.get(`${API_URL}/v1/models?limit=-1`).json<Data>()) .then((e) => typeof e === 'object' ? e.data.map((e) => this.transformModel(e)) : [] ) }
/** * Fetches models list from cortex.cpp * @param model * @returns */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/cortex.ts#L57-L63
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
CortexAPI.pullModel
pullModel(model: string, id?: string, name?: string): Promise<void> { return this.queue.add(() => ky .post(`${API_URL}/v1/models/pull`, { json: { model, id, name } }) .json() .catch(async (e) => { throw (await e.response?.json()) ?? e }) .then() ) }
/** * Pulls a model from HuggingFace via cortex.cpp * @param model * @returns */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/cortex.ts#L70-L80
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
CortexAPI.importModel
importModel( model: string, modelPath: string, name?: string, option?: string ): Promise<void> { return this.queue.add(() => ky .post(`${API_URL}/v1/models/import`, { json: { model, modelPath, name, option }, }) .json() .catch((e) => console.debug(e)...
/** * Imports a model from a local path via cortex.cpp * @param model * @returns */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/cortex.ts#L87-L102
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
CortexAPI.deleteModel
deleteModel(model: string): Promise<void> { return this.queue.add(() => ky.delete(`${API_URL}/v1/models/${model}`).json().then() ) }
/** * Deletes a model from cortex.cpp * @param model * @returns */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/cortex.ts#L109-L113
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
CortexAPI.updateModel
updateModel(model: Partial<Model>): Promise<void> { return this.queue.add(() => ky .patch(`${API_URL}/v1/models/${model.id}`, { json: { ...model } }) .json() .then() ) }
/** * Update a model in cortex.cpp * @param model * @returns */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/cortex.ts#L120-L127
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
CortexAPI.cancelModelPull
cancelModelPull(model: string): Promise<void> { return this.queue.add(() => ky .delete(`${API_URL}/v1/models/pull`, { json: { taskId: model } }) .json() .then() ) }
/** * Cancel model pull in cortex.cpp * @param model * @returns */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/cortex.ts#L134-L141
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
CortexAPI.getModelStatus
async getModelStatus(model: string): Promise<boolean> { return this.queue .add(() => ky.get(`${API_URL}/v1/models/status/${model}`)) .then((e) => true) .catch(() => false) }
/** * Check model status * @param model */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/cortex.ts#L147-L152
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
CortexAPI.getSources
async getSources(): Promise<ModelSource[]> { return this.queue .add(() => ky.get(`${API_URL}/v1/models/sources`).json<Data>()) .then((e) => (typeof e === 'object' ? (e.data as ModelSource[]) : [])) .catch(() => []) }
/** * Get model sources * @param model */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/cortex.ts#L159-L164
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
CortexAPI.addSource
async addSource(source: string): Promise<any> { return this.queue.add(() => ky.post(`${API_URL}/v1/models/sources`, { json: { source, }, }) ) }
/** * Add a model source * @param model */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/cortex.ts#L170-L178
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
CortexAPI.deleteSource
async deleteSource(source: string): Promise<any> { return this.queue.add(() => ky.delete(`${API_URL}/v1/models/sources`, { json: { source, }, }) ) }
/** * Delete a model source * @param model */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/cortex.ts#L184-L192
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
CortexAPI.healthz
healthz(): Promise<void> { return ky .get(`${API_URL}/healthz`, { retry: { limit: 20, delay: () => 500, methods: ['get'], }, }) .then(() => {}) }
/** * Do health check on cortex.cpp * @returns */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/cortex.ts#L199-L209
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
CortexAPI.configs
configs(body: { [key: string]: any }): Promise<void> { return this.queue.add(() => ky.patch(`${API_URL}/v1/configs`, { json: body }).then(() => {}) ) }
/** * Configure model pull options * @param body */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/cortex.ts#L215-L219
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
CortexAPI.transformModel
private transformModel(model: any) { model.parameters = { ...extractInferenceParams(model), ...model.parameters, ...model.inference_params, } model.settings = { ...extractModelLoadParams(model), ...model.settings, } model.metadata = model.metadata ?? { tags: [], ...
/** * TRansform model to the expected format (e.g. parameters, settings, metadata) * @param model * @returns */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/cortex.ts#L226-L241
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanModelExtension.onLoad
async onLoad() { this.registerSettings(SETTINGS) // Configure huggingface token if available const huggingfaceToken = await this.getSetting<string>( Settings.huggingfaceToken, undefined ) if (huggingfaceToken) this.cortexAPI.configs({ huggingface_token: huggingfaceToken }) //...
/** * Called when the extension is loaded. * @override */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/index.ts#L36-L49
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanModelExtension.onSettingUpdate
onSettingUpdate<T>(key: string, value: T): void { if (key === Settings.huggingfaceToken) { this.cortexAPI.configs({ huggingface_token: value }) } }
/** * Subscribe to settings update and make change accordingly * @param key * @param value */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/index.ts#L56-L60
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanModelExtension.onUnload
async onUnload() {}
/** * Called when the extension is unloaded. * @override */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/index.ts#L66-L66
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanModelExtension.pullModel
async pullModel(model: string, id?: string, name?: string): Promise<void> { if (id) { const model: Model = ModelManager.instance().get(id) // Clip vision model - should not be handled by cortex.cpp // TensorRT model - should not be handled by cortex.cpp if ( model && (model.e...
/** * Downloads a machine learning model. * @param model - The model to download. * @returns A Promise that resolves when the model is downloaded. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/index.ts#L73-L90
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanModelExtension.cancelModelPull
async cancelModelPull(model: string): Promise<void> { if (model) { const modelDto: Model = ModelManager.instance().get(model) // Clip vision model - should not be handled by cortex.cpp // TensorRT model - should not be handled by cortex.cpp if ( modelDto && (modelDto.engine =...
/** * Cancels the download of a specific machine learning model. * * @param {string} model - The ID of the model whose download is to be cancelled. * @returns {Promise<void>} A promise that resolves when the download has been cancelled. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/index.ts#L98-L118
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanModelExtension.deleteModel
async deleteModel(model: string): Promise<void> { return this.cortexAPI .deleteModel(model) .catch((e) => console.debug(e)) .finally(async () => { // Delete legacy model files await deleteModelFiles(model).catch((e) => console.debug(e)) }) }
/** * Deletes a pulled model * @param model - The model to delete * @returns A Promise that resolves when the model is deleted. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/index.ts#L125-L133
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanModelExtension.getModels
async getModels(): Promise<Model[]> { /** * Legacy models should be supported */ let legacyModels = await scanModelsFolder() /** * Here we are filtering out the models that are not imported * and are not using llama.cpp engine */ var toImportModels = legacyModels.filter( ...
/** * Gets all pulled models * @returns A Promise that resolves with an array of all models. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/index.ts#L139-L221
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanModelExtension.updateModel
async updateModel(model: Partial<Model>): Promise<Model> { return this.cortexAPI ?.updateModel(model) .then(() => this.cortexAPI!.getModel(model.id)) }
/** * Update a pulled model metadata * @param model - The metadata of the model */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/index.ts#L227-L231
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanModelExtension.importModel
async importModel( model: string, modelPath: string, name?: string, option?: OptionType ): Promise<void> { return this.cortexAPI.importModel(model, modelPath, name, option) }
/** * Import an existing model file * @param model * @param optionType */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/index.ts#L238-L245
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanModelExtension.getSources
async getSources(): Promise<ModelSource[]> { const sources = await this.cortexAPI.getSources() return sources.concat( DEFAULT_MODEL_SOURCES.filter((e) => !sources.some((x) => x.id === e.id)) ) }
/** * Get model sources * @param model */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/index.ts#L252-L257
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanModelExtension.addSource
async addSource(source: string): Promise<any> { return this.cortexAPI.addSource(source) }
/** * Add a model source * @param model */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/index.ts#L263-L265
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanModelExtension.deleteSource
async deleteSource(source: string): Promise<any> { return this.cortexAPI.deleteSource(source) }
/** * Delete a model source * @param model */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/index.ts#L271-L273
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanModelExtension.isModelLoaded
async isModelLoaded(model: string): Promise<boolean> { return this.cortexAPI.getModelStatus(model) }
/** * Check model status * @param model */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/index.ts#L280-L282
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanModelExtension.configurePullOptions
async configurePullOptions(options: { [key: string]: any }): Promise<any> { return this.cortexAPI.configs(options).catch((e) => console.debug(e)) }
/** * Configure pull options such as proxy, headers, etc. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/index.ts#L287-L289
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanModelExtension.handleDesktopEvents
handleDesktopEvents() { if (window && window.electronAPI) { window.electronAPI.onFileDownloadUpdate( async (_event: string, state: DownloadState | undefined) => { if (!state) return state.downloadState = 'downloading' events.emit(DownloadEvent.onFileDownloadUpdate, state)...
/** * Handle download state from main app */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/index.ts#L294-L316
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
extractFileName
function extractFileName(url: string, fileExtension: string): string { if (!url) return fileExtension const extractedFileName = url.split('/').pop() const fileName = extractedFileName.toLowerCase().endsWith(fileExtension) ? extractedFileName : extractedFileName + fileExtension return fileName }
/** * try to retrieve the download file name from the source url */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/model-extension/src/legacy/download.ts#L97-L105
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanMonitoringExtension.onLoad
async onLoad() { // Register extension settings this.registerSettings(SETTINGS) const logEnabled = await this.getSetting<boolean>(Settings.logEnabled, true) const logCleaningInterval = parseInt( await this.getSetting<string>(Settings.logCleaningInterval, '120000') ) // Register File Logge...
/** * Called when the extension is loaded. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/monitoring-extension/src/index.ts#L22-L41
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanMonitoringExtension.onUnload
onUnload(): void { // Register File Logger provided by this extension executeOnMain(NODE, 'unregisterLogger') }
/** * Called when the extension is unloaded. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/monitoring-extension/src/index.ts#L54-L57
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanMonitoringExtension.getGpuSetting
async getGpuSetting(): Promise<GpuSetting | undefined> { return executeOnMain(NODE, 'getGpuConfig') }
/** * Returns the GPU configuration. * @returns A Promise that resolves to an object containing the GPU configuration. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/monitoring-extension/src/index.ts#L63-L65
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanMonitoringExtension.getResourcesInfo
getResourcesInfo(): Promise<any> { return executeOnMain(NODE, 'getResourcesInfo') }
/** * Returns information about the system resources. * @returns A Promise that resolves to an object containing information about the system resources. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/monitoring-extension/src/index.ts#L71-L73
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanMonitoringExtension.getCurrentLoad
getCurrentLoad(): Promise<any> { return executeOnMain(NODE, 'getCurrentLoad') }
/** * Returns information about the current system load. * @returns A Promise that resolves to an object containing information about the current system load. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/monitoring-extension/src/index.ts#L79-L81
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
JanMonitoringExtension.getOsInfo
getOsInfo(): Promise<OperatingSystemInfo> { return executeOnMain(NODE, 'getOsInfo') }
/** * Returns information about the OS * @returns */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/monitoring-extension/src/index.ts#L87-L89
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
checkFileExistenceInPaths
const checkFileExistenceInPaths = (file: string, paths: string[]): boolean => { return paths.some((p) => existsSync(path.join(p, file))) }
/** * Check if file exists in paths */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/monitoring-extension/src/node/index.ts#L282-L284
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
updateCudaExistence
const updateCudaExistence = async ( data: GpuSetting = DEFAULT_SETTINGS ): Promise<GpuSetting> => { let filesCuda12: string[] let filesCuda11: string[] let paths: string[] let cudaVersion: string = '' if (process.platform === 'win32') { filesCuda12 = ['cublas64_12.dll', 'cudart64_12.dll', 'cublasLt64_1...
/** * Validate cuda for linux and windows */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/extensions/monitoring-extension/src/node/index.ts#L289-L353
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
attachMediaListener
function attachMediaListener( query: MediaQueryList, callback: MediaQueryCallback ) { try { query.addEventListener('change', callback) return () => query.removeEventListener('change', callback) } catch (e) { query.addListener(callback) return () => query.removeListener(callback) } }
/** * Older versions of Safari (shipped withCatalina and before) do not support addEventListener on matchMedia * https://stackoverflow.com/questions/56466261/matchmedia-addlistener-marked-as-deprecated-addeventlistener-equivalent * */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/joi/src/hooks/useMediaQuery/index.ts#L13-L24
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
ExtensionManager.register
register<T extends BaseExtension>(name: string, extension: T) { // Register for naming use this.extensions.set(name, extension) // Register AI Engines if ('provider' in extension && typeof extension.provider === 'string') { this.engines.set( extension.provider as unknown as string, ...
/** * Registers an extension. * @param extension - The extension to register. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/web/extension/ExtensionManager.ts#L22-L33
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
ExtensionManager.get
get<T extends BaseExtension>(type: ExtensionTypeEnum): T | undefined { return this.getAll().findLast((e) => e.type() === type) as T | undefined }
/** * Retrieves a extension by its type. * @param type - The type of the extension to retrieve. * @returns The extension, if found. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/web/extension/ExtensionManager.ts#L40-L42
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
ExtensionManager.getByName
getByName(name: string): BaseExtension | undefined { return this.extensions.get(name) as BaseExtension | undefined }
/** * Retrieves a extension by its type. * @param type - The type of the extension to retrieve. * @returns The extension, if found. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/web/extension/ExtensionManager.ts#L49-L51
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
ExtensionManager.getAll
getAll(): BaseExtension[] { return Array.from(this.extensions.values()) }
/** * Retrieves a extension by its type. * @param type - The type of the extension to retrieve. * @returns The extension, if found. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/web/extension/ExtensionManager.ts#L58-L60
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
ExtensionManager.getEngine
getEngine<T extends AIEngine>(engine: string): T | undefined { return this.engines.get(engine) as T | undefined }
/** * Retrieves a extension by its type. * @param engine - The engine name to retrieve. * @returns The extension, if found. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/web/extension/ExtensionManager.ts#L67-L69
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
ExtensionManager.load
load() { this.listExtensions().forEach((ext) => { ext.onLoad() }) }
/** * Loads all registered extension. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/web/extension/ExtensionManager.ts#L74-L78
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
ExtensionManager.unload
unload() { this.listExtensions().forEach((ext) => { ext.onUnload() }) }
/** * Unloads all registered extensions. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/web/extension/ExtensionManager.ts#L83-L87
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
ExtensionManager.listExtensions
listExtensions() { return [...this.extensions.values()] }
/** * Retrieves a list of all registered extensions. * @returns An array of extensions. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/web/extension/ExtensionManager.ts#L93-L95
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
ExtensionManager.getActive
async getActive(): Promise<Extension[]> { const res = await window.core?.api?.getActiveExtensions() if (!res || !Array.isArray(res)) return [] const extensions: Extension[] = res.map( (ext: any) => new Extension( ext.url, ext.name, ext.productName, ext....
/** * Retrieves a list of all registered extensions. * @returns An array of extensions. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/web/extension/ExtensionManager.ts#L101-L117
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
ExtensionManager.activateExtension
async activateExtension(extension: Extension) { // Import class const extensionUrl = window.electronAPI ? extension.url : extension.url.replace( 'extension://', `${window.core?.api?.baseApiUrl ?? ''}/extensions/` ) await import(/* webpackIgnore: true */ extensionUrl)....
/** * Register a extension with its class. * @param {Extension} extension extension object as provided by the main process. * @returns {void} */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/web/extension/ExtensionManager.ts#L124-L153
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
ExtensionManager.registerActive
async registerActive() { // Get active extensions const activeExtensions = await this.getActive() // Activate all await Promise.all( activeExtensions.map((ext: Extension) => this.activateExtension(ext)) ) }
/** * Registers all active extensions. * @returns {void} */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/web/extension/ExtensionManager.ts#L159-L166
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
ExtensionManager.install
async install(extensions: any[]) { if (typeof window === 'undefined') { return } const res = await window.core?.api?.installExtension(extensions) if (res.cancelled) return false return res.map(async (ext: any) => { const extension = new Extension(ext.name, ext.url, ext.active) awai...
/** * Install a new extension. * @param {Array.<installOptions | string>} extensions A list of NPM specifiers, or installation configuration objects. * @returns {Promise.<Array.<Extension> | false>} extension as defined by the main process. Has property cancelled set to true if installation was cancelled in th...
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/web/extension/ExtensionManager.ts#L173-L184
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
ExtensionManager.uninstall
uninstall(extensions: string[], reload = true) { if (typeof window === 'undefined') { return } return window.core?.api?.uninstallExtension(extensions, reload) }
/** * Uninstall provided extensions * @param {Array.<string>} extensions List of names of extensions to uninstall. * @param {boolean} reload Whether to reload all renderers after updating the extensions. * @returns {Promise.<boolean>} Whether uninstalling the extensions was successful. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/web/extension/ExtensionManager.ts#L192-L197
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
fetchExtensionData
async function fetchExtensionData<T>( extension: EngineManagementExtension | null, method: (extension: EngineManagementExtension) => Promise<T> ): Promise<T> { if (!extension) { throw new Error('Extension not found') } return method(extension) }
// fetcher function
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/web/hooks/useEngineManagement.ts#L36-L44
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
addModelSource
const addModelSource = async (source: string) => { try { // Call the extension's method return await extension?.addSource(source) } catch (error) { console.error('Failed to install engine variant:', error) throw error } }
/** * Add a new model source * @returns A Promise that resolves to intall of engine. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/web/hooks/useModelSource.ts#L48-L56
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
deleteModelSource
const deleteModelSource = async (source: string) => { try { // Call the extension's method return await extension?.deleteSource(source) } catch (error) { console.error('Failed to install engine variant:', error) throw error } }
/** * Delete a new model source * @returns A Promise that resolves to intall of engine. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/web/hooks/useModelSource.ts#L62-L70
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
useModels
const useModels = () => { const setDownloadedModels = useSetAtom(downloadedModelsAtom) const setExtensionModels = useSetAtom(configuredModelsAtom) const getData = useCallback(() => { const getDownloadedModels = async () => { const localModels = (await getModels()) .map((e) => ({ ...e,...
/** * useModels hook - Handles the state of models * It fetches the downloaded models, configured models and default model from Model Extension * and updates the atoms accordingly. */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/web/hooks/useModels.ts#L29-L118
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
clearLogs
const clearLogs = async () => { try { await fs.rm(`file://logs`) } catch (err) { console.error('Error clearing logs: ', err) } toaster({ title: 'Logs cleared', description: 'All logs have been cleared.', type: 'success', }) }
/** * Clear logs * @returns */
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/web/screens/Settings/Privacy/index.tsx#L20-L32
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
getTextFromNode
function getTextFromNode(node: { type: string value: any children: any[] }): string { if (node.type === 'text') { return node.value } else if (node.children) { return node.children.map(getTextFromNode).join('') } return '' }
// Helper function to extract text recursively from children
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/web/screens/Thread/ThreadCenterPanel/TextMessage/MarkdownTextMessage.tsx#L46-L57
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
EventEmitter.emit
public emit(eventName: string, args: any): void { if (!this.handlers.has(eventName)) { return } const handlers = this.handlers.get(eventName) handlers?.forEach((handler) => { handler(args) }) }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/web/services/eventsService.ts#L31-L41
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
MessageRequestBuilder.pushMessage
pushMessage( message: string, base64Blob: string | undefined, fileInfo?: FileInfo ) { if (base64Blob && fileInfo?.type === 'pdf') return this.addDocMessage(message, fileInfo?.name) else if (base64Blob && fileInfo?.type === 'image') { return this.addImageMessage(message, base64Blob) ...
// Chainable
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/web/utils/messageRequestBuilder.ts#L45-L63
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
MessageRequestBuilder.addSystemMessage
addSystemMessage(message: string | undefined) { if (!message || message.trim() === '') return this this.messages = [ { role: ChatCompletionRole.System, content: message, }, ...this.messages, ] return this }
// Chainable
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/web/utils/messageRequestBuilder.ts#L66-L76
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
MessageRequestBuilder.addDocMessage
addDocMessage(prompt: string, name?: string) { const message: ChatCompletionMessage = { role: ChatCompletionRole.User, content: [ { type: ChatCompletionMessageContentType.Text, text: prompt, } as ChatCompletionMessageContentText, { type: ChatCompleti...
// Chainable
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/web/utils/messageRequestBuilder.ts#L79-L97
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
jan
github_2023
janhq
typescript
MessageRequestBuilder.addImageMessage
addImageMessage(prompt: string, base64: string) { const message: ChatCompletionMessage = { role: ChatCompletionRole.User, content: [ { type: ChatCompletionMessageContentType.Text, text: prompt, } as ChatCompletionMessageContentText, { type: ChatCompl...
// Chainable
https://github.com/janhq/jan/blob/f8f19af8c54989ad9f58e108bf93c08ef6beb03b/web/utils/messageRequestBuilder.ts#L100-L119
f8f19af8c54989ad9f58e108bf93c08ef6beb03b
genaiscript
github_2023
microsoft
typescript
visit
const visit = ( header: string, parent: Command, commands: readonly Command[] ) => { commands.forEach((c) => { // Construct and print the command's header in Markdown console.log( `\n${header} \`${[parent?.name(), c.name()].filter((c) => c).joi...
/** * Recursive function to visit all commands and their subcommands. * Processes each command and generates corresponding Markdown documentation. * * @param header - The Markdown header level as a string. * @param parent - The parent command, which may be undefined for top-level commands. ...
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/cli/src/help.ts#L31-L51
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
resolveScriptsConnectionInfo
async function resolveScriptsConnectionInfo( scripts: ModelConnectionOptions[], options?: { token?: boolean } ): Promise<ModelConnectionInfo[]> { const models: Record<string, ModelConnectionOptions> = {} // Deduplicate model connection options for (const script of scripts) { const conn: Mod...
/** * Resolves connection information for script templates by deduplicating model options. * @param scripts - Array of model connection options to resolve. * @param options - Configuration options, including whether to show tokens. * @returns A promise that resolves to an array of model connection information. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/cli/src/info.ts#L53-L75
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
wrapArgs
function wrapArgs(color: number, args: any[]) { if ( consoleColors && args.every((e) => typeof e == "string" || typeof e == "number") ) { // if it's just strings & numbers use the coloring const msg = args.join(" ") return [wrapColor(color, msg)] } else { // o...
/** * Wraps arguments for logging, applying color if appropriate. * Combines string and number arguments into a single colored message. * @param color - The color code * @param args - The arguments to process * @returns An array with either color wrapped or original arguments */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/cli/src/log.ts#L92-L104
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
NodeHost.python
python( options?: PythonRuntimeOptions & TraceOptions ): Promise<PythonRuntime> { return createPythonRuntime(options) }
/** * Instantiates a python evaluation environment */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/cli/src/nodehost.ts#L443-L447
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
NodeHost.container
async container( options: ContainerOptions & TraceOptions ): Promise<ContainerHost> { return await this.containers.startContainer(options) }
/** * Starts a container to execute sandboxed code * @param options */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/cli/src/nodehost.ts#L517-L521
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
NodeHost.select
async select(message: string, options: string[]): Promise<string> { return await this.userInputQueue.add(() => shellSelect(message, options) ) }
/** * Asks the user to select between options * @param message question to ask * @param options options to select from */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/cli/src/nodehost.ts#L536-L540
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
NodeHost.input
async input(message: string): Promise<string> { return await this.userInputQueue.add(() => shellInput(message)) }
/** * Asks the user to input a text * @param message message to ask */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/cli/src/nodehost.ts#L546-L548
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
NodeHost.confirm
async confirm(message: string): Promise<boolean> { return await this.userInputQueue.add(() => shellConfirm(message)) }
/** * Asks the user to confirm a message * @param message message to ask */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/cli/src/nodehost.ts#L554-L556
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
BrowserManager.constructor
constructor() {}
// Stores active pages
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/cli/src/playwright.ts#L25-L25
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
BrowserManager.init
private async init() { const p = await import("playwright") if (!p) throw new Error("playwright installation not completed") return p }
/** * Imports the Playwright module if available. * @returns The imported Playwright module. * @throws Error if the Playwright module is not available. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/cli/src/playwright.ts#L32-L36
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
BrowserManager.installDependencies
private async installDependencies(vendor: string) { const res = await runtimeHost.exec( undefined, "npx", [ "--yes", `playwright@${PLAYWRIGHT_VERSION}`, "install", "--with-deps", vendor, ...
/** * Installs Playwright dependencies for a specific vendor. * Uses the runtimeHost to execute the necessary commands. * @param vendor The vendor for which to install Playwright. * @throws Error if the installation fails. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/cli/src/playwright.ts#L44-L60
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
BrowserManager.launchBrowser
private async launchBrowser(options?: BrowserOptions): Promise<Browser> { const { browser = PLAYWRIGHT_DEFAULT_BROWSER, ...rest } = options || {} try { const playwright = await this.init() return await playwright[browser].launch(rest) } catch { logVerbose("try...
/** * Launches a browser instance with the given options. * Attempts installation if the browser launch fails initially. * @param options Optional settings for the browser launch. * @returns A promise that resolves to a Browser instance. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/cli/src/playwright.ts#L68-L79
fde9f9a763333bd67ede17209c4b32ba17df94f2
genaiscript
github_2023
microsoft
typescript
BrowserManager.stopAndRemove
async stopAndRemove() { const browsers = this._browsers.slice(0) const contexts = this._contexts.slice(0) const pages = this._pages.slice(0) this._browsers = [] this._contexts = [] this._pages = [] // Close all active pages for (const page of pages) { ...
/** * Stops all browser instances and closes all pages. * Handles any errors that occur during the closure. */
https://github.com/microsoft/genaiscript/blob/fde9f9a763333bd67ede17209c4b32ba17df94f2/packages/cli/src/playwright.ts#L85-L126
fde9f9a763333bd67ede17209c4b32ba17df94f2