Sim-Ph is a powerful Node.js library for interacting with the SimSimi API. It provides seamless integration for chat and teach functionalities, complete with a backup API for enhanced reliability.
- 🗨️ Sim: Chat with SimSimi to get AI-generated responses.
- 📚 Teach: Teach SimSimi custom responses for specific queries.
- 🔧 Backup Server: Automatically switches to a backup Server if the primary Server fails.
Install the package via npm:
npm install sim-ph
Require the sim-ph
library in your project:
const { sim, teach } = require('sim-ph');
Interact with the SimSimi chat API using the sim
function:
const { sim } = require('sim-ph');
async function chatWithSim() {
const query = 'hi';
try {
const response = await sim(query);
console.log('SimSimi says:', response);
} catch (error) {
console.error('Error:', error.message);
}
}
chatWithSim();
Output Example:
SimSimi says: Hello! How can I assist you today?
Teach SimSimi custom responses using the teach
function:
const { teach } = require('sim-ph');
async function teachSim() {
const ask = 'how are you?';
const ans = 'I am doing great!';
try {
const response = await teach(ask, ans);
console.log('Teach Response:', response);
} catch (error) {
console.error('Error:', error.message);
}
}
teachSim();
Output Example:
Teach Response: { status: 'success', message: 'Sim has learned a new response!' }
If the primary API (https://simsimi-api-pro.onrender.com
) fails, the library automatically switches to the backup API (https://simsimi.gleeze.com
). This ensures smooth operation.
Handle errors gracefully when both APIs fail:
const { sim } = require('sim-ph');
async function chatWithSim() {
try {
const response = await sim('hello');
console.log(response);
} catch (error) {
console.error('Both primary and backup APIs failed:', error.message);
}
}
chatWithSim();
Output Example (if both APIs fail):
Both primary and backup APIs failed: Both primary and backup APIs failed
Feel free to fork this repository and submit pull requests for improvements or new features.
MIT License. See LICENSE for details.