-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6200cce
commit 25057f5
Showing
14 changed files
with
262 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
cortex-js/src/infrastructure/commanders/constants/huggingface.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
cortex-js/src/infrastructure/commanders/embeddings.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { | ||
CommandRunner, | ||
InquirerService, | ||
Option, | ||
SubCommand, | ||
} from 'nest-commander'; | ||
import { ModelsUsecases } from '@/usecases/models/models.usecases'; | ||
import { ModelStat, PSCliUsecases } from './usecases/ps.cli.usecases'; | ||
import { ChatCliUsecases } from './usecases/chat.cli.usecases'; | ||
import { inspect } from 'util'; | ||
|
||
interface EmbeddingCommandOptions { | ||
encoding_format?: string; | ||
input?: string; | ||
dimensions?: number; | ||
} | ||
|
||
@SubCommand({ | ||
name: 'embeddings', | ||
description: 'Creates an embedding vector representing the input text.', | ||
}) | ||
export class EmbeddingCommand extends CommandRunner { | ||
constructor( | ||
private readonly chatCliUsecases: ChatCliUsecases, | ||
private readonly modelsUsecases: ModelsUsecases, | ||
private readonly psCliUsecases: PSCliUsecases, | ||
private readonly inquirerService: InquirerService, | ||
) { | ||
super(); | ||
} | ||
async run(_input: string[], options: EmbeddingCommandOptions): Promise<void> { | ||
let modelId = _input[0]; | ||
// First attempt to get message from input or options | ||
let input: string | string[] = options.input ?? _input.splice(1); | ||
|
||
// Check for model existing | ||
if (!modelId || !(await this.modelsUsecases.findOne(modelId))) { | ||
// Model ID is not provided | ||
// first input might be message input | ||
input = _input ?? options.input; | ||
// If model ID is not provided, prompt user to select from running models | ||
const models = await this.psCliUsecases.getModels(); | ||
if (models.length === 1) { | ||
modelId = models[0].modelId; | ||
} else if (models.length > 0) { | ||
modelId = await this.modelInquiry(models); | ||
} else { | ||
console.error('Model ID is required'); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
return this.chatCliUsecases | ||
.embeddings(modelId, input) | ||
.then((res) => | ||
inspect(res, { showHidden: false, depth: null, colors: true }), | ||
) | ||
.then(console.log) | ||
.catch(console.error); | ||
} | ||
|
||
modelInquiry = async (models: ModelStat[]) => { | ||
const { model } = await this.inquirerService.inquirer.prompt({ | ||
type: 'list', | ||
name: 'model', | ||
message: 'Select running model to chat with:', | ||
choices: models.map((e) => ({ | ||
name: e.modelId, | ||
value: e.modelId, | ||
})), | ||
}); | ||
return model; | ||
}; | ||
|
||
@Option({ | ||
flags: '-i, --input <input>', | ||
description: | ||
'Input text to embed, encoded as a string or array of tokens. To embed multiple inputs in a single request, pass an array of strings or array of token arrays.', | ||
}) | ||
parseInput(value: string) { | ||
return value; | ||
} | ||
|
||
@Option({ | ||
flags: '-e, --encoding_format <encoding_format>', | ||
description: | ||
'Encoding format for the embeddings. Supported formats are float and int.', | ||
}) | ||
parseEncodingFormat(value: string) { | ||
return value; | ||
} | ||
|
||
@Option({ | ||
flags: '-d, --dimensions <dimensions>', | ||
description: | ||
'The number of dimensions the resulting output embeddings should have. Only supported in some models.', | ||
}) | ||
parseDimensionsFormat(value: string) { | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { defaultCortexCppHost, defaultCortexCppPort } from 'constant'; | ||
|
||
// CORTEX CPP | ||
export const CORTEX_CPP_EMBEDDINGS_URL = ( | ||
host: string = defaultCortexCppHost, | ||
port: number = defaultCortexCppPort, | ||
) => `http://${host}:${port}/inferences/server/embedding`; | ||
|
||
export const CORTEX_CPP_PROCESS_DESTROY_URL = ( | ||
host: string = defaultCortexCppHost, | ||
port: number = defaultCortexCppPort, | ||
) => `http://${host}:${port}/processmanager/destroy`; | ||
|
||
export const CORTEX_CPP_HEALTH_Z_URL = ( | ||
host: string = defaultCortexCppHost, | ||
port: number = defaultCortexCppPort, | ||
) => `http://${host}:${port}/healthz`; | ||
|
||
// INITIALIZATION | ||
export const CORTEX_RELEASES_URL = | ||
'https://api.github.com/repos/janhq/cortex/releases'; | ||
|
||
export const CUDA_DOWNLOAD_URL = | ||
'https://catalog.jan.ai/dist/cuda-dependencies/<version>/<platform>/cuda.tar.gz'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
export const HUGGING_FACE_TREE_REF_URL = ( | ||
repo: string, | ||
tree: string, | ||
path: string, | ||
) => `https://huggingface.co/janhq/${repo}/resolve/${tree}/${path}`; | ||
|
||
export const HUGGING_FACE_DOWNLOAD_FILE_MAIN_URL = ( | ||
author: string, | ||
repo: string, | ||
fileName: string, | ||
) => `https://huggingface.co/${author}/${repo}/resolve/main/${fileName}`; | ||
|
||
export const HUGGING_FACE_REPO_URL = (author: string, repo: string) => | ||
`https://huggingface.co/${author}/${repo}`; | ||
|
||
export const HUGGING_FACE_REPO_MODEL_API_URL = (repo: string) => | ||
`https://huggingface.co/api/models/${repo}`; | ||
|
||
export const AllQuantizations = [ | ||
'Q3_K_S', | ||
'Q3_K_M', | ||
'Q3_K_L', | ||
'Q4_K_S', | ||
'Q4_K_M', | ||
'Q5_K_S', | ||
'Q5_K_M', | ||
'Q4_0', | ||
'Q4_1', | ||
'Q5_0', | ||
'Q5_1', | ||
'IQ2_XXS', | ||
'IQ2_XS', | ||
'Q2_K', | ||
'Q2_K_S', | ||
'Q6_K', | ||
'Q8_0', | ||
'F16', | ||
'F32', | ||
'COPY', | ||
]; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.