srush commited on
Commit
8947111
·
1 Parent(s): b523c4a

Upload with huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +16 -9
  2. gatsby.pmpt.tpl +3 -0
app.py CHANGED
@@ -14,12 +14,13 @@ gatsby.add_faiss_index("embeddings")
14
 
15
  # Fast KNN retieval prompt
16
 
17
-
18
  class KNNPrompt(EmbeddingPrompt):
 
 
 
19
  def find(self, out, inp):
20
  res = gatsby.get_nearest_examples("embeddings", np.array(out), 1)
21
- return {"question": inp, "docs": res.examples["passages"]}
22
-
23
 
24
  # QA prompt to ask question with examples
25
 
@@ -29,15 +30,21 @@ class QAPrompt(TemplatePrompt):
29
 
30
 
31
  with start_chain("gatsby") as backend:
32
- question = "What did Gatsby do before he met Daisy?"
33
  prompt = KNNPrompt(
34
  backend.HuggingFaceEmbed("sentence-transformers/all-mpnet-base-v2")
35
  ).chain(QAPrompt(backend.OpenAI()))
36
- result = prompt(question)
37
- print(result)
 
 
 
 
 
 
38
 
39
  # + tags=["hide_inp"]
40
- QAPrompt().show({"question": "Who was Gatsby?", "docs": ["doc1", "doc2", "doc3"]}, "")
41
- # -
42
 
43
- show_log("gatsby.log")
 
14
 
15
  # Fast KNN retieval prompt
16
 
 
17
  class KNNPrompt(EmbeddingPrompt):
18
+ def prompt(self, inp):
19
+ return inp["query"]
20
+
21
  def find(self, out, inp):
22
  res = gatsby.get_nearest_examples("embeddings", np.array(out), 1)
23
+ return {"question": inp["query"], "docs": res.examples["passages"]}
 
24
 
25
  # QA prompt to ask question with examples
26
 
 
30
 
31
 
32
  with start_chain("gatsby") as backend:
33
+ # question = "What did Gatsby do before he met Daisy?"
34
  prompt = KNNPrompt(
35
  backend.HuggingFaceEmbed("sentence-transformers/all-mpnet-base-v2")
36
  ).chain(QAPrompt(backend.OpenAI()))
37
+ # result = prompt(question)
38
+ # print(result)
39
+
40
+
41
+ prompt.to_gradio(fields=["query"],
42
+ examples=["What did Gatsby do before he met Daisy?"]).launch()
43
+
44
+
45
 
46
  # + tags=["hide_inp"]
47
+ # QAPrompt().show({"question": "Who was Gatsby?", "docs": ["doc1", "doc2", "doc3"]}, "")
48
+ # # -
49
 
50
+ # show_log("gatsby.log")
gatsby.pmpt.tpl CHANGED
@@ -1,6 +1,9 @@
1
  Context information is below.
 
 
2
  ---------------------
3
 
 
4
  {% for doc in docs %}
5
  * {{doc}}
6
  {% endfor %}
 
1
  Context information is below.
2
+
3
+
4
  ---------------------
5
 
6
+
7
  {% for doc in docs %}
8
  * {{doc}}
9
  {% endfor %}