The GGUF SPECIFICATIONS object contains a list of model names and their corresponding specifications, while the GGUF_INSTRUCTIONS object contains a list of model names and their corresponding instructions or behaviors. The instructions for specific models, such as 'Code', provide templates for the response, while others are set to 'void 0' indicating no specific instruction is defined.
npm run import -- "select llm"
const GGUF_SPECIFICATIONS = {
'Meta': 'Meta-Llama-3.1-8B-Instruct-Q6_K_L.gguf',
'Default': 'Meta-Llama-3.1-8B-Instruct-Q6_K_L.gguf',
'DeepSeek': 'DeepSeek-R1-Distill-Llama-8B-Q6_K.gguf',
'Llama': 'Meta-Llama-3-70B-Instruct-Q5_K_M.gguf',
'Qwen': 'Qwen2.5-14B-Instruct-1M-Q6_K_L.gguf',
'Code': 'DeepSeek-R1-Distill-Llama-70B-Q5_K_S.gguf',
'Mistral': 'Mistral-Small-24B-Instruct-2501-Q6_K_L.gguf',
'Mesh': 'LLaMA-Mesh-Q6_K_L.gguf',
'Meta-Llama-3.1-8B-Instruct-Q6_K_L': 'Meta-Llama-3.1-8B-Instruct-Q6_K_L.gguf',
'DeepSeek-R1-Distill-Llama-8B-Q6_K': 'DeepSeek-R1-Distill-Llama-8B-Q6_K.gguf',
'Meta-Llama-3-70B-Instruct-Q5_K_M': 'Meta-Llama-3-70B-Instruct-Q5_K_M.gguf',
'Qwen2.5-14B-Instruct-1M-Q6_K_L': 'Qwen2.5-14B-Instruct-1M-Q6_K_L.gguf',
'DeepSeek-R1-Distill-Llama-70B-Q5_K_S': 'DeepSeek-R1-Distill-Llama-70B-Q5_K_S.gguf',
'Mistral-Small-24B-Instruct-2501-Q6_K_L': 'Mistral-Small-24B-Instruct-2501-Q6_K_L.gguf',
'LLaMA-Mesh-Q6_K_L': 'LLaMA-Mesh-Q6_K_L.gguf'
}
const GGUF_INSTRUCTIONS = {
'Meta': void 0,
'Default': void 0,
'DeepSeek': void 0,
'Llama': void 0,
'Qwen': void 0,
'Code': '```markdown\n# You are a\n##helpful coding module\nnamed ' + (process.env.MODEL_NAME || 'Llama') + ' that responds to every request using beautifully crafted `markdown`. Return only a single code block in the specified language without reasoning or instructions if requested.\n</think>\n...```\n',
'Mistral': void 0,
'Mesh': 'You are an LLM that responds with high quality detailed OBJ format models',
'Meta-Llama-3.1-8B-Instruct-Q6_K_L': void 0,
'DeepSeek-R1-Distill-Llama-8B-Q6_K': void 0,
'Meta-Llama-3-70B-Instruct-Q5_K_M': void 0,
'Qwen2.5-14B-Instruct-1M-Q6_K_L': void 0,
'DeepSeek-R1-Distill-Llama-70B-Q5_K_S': '```markdown\n# You are a\n##helpful coding module\nnamed ' + (process.env.MODEL_NAME || 'Llama') + ' that responds to every request using beautifully crafted `markdown`. Return only a single code block in the specified language without reasoning or instructions if requested.\n</think>\n...```\n',
'Mistral-Small-24B-Instruct-2501-Q6_K_L': void 0,
'LLaMA-Mesh-Q6_K_L': 'You are an LLM that responds with high quality detailed OBJ format models'
}
async function promptModel(temperature, initialChatHistory, session, prompt) {
let result = await session.prompt(prompt, {
temperature: temperature,
onTextChunk: function (text) {
process.stdout.write(text)
}
})
session.setChatHistory(initialChatHistory);
return result
}
// TODO: call llm rpc service with selectModel?
const modelSessions = {}
const modelInit = {}
async function selectModel(model, temperature) {
const {createSession} = await importer.import("llama vision")
if(typeof model == 'string') {
let modelNames = Object.keys(GGUF_SPECIFICATIONS)
for(let i = 0; i < modelNames.length; i++) {
if(modelNames[i].match(model)) {
let gguf = GGUF_SPECIFICATIONS[modelNames[i]]
if(!modelSessions[modelNames[i]]) {
modelSessions[modelNames[i]] = await createSession(gguf, GGUF_INSTRUCTIONS[modelNames[i]])
modelInit[modelNames[i]] = modelSessions[modelNames[i]].getChatHistory()
}
return promptModel.bind(null, temperature, modelInit[modelNames[i]], modelSessions[modelNames[i]])
}
}
}
throw new Error('Model not found: ' + model)
}
module.exports = selectModel
// Import the required modules
const importer = require('./importer');
// Define the model specifications and instructions
const GGUF_SPECIFICATIONS = {
'Meta': 'Meta-Llama-3.1-8B-Instruct-Q6_K_L.gguf',
'Default': 'Meta-Llama-3.1-8B-Instruct-Q6_K_L.gguf',
'DeepSeek': 'DeepSeek-R1-Distill-Llama-8B-Q6_K.gguf',
'Llama': 'Meta-Llama-3-70B-Instruct-Q5_K_M.gguf',
'Qwen': 'Qwen2.5-14B-Instruct-1M-Q6_K_L.gguf',
'Code': 'DeepSeek-R1-Distill-Llama-70B-Q5_K_S.gguf',
'Mistral': 'Mistral-Small-24B-Instruct-2501-Q6_K_L.gguf',
'Mesh': 'LLaMA-Mesh-Q6_K_L.gguf',
};
const GGUF_INSTRUCTIONS = {
'Meta': void 0,
'Default': void 0,
'DeepSeek': void 0,
'Llama': void 0,
'Qwen': void 0,
'Code': (modelName) => `# You are a helpful coding module named ${modelName} that responds to every request using beautifully crafted `markdown`. Return only a single code block in the specified language without reasoning or instructions if requested.`,
'Mistral': void 0,
'Mesh': (modelName) => `You are an LLM named ${modelName} that responds with high quality detailed OBJ format models.`,
};
// Define the function to prompt the model
async function promptModel(temperature, chatHistory, session, prompt) {
const result = await session.prompt(prompt, {
temperature,
onTextChunk: (text) => process.stdout.write(text),
});
session.setChatHistory(chatHistory);
return result;
}
// Define the function to select a model
async function selectModel(modelName, temperature) {
const createSession = await importer.import('llama vision').createSession;
// Check if the model name is a string
if (typeof modelName ==='string') {
// Find the matching model specification
const modelSpecification = Object.keys(GGUF_SPECIFICATIONS).find((modelName) => modelName.match(modelName));
if (!modelSpecification) {
throw new Error(`Model not found: ${modelName}`);
}
// Create a new session or reuse an existing one
const session = modelSessions[modelSpecification] || (await createSession(GGUF_SPECIFICATIONS[modelSpecification], GGUF_INSTRUCTIONS[modelSpecification](modelName)));
// Initialize the chat history
const chatHistory = session.getChatHistory();
// Return the prompt model function
return async (prompt = '') => {
await promptModel(temperature, chatHistory, session, prompt);
return session.getChatHistory();
};
}
throw new Error('Invalid model name:'+ modelName);
}
// Export the selectModel function
module.exports = selectModel;
GGUF SPECIFICATIONS AND INSTRUCTIONS
This code defines two objects: GGUF_SPECIFICATIONS
and GGUF_INSTRUCTIONS
.
This object contains a list of model specifications, where each key is a model name and the corresponding value is a string representing the model's specification.
const GGUF_SPECIFICATIONS = {
'Meta': 'Meta-Llama-3.1-8B-Instruct-Q6_K_L.gguf',
//...
}
This object contains a list of model instructions, where each key is a model name and the corresponding value is a string representing the model's behavior or response.
const GGUF_INSTRUCTIONS = {
'Meta': void 0, // no instruction specified for 'Meta'
'Default': void 0, // no instruction specified for 'Default'
'Code': '```markdown\n#...```', // specific instruction for 'Code'
//...
}
NOTABLE POINTS
process.env.MODEL_NAME
variable is used to retrieve the model name from the environment variables, and defaults to 'Llama'
if not found.void 0
, indicating that no specific instruction is defined for those models.