Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
c01737f
refactor: Change inference-extension to inference-nitro-extension
hiro-v Dec 1, 2023
48fd8de
feat: Init commit for inference engine for openai extension
hiro-v Dec 1, 2023
19637c4
feat: Add nitro engine settings
hiro-v Dec 1, 2023
337da50
fix: Add fs to read and write nitro engine settings
hiro-v Dec 1, 2023
d69f0e3
chore: Update openai engine
hiro-v Dec 1, 2023
6d3bf24
chore: remove gitkeep
hiro-v Dec 1, 2023
a985626
feat: Add openai gpt-3.5 model.json
hiro-v Dec 1, 2023
5f8e2ae
fix: Add engine llama.cpp to local models
hiro-v Dec 1, 2023
68ee669
chore: Remove default nitro.json file
hiro-v Dec 3, 2023
9a18d31
chore: refactor openai file structure
hiro-v Dec 3, 2023
8ab36d7
feat: Add openai engine json reader and writer
hiro-v Dec 3, 2023
56b7786
feat: Add nitro engine json reader and writer
hiro-v Dec 3, 2023
9aca37a
chore: Add fs abstraction for checkFileExists
hiro-v Dec 4, 2023
1bc5fe6
fix: Use Events for init, load, stop models
hiro-v Dec 4, 2023
2c648ca
fix: Update nitro with read/ write for engine.json
hiro-v Dec 4, 2023
486c5b8
fix: Update openai with read/ write for engine.json
hiro-v Dec 4, 2023
22f12cd
fix: Update model.json for Hub with engine nitro/ openai
hiro-v Dec 4, 2023
489c858
chore: models ref event handler
louis-jan Dec 4, 2023
750f09c
fix: update engine field in tiny llama 1.1b
hiro-v Dec 4, 2023
0c838ce
fix: Update event types
hiro-v Dec 4, 2023
a8e33c2
fix: Update engine as enum
hiro-v Dec 4, 2023
a51b206
fix: Add OnModelStopped Event
hiro-v Dec 4, 2023
ffbfaf1
feat: Add Event OnModelStop emission to web
hiro-v Dec 4, 2023
05b9a7b
fix: Delete default oai gpt 3.5 settings
hiro-v Dec 4, 2023
cb60a7c
chore: Change type ModelRuntimeParam to ModelRuntimeParams
hiro-v Dec 4, 2023
fb8729b
fix: Check model engine openai for `Use`
hiro-v Dec 4, 2023
6f55cff
fix: Add model object to MessageRequest
hiro-v Dec 4, 2023
b970e97
chore: Move interface definition location
hiro-v Dec 4, 2023
516e226
chore: Move interface definition location
hiro-v Dec 4, 2023
4f2a3b7
fix: Add dynamic values from engine settings and model params to infe…
hiro-v Dec 4, 2023
16f2ffe
fix: Add dynamic values from engine settings and model params to infe…
hiro-v Dec 4, 2023
0c3e236
fix: Add dynamic values from engine settings and model params
hiro-v Dec 4, 2023
7ed8c31
fix: Add dynamic values from engine settings and model params
hiro-v Dec 4, 2023
06ca414
fix: Change model folder name for openai gpt-3.5-turbo
hiro-v Dec 4, 2023
4266d86
fix: Passing model object instead of model id
hiro-v Dec 4, 2023
f34024a
fix: spreading model.paramters object and update chatCompletion route
hiro-v Dec 4, 2023
a2cf42a
fix: Spreading model.parameters
hiro-v Dec 4, 2023
44bfcaa
fix: Add type def global for nitro extension - inference
hiro-v Dec 4, 2023
3987fdc
feat: Add nitro inference engine stop model handler
hiro-v Dec 4, 2023
6add24c
fix: debugging
hiro-v Dec 5, 2023
bb4b4c5
fix: Fix resend button with model object
hiro-v Dec 5, 2023
28368ee
fix: Add engine nitro
hiro-v Dec 5, 2023
6fe901b
fix: Hub fix for undefined model size
hiro-v Dec 5, 2023
2a853a2
feat: Add openai models
hiro-v Dec 5, 2023
5f3cf2b
fix: Temporary disable model parameters spreading
hiro-v Dec 5, 2023
e1190ec
fix: Enforce openai inference to load settings from openai.json onLoa…
hiro-v Dec 5, 2023
975e971
chore: remove unused console.log
hiro-v Dec 5, 2023
9daee14
fix: Add hack waiting for model loading
hiro-v Dec 5, 2023
6cd4cb9
fix: model gpt json
hiro-v Dec 6, 2023
fbf8ff9
fix: Update lint for engine in ThreadAssistantInfo
hiro-v Dec 6, 2023
1177007
fix: Update code based on comments from @james
hiro-v Dec 7, 2023
ef9dfc9
chore: add ready state to remote models
louis-jan Dec 8, 2023
b939692
chore: stop inference event
louis-jan Dec 8, 2023
f9e73b0
fix: Change base_url to full_url
hiro-v Dec 8, 2023
0ef9a58
fix: BAT for nitro
hiro-v Dec 8, 2023
c32ad0a
fix: small change in nitro bin location
hiro-v Dec 8, 2023
7e3e648
fix: inference extensions small syntax fix
hiro-v Dec 8, 2023
bbffaaf
feat: Added support for Azure OpenAI API
hiro-v Dec 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package-lock.json
core/lib/**

# Nitro binary files
extensions/inference-extension/nitro/*/nitro
extensions/inference-extension/nitro/*/*.exe
extensions/inference-extension/nitro/*/*.dll
extensions/inference-extension/nitro/*/*.metal
extensions/inference-nitro-extension/bin/*/nitro
extensions/inference-nitro-extension/bin/*/*.exe
extensions/inference-nitro-extension/bin/*/*.dll
extensions/inference-nitro-extension/bin/*/*.metal
12 changes: 12 additions & 0 deletions core/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ export enum EventName {
OnMessageResponse = "OnMessageResponse",
/** The `OnMessageUpdate` event is emitted when a message is updated. */
OnMessageUpdate = "OnMessageUpdate",
/** The `OnModelInit` event is emitted when a model inits. */
OnModelInit = "OnModelInit",
/** The `OnModelReady` event is emitted when a model ready. */
OnModelReady = "OnModelReady",
/** The `OnModelFail` event is emitted when a model fails loading. */
OnModelFail = "OnModelFail",
/** The `OnModelStop` event is emitted when a model start to stop. */
OnModelStop = "OnModelStop",
/** The `OnModelStopped` event is emitted when a model stopped ok. */
OnModelStopped = "OnModelStopped",
/** The `OnInferenceStopped` event is emitted when a inference is stopped. */
OnInferenceStopped = "OnInferenceStopped",
}

/**
Expand Down
18 changes: 1 addition & 17 deletions core/src/extensions/inference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,10 @@ import { BaseExtension } from "../extension";
* Inference extension. Start, stop and inference models.
*/
export abstract class InferenceExtension extends BaseExtension {
/**
* Initializes the model for the extension.
* @param modelId - The ID of the model to initialize.
*/
abstract initModel(modelId: string, settings?: ModelSettingParams): Promise<void>;

/**
* Stops the model for the extension.
*/
abstract stopModel(): Promise<void>;

/**
* Stops the streaming inference.
*/
abstract stopInference(): Promise<void>;

/**
* Processes an inference request.
* @param data - The data for the inference request.
* @returns The result of the inference request.
*/
abstract inferenceRequest(data: MessageRequest): Promise<ThreadMessage>;
abstract inference(data: MessageRequest): Promise<ThreadMessage>;
}
35 changes: 18 additions & 17 deletions core/src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,81 +5,82 @@
* @returns {Promise<any>} A Promise that resolves when the file is written successfully.
*/
const writeFile: (path: string, data: string) => Promise<any> = (path, data) =>
global.core.api?.writeFile(path, data);
global.core.api?.writeFile(path, data)

/**
* Checks whether the path is a directory.
* @param path - The path to check.
* @returns {boolean} A boolean indicating whether the path is a directory.
*/
const isDirectory = (path: string): Promise<boolean> =>
global.core.api?.isDirectory(path);
const isDirectory = (path: string): Promise<boolean> => global.core.api?.isDirectory(path)

/**
* Reads the contents of a file at the specified path.
* @param {string} path - The path of the file to read.
* @returns {Promise<any>} A Promise that resolves with the contents of the file.
*/
const readFile: (path: string) => Promise<any> = (path) =>
global.core.api?.readFile(path);
const readFile: (path: string) => Promise<any> = (path) => global.core.api?.readFile(path)
/**
* Check whether the file exists
* @param {string} path
* @returns {boolean} A boolean indicating whether the path is a file.
*/
const exists = (path: string): Promise<boolean> => global.core.api?.exists(path)
/**
* List the directory files
* @param {string} path - The path of the directory to list files.
* @returns {Promise<any>} A Promise that resolves with the contents of the directory.
*/
const listFiles: (path: string) => Promise<any> = (path) =>
global.core.api?.listFiles(path);
const listFiles: (path: string) => Promise<any> = (path) => global.core.api?.listFiles(path)
/**
* Creates a directory at the specified path.
* @param {string} path - The path of the directory to create.
* @returns {Promise<any>} A Promise that resolves when the directory is created successfully.
*/
const mkdir: (path: string) => Promise<any> = (path) =>
global.core.api?.mkdir(path);
const mkdir: (path: string) => Promise<any> = (path) => global.core.api?.mkdir(path)

/**
* Removes a directory at the specified path.
* @param {string} path - The path of the directory to remove.
* @returns {Promise<any>} A Promise that resolves when the directory is removed successfully.
*/
const rmdir: (path: string) => Promise<any> = (path) =>
global.core.api?.rmdir(path);
const rmdir: (path: string) => Promise<any> = (path) => global.core.api?.rmdir(path)
/**
* Deletes a file from the local file system.
* @param {string} path - The path of the file to delete.
* @returns {Promise<any>} A Promise that resolves when the file is deleted.
*/
const deleteFile: (path: string) => Promise<any> = (path) =>
global.core.api?.deleteFile(path);
const deleteFile: (path: string) => Promise<any> = (path) => global.core.api?.deleteFile(path)

/**
* Appends data to a file at the specified path.
* @param path path to the file
* @param data data to append
*/
const appendFile: (path: string, data: string) => Promise<any> = (path, data) =>
global.core.api?.appendFile(path, data);
global.core.api?.appendFile(path, data)

const copyFile: (src: string, dest: string) => Promise<any> = (src, dest) =>
global.core.api?.copyFile(src, dest);
global.core.api?.copyFile(src, dest)

/**
* Reads a file line by line.
* @param {string} path - The path of the file to read.
* @returns {Promise<any>} A promise that resolves to the lines of the file.
*/
const readLineByLine: (path: string) => Promise<any> = (path) =>
global.core.api?.readLineByLine(path);
global.core.api?.readLineByLine(path)

export const fs = {
isDirectory,
writeFile,
readFile,
exists,
listFiles,
mkdir,
rmdir,
deleteFile,
appendFile,
readLineByLine,
copyFile,
};
}
26 changes: 21 additions & 5 deletions core/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export type MessageRequest = {
/** Messages for constructing a chat completion request **/
messages?: ChatCompletionMessage[];

/** Runtime parameters for constructing a chat completion request **/
parameters?: ModelRuntimeParam;
/** Settings for constructing a chat completion request **/
model?: ModelInfo;
};

/**
Expand Down Expand Up @@ -153,7 +153,8 @@ export type ThreadAssistantInfo = {
export type ModelInfo = {
id: string;
settings: ModelSettingParams;
parameters: ModelRuntimeParam;
parameters: ModelRuntimeParams;
engine?: InferenceEngine;
};

/**
Expand All @@ -166,6 +167,17 @@ export type ThreadState = {
error?: Error;
lastMessage?: string;
};
/**
* Represents the inference engine.
* @stored
*/

enum InferenceEngine {
nitro = "nitro",
openai = "openai",
nvidia_triton = "nvidia_triton",
hf_endpoint = "hf_endpoint",
}

/**
* Model type defines the shape of a model object.
Expand Down Expand Up @@ -228,12 +240,16 @@ export interface Model {
/**
* The model runtime parameters.
*/
parameters: ModelRuntimeParam;
parameters: ModelRuntimeParams;

/**
* Metadata of the model.
*/
metadata: ModelMetadata;
/**
* The model engine.
*/
engine: InferenceEngine;
}

export type ModelMetadata = {
Expand Down Expand Up @@ -268,7 +284,7 @@ export type ModelSettingParams = {
/**
* The available model runtime parameters.
*/
export type ModelRuntimeParam = {
export type ModelRuntimeParams = {
temperature?: number;
token_limit?: number;
top_k?: number;
Expand Down
2 changes: 1 addition & 1 deletion docs/openapi/specs/models.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ components:
engine:
type: string
description: "The engine used by the model."
example: "llamacpp"
enum: [nitro, openai, hf_inference]
quantization:
type: string
description: "Quantization parameter of the model."
Expand Down
13 changes: 13 additions & 0 deletions electron/handlers/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ export function handleFsIPCs() {
})
})

/**
* Checks whether a file exists in the user data directory.
* @param event - The event object.
* @param path - The path of the file to check.
* @returns A promise that resolves with a boolean indicating whether the file exists.
*/
ipcMain.handle('exists', async (_event, path: string) => {
return new Promise((resolve, reject) => {
const fullPath = join(userSpacePath, path)
fs.existsSync(fullPath) ? resolve(true) : resolve(false)
})
})

/**
* Writes data to a file in the user data directory.
* @param event - The event object.
Expand Down
6 changes: 6 additions & 0 deletions electron/invokers/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ export function fsInvokers() {
*/
readFile: (path: string) => ipcRenderer.invoke('readFile', path),

/**
* Reads a file at the specified path.
* @param {string} path - The path of the file to read.
*/
exists: (path: string) => ipcRenderer.invoke('exists', path),

/**
* Writes data to a file at the specified path.
* @param {string} path - The path of the file to write to.
Expand Down
3 changes: 0 additions & 3 deletions extensions/inference-extension/download.bat

This file was deleted.

Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
57 changes: 0 additions & 57 deletions extensions/inference-extension/package.json

This file was deleted.

2 changes: 0 additions & 2 deletions extensions/inference-extension/src/@types/global.d.ts

This file was deleted.

3 changes: 3 additions & 0 deletions extensions/inference-nitro-extension/download.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
set /p NITRO_VERSION=<./bin/version.txt
.\node_modules\.bin\download https://github.com/janhq/nitro/releases/download/v%NITRO_VERSION%/nitro-%NITRO_VERSION%-win-amd64-cuda.tar.gz -e --strip 1 -o ./bin/win-cuda && .\node_modules\.bin\download https://github.com/janhq/nitro/releases/download/v%NITRO_VERSION%/nitro-%NITRO_VERSION%-win-amd64.tar.gz -e --strip 1 -o ./bin/win-cpu
57 changes: 57 additions & 0 deletions extensions/inference-nitro-extension/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "@janhq/inference-nitro-extension",
"version": "1.0.0",
"description": "Inference Engine for Nitro Extension, powered by @janhq/nitro, bring a high-performance Llama model inference in pure C++.",
"main": "dist/index.js",
"module": "dist/module.js",
"author": "Jan <[email protected]>",
"license": "AGPL-3.0",
"scripts": {
"build": "tsc -b . && webpack --config webpack.config.js",
"downloadnitro:linux": "NITRO_VERSION=$(cat ./bin/version.txt) && download https://github.com/janhq/nitro/releases/download/v${NITRO_VERSION}/nitro-${NITRO_VERSION}-linux-amd64.tar.gz -e --strip 1 -o ./bin/linux-cpu && chmod +x ./bin/linux-cpu/nitro && chmod +x ./bin/linux-start.sh && download https://github.com/janhq/nitro/releases/download/v${NITRO_VERSION}/nitro-${NITRO_VERSION}-linux-amd64-cuda.tar.gz -e --strip 1 -o ./bin/linux-cuda && chmod +x ./bin/linux-cuda/nitro && chmod +x ./bin/linux-start.sh",
"downloadnitro:darwin": "NITRO_VERSION=$(cat ./bin/version.txt) && download https://github.com/janhq/nitro/releases/download/v${NITRO_VERSION}/nitro-${NITRO_VERSION}-mac-arm64.tar.gz -e --strip 1 -o ./bin/mac-arm64 && chmod +x ./bin/mac-arm64/nitro && download https://github.com/janhq/nitro/releases/download/v${NITRO_VERSION}/nitro-${NITRO_VERSION}-mac-amd64.tar.gz -e --strip 1 -o ./bin/mac-x64 && chmod +x ./bin/mac-x64/nitro",
"downloadnitro:win32": "download.bat",
"downloadnitro": "run-script-os",
"build:publish:darwin": "rimraf *.tgz --glob && npm run build && npm run downloadnitro && ../../.github/scripts/auto-sign.sh && cpx \"bin/**\" \"dist/bin\" && npm pack && cpx *.tgz ../../electron/pre-install",
"build:publish:win32": "rimraf *.tgz --glob && npm run build && npm run downloadnitro && cpx \"bin/**\" \"dist/bin\" && npm pack && cpx *.tgz ../../electron/pre-install",
"build:publish:linux": "rimraf *.tgz --glob && npm run build && npm run downloadnitro && cpx \"bin/**\" \"dist/bin\" && npm pack && cpx *.tgz ../../electron/pre-install",
"build:publish": "run-script-os"
},
"exports": {
".": "./dist/index.js",
"./main": "./dist/module.js"
},
"devDependencies": {
"cpx": "^1.5.0",
"rimraf": "^3.0.2",
"run-script-os": "^1.1.6",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@janhq/core": "file:../../core",
"download-cli": "^1.1.1",
"electron-log": "^5.0.1",
"fetch-retry": "^5.0.6",
"kill-port": "^2.0.1",
"path-browserify": "^1.0.1",
"rxjs": "^7.8.1",
"tcp-port-used": "^1.0.2",
"ts-loader": "^9.5.0",
"ulid": "^2.3.0"
},
"engines": {
"node": ">=18.0.0"
},
"files": [
"dist/*",
"package.json",
"README.md"
],
"bundleDependencies": [
"tcp-port-used",
"kill-port",
"fetch-retry",
"electron-log"
]
}
Loading