Spaces:
Runtime error
Runtime error
run several at once
Browse files
app.py
CHANGED
@@ -11,7 +11,15 @@ from jinja2 import Environment, FileSystemLoader
|
|
11 |
|
12 |
from backend.query_llm import generate_hf, generate_openai
|
13 |
from backend.semantic_search import retrieve
|
|
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
TOP_K = int(os.getenv("TOP_K", 4))
|
17 |
|
@@ -54,17 +62,31 @@ def bot(history, api_kind,
|
|
54 |
prompt = template.render(documents=documents, query=query)
|
55 |
prompt_html = template_html.render(documents=documents, query=query)
|
56 |
|
|
|
57 |
if api_kind == "HuggingFace":
|
58 |
generate_fn = generate_hf
|
59 |
elif api_kind == "OpenAI":
|
60 |
generate_fn = generate_openai
|
61 |
else:
|
62 |
raise gr.Error(f"API {api_kind} is not supported")
|
|
|
63 |
|
64 |
history[-1][1] = ""
|
65 |
-
for character in generate_fn(prompt, history[:-1]):
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
|
70 |
with gr.Blocks() as demo:
|
@@ -90,12 +112,12 @@ with gr.Blocks() as demo:
|
|
90 |
|
91 |
with gr.Row():
|
92 |
num_docs = gr.Slider(1, 20, label="number of docs", step=1, value=4)
|
93 |
-
model_kind = gr.Radio(choices=
|
94 |
-
sub_vector_size = gr.Radio(choices=
|
95 |
with gr.Row():
|
96 |
api_kind = gr.Radio(choices=["HuggingFace", "OpenAI"], value="HuggingFace", label="Chat model engine")
|
97 |
-
chunk_size = gr.Radio(choices=
|
98 |
-
splitter_type = gr.Radio(choices=
|
99 |
|
100 |
prompt_html = gr.HTML()
|
101 |
# Turn off interactivity while generating if you click
|
|
|
11 |
|
12 |
from backend.query_llm import generate_hf, generate_openai
|
13 |
from backend.semantic_search import retrieve
|
14 |
+
import itertools
|
15 |
|
16 |
+
emb_models = ["bge", "minilm"]
|
17 |
+
splitters = ['ct', 'rct', 'nltk']
|
18 |
+
chunk_sizes = ["500", "2000"]
|
19 |
+
sub_vectors = ["8", "16", "32"]
|
20 |
+
|
21 |
+
# Create all combinations of the provided arrays
|
22 |
+
combinations = itertools.product(emb_models, splitters, chunk_sizes, sub_vectors)
|
23 |
|
24 |
TOP_K = int(os.getenv("TOP_K", 4))
|
25 |
|
|
|
62 |
prompt = template.render(documents=documents, query=query)
|
63 |
prompt_html = template_html.render(documents=documents, query=query)
|
64 |
|
65 |
+
|
66 |
if api_kind == "HuggingFace":
|
67 |
generate_fn = generate_hf
|
68 |
elif api_kind == "OpenAI":
|
69 |
generate_fn = generate_openai
|
70 |
else:
|
71 |
raise gr.Error(f"API {api_kind} is not supported")
|
72 |
+
|
73 |
|
74 |
history[-1][1] = ""
|
75 |
+
# for character in generate_fn(prompt, history[:-1]):
|
76 |
+
# history[-1][1] = character
|
77 |
+
# yield history, prompt_html
|
78 |
+
|
79 |
+
for model_name, doc, size, sub_vector in combinations:
|
80 |
+
documents_i = retrieve(query, int(num_docs), model_name, sub_vector, size, doc)
|
81 |
+
prompt_i = template.render(documents=documents_i, query=query)
|
82 |
+
prompt_html = template_html.render(documents=documents, query=query)
|
83 |
+
|
84 |
+
hist_chunk = ""
|
85 |
+
prev_hist = history[-1][1] + f"\nmodel {model_name}, splitter {doc}, size {size}, sub vector {sub_vector}\n"
|
86 |
+
for character in generate_fn(prompt_i, history[:-1]):
|
87 |
+
hist_chunk = character
|
88 |
+
history[-1][1] = prev_hist + hist_chunk
|
89 |
+
yield history, prompt_html
|
90 |
|
91 |
|
92 |
with gr.Blocks() as demo:
|
|
|
112 |
|
113 |
with gr.Row():
|
114 |
num_docs = gr.Slider(1, 20, label="number of docs", step=1, value=4)
|
115 |
+
model_kind = gr.Radio(choices=emb_models, value="bge", label="embedding model")
|
116 |
+
sub_vector_size = gr.Radio(choices=sub_vectors, value="32", label="sub-vector size")
|
117 |
with gr.Row():
|
118 |
api_kind = gr.Radio(choices=["HuggingFace", "OpenAI"], value="HuggingFace", label="Chat model engine")
|
119 |
+
chunk_size = gr.Radio(choices=chunk_sizes, value="2000", label="chunk size")
|
120 |
+
splitter_type = gr.Radio(choices=splitters, value="nltk", label="splitter")
|
121 |
|
122 |
prompt_html = gr.HTML()
|
123 |
# Turn off interactivity while generating if you click
|