Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Multiple inference engines for nitro and openai #814

Merged
merged 58 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: stop inference event
  • Loading branch information
louis-jan authored and hiro-v committed Dec 8, 2023
commit b939692187d67ff5d03c5b8f2f6e28412d2330e1
2 changes: 2 additions & 0 deletions core/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 18,8 @@ export enum EventName {
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>;
}
43 changes: 13 additions & 30 deletions extensions/inference-nitro-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,41 74,17 @@ export default class JanInferenceNitroExtension implements InferenceExtension {
events.on(EventName.OnModelStop, (model: Model) => {
JanInferenceNitroExtension.handleModelStop(model);
});
}

/**
* Stops the model inference.
*/
onUnload(): void {
this.stopModel();
events.on(EventName.OnInferenceStopped, () => {
JanInferenceNitroExtension.handleInferenceStopped(this);
});
}

/**
* Initializes the model with the specified file name.
* @param {string} modelId - The ID of the model to initialize.
* @returns {Promise<void>} A promise that resolves when the model is initialized.
* Stops the model inference.
*/
async initModel(
modelId: string,
settings?: ModelSettingParams
): Promise<void> {}
onUnload(): void {}

/**
* Stops the model.
* @returns {Promise<void>} A promise that resolves when the model is stopped.
*/
async stopModel(): Promise<void> {
return executeOnMain(MODULE, "killSubprocess");
}

/**
* Stops streaming inference.
* @returns {Promise<void>} A promise that resolves when the streaming is stopped.
*/
async stopInference(): Promise<void> {
this.isCancelled = true;
this.controller?.abort();
}

private async writeDefaultEngineSettings() {
try {
Expand Down Expand Up @@ -160,12 136,19 @@ export default class JanInferenceNitroExtension implements InferenceExtension {
}
}

private static async handleInferenceStopped(
instance: JanInferenceNitroExtension
) {
instance.isCancelled = true;
instance.controller?.abort();
}

/**
* Makes a single response inference request.
* @param {MessageRequest} data - The data for the inference request.
* @returns {Promise<any>} A promise that resolves with the inference response.
*/
async inferenceRequest(data: MessageRequest): Promise<ThreadMessage> {
async inference(data: MessageRequest): Promise<ThreadMessage> {
const timestamp = Date.now();
const message: ThreadMessage = {
thread_id: data.threadId,
Expand Down
39 changes: 11 additions & 28 deletions extensions/inference-openai-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 71,16 @@ export default class JanInferenceOpenAIExtension implements InferenceExtension {
events.on(EventName.OnModelStop, (model: OpenAIModel) => {
JanInferenceOpenAIExtension.handleModelStop(model);
});
events.on(EventName.OnInferenceStopped, () => {
JanInferenceOpenAIExtension.handleInferenceStopped(this);
});
}

/**
* Stops the model inference.
*/
onUnload(): void {}

/**
* Initializes the model with the specified file name.
* @param {string} modelId - The ID of the model to initialize.
* @returns {Promise<void>} A promise that resolves when the model is initialized.
*/
async initModel(
modelId: string,
settings?: ModelSettingParams
): Promise<void> {
return;
}

static async writeDefaultEngineSettings() {
try {
const engineFile = join(
Expand All @@ -110,27 101,13 @@ export default class JanInferenceOpenAIExtension implements InferenceExtension {
console.error(err);
}
}
/**
* Stops the model.
* @returns {Promise<void>} A promise that resolves when the model is stopped.
*/
async stopModel(): Promise<void> {}

/**
* Stops streaming inference.
* @returns {Promise<void>} A promise that resolves when the streaming is stopped.
*/
async stopInference(): Promise<void> {
this.isCancelled = true;
this.controller?.abort();
}

/**
* Makes a single response inference request.
* @param {MessageRequest} data - The data for the inference request.
* @returns {Promise<any>} A promise that resolves with the inference response.
*/
async inferenceRequest(data: MessageRequest): Promise<ThreadMessage> {
async inference(data: MessageRequest): Promise<ThreadMessage> {
const timestamp = Date.now();
const message: ThreadMessage = {
thread_id: data.threadId,
Expand Down Expand Up @@ -168,7 145,6 @@ export default class JanInferenceOpenAIExtension implements InferenceExtension {
JanInferenceOpenAIExtension.writeDefaultEngineSettings();
// Todo: Check model list with API key
events.emit(EventName.OnModelReady, model);
// events.emit(EventName.OnModelFail, model)
}
}

Expand All @@ -179,6 155,13 @@ export default class JanInferenceOpenAIExtension implements InferenceExtension {
events.emit(EventName.OnModelStopped, model);
}

private static async handleInferenceStopped(
instance: JanInferenceOpenAIExtension
) {
instance.isCancelled = true;
instance.controller?.abort();
}

/**
* Handles a new message request by making an inference request and emitting events.
* Function registered in event manager, should be static to avoid binding issues.
Expand Down
5 changes: 2 additions & 3 deletions web/screens/Chat/MessageToolbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 30,8 @@ const MessageToolbar = ({ message }: { message: ThreadMessage }) => {
const { resendChatMessage } = useSendChatMessage()

const onStopInferenceClick = async () => {
await extensionManager
.get<InferenceExtension>(ExtensionType.Inference)
?.stopInference()
events.emit(EventName.OnInferenceStopped, {})

setTimeout(() => {
events.emit(EventName.OnMessageUpdate, {
...message,
Expand Down
20 changes: 3 additions & 17 deletions web/screens/ExploreModels/ExploreModelItemHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 55,9 @@ const ExploreModelItemHeader: React.FC<Props> = ({ model, onClick, open }) => {

const isDownloaded = downloadedModels.find((md) => md.id === model.id) != null

let downloadButton;

if (model.engine === 'openai') {
downloadButton = (
<Button onClick={() => onDownloadClick()}>
Use
</Button>
);
} else if (model.engine === 'nitro') {
downloadButton = (
<Button onClick={() => onDownloadClick()}>
{model.metadata.size
? `Download (${toGigabytes(model.metadata.size)})`
: 'Download'}
</Button>
);
}
let downloadButton = (
<Button onClick={() => onDownloadClick()}>Download</Button>
)

const onUseModelClick = () => {
startModel(model.id)
Expand Down