harshitv804 commited on
Commit
f69a536
1 Parent(s): b58ab7d

Rename app1.py to app.py

Browse files
Files changed (1) hide show
  1. app1.py → app.py +15 -16
app1.py → app.py RENAMED
@@ -1,7 +1,8 @@
1
  from langchain_community.vectorstores import FAISS
2
  from langchain_community.embeddings import HuggingFaceEmbeddings
3
  from langchain.prompts import PromptTemplate
4
- from langchain_community.llms import LlamaCpp
 
5
  from langchain.memory import ConversationBufferWindowMemory
6
  from langchain.chains import ConversationalRetrievalChain
7
  import streamlit as st
@@ -50,31 +51,29 @@ if "memory" not in st.session_state:
50
  st.session_state.memory = ConversationBufferWindowMemory(k=3, memory_key="chat_history",return_messages=True)
51
 
52
  embeddings = HuggingFaceEmbeddings(model_name="BAAI/llm-embedder")
53
- db = FAISS.load_local("faiss_index", embeddings)
54
  db_retriever = db.as_retriever(search_type="similarity",search_kwargs={"k": 3})
55
 
56
- llm = LlamaCpp(
57
- model_path="stablelm-zephyr-3b.Q4_K_M.gguf",
58
- temperature=0.75,
59
- max_tokens=2000,
60
- n_ctx = 4000,
61
- n_batch=126,
62
- top_p=1)
63
 
 
64
 
65
- custom_prompt_template = """You are a medical practitioner who provides right medical information. Use the given following pieces of information to answer the user's question correctly. If you don't know the answer, just say that you don't know, don't try to make up an answer. Utilize the provided knowledge base and search for relevant information. Follow and answer the question format closely. Give only the important information. The information should be abstract, high quality content and comprehensive.
66
 
67
- Context: {context}
68
 
69
- History: {chat_history}
70
-
71
- Question: {question}
72
-
73
- Answer:
74
  """
75
  prompt = PromptTemplate(template=custom_prompt_template,
76
  input_variables=['context', 'question', 'chat_history'])
77
 
 
 
 
 
 
 
 
78
  qa = ConversationalRetrievalChain.from_llm(
79
  llm=llm,
80
  memory=st.session_state.memory,
 
1
  from langchain_community.vectorstores import FAISS
2
  from langchain_community.embeddings import HuggingFaceEmbeddings
3
  from langchain.prompts import PromptTemplate
4
+ from langchain_together import Together
5
+ import os
6
  from langchain.memory import ConversationBufferWindowMemory
7
  from langchain.chains import ConversationalRetrievalChain
8
  import streamlit as st
 
51
  st.session_state.memory = ConversationBufferWindowMemory(k=3, memory_key="chat_history",return_messages=True)
52
 
53
  embeddings = HuggingFaceEmbeddings(model_name="BAAI/llm-embedder")
54
+ db = FAISS.load_local("fdb_pg1_a", embeddings)
55
  db_retriever = db.as_retriever(search_type="similarity",search_kwargs={"k": 3})
56
 
57
+ custom_prompt_template = """This is a chat tempalte and you are a medical practitioner lmm who provides correct medical information. Use the given following pieces of information to answer the user's question correctly. Utilize the provided knowledge base and search for relevant information. Follow the question format closely. The information should be abstract and concise. Understand all the context given here and generate only the answer. If you don't know the answer, just say that you don't know, don't try to make up an answer.
 
 
 
 
 
 
58
 
59
+ CONTEXT: {context}
60
 
61
+ CHAT HISTORY: {chat_history}
62
 
63
+ QUESTION: {question}
64
 
65
+ ANSWER
 
 
 
 
66
  """
67
  prompt = PromptTemplate(template=custom_prompt_template,
68
  input_variables=['context', 'question', 'chat_history'])
69
 
70
+ llm = Together(
71
+ model="mistralai/Mistral-7B-Instruct-v0.2",
72
+ temperature=0.7,
73
+ max_tokens=1024,
74
+ together_api_key=f"{os.environ.getattribute("TOGETHER_AI")}"
75
+ )
76
+
77
  qa = ConversationalRetrievalChain.from_llm(
78
  llm=llm,
79
  memory=st.session_state.memory,