/**
* Function to retrieve models from the LM Studio API.
*
* @returns {Promise<Array>} - A promise that resolves to an array of models.
*/
const executeFunction = async () => {
const url = 'http://127.0.0.1:1234/v1/models/';
try {
// Perform the fetch request
const response = await fetch(url, {
method: 'GET'
});
// Check if the response was successful
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData);
}
// Parse and return the response data
const data = await response.json();
return data;
} catch (error) {
console.error('Error retrieving models:', error);
return { error: 'An error occurred while retrieving models.' };
}
};
/**
* Tool configuration for retrieving models from the LM Studio API.
* @type {Object}
*/
const apiTool = {
function: executeFunction,
definition: {
type: 'function',
function: {
name: 'get_models',
description: 'Retrieve models from the LM Studio API.',
parameters: {
type: 'object',
properties: {},
required: []
}
}
}
};
export { apiTool };