sim-ph

1.0.1 • Public • Published

🐥 Sim-Ph

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.

Follow on Facebook


Features

  • 🗨️ 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.

Installation

Install the package via npm:

npm install sim-ph  

🚀 Usage

📥 Importing the Library

Require the sim-ph library in your project:

const { sim, teach } = require('sim-ph');  

💬 Sim API Example

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 API Example

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!' }  

🔄 Fallback API

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.


⚠️ Error Handling

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  

🤝 Contributing

Feel free to fork this repository and submit pull requests for improvements or new features.


📜 License

MIT License. See LICENSE for details.


👤 Author

Jerome Jamis
Facebook

Package Sidebar

Install

npm i sim-ph

Weekly Downloads

13

Version

1.0.1

License

MIT

Unpacked Size

7.45 kB

Total Files

7

Last publish

Collaborators

  • jerome84575