Spaces:
Runtime error
Runtime error
Jason St George
commited on
Commit
·
786ee8a
1
Parent(s):
b4a4b5f
fix vectorstore path
Browse files
app.py
CHANGED
@@ -15,7 +15,7 @@ dotenv.load_dotenv()
|
|
15 |
|
16 |
import argparse
|
17 |
parser = argparse.ArgumentParser()
|
18 |
-
parser.add_argument('-v', '--vectorstore_path', type=str, default='
|
19 |
parser.add_argument('-pp', '--prompt_path', type=str, help='Path to custom prompt template to use with LLM ChatBot + Vectorstore')
|
20 |
parser.add_argument('-t', '--temperature', type=float, default=0.7, help='LLM temperature setting... lower == more deterministic')
|
21 |
parser.add_argument('-m', '--max_tokens', type=int, default=384, help='LLM maximum number of output tokens')
|
@@ -65,44 +65,6 @@ PLANT_PATH_PROMPT = PromptTemplate(input_variables=["question", "context"], tem
|
|
65 |
|
66 |
|
67 |
|
68 |
-
# TODO: Update and tweak this to add a medical flair, like a doctor who gives you detailed instructions
|
69 |
-
qa_template ="""Terence is a research assistant that has been trained on a vast corpus of medical and anecdotal knowledge about psychedelics, their use, their medical benefits, mechanisms of action, as well as their historical use and potential applications.
|
70 |
-
|
71 |
-
Terence is designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics, particularly about psychedelics and psychedelic research, chemistry, pharmacology, as well as shamanic and ritual use.
|
72 |
-
|
73 |
-
As a language model, Terence is able to generate human-like text based on the input it receives, allowing it to engage in natural-sounding conversations and provide responses that are coherent and relevant to the topic at hand.
|
74 |
-
|
75 |
-
Terence can engage in discussions, reason about, and provide explanations for the potential implications of psychedelic research and answer questions that humans may have based on this knowledge and Terence's own speculations.
|
76 |
-
|
77 |
-
Overall, Terence is a powerful tool that can help with a wide range of tasks and provide valuable insights and information on psychedlics and the state of art modern research.
|
78 |
-
|
79 |
-
Whether you need help with a specific question or just want to have a conversation about a particular topic, Terence is here to assist.
|
80 |
-
|
81 |
-
Terence is given the following extracted parts of a long document and a question. Provide a conversational answer.
|
82 |
-
Human: {question}
|
83 |
-
=========
|
84 |
-
{context}
|
85 |
-
=========
|
86 |
-
Answer:"""
|
87 |
-
|
88 |
-
qa_template_lite ="""Terence is a research assistant that has been trained on a vast corpus of medical and anecdotal knowledge about psychedelics, their use, their medical benefits, mechanisms of action, as well as their historical use and potential applications.
|
89 |
-
|
90 |
-
Terence is designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions, particularly about psychedelics and psychedelic research, chemistry, pharmacology, as well as shamanic and ritual use of psychedelic plant medicine.
|
91 |
-
|
92 |
-
Terence can engage in discussions, reason about, and provide explanations for the potential implications of psychedelic research and answer questions that humans may have based on this knowledge.
|
93 |
-
|
94 |
-
Overall, Terence is a powerful tool that can help with a wide range of tasks and provide valuable insights and information on psychedlics and the state of art scientific research.
|
95 |
-
|
96 |
-
Terence is given the following extracted parts of a long document and a question. Provide a conversational answer.
|
97 |
-
Human: {question}
|
98 |
-
=========
|
99 |
-
{context}
|
100 |
-
=========
|
101 |
-
Answer:"""
|
102 |
-
|
103 |
-
|
104 |
-
QA_PROMPT = PromptTemplate(template=qa_template_lite, input_variables=["question", "context"])
|
105 |
-
|
106 |
|
107 |
condense_template ="""Given the following conversation and a follow up question, rephrase the follow up question to be a standalone question.
|
108 |
|
@@ -113,27 +75,6 @@ Standalone question:"""
|
|
113 |
CONDENSE_QUESTION_PROMPT = PromptTemplate.from_template(condense_template)
|
114 |
|
115 |
|
116 |
-
prompts = {
|
117 |
-
'plant': PLANT_PATH_PROMPT,
|
118 |
-
'qa': QA_PROMPT,
|
119 |
-
'research': QA_PROMPT,
|
120 |
-
'lite': PRETEND_PROMPT,
|
121 |
-
}
|
122 |
-
|
123 |
-
def get_chain(vectorstore,
|
124 |
-
qa_prompt=PLANT_PATH_PROMPT,
|
125 |
-
condense_prompt=CONDENSE_QUESTION_PROMPT):
|
126 |
-
|
127 |
-
llm = OpenAI(temperature=args.temperature, max_tokens=args.max_tokens)
|
128 |
-
|
129 |
-
qa_chain = ChatVectorDBChain.from_llm(
|
130 |
-
llm,
|
131 |
-
vectorstore,
|
132 |
-
qa_prompt=qa_prompt,
|
133 |
-
condense_question_prompt=condense_prompt,
|
134 |
-
)
|
135 |
-
return qa_chain
|
136 |
-
|
137 |
|
138 |
def get_chat_chain(vectorstore,
|
139 |
temperature, max_tokens,
|
@@ -158,16 +99,6 @@ def initialize_chat_chain():
|
|
158 |
return chain
|
159 |
|
160 |
|
161 |
-
def initialize_chain():
|
162 |
-
chain = get_chain(
|
163 |
-
VECTORSTORE,
|
164 |
-
temperature=args.temperature,
|
165 |
-
max_tokens=args.max_tokens,
|
166 |
-
)
|
167 |
-
print("LangChain initialized!")
|
168 |
-
return chain
|
169 |
-
|
170 |
-
|
171 |
# Attempt to load base vectorstore
|
172 |
try:
|
173 |
|
@@ -232,13 +163,13 @@ with block:
|
|
232 |
gr.Markdown("<h3><center>Walking the Plant Path, with John McIllwain</center></h3>")
|
233 |
|
234 |
with gr.Row():
|
235 |
-
with gr.Column(min_width=
|
236 |
pass
|
237 |
|
238 |
with gr.Column():
|
239 |
gr.Image(type='filepath', value='JohnMcIllwain.jpg') #, shape=(200,100))
|
240 |
|
241 |
-
with gr.Column(min_width=
|
242 |
pass
|
243 |
|
244 |
chatbot = gr.Chatbot().style()
|
|
|
15 |
|
16 |
import argparse
|
17 |
parser = argparse.ArgumentParser()
|
18 |
+
parser.add_argument('-v', '--vectorstore_path', type=str, default='plant_path_new.pkl', help='Path to saved index')
|
19 |
parser.add_argument('-pp', '--prompt_path', type=str, help='Path to custom prompt template to use with LLM ChatBot + Vectorstore')
|
20 |
parser.add_argument('-t', '--temperature', type=float, default=0.7, help='LLM temperature setting... lower == more deterministic')
|
21 |
parser.add_argument('-m', '--max_tokens', type=int, default=384, help='LLM maximum number of output tokens')
|
|
|
65 |
|
66 |
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
condense_template ="""Given the following conversation and a follow up question, rephrase the follow up question to be a standalone question.
|
70 |
|
|
|
75 |
CONDENSE_QUESTION_PROMPT = PromptTemplate.from_template(condense_template)
|
76 |
|
77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
def get_chat_chain(vectorstore,
|
80 |
temperature, max_tokens,
|
|
|
99 |
return chain
|
100 |
|
101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
# Attempt to load base vectorstore
|
103 |
try:
|
104 |
|
|
|
163 |
gr.Markdown("<h3><center>Walking the Plant Path, with John McIllwain</center></h3>")
|
164 |
|
165 |
with gr.Row():
|
166 |
+
with gr.Column(min_width=150):
|
167 |
pass
|
168 |
|
169 |
with gr.Column():
|
170 |
gr.Image(type='filepath', value='JohnMcIllwain.jpg') #, shape=(200,100))
|
171 |
|
172 |
+
with gr.Column(min_width=150):
|
173 |
pass
|
174 |
|
175 |
chatbot = gr.Chatbot().style()
|