derek-thomas HF staff commited on
Commit
83e218d
1 Parent(s): 9e6b8ed

Fixed imports and cleaned code

Browse files
app.py CHANGED
@@ -1,7 +1,9 @@
1
  from time import perf_counter
2
 
 
3
  from jinja2 import Template
4
 
 
5
  from backend.semantic_search import qd_retriever
6
 
7
  template_string = """
@@ -53,9 +55,6 @@ function toggleContent(docID) {
53
 
54
  template = Template(template_string)
55
  md_template = Template(md_template_string)
56
- import gradio as gr
57
-
58
- from backend.query_llm import generate
59
 
60
 
61
  def add_text(history, text):
@@ -77,12 +76,6 @@ def bot(history, system_prompt=""):
77
  prompt = template.render(documents=documents, query=query)
78
  md_prompt = md_template.render(documents=documents, query=query)
79
 
80
- # # Query LLM with prompt based on relevant documents
81
- # llm_start = perf_counter()
82
- # result = generate(prompt=prompt, history='')
83
- # llm_time = llm_start - perf_counter()
84
- # times = (document_time, llm_time)
85
-
86
  history[-1][1] = ""
87
  for character in generate(prompt, history[:-1]):
88
  history[-1][1] = character
 
1
  from time import perf_counter
2
 
3
+ import gradio as gr
4
  from jinja2 import Template
5
 
6
+ from backend.query_llm import generate
7
  from backend.semantic_search import qd_retriever
8
 
9
  template_string = """
 
55
 
56
  template = Template(template_string)
57
  md_template = Template(md_template_string)
 
 
 
58
 
59
 
60
  def add_text(history, text):
 
76
  prompt = template.render(documents=documents, query=query)
77
  md_prompt = md_template.render(documents=documents, query=query)
78
 
 
 
 
 
 
 
79
  history[-1][1] = ""
80
  for character in generate(prompt, history[:-1]):
81
  history[-1][1] = character
backend/retrieval_augmented_generation.py DELETED
@@ -1,38 +0,0 @@
1
- from time import perf_counter
2
- from jinja2 import Template
3
-
4
- from backend.query_llm import generate
5
- from backend.semantic_search import qd_retriever
6
-
7
- template_string = """
8
- Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.
9
- Context:
10
- ---
11
- {% for doc in documents %}
12
- {{ doc.content }}
13
- ---
14
- {% endfor %}
15
- Query: {{ query }}
16
- """
17
-
18
- template = Template(template_string)
19
-
20
-
21
- def rag(query, top_k=5):
22
-
23
- # Retrieve documents relevant to query
24
- document_start = perf_counter()
25
- documents = qd_retriever.retrieve(query, top_k=top_k)
26
- document_time = document_start - perf_counter()
27
-
28
- # Create Prompt
29
- prompt = template.render(documents=documents, query=query)
30
-
31
- # Query LLM with prompt based on relevant documents
32
- llm_start = perf_counter()
33
- result = generate(prompt=prompt, history='')
34
- llm_time = llm_start - perf_counter()
35
-
36
- times = (document_time, llm_time)
37
- return prompt, result
38
-