This project developed a pharmacist chatbot using an LLM and LangChain-managed pipelines to provide accurate recommendations and analyses of supplements and medications, ensuring user safety through interaction checks.
Our project is a pharmacist chatbot AI that analyzes the ingredients in multiple supplements or medications. It identifies cases where the dosage exceeds recommended levels, potentially causing side effects, or detects harmful ingredient interactions. When necessary, the system also recommends products available in Korea. We have implemented this solution using various Upstage APIs, integrated with LangGraph to handle multiple scenarios effectively.
![image](https://private-user-images.githubusercontent.com/156292946/371823387-4dba634d-026b-49e2-9447-7348749b108f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyNzY2NzEsIm5iZiI6MTczOTI3NjM3MSwicGF0aCI6Ii8xNTYyOTI5NDYvMzcxODIzMzg3LTRkYmE2MzRkLTAyNmItNDllMi05NDQ3LTczNDg3NDliMTA4Zi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjExJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxMVQxMjE5MzFaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1jN2YwNDMwYzliYTJjNjNjZWJlZjY0MzJhMjUyYjJkY2U1MTE3YzcwMTAyMWY2ZDdjODc0MGU2MGEzNTQ1ZWVkJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.00S_248z8j3w4i4Vq3nTMTRW61iWlPDvWEw8F05uTFQ)
The technology stack used in this project includes Python for development, with frameworks such as LangChain for managing task pipelines, and LLMs for generating responses. The Upstage API was utilized in several key areas:
- it facilitated chatbot interactions to determine pipeline direction and generate final answers
- it provided embeddings for database creation and query retrieval searches
- it was employed for Ground Check to verify the reliability of responses
- it processed image data using OCR
- it handled PDF file processing through document parsing.
![image](https://private-user-images.githubusercontent.com/156292946/371823491-b1f23602-61c0-48d1-a03b-3d0f77e801ee.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyNzY2NzEsIm5iZiI6MTczOTI3NjM3MSwicGF0aCI6Ii8xNTYyOTI5NDYvMzcxODIzNDkxLWIxZjIzNjAyLTYxYzAtNDhkMS1hMDNiLTNkMGY3N2U4MDFlZS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjExJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxMVQxMjE5MzFaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT03OGY5Yjg2OGIyYWIxYzBjMGY3N2YzNDg4MmYxZTRhNTA1Mjc5Y2Q0MWMyNmI5MDIyNTY2NTg2NjliYWM0YTVlJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.sAhTqv69-HLaYEQ-CCNsrNctDFFJEjPzXKL7tRHAk40)
In this work, we primarily used the Gradio, LangChain and the Upstage API for solar-1-mini-chat-240612 model fine-tuning, generation, and checking groundness.
You have to build the conda enviroment. After clone the repository, please make the conda enviroment by Anaconda.
$ conda create -n 'env_name' python==3.10.14
$ conda activate 'env_name'
$ pip install -r requirements.txt
$ pip install gradio
- because of module version conflict, please install some module after create conda enviroment! Although, there will be some error, it works well. So don't be worry about it. (updatad in 24.08.22)
> $ conda env create -f enviroment.yml
-
If you want to use this tool, you have to need 4 of api keys.
- Langchain API key
- OpenAI API key
- Upstage API key
- Predibase API key
-
After get the key, please insert it in Module/RAG.py. Then, you can use the RAG function to get the correct answers from db.
-
Furthermore, you also have to Predibase API key in app.py.
-
Before run the app.py code, you have to fine-tune the model in the Predibase. There are 2 fine-tuned models in the project; Answer_bot and medi_chatbot. After train the model, there will be adapter_id which have to fill in RAG.py and app_final.py!
4.1 Train the answer_bot
with ./dataset/final_nutrient_prompt_completion.jsonl, please use the name for the model as 'AIMedicine'. It's for theRAG.py.
4.2 Train the medi_chatbot
with ./dataset/dataset_prompt_completion.jsonl, please use the name for the model as 'medicine_suggest_model'. It's for the app_final.py.
-
In the ends, please run the app.py code in your conda enviroments. Then you can access to our webpage which are undisclosed.
In the webpage, you can use 2 service, "Check the recommended dosage of nutritional supplements" and "Chat with Chatbot". Just click the one section!
-
"Check the recommended dosage of nutritional supplements"
In this section, you can check the recommended dosage of nutritional supplements.
please input the information; heights, weights, age, sex.
Additionally, you can choose the nutritional supplements from the nutritional supplement selection. If the nutritional supplements you want to check do not exist in the selection, just write down next to selection and push the add button. Then the prompt will be generated.
Please write the question what you want. We suggest that there are baseline questions, so you just click the 'generation' button!
Then you can get the recommended dosage of nutritional supplements from our service!
-
"Chat with Chatbot"
In this section, you can chat with our chatbot fine-tuned by the SolarAI.
Suggestion input message: "your symptoms" with "please suggest the medicine".
During the Global AI week AI Hackaton presentation periods, this webpage will be opened for 72hours!