"Yorozuya" is a fictional establishment in the Japanese manga and anime series "Gintama", operated by the protagonist, Gintoki Sakata. Yorozuya is a business that handles various tasks and requests, ranging from finding lost items to resolving disputes.
The project was named "Yorozuya" because it was hoped that the LineBot would make it easier for Line users to access OpenAPI to solve problems, and also to commemorate the end of Gintama.
- ๐ Table of Contents
- ๐ Overview
- ๐ Getting Started
- ๐จโ๐ซ Demo
- ๐ Note
- ๐ Next
- ๐ License
The yuwen-yorozuya-linebot project is a feature-rich chat interface built on the LINE platform that enables seamless and interactive communication. This project has undergone a significant transformation, adopting the principles of Clean Architecture, which has not only enhanced its maintainability but also unlocked several key benefits.
-
Cleaner Code: The separation of concerns and modularization result in cleaner, more organized code, making it easier to read and maintain.
-
Testability: With well-defined interfaces and dependency injection, unit testing becomes straightforward, ensuring the reliability of the codebase.
-
Scalability: The architecture's modular nature allows for easy expansion and addition of new features, making the project adaptable to future requirements.
-
Maintainability: Clean Architecture promotes code maintainability, reducing the risk of technical debt and simplifying future updates and enhancements.
yuwen-yorozuya-linebot serves as a dynamic chat agent chain with an array of essential features including:
In addition to its core features, this project implements OpenAI Function Calling. This means that developers can
encapsulate desired services as functions and incorporate them into the chatbot through the LangChain agent. We can
implement this in src\infrastructure\tools\
.
The project leverages the LangChain framework, a powerful tool designed to simplify the integration of language models into applications. Specifically, LangChain is used in this project to seamlessly connect with the OpenAI Language Model (LLM), allowing developers to focus on application development without getting bogged down in the complexities of language processing.
The ability to remember and recall previous conversations, providing a personalized user experience. Default is PostgreSQL. You can use your memory repositorios by implementing the BaseChatMemory interface.
You can custom your LineBot's personality by setting the CHATBOT_DESCRIPTION in .env file.
Before you begin, ensure that you have the following prerequisites installed:
- Setup LINE Channel to get CHANNEL_SECRET and CHANNEL_ACCESS_TOKEN
- Get SerpAPI Token
ref: SerpAPI
- Get OpenAI Token
ref: OpenAI-API-keys
- Setup PostgreSQL and get connect string
You can use some PostgreSQL provider like: ElephantSQL, Vercel Postgre...etc. I recommand Zeabur for a web-hosting PostgreSQL because you can create a project and run the LineBot and PostgreSQL in the same platform. So fast! So easy! So convenient!
- Setup environment variables by creating a .env file
CHANNEL_SECRET= CHANNEL_ACCESS_TOKEN= OPENAI_API_KEY= PORT= SERPAPI_API_KEY= SQLALCHEMY_DATABASE_URI= CHATBOT_DESCRIPTION= CHATBOT_LANGUAGE=
- Clone the yuwen-yorozuya-linebot repository:
git clone https://github.com/ttpss930141011/yuwen-yorozuya-linebot.git
- Change to the project directory:
cd yuwen-yorozuya-linebot
- Install the dependencies:
Poetry install
pytest
python app.py
-
Use ngrok
ngrok http {PORT}
-
Then put the forwarding url to LineBot Messaging API Webhook url settings.
-
New project
-
New services to add PostgreSQL and Git repository
-
Public the networking
-
Setup environment variables
Keeping the Memory Alive | Search information on the internet | Group assistant |
---|---|---|
In the quest for code quality, maintainability, and scalability, the yuwen-yorozuya-linebot project has embraced Clean Architecture principles. Here's how Clean Architecture has influenced this project's development:
-
Flask + LINE SDK: The project continues to utilize Flask and the LINE SDK as its core technologies, but the key transformation lies in the architecture.
-
Blueprints as Handlers: In the Clean Architecture paradigm, message handlers are treated as blueprints. This approach decouples the handling of messages from the application's core logic, making the codebase more modular and maintainable.
-
Controller and Usecase Separation: The traditional controller and use case layers have been restructured, promoting a separation of concerns. Controllers are responsible for handling incoming requests and orchestrating the flow, while use cases encapsulate the application's business logic.
-
Dependency Injection: Extensive use of dependency injection enhances code cleanliness, testability, and extensibility. Dependencies are injected into components, reducing tight coupling and simplifying unit testing.
I am used to implement 3-tier architecture in my project. Accidentally, I heard a sharing by a senior software engineer in development community. He was talking about what is the adventages he felt when he migrated the application to the another application from other company.
3-tier architecture | Clean architecture |
---|---|
I started to study what is the Clean Architectre by reading two books "Clean Architecture: A Craftsman's Guide to Software Structure and Design" and "Architecture Patterns with Python: Enabling Test-Driven Development, Domain-Driven Design, and Event-Driven Microservices".
Although the project I made in formar job didn't have too complicated dependency like "Big Ball of yarn", I can imagine it will be annoying if I gonna change infrustructure or framework one day. In the project, I wrote many interfaces to make dependency to easily inject. I think a large number of dependency inversions is one of the important aspects why Clean Architecture is attractive.
Finally, I will continue to delve deeper into Clean Architecture, especially with regards to the implementation of entities and the definition of value objects. I'm not yet entirely familiar with these concepts in the context of this project, so my plan is to further study and explore them in greater detail.
The following is todo-list on LineBot:
- Implement muting and unmuting functions
- Invoke LineBot by calling a key word.(it's too noisy in group.)
- Give YouTube link and return video summary
- Give the file and start the document conversation
This project is licensed under the MIT License. See the LICENSE file for additional info.