Tuana commited on
Commit
1c1d5b6
1 Parent(s): 482bee0

updating the requirements and prompt template

Browse files
Files changed (2) hide show
  1. requirements.txt +2 -2
  2. utils/haystack.py +30 -36
requirements.txt CHANGED
@@ -1,5 +1,5 @@
1
- git+https://github.com/deepset-ai/haystack.git@openai/token_limit#egg=farm-haystack
2
- streamlit==1.17.0
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(name="twitter-voice", prompt_text="""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.
15
- You may go into some detail about what topics they tend to like tweeting about. Please also mention their overall tone, for example: positive,
16
- negative, political, sarcastic or something else.
17
-
18
- Examples:
19
-
20
- 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…
21
- 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…
22
- 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…
23
- RT @tuanacelik: So many updates from @deepset_ai today!
24
-
25
- 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
26
- been posting in English, and have had a positive, informative tone.
27
-
28
- Twitter stream: I've directed my team to set sharper rules on how we deal with unidentified objects.\n\nWe will inventory, improve ca…
29
- the incursion by China’s high-altitude balloon, we enhanced radar to pick up slower objects.\n \nBy doing so, w…
30
- I gave an update on the United States’ response to recent aerial objects.
31
-
32
- Summary: This user has lately been tweeting about having sharper rules to deal with unidentified objects and an incursuin by China's high-altitude
33
- baloon. Their tweets have mostly been neutral but determined in tone. They mostly post in English.
34
-
35
- Twitter stream: $tweets
36
-
37
- Summary:
38
- """)
39
 
40
  st.session_state["haystack_started"] = True
41
  return prompt_node, twitter_template
42
 
43
 
44
- @st.cache(hash_funcs={"builtins.CoreBPE": lambda _: None}, show_spinner=False, allow_output_mutation=True)
45
- def query(username, prompter, template):
46
-
47
- bearer_token = TWITTER_BEARER
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 = prompter.prompt(prompt_template=template, tweets=twitter_stream)
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