tferhan commited on
Commit
efe6762
·
verified ·
1 Parent(s): ce3f508

Update qa_txt.py

Browse files
Files changed (1) hide show
  1. qa_txt.py +86 -86
qa_txt.py CHANGED
@@ -1,86 +1,86 @@
1
- # from langchain_community.document_loaders import TextLoader
2
- # from langchain.text_splitter import RecursiveCharacterTextSplitter, CharacterTextSplitter
3
- # from langchain.chains import ConversationalRetrievalChain
4
-
5
- from langchain_community.embeddings import HuggingFaceEmbeddings
6
- # from langchain_community.llms import HuggingFaceEndpoint
7
- from langchain.prompts.prompt import PromptTemplate
8
- # from pathlib import Path
9
- from langchain_core.output_parsers import StrOutputParser
10
- from unidecode import unidecode
11
- # # import tqdm
12
- # from langchain_community.vectorstores import FAISS
13
- from langchain_huggingface import HuggingFaceEndpoint
14
- import os
15
- # import accelerate
16
-
17
- # c_splitter = CharacterTextSplitter(
18
-
19
- # chunk_size = 350,
20
- # chunk_overlap = 4,
21
- # separator = """,
22
- # ]""",
23
-
24
- # )
25
-
26
- # def load_doc(file_path):
27
- # loader = TextLoader(file_path)
28
- # pages = loader.load()
29
- # text_splitter = c_splitter
30
- # doc_splits = text_splitter.split_documents(pages)
31
- # return doc_splits
32
-
33
- huggingfacehub_api_token = os.getenv("HUGGINGFACEHUB_API_TOKEN")
34
-
35
- llm = HuggingFaceEndpoint(
36
- repo_id='mistralai/Mixtral-8x7B-Instruct-v0.1',
37
- temperature = 0.17,
38
- max_new_tokens = 512,
39
- top_k = 30,
40
- huggingfacehub_api_token = huggingfacehub_api_token,
41
- add_to_git_credential=True,
42
- )
43
-
44
- # def process_data():
45
- # splt = load_doc('intents_v2.txt')
46
- # embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2")
47
- # db = FAISS.from_documents(splt, embeddings)
48
- # return db
49
-
50
- # db = process_data()
51
-
52
-
53
- prompt = """You are an Assistant with expertise in providing answers based on provided information about a specific website. The user will present a general question related to the site, and using the available data, you should formulate an accurate and helpful answer. Your role includes web data comprehension, question interpretation, and clear communication. Remember to tailor your responses according to the context presented by the user and the details extracted from the pertinent website."
54
-
55
- For a more detailed breakdown, consider these elements:
56
-
57
- Role: Website Information Assistant
58
-
59
- Skills: Web Data Comprehension, Question Interpretation, Clear Communication
60
-
61
- Context: User presents a general question related to a particular website; you provide an accurate and helpful answer utilizing available data.
62
-
63
- Task: Analyze user questions, understand associated web data, and construct appropriate answers.
64
-
65
- Steps:
66
-
67
- Acknowledge the user's question and express understanding.
68
- Identify keywords or concepts within the question that relate to the website data.
69
- Search through the available data to locate relevant facts or explanations.
70
- Formulate a concise and engaging response addressing the user's query.
71
- Validate the accuracy and relevancy of the generated answer before delivering it.
72
- Answer Characteristics: Accurate, well-structured, easy to comprehend, directly addresses the user's question.
73
- Here is the website informations : {document}
74
- Human: {input}
75
- AI Assistant:
76
- """
77
-
78
- prompt_2 = PromptTemplate(input_variables=['input', 'document'], template = prompt)
79
- conversation_chain = prompt_2 | llm | StrOutputParser()
80
- # Set up a conversational chain to retrieve and generate responses.
81
- # conversation_chain = ConversationalRetrievalChain.from_llm(
82
- # llm=llm,
83
- # retriever=db.as_retriever(),
84
- # condense_question_prompt=PromptTemplate(input_variables=['input'], template=prompt),
85
- # )
86
-
 
1
+ # from langchain_community.document_loaders import TextLoader
2
+ # from langchain.text_splitter import RecursiveCharacterTextSplitter, CharacterTextSplitter
3
+ # from langchain.chains import ConversationalRetrievalChain
4
+
5
+ from langchain_community.embeddings import HuggingFaceEmbeddings
6
+ # from langchain_community.llms import HuggingFaceEndpoint
7
+ from langchain.prompts.prompt import PromptTemplate
8
+ # from pathlib import Path
9
+ from langchain_core.output_parsers import StrOutputParser
10
+ from unidecode import unidecode
11
+ # # import tqdm
12
+ # from langchain_community.vectorstores import FAISS
13
+ from langchain_huggingface import HuggingFaceEndpoint
14
+ import os
15
+ # import accelerate
16
+
17
+ # c_splitter = CharacterTextSplitter(
18
+
19
+ # chunk_size = 350,
20
+ # chunk_overlap = 4,
21
+ # separator = """,
22
+ # ]""",
23
+
24
+ # )
25
+
26
+ # def load_doc(file_path):
27
+ # loader = TextLoader(file_path)
28
+ # pages = loader.load()
29
+ # text_splitter = c_splitter
30
+ # doc_splits = text_splitter.split_documents(pages)
31
+ # return doc_splits
32
+
33
+ huggingfacehub_api_token = os.getenv("HUGGINGFACEHUB_API_TOKEN")
34
+
35
+ llm = HuggingFaceEndpoint(
36
+ repo_id='mistralai/Mixtral-8x7B-Instruct-v0.1',
37
+ temperature = 0.17,
38
+ max_new_tokens = 512,
39
+ top_k = 30,
40
+ huggingfacehub_api_token = huggingfacehub_api_token,
41
+
42
+ )
43
+
44
+ # def process_data():
45
+ # splt = load_doc('intents_v2.txt')
46
+ # embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2")
47
+ # db = FAISS.from_documents(splt, embeddings)
48
+ # return db
49
+
50
+ # db = process_data()
51
+
52
+
53
+ prompt = """You are an Assistant with expertise in providing answers based on provided information about a specific website. The user will present a general question related to the site, and using the available data, you should formulate an accurate and helpful answer. Your role includes web data comprehension, question interpretation, and clear communication. Remember to tailor your responses according to the context presented by the user and the details extracted from the pertinent website."
54
+
55
+ For a more detailed breakdown, consider these elements:
56
+
57
+ Role: Website Information Assistant
58
+
59
+ Skills: Web Data Comprehension, Question Interpretation, Clear Communication
60
+
61
+ Context: User presents a general question related to a particular website; you provide an accurate and helpful answer utilizing available data.
62
+
63
+ Task: Analyze user questions, understand associated web data, and construct appropriate answers.
64
+
65
+ Steps:
66
+
67
+ Acknowledge the user's question and express understanding.
68
+ Identify keywords or concepts within the question that relate to the website data.
69
+ Search through the available data to locate relevant facts or explanations.
70
+ Formulate a concise and engaging response addressing the user's query.
71
+ Validate the accuracy and relevancy of the generated answer before delivering it.
72
+ Answer Characteristics: Accurate, well-structured, easy to comprehend, directly addresses the user's question.
73
+ Here is the website informations : {document}
74
+ Human: {input}
75
+ AI Assistant:
76
+ """
77
+
78
+ prompt_2 = PromptTemplate(input_variables=['input', 'document'], template = prompt)
79
+ conversation_chain = prompt_2 | llm | StrOutputParser()
80
+ # Set up a conversational chain to retrieve and generate responses.
81
+ # conversation_chain = ConversationalRetrievalChain.from_llm(
82
+ # llm=llm,
83
+ # retriever=db.as_retriever(),
84
+ # condense_question_prompt=PromptTemplate(input_variables=['input'], template=prompt),
85
+ # )
86
+