sabatale commited on
Commit
929443d
1 Parent(s): 37dde2c

Update utils/haystack.py

Browse files
Files changed (1) hide show
  1. utils/haystack.py +25 -22
utils/haystack.py CHANGED
@@ -8,7 +8,7 @@ from haystack_integrations.components.retrievers.pinecone import PineconeEmbeddi
8
  from haystack_integrations.components.generators.cohere import CohereGenerator
9
  from haystack import Document
10
 
11
- def start_haystack(openai_key):
12
  document_store = PineconeDocumentStore(dimension=1024, index="zen", environment = "gcp-starter")
13
 
14
  template = """
@@ -46,24 +46,27 @@ def start_haystack(openai_key):
46
 
47
  @st.cache_data(show_spinner=True)
48
  def query(prompt, _pipe):
49
- try:
50
- replies = _pipe.run({
51
- "text_embedder": {
52
- "text": prompt
53
- },
54
- "prompt_builder": {
55
- "query": prompt
56
- },
57
- "answer_builder": {
58
- "query": prompt
59
- }
60
- })
61
-
62
- raw = replies['answer_builder']['answers'][0]
63
- result = raw.data + "\n\n -- Source: " + raw.documents[0].content + " --"
64
- print(raw)
65
- except Exception as e:
66
- print("Hay:")
67
- print(e)
68
- result = ["Something went wrong!"]
69
- return result
 
 
 
 
8
  from haystack_integrations.components.generators.cohere import CohereGenerator
9
  from haystack import Document
10
 
11
+ def start_haystack(openai_key):
12
  document_store = PineconeDocumentStore(dimension=1024, index="zen", environment = "gcp-starter")
13
 
14
  template = """
 
46
 
47
  @st.cache_data(show_spinner=True)
48
  def query(prompt, _pipe):
49
+ with st.spinner('Processing'):
50
+ try:
51
+ replies = _pipe.run({
52
+ "text_embedder": {
53
+ "text": prompt
54
+ },
55
+ "prompt_builder": {
56
+ "query": prompt
57
+ },
58
+ "answer_builder": {
59
+ "query": prompt
60
+ }
61
+ })
62
+
63
+ raw = replies['answer_builder']['answers'][0]
64
+ result = raw.data + "\n\n -- Source: " + raw.documents[0].content + " --"
65
+ print(raw)
66
+ st.success('Completed!')
67
+ except Exception as e:
68
+ print("Hay:")
69
+ print(e)
70
+ result = ["Something went wrong!"]
71
+ st.error('Failed!')
72
+ return result