ContextoModel is an advanced, context-aware language model with function-calling capabilities, conversation history tracking, and stream-based response generation. It uses n-gram based prediction to generate contextually appropriate responses and can be trained on various contexts.
- Context-aware language modeling
- N-gram based prediction with variable length
- Conversation history tracking
- Stream-based response generation
- Function calling integration
- Debug mode for detailed logging
- Easy to train and use
- Save and load model states
- Clone this repository or copy the
ContextoModel.js
file into your project. - Ensure you have Node.js installed on your system.
- Install the required dependencies:
npm install
const ContextoModel = require('./path/to/ContextoModel');
const model = new ContextoModel(3, ['casual', 'formal'], 5);
This creates a new model with trigrams (n=3), two contexts: 'casual' and 'formal', and a history size of 5.
model.train("This is a sample sentence.", 'casual');
const response = model.generateResponse('casual', "This is a", 20);
console.log(response);
const responseGenerator = model.generateResponseStream('casual', "This is a", 20);
for (const partialResponse of responseGenerator) {
console.log(partialResponse);
}
model.registerFunction('getTime', () => new Date().toLocaleTimeString(), 'Get current time');
// Saving
model.save('model.json');
// Loading
model.load('model.json');
model.debugMode = true;
Creates a new ContextoModel instance.
n
: The n-gram sizecontexts
: An array of context nameshistorySize
: Number of previous interactions to consider
Trains the model on the given text in the specified context.
Predicts the next word given a context and a phrase.
Registers a function that can be called during response generation.
Generates a complete response given a context and an input phrase.
Generates a response stream, yielding each part of the response as it's generated.
Filters the generated response to avoid repetition and improve coherence.
Saves the current model state to a file.
Loads a model state from a file.
Contributions are welcome! Please feel free to submit a Pull Request.
If you have any questions or need help with using ContextoModel, please open an issue in the GitHub repository.