Giter Site home page Giter Site logo

textbase's Introduction

Textbase python library

Documentation

✨ Textbase is a framework for building chatbots using NLP and ML. ✨

Just implement the on_message function in main.py and Textbase will take care of the rest :)

Since it is just Python you can use whatever models, libraries, vector databases and APIs you want.

Coming soon:

Demo Deploy GIF

Installation

Make sure you have python version >=3.9.0, it's always good to follow the docs 👈🏻

1. Through pip

pip install textbase-client

2. Local installation

Clone the repository and install the dependencies using Poetry (you might have to install Poetry first).

For proper details see here

git clone https://github.com/cofactoryai/textbase
cd textbase
poetry shell
poetry install

Start development server

If you're using the default template, remember to set the OpenAI API key in main.py.

Run the following command:

  • if installed locally
    poetry run python textbase/textbase_cli.py test
  • if installed through pip
    textbase-client test

Response:

Path to the main.py file: examples/openai-bot/main.py # You can create a main.py by yourself and add that path here. NOTE: The path should not be in quotes

Now go to the link in blue color which is shown on the CLI and you will be able to chat with your bot! Local UI

Other commands have been mentioned in the documentation website. Have a look 😃!

Contributions

Contributions are welcome! Please open an issue or create a pull request. Follow our contributions guide for more details!

textbase's People

Contributors

ankushdutt avatar bharatchhabraai avatar deepto98 avatar eltociear avatar haleshot avatar harshs1611 avatar jahanvir avatar kausmeows avatar kaustubh-cf avatar missusk avatar mitanshudodia avatar neerajsati avatar nini0309 avatar sammycofactory avatar shephinphilip avatar sidharth-sethi-cofactoryai avatar silasalberti avatar thenakulgupta-backup avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

textbase's Issues

LLM Integration: implement Claude 2.0 in `models.py`

What do we need?

If you go to the textbase/models.py, there exists classes for various models like OpenAI (GPT3.5/4), Dalle-2, Huggingface inference API etc that can be used for various tasks from text generation to chatbots and many more.

Claude 2.0 is another such promising LLM that we would very much like to integrate in textbase.

Just make another class in there like:

class Claude:
    def generate():
        pass
  • You can refer to the Python Client SDK mentioned in the documentation. Keep in mind that you might have to restructure the response in the format that textbase accepts. 👉🏻 Reference

Refer to the code in models.py, play around with it after setting things up locally.

  • After implementing the model, import that and test it by making a main.py, just like the one for OpenAI.
    Reference -> docs.textbase.ai

Docs

  • After writing the code make sure you update the corresponding docs as well in here.
  • Create a file named claude-bot.md and add relevant information there.

Let us know if you face any issues!

Resource not found error

The server is up and running on my local, but when I try to interact with the chatbot I am getting the following error.
"filepath_of_main.py/main.py that is expected to define function doesn't exist" on the command line.

When I inspected the frontend page . I am getting the following error.
POST http://localhost:8080/sendMessage net::ERR_CONNECTION_REFUSED.

I am also attaching the screenshot.

Screenshot (1)
Screenshot (2)

Lacking sentiment analysis

The textbase project lacked sentiment analysis, which is a critical feature for effective chatbot interactions. Without sentiment analysis, the chatbots were unable to respond appropriately to the emotional content of user input, leading to generic and often unsuitable responses for negative or neutral inputs.

Stable Diffusion integration

Requirement

Just like the the Dalle Bot we also want to integrate Stable Diffusion for image generation techniques. Replicate provides an API through which we can do this.

Have a look at this demo here on how to use the API.
In the textbase/models.py you'll see a class for DallE which returns the URL of the generated image.

It appears on the UI something like this-
Screenshot 2023-09-25 at 3 30 58 AM

To make sure that this is rendered properly in the frontend, in the response inside main.py we will use the Image class as done in DallE

return {
    "messages": [Image(url=bot_response)],
    "state": state
}

Add a StableDiffusion class in the models.py and add the logic there.

On the same line, I guess replicate must give a URL for the image generated. We can use a similar approach in that as well.
Make sure to make another directory as textbase/examples/stable-diffusion after testing that things are working fine and also add the respective docs.

Refer to docs.textbase.ai for setting up the project locally

Network Error

When I am deploying chatbot at my end It is showing network error.
I created a new chatbot at my end but results are same getting same message "Network Error".

Example Template Addition: Add a other popular Chatbot Template in the template section.

Issue Overview

The Textbase AI page has three chatbot templates. Among them, ChatGPT 3.5 is the most popular one. However, it lacks other popular chatbot templates like Bard AI, CloudE AI 2 and many more.

Screenshots

image

Tasks

  • Addition of a new model in Textbase/Textbase/Model.
  • Addition of a new example in the Textbase/Examples.

I would like to add the a chatbot template for Bard AI in the codebase if this issue is relevant.

add --port flag in test command so that user can change the port from 8080 to something else

What's happening right now?

in textbase_cli.py
Screenshot 2023-09-03 at 4 02 52 PM
there is only one flag called --path for taking in the path to your main.py file.

What we want is a way that by default the port for the command functions_framework --target=on_message --source={dir} --debug in line number 29 be 8080 (which is already the default case), but it should be changeable to any other other lets say 8081.

So-

  • User can enter the port via a --port flag or if he doesn't it takes it as 8080.
  • Now in utils/server.py we are using localhost:8080 directly here. the PORT 4000 is of frontend UI and 8080 is for backend and these two communicate together.
Screenshot 2023-09-03 at 4 06 05 PM

Now in this file also, you'll have to get the port from the textbase_cli.py file which should be 8080 by default and the new one if user changed it, so that the new URL with new port is displayed in the line 36.
Screenshot 2023-09-03 at 4 08 09 PM

Figure out a way to do this and create a PR with proper working screenshots in local setup 🚀

add GIFs in the example section of doc

Requirements

If you go to the example section in the docs website it contains basic starter code for various types of bots like a DALL-E bot that can return images for the text input. To make it more visually intuitive of the final working we want to include a GIF for the final bot interface with a small conversation to show the responses.

For example if you go to the Installation section and scroll down you'll see some gifs to show how to locally setup the cli code. In the same way we want GIFs for all the example bots- OpenAI, Palm, Mimicking, DALL-E.

Issue: Shortening Open API Usage and Enhancing Customer Friendliness for Off-Topic Queries

Description:
The current version of our chatbot heavily relies on the Open API for responding to user queries. However, there is an opportunity to optimize the Open API usage and enhance customer friendliness when users ask questions that are not directly related to the bot's core functionality. To address this, we propose a solution that utilizes a pre-trained chatbot dataset and employs techniques such as TF-IDF, cosine similarity search, and sentiment analysis. This approach aims to provide more accurate and contextually relevant responses to user queries, ultimately improving user satisfaction and reducing dependence on Open API calls.

Proposed Solution:

Dataset Utilization: We have obtained a pre-trained chatbot dataset from Kaggle, which contains a diverse range of user interactions. This dataset will be transformed into a CSV file format to facilitate easy access and retrieval of chatbot responses.

Response Handling:

Legal Check: The system will first evaluate whether the user query pertains to legal matters. If it does, the query will be directed to the GPT model to provide a relevant response.

Off-Topic Queries: If the query is not related to legal topics, the system will:

Utilize TF-IDF and cosine similarity to compare the user query with entries in the CSV file.
If a suitable match is found, the corresponding response will be retrieved from the CSV file and provided to the user.
In case of a mismatch, the system will perform sentiment analysis on the query.
Sentiment Analysis:

If the sentiment analysis indicates a positive or neutral sentiment, the system will prompt the user for further clarification with a response like "Please provide more context or details."
If the sentiment analysis identifies a negative sentiment, the system will respond with "I'm having trouble understanding your query. Could you please provide more information?"
Benefits:

Reduced reliance on Open API calls, leading to potential cost savings.
Enhanced customer experience by providing contextually relevant responses.
Improved user engagement through tailored responses to off-topic queries.
Decreased frustration for users encountering difficulties in communicating their queries.
Possibility of gathering more accurate user information through follow-up prompts.

Update the readme

-[ ] changes > add link in title :
-[ ] changes > add YT video Installation:
-[ ] changes > add links coming soon:
-[ ] changes > main.py file

Empty Input on Send Button Click

Issue Overview:

When the user clicks on the "Send" button without providing any input, the application encounters an unexpected behavior. Instead of gracefully handling the empty input scenario, it currently proceeds with the interaction, which may lead to unintended outcomes. This issue aims to address this problem and improve the user experience.

Expected Behavior:

The application should handle the case of an empty input field when the user clicks the "Send" button. It should prompt the user to provide valid input and prevent any unintended actions based on empty inputs.

Proposed Solution:

To enhance the user experience and avoid issues arising from empty inputs, the application should implement client-side validation for the input field. When the user clicks the "Send" button, the application should check if the input field is empty. If it is, a user-friendly message or a tooltip should be displayed, prompting the user to enter valid input. This approach ensures that the user is aware of the requirement to provide meaningful input and helps prevent unnecessary interactions with the chatbot.

Steps to Reproduce:

Open the application.
Type nothing in the input field.
Click the "Send" button.
Current Outcome:

The application proceeds with the interaction despite an empty input, potentially leading to undesired behavior or empty responses from the chatbot.

Expected Outcome:

Upon clicking the "Send" button with an empty input field, the application should display a prompt or tooltip informing the user to enter valid input before proceeding with the interaction.

Getting package error while running test

I have installed the packages as given in the ReadMe document.

poetry run python textbase/textbase_cli.py test --path main.py

But I get "textbase" is not a package error. Can someone please help?

File "C:\Users\HEMA S\Python_Projects\textbase\textbase\textbase_cli.py", line 23, in test
server_path = importlib.resources.files('textbase').joinpath('utils', 'server.py')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\HEMA S\AppData\Local\Programs\Python\Python311\Lib\importlib\resources_common.py", line 22, in files
return from_package(get_package(package))
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\HEMA S\AppData\Local\Programs\Python\Python311\Lib\importlib\resources_common.py", line 55, in get_package
raise TypeError(f'{package!r} is not a package')
TypeError: 'textbase' is not a package

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.