Spaces:
Runtime error
Runtime error
add k value option
Browse files
app.py
CHANGED
|
@@ -100,16 +100,18 @@ def get_docs():
|
|
| 100 |
documents.extend(text_splitter.split_documents(load))
|
| 101 |
return documents
|
| 102 |
|
| 103 |
-
def set_chain_up(api_key, model_selector, agent):
|
| 104 |
if api_key:
|
| 105 |
os.environ["OPENAI_API_KEY"] = api_key
|
| 106 |
documents = get_docs()
|
| 107 |
embeddings = OpenAIEmbeddings()
|
| 108 |
vectorstore = CachedChroma.from_documents_with_cache(".persisted_data", documents, embedding=embeddings, collection_name="pycbc")
|
| 109 |
-
if model_selector:
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
|
|
|
|
|
|
| 113 |
os.environ["OPENAI_API_KEY"] = ""
|
| 114 |
return qa_chain
|
| 115 |
|
|
@@ -141,20 +143,26 @@ with block:
|
|
| 141 |
type="password",
|
| 142 |
)
|
| 143 |
model_selector = gr.Dropdown(["gpt-3.5-turbo", "gpt-4"], label="Model", show_label=True)
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
chatbot = gr.Chatbot()
|
| 146 |
|
| 147 |
with gr.Row():
|
| 148 |
message = gr.Textbox(
|
| 149 |
label="What's your question?",
|
| 150 |
-
placeholder="What
|
| 151 |
lines=1,
|
| 152 |
)
|
| 153 |
submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
|
| 154 |
|
| 155 |
gr.Examples(
|
| 156 |
examples=[
|
| 157 |
-
"What is
|
|
|
|
| 158 |
],
|
| 159 |
inputs=message,
|
| 160 |
)
|
|
@@ -176,12 +184,12 @@ with block:
|
|
| 176 |
|
| 177 |
openai_api_key_textbox.change(
|
| 178 |
set_chain_up,
|
| 179 |
-
inputs=[openai_api_key_textbox, model_selector, agent_state],
|
| 180 |
outputs=[agent_state],
|
| 181 |
)
|
| 182 |
model_selector.change(
|
| 183 |
set_chain_up,
|
| 184 |
-
inputs=[openai_api_key_textbox, model_selector, agent_state],
|
| 185 |
outputs=[agent_state],
|
| 186 |
)
|
| 187 |
|
|
|
|
| 100 |
documents.extend(text_splitter.split_documents(load))
|
| 101 |
return documents
|
| 102 |
|
| 103 |
+
def set_chain_up(api_key, model_selector, k_textbox, agent):
|
| 104 |
if api_key:
|
| 105 |
os.environ["OPENAI_API_KEY"] = api_key
|
| 106 |
documents = get_docs()
|
| 107 |
embeddings = OpenAIEmbeddings()
|
| 108 |
vectorstore = CachedChroma.from_documents_with_cache(".persisted_data", documents, embedding=embeddings, collection_name="pycbc")
|
| 109 |
+
if not model_selector:
|
| 110 |
+
model_selector = "gpt-3.5-turbo"
|
| 111 |
+
if not k_textbox:
|
| 112 |
+
k_textbox = 10
|
| 113 |
+
k_textbox = int(k_textbox)
|
| 114 |
+
qa_chain = get_new_chain1(vectorstore, model_selector, k_textbox)
|
| 115 |
os.environ["OPENAI_API_KEY"] = ""
|
| 116 |
return qa_chain
|
| 117 |
|
|
|
|
| 143 |
type="password",
|
| 144 |
)
|
| 145 |
model_selector = gr.Dropdown(["gpt-3.5-turbo", "gpt-4"], label="Model", show_label=True)
|
| 146 |
+
k_textbox = gr.Textbox(
|
| 147 |
+
placeholder="k: Number of search results to consider",
|
| 148 |
+
label="Search Results k:"
|
| 149 |
+
show_label=True,
|
| 150 |
+
lines=1,
|
| 151 |
+
)
|
| 152 |
chatbot = gr.Chatbot()
|
| 153 |
|
| 154 |
with gr.Row():
|
| 155 |
message = gr.Textbox(
|
| 156 |
label="What's your question?",
|
| 157 |
+
placeholder="What is pycbc?",
|
| 158 |
lines=1,
|
| 159 |
)
|
| 160 |
submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
|
| 161 |
|
| 162 |
gr.Examples(
|
| 163 |
examples=[
|
| 164 |
+
"What is PyCBC?",
|
| 165 |
+
"Where is the matched filtering done in the pycbc_live script?"
|
| 166 |
],
|
| 167 |
inputs=message,
|
| 168 |
)
|
|
|
|
| 184 |
|
| 185 |
openai_api_key_textbox.change(
|
| 186 |
set_chain_up,
|
| 187 |
+
inputs=[openai_api_key_textbox, model_selector, k_textbox, agent_state],
|
| 188 |
outputs=[agent_state],
|
| 189 |
)
|
| 190 |
model_selector.change(
|
| 191 |
set_chain_up,
|
| 192 |
+
inputs=[openai_api_key_textbox, model_selector, k_textbox, agent_state],
|
| 193 |
outputs=[agent_state],
|
| 194 |
)
|
| 195 |
|