Samarth991 commited on
Commit
989332e
·
1 Parent(s): 40568e3

adding Prompt

Browse files
Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -5,7 +5,6 @@ from langchain.document_loaders import PDFMinerLoader,CSVLoader ,UnstructuredWor
5
  from langchain.text_splitter import CharacterTextSplitter
6
  from langchain.embeddings import SentenceTransformerEmbeddings
7
  from langchain.vectorstores import FAISS
8
- from langchain import HuggingFaceHub
9
  from langchain.chains import RetrievalQA
10
  from langchain.prompts import PromptTemplate
11
  from langchain.docstore.document import Document
@@ -51,6 +50,20 @@ def process_youtube_link(link, document_name="youtube-content"):
51
  logger.error(f'Error in reading document. {err}')
52
 
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  def youtube_chat(youtube_link,API_key,llm='HuggingFace',temperature=0.1,max_tokens=1096,char_length=1500):
55
 
56
  document = process_youtube_link(link=youtube_link)
@@ -69,11 +82,12 @@ def youtube_chat(youtube_link,API_key,llm='HuggingFace',temperature=0.1,max_toke
69
  )
70
  else:
71
  chat = chatops.get_openai_chat_model(API_key=API_key)
 
72
 
73
  qa = RetrievalQA.from_chain_type(llm=chat,
74
  chain_type='stuff',
75
  retriever=vector_db.as_retriever(),
76
- # chain_type_kwargs=chain_type_kwargs,
77
  return_source_documents=True
78
  )
79
  return "Youtube link Processing completed ..."
@@ -85,7 +99,6 @@ def infer(question, history):
85
  # # res.append(pair)
86
 
87
  # chat_history = res
88
- print("Question in infer :",question)
89
  result = qa({"query": question})
90
  matching_docs_score = vector_db.similarity_search_with_score(question)
91
 
 
5
  from langchain.text_splitter import CharacterTextSplitter
6
  from langchain.embeddings import SentenceTransformerEmbeddings
7
  from langchain.vectorstores import FAISS
 
8
  from langchain.chains import RetrievalQA
9
  from langchain.prompts import PromptTemplate
10
  from langchain.docstore.document import Document
 
50
  logger.error(f'Error in reading document. {err}')
51
 
52
 
53
+ def create_prompt():
54
+ prompt_template = """As a chatbot asnwer the questions regarding the content in the video.
55
+ Use the following context to answer.
56
+ If you don't know the answer, just say I don't know.
57
+
58
+ {context}
59
+
60
+ Question: {question}
61
+ Answer :"""
62
+ prompt = PromptTemplate(
63
+ template=prompt_template, input_variables=["context", "question"]
64
+ )
65
+ return prompt
66
+
67
  def youtube_chat(youtube_link,API_key,llm='HuggingFace',temperature=0.1,max_tokens=1096,char_length=1500):
68
 
69
  document = process_youtube_link(link=youtube_link)
 
82
  )
83
  else:
84
  chat = chatops.get_openai_chat_model(API_key=API_key)
85
+ chain_type_kwargs = {"prompt": create_prompt()}
86
 
87
  qa = RetrievalQA.from_chain_type(llm=chat,
88
  chain_type='stuff',
89
  retriever=vector_db.as_retriever(),
90
+ chain_type_kwargs=chain_type_kwargs,
91
  return_source_documents=True
92
  )
93
  return "Youtube link Processing completed ..."
 
99
  # # res.append(pair)
100
 
101
  # chat_history = res
 
102
  result = qa({"query": question})
103
  matching_docs_score = vector_db.similarity_search_with_score(question)
104