Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Langchain Chatbot #58

Open
Haste171 opened this issue Jan 28, 2024 · 3 comments
Open

Update Langchain Chatbot #58

Haste171 opened this issue Jan 28, 2024 · 3 comments

Comments

@Haste171
Copy link
Owner

Switch to API

@Haste171
Copy link
Owner Author

Haste171 commented Jan 30, 2024

1. 📝 Indexing

I'm indexing the files within your repository.

2. 🔎 Searching

I'm searching for relevant snippets in your repository.

I found the following snippets in your repository.

View Snippets

https://github.com/Haste171/langchain-chatbot/blob/5f913d074827946f318181c11e17229846441352/README.md#L0-L15

<a href="https://discord.gg/KgmN4FPxxT"><img src="https://dcbadge.vercel.app/api/server/KgmN4FPxxT?compact=true&style=flat"></a>
</a>
<!-- *The LangChain Chatbot is an AI chat interface for the open-source library LangChain. It provides conversational answers to questions about vector ingested documents.* -->
<!-- *Existing repo development is at a freeze while we develop a langchain chat bot website :)* -->
# 🚀 Installation
## User-Setup
You can either join the [Discord](https://discord.gg/8vzXR9MGyc) server to use the bot or invite the [Langchain Chatbot](https://discord.com/api/oauth2/authorize?client_id=1113492778899476533&permissions=8&scope=bot) to your own server.
*If not you can following to steps below to setup your own Langchain Chatbot*
## Dev-Setup

## Dev-Setup
Prerequisites:
- [Git](https://git-scm.com/downloads) - Free
- [Docker](https://www.docker.com/products/docker-desktop/) - Free
- [Discord Bot](https://discord.com/developers/applications) - Free
- [Mongo Database](https://youtu.be/dnEfQhjZgw0?t=326) - Free
- [Pinecone Database](https://youtu.be/tp0bQNDtLPc?t=48) - Free
- [OpenAI API Key](https://platform.openai.com/account/api-keys) - Billing Required
### Setup
```
git clone https://github.com/Haste171/langchain-chatbot.git
```
Reference [example.env](https://github.com/Haste171/langchain-chatbot/blob/main/example.env) to create `.env` file
```python

```python
BOT_TOKEN=
MONGO_URI=
PINECONE_API_KEY=
PINECONE_INDEX=
PINECONE_ENV=
```
*Recommended to use a Docker Container for Deployment*
```
docker build -t langchain-chatbot .
docker run -d langchain-chatbot
```
# 🔧 Key Features

✅ Credential Manager (OpenAI Keys)
✅ Space Manager (Ingestions)
✅ Documentation Ingester (For readthedocs.io sites)
Soon:
- Compatibility with multiple files types (Llama Index)
- Compatibility with offline models (HuggingFace, Vicuna, Alpaca)
- Re-adding PDF Ingester Will be implemented along with docx, doc, excel, etc.
# 💻 Contributing
If you would like to contribute to the LangChain Chatbot, please follow these steps:

3. 🌐 Planning

I'm creating a plan for the discussion and coding steps.

I have created the following workflow as a basis for how the discussion and coding will be derived.

💡 Steps

Update MongoDBHandler

Action: modify
File: utils/mongo_db.py
Lines: [1, 100]
Dependencies: []
Instructions: Update the MongoDBHandler class to include methods for interacting with the new API. This includes methods for sending requests to the API, handling responses, and error handling. Ensure that the methods are asynchronous to maintain the non-blocking nature of the chatbot. Import any necessary libraries for making HTTP requests.

Update Credentials Module

Action: modify
File: modules/credentials.py
Lines: [1, 28]
Dependencies: ['Step 1']
Instructions: Update the Credentials class to use the new methods in the MongoDBHandler for interacting with the API. This includes updating the credentials method to use the new method for sending requests to the API. Ensure that the method is asynchronous and handles any errors that may occur during the request.

Update IngestDocs Module

Action: modify
File: modules/ingest_docs.py
Lines: [1, 49]
Dependencies: ['Step 1']
Instructions: Update the IngestDocs class to use the new methods in the MongoDBHandler for interacting with the API. This includes updating the ingest_docs method to use the new method for sending requests to the API. Ensure that the method is asynchronous and handles any errors that may occur during the request.

Update QueryDocs Module

Action: modify
File: modules/query_docs.py
Lines: [1, 87]
Dependencies: ['Step 1']
Instructions: Update the QueryDocs class to use the new methods in the MongoDBHandler for interacting with the API. This includes updating the query_docs method to use the new method for sending requests to the API. Ensure that the method is asynchronous and handles any errors that may occur during the request.

Test the Changes

Action: create
File: tests/test_api_integration.py
Lines: [1, 100]
Dependencies: ['Step 1', 'Step 2', 'Step 3', 'Step 4']
Instructions: Create a new test file to test the changes made to the MongoDBHandler and the modules. The tests should cover all possible scenarios, including successful requests, failed requests, and error handling. Use mock data for the tests and ensure that all tests pass before committing the changes.

I have created the following workflow as a basis for how the discussion and coding will be derived.

💡 Steps

Refactor MongoDBHandler

Action: modify
File: utils/mongo_db.py
Lines: [1, 100]
Dependencies: []
Instructions: Refactor the MongoDBHandler class to separate the concerns of different operations. Create separate methods for each operation such as get_user_credentials, handle_data, and check_ownership. This will make the code more maintainable and easier to test.

Refactor Credentials Class

Action: modify
File: modules/credentials.py
Lines: [1, 28]
Dependencies: ['Step 1']
Instructions: Refactor the Credentials class to use the new methods in the MongoDBHandler class. This will involve changing the way the handler is used in the credentials method.

Refactor IngestDocs Class

Action: modify
File: modules/ingest_docs.py
Lines: [1, 49]
Dependencies: ['Step 1']
Instructions: Refactor the IngestDocs class to use the new methods in the MongoDBHandler class. This will involve changing the way the handler is used in the ingest_docs method.

Refactor QueryDocs Class

Action: modify
File: modules/query_docs.py
Lines: [1, 87]
Dependencies: ['Step 1']
Instructions: Refactor the QueryDocs class to use the new methods in the MongoDBHandler class. This will involve changing the way the handler is used in the query_docs method.

Write Tests for MongoDBHandler

Action: create
File: tests/test_mongo_db.py
Lines: [1, 100]
Dependencies: ['Step 1']
Instructions: Write tests for the new methods in the MongoDBHandler class. These tests should cover all possible edge cases and ensure that the methods work as expected.

Write Tests for Credentials Class

Action: create
File: tests/test_credentials.py
Lines: [1, 100]
Dependencies: ['Step 2']
Instructions: Write tests for the Credentials class. These tests should cover all possible edge cases and ensure that the class works as expected.

Write Tests for IngestDocs Class

Action: create
File: tests/test_ingest_docs.py
Lines: [1, 100]
Dependencies: ['Step 3']
Instructions: Write tests for the IngestDocs class. These tests should cover all possible edge cases and ensure that the class works as expected.

Write Tests for QueryDocs Class

Action: create
File: tests/test_query_docs.py
Lines: [1, 100]
Dependencies: ['Step 4']
Instructions: Write tests for the QueryDocs class. These tests should cover all possible edge cases and ensure that the class works as expected.

Code Review

Action: review
File: ``
Lines: [0, -1]
Dependencies: `['Step 1', 'Step 2', 'Step 3', 'Step 4', 'Step 5', 'Step 6', 'Step 7', 'Step 8']`
Instructions: `Have another developer review the changes to ensure that they meet the project's standards and don't introduce any new issues.`

I have created the following workflow as a basis for how the discussion and coding will be derived.

💡 Steps

Create Rollback Mechanism

Action: create
File: utils/rollback.py
Lines: [1, 20]
Dependencies: []
Instructions: Create a new file named rollback.py in the utils directory. This file will contain the Rollback class, which will be responsible for storing the state of the database before any changes are made and restoring the state if an error occurs. The class should have methods for saving the state, restoring the state, and clearing the saved state. The state should be saved as a dictionary, with keys representing collection names and values representing lists of documents in those collections.

Modify IngestDocs Class

Action: modify
File: modules/ingest_docs.py
Lines: [17, 41]
Dependencies: ['Step 1']
Instructions: In the ingest_docs method of the IngestDocs class, add a call to the save_state method of the Rollback class before any changes are made to the database. In the exception handling block, add a call to the restore_state method of the Rollback class. After the changes have been successfully made, add a call to the clear_state method of the Rollback class. Import the Rollback class at the beginning of the file.

Modify QueryDocs Class

Action: modify
File: modules/query_docs.py
Lines: [17, 81]
Dependencies: ['Step 1']
Instructions: In the query_docs method of the QueryDocs class, add a call to the save_state method of the Rollback class before any changes are made to the database. In the exception handling block, add a call to the restore_state method of the Rollback class. After the changes have been successfully made, add a call to the clear_state method of the Rollback class. Import the Rollback class at the beginning of the file.

Create Tests

Action: create
File: tests/test_rollback.py
Lines: [1, 50]
Dependencies: ['Step 1']
Instructions: Create a new file named test_rollback.py in the tests directory. This file will contain tests for the Rollback class. The tests should cover all methods of the class and should test the class's ability to save, restore, and clear the state of the database. Use mock data for these tests.

Run Tests

Action: run
File: tests/test_rollback.py
Lines: [1, 50]
Dependencies: ['Step 4']
Instructions: Run the tests in test_rollback.py to ensure that the Rollback class is functioning correctly. If any tests fail, debug the Rollback class and rerun the tests until all tests pass.

@Haste171
Copy link
Owner Author

Given the complexity of the task and the dependencies on Step 1, I suggest breaking down Step 1 into smaller tasks. This could include separate tasks for creating the methods for sending requests, handling responses, and error handling. This would make the task more manageable and allow for more focused testing. Additionally, consider implementing a code review process to catch potential issues early. This could involve another developer reviewing the changes before they are committed.

@Haste171
Copy link
Owner Author

Haste171 commented Jan 30, 2024

I agree, given the complexity of the task and the dependencies between the steps, I suggest implementing a rollback mechanism. This will ensure that if a step fails, the changes made in that step and any subsequent steps can be undone, preventing inconsistencies and bugs. Additionally, consider using a feature branch for the changes to avoid impacting the main branch. This will allow for isolated testing and development without affecting the main codebase. Lastly, while mock data is useful for initial testing, it's important to also test with real data to ensure the changes work as expected in a real-world scenario.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant