Update utils/haystack.py
Browse files- 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 |
-
|
50 |
-
|
51 |
-
|
52 |
-
"
|
53 |
-
|
54 |
-
|
55 |
-
"
|
56 |
-
|
57 |
-
|
58 |
-
"
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
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
|