updating the requirements and prompt template
Browse files- requirements.txt +2 -2
- utils/haystack.py +30 -36
requirements.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
-
|
2 |
-
streamlit==1.
|
3 |
markdown
|
4 |
st-annotated-text
|
5 |
python-dotenv
|
|
|
1 |
+
farm-haystack==1.18.1
|
2 |
+
streamlit==1.21.0
|
3 |
markdown
|
4 |
st-annotated-text
|
5 |
python-dotenv
|
utils/haystack.py
CHANGED
@@ -4,58 +4,52 @@ from utils.config import TWITTER_BEARER
|
|
4 |
|
5 |
from haystack.nodes import PromptNode, PromptTemplate
|
6 |
|
7 |
-
# cached to make index and models load only at start
|
8 |
-
@st.cache(hash_funcs={"builtins.CoreBPE": lambda _: None}, show_spinner=False, allow_output_mutation=True)
|
9 |
def start_haystack(openai_key):
|
10 |
#Use this function to contruct a pipeline
|
11 |
prompt_node = PromptNode(model_name_or_path="text-davinci-003", api_key=openai_key)
|
12 |
|
13 |
|
14 |
-
twitter_template = PromptTemplate(
|
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 |
st.session_state["haystack_started"] = True
|
41 |
return prompt_node, twitter_template
|
42 |
|
43 |
|
44 |
-
@st.
|
45 |
-
def query(username,
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
headers = {"Authorization": "Bearer {}".format(bearer_token)}
|
50 |
-
|
51 |
url = f"https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name={username}&count={60}"
|
52 |
try:
|
53 |
response = requests.request("GET", url, headers = headers)
|
54 |
twitter_stream = ""
|
55 |
for tweet in response.json():
|
56 |
twitter_stream += tweet["text"]
|
57 |
-
result =
|
58 |
except Exception as e:
|
59 |
-
print(e)
|
60 |
result = ["Please make sure you are providing a correct, public twitter account"]
|
61 |
return result
|
|
|
4 |
|
5 |
from haystack.nodes import PromptNode, PromptTemplate
|
6 |
|
|
|
|
|
7 |
def start_haystack(openai_key):
|
8 |
#Use this function to contruct a pipeline
|
9 |
prompt_node = PromptNode(model_name_or_path="text-davinci-003", api_key=openai_key)
|
10 |
|
11 |
|
12 |
+
twitter_template = PromptTemplate(prompt="""You will be given a twitter stream belonging to a specific profile. Answer with a summary of what they've lately been tweeting about and in what languages.
|
13 |
+
You may go into some detail about what topics they tend to like tweeting about. Please also mention their overall tone, for example: positive,
|
14 |
+
negative, political, sarcastic or something else.
|
15 |
+
|
16 |
+
Examples:
|
17 |
+
|
18 |
+
Twitter stream: RT @deepset_ai: Come join our Haystack server for our first Discord event tomorrow, a deepset AMA session with @rusic_milos @malte_pietsch…
|
19 |
+
RT @deepset_ai: Join us for a chat! On Thursday 25th we are hosting a 'deepset - Ask Me Anything' session on our brand new Discord. Come…
|
20 |
+
RT @deepset_ai: Curious about how you can use @OpenAI GPT3 in a Haystack pipeline? This week we released Haystack 1.7 with which we introdu…
|
21 |
+
RT @tuanacelik: So many updates from @deepset_ai today!
|
22 |
+
|
23 |
+
Summary: This user has lately been retweeting tweets fomr @deepset_ai. The topics of the tweets have been around the Haystack community, NLP and GPT. They've
|
24 |
+
been posting in English, and have had a positive, informative tone.
|
25 |
+
|
26 |
+
Twitter stream: I've directed my team to set sharper rules on how we deal with unidentified objects.\n\nWe will inventory, improve ca…
|
27 |
+
the incursion by China’s high-altitude balloon, we enhanced radar to pick up slower objects.\n \nBy doing so, w…
|
28 |
+
I gave an update on the United States’ response to recent aerial objects.
|
29 |
+
|
30 |
+
Summary: This user has lately been tweeting about having sharper rules to deal with unidentified objects and an incursuin by China's high-altitude
|
31 |
+
baloon. Their tweets have mostly been neutral but determined in tone. They mostly post in English.
|
32 |
+
|
33 |
+
Twitter stream: {tweets}
|
34 |
+
|
35 |
+
Summary:
|
36 |
+
""")
|
37 |
|
38 |
st.session_state["haystack_started"] = True
|
39 |
return prompt_node, twitter_template
|
40 |
|
41 |
|
42 |
+
@st.cache_data(show_spinner=True)
|
43 |
+
def query(username, _prompter, _template):
|
44 |
+
headers = {"Authorization": "Bearer {}".format(TWITTER_BEARER)}
|
45 |
+
print(username)
|
|
|
|
|
|
|
46 |
url = f"https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name={username}&count={60}"
|
47 |
try:
|
48 |
response = requests.request("GET", url, headers = headers)
|
49 |
twitter_stream = ""
|
50 |
for tweet in response.json():
|
51 |
twitter_stream += tweet["text"]
|
52 |
+
result = _prompter.prompt(prompt_template=_template, tweets=twitter_stream)
|
53 |
except Exception as e:
|
|
|
54 |
result = ["Please make sure you are providing a correct, public twitter account"]
|
55 |
return result
|