-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.py
41 lines (29 loc) · 1.31 KB
/
search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import streamlit as st
import openai
from database import get_redis_connection, get_redis_results
from config import INDEX_NAME, COMPLETIONS_MODEL, OPENAI_API_KEY
openai.api_key = OPENAI_API_KEY
# initialise Redis connection
client = get_redis_connection()
### SEARCH APP
st.set_page_config(
page_title="Streamlit Search - Demo",
page_icon=":robot:"
)
st.title('Moodfit Search')
st.subheader("Search for any Formula 1 rule questions you have")
prompt = st.text_input("Enter your search here","", key="input")
if st.button('Submit', key='generationSubmit'):
result_df = get_redis_results(client,prompt,INDEX_NAME)
# Build a prompt to provide the original query, the result and ask to summarise for the user
summary_prompt = '''Summarise this result in a bulleted list to answer the search query a customer has sent.
Search query: SEARCH_QUERY_HERE
Search result: SEARCH_RESULT_HERE
Summary:
'''
summary_prepped = summary_prompt.replace('SEARCH_QUERY_HERE',prompt).replace('SEARCH_RESULT_HERE',result_df['result'][0])
summary = openai.Completion.create(engine=COMPLETIONS_MODEL,prompt=summary_prepped,max_tokens=500)
# Response provided by GPT-3
st.write(summary['choices'][0]['text'])
# Option to display raw table instead of summary from GPT-3
#st.table(result_df)