raannakasturi commited on
Commit
66ae8c7
·
1 Parent(s): 1d88c48

Refactor NLP functions to add error handling and remove unused blackbox.json file

Browse files
Files changed (2) hide show
  1. har_and_cookies/blackbox.json +0 -1
  2. nlp_processes.py +52 -28
har_and_cookies/blackbox.json DELETED
@@ -1 +0,0 @@
1
- {"validated_value": "00f37b34-a166-4efb-bce5-1312d87f2f94"}
 
 
nlp_processes.py CHANGED
@@ -4,40 +4,64 @@ import threading
4
 
5
  def generate_nlp_summary(temp_summary):
6
  try:
7
- client = Client()
8
- completion = client.chat.completions.create(
9
- provider=RetryProvider(
10
- providers=[Liaobots, Mhystical, PollinationsAI],
11
- shuffle=True,
12
- max_retries=6,
13
- ),
14
- model="gpt-4",
15
- messages=[
16
- {"role": "system", "content": "You are a helpful research assistant for generating well-formatted summaries from scientific research papers."},
17
- {"role": "user", "content": f'As a text script expert, please help me to write a short text script with the topic \" {temp_summary}\".You have three tasks, which are:\\n 1.to summarize the text I provided into a Summary .Please answer within 150-300 characters.\\n 2.to summarize the text I provided, using up to seven Highlight.\\n 3.to summarize the text I provided, using up to seven Key Insights. Each insight should include a brief in-depth analysis. Key Insight should not include timestamps.\\n Your output should use the following template strictly, provide the results for the three tasks:\\n ## Summary\\n ## Highlights\\n - Highlights\\n ## Key Insights\\n - Key Insights .\\n Importantly your output must use language \"English\"'}
18
- ],
19
- )
20
- return completion.choices[0].message.content.replace("**", "").replace("\n\n", "\n").replace("\n \n", "\n").replace("##", "\n##").strip()
 
 
 
 
 
 
 
 
 
 
 
 
21
  except Exception as e:
22
  print(str(e))
23
  return False
24
 
25
  def generate_nlp_mindmap(temp_summary):
26
  try:
27
- client = Client()
28
- completion = client.chat.completions.create(
29
- provider=RetryProvider(
30
- providers=[Liaobots, Mhystical, PollinationsAI],
31
- shuffle=True,
32
- max_retries=6,
33
- ),
34
- model="gpt-4",
35
- messages=[
36
- {"role": "system", "content": "You are a helpful research assistant for generating well-formatted mindmaps from scientific research papers."},
37
- {"role": "user", "content": f'As a text script expert, please help me to write a short text script with the topic \"{temp_summary}\".Your output should use the following template:\\n\\n## {{Subtitle01}}\\n- {{Bulletpoint01}}\\n- {{Bulletpoint02}}\\n## {{Subtitle02}}\\n- {{Bulletpoint03}}\\n- {{Bulletpoint04}}\\n\\nSummarize the giving topic to generate a mind map (as many subtitles as possible, with a minimum of three subtitles) structure markdown. Do not include anything in the response, that is not the part of mindmap.\\n Most Importantly your output must use language \"English\" and each point or pointer should include no more than 9 words.'}
38
- ],
39
- )
40
- return completion.choices[0].message.content.replace("**", "").replace("\n\n", "\n").replace("\n \n", "\n").replace("##", "\n##").strip()
 
 
 
 
 
 
 
 
 
 
 
 
41
  except Exception as e:
42
  print(str(e))
43
  return False
 
4
 
5
  def generate_nlp_summary(temp_summary):
6
  try:
7
+ try:
8
+ client = Client()
9
+ completion = client.chat.completions.create(
10
+ provider=RetryProvider(
11
+ providers=[Liaobots, Mhystical, PollinationsAI],
12
+ shuffle=True,
13
+ max_retries=6,
14
+ ),
15
+ model="gpt-4",
16
+ messages=[
17
+ {"role": "system", "content": "You are a helpful research assistant for generating well-formatted summaries from scientific research papers."},
18
+ {"role": "user", "content": f'As a text script expert, please help me to write a short text script with the topic \" {temp_summary}\".You have three tasks, which are:\\n 1.to summarize the text I provided into a Summary .Please answer within 150-300 characters.\\n 2.to summarize the text I provided, using up to seven Highlight.\\n 3.to summarize the text I provided, using up to seven Key Insights. Each insight should include a brief in-depth analysis. Key Insight should not include timestamps.\\n Your output should use the following template strictly, provide the results for the three tasks:\\n ## Summary\\n ## Highlights\\n - Highlights\\n ## Key Insights\\n - Key Insights .\\n Importantly your output must use language \"English\"'}
19
+ ],
20
+ )
21
+ return completion.choices[0].message.content.replace("**", "").replace("\n\n", "\n").replace("\n \n", "\n").replace("##", "\n##").strip()
22
+ except Exception as e:
23
+ print(str(e))
24
+ client = Client()
25
+ completion = client.chat.completions.create(
26
+ model="gpt-4",
27
+ messages=[
28
+ {"role": "system", "content": "You are a helpful research assistant for generating well-formatted summaries from scientific research papers."},
29
+ {"role": "user", "content": f'As a text script expert, please help me to write a short text script with the topic \" {temp_summary}\".You have three tasks, which are:\\n 1.to summarize the text I provided into a Summary .Please answer within 150-300 characters.\\n 2.to summarize the text I provided, using up to seven Highlight.\\n 3.to summarize the text I provided, using up to seven Key Insights. Each insight should include a brief in-depth analysis. Key Insight should not include timestamps.\\n Your output should use the following template strictly, provide the results for the three tasks:\\n ## Summary\\n ## Highlights\\n - Highlights\\n ## Key Insights\\n - Key Insights .\\n Importantly your output must use language \"English\"'}
30
+ ],
31
+ )
32
+ return completion.choices[0].message.content.replace("**", "").replace("\n\n", "\n").replace("\n \n", "\n").replace("##", "\n##").strip()
33
  except Exception as e:
34
  print(str(e))
35
  return False
36
 
37
  def generate_nlp_mindmap(temp_summary):
38
  try:
39
+ try:
40
+ client = Client()
41
+ completion = client.chat.completions.create(
42
+ provider=RetryProvider(
43
+ providers=[Liaobots, Mhystical, PollinationsAI],
44
+ shuffle=True,
45
+ max_retries=6,
46
+ ),
47
+ model="gpt-4",
48
+ messages=[
49
+ {"role": "system", "content": "You are a helpful research assistant for generating well-formatted mindmaps from scientific research papers."},
50
+ {"role": "user", "content": f'As a text script expert, please help me to write a short text script with the topic \"{temp_summary}\".Your output should use the following template:\\n\\n## {{Subtitle01}}\\n- {{Bulletpoint01}}\\n- {{Bulletpoint02}}\\n## {{Subtitle02}}\\n- {{Bulletpoint03}}\\n- {{Bulletpoint04}}\\n\\nSummarize the giving topic to generate a mind map (as many subtitles as possible, with a minimum of three subtitles) structure markdown. Do not include anything in the response, that is not the part of mindmap.\\n Most Importantly your output must use language \"English\" and each point or pointer should include no more than 9 words.'}
51
+ ],
52
+ )
53
+ return completion.choices[0].message.content.replace("**", "").replace("\n\n", "\n").replace("\n \n", "\n").replace("##", "\n##").strip()
54
+ except Exception as e:
55
+ print(str(e))
56
+ client = Client()
57
+ completion = client.chat.completions.create(
58
+ model="gpt-4",
59
+ messages=[
60
+ {"role": "system", "content": "You are a helpful research assistant for generating well-formatted mindmaps from scientific research papers."},
61
+ {"role": "user", "content": f'As a text script expert, please help me to write a short text script with the topic \"{temp_summary}\".Your output should use the following template:\\n\\n## {{Subtitle01}}\\n- {{Bulletpoint01}}\\n- {{Bulletpoint02}}\\n## {{Subtitle02}}\\n- {{Bulletpoint03}}\\n- {{Bulletpoint04}}\\n\\nSummarize the giving topic to generate a mind map (as many subtitles as possible, with a minimum of three subtitles) structure markdown. Do not include anything in the response, that is not the part of mindmap.\\n Most Importantly your output must use language \"English\" and each point or pointer should include no more than 9 words.'}
62
+ ],
63
+ )
64
+ return completion.choices[0].message.content.replace("**", "").replace("\n\n", "\n").replace("\n \n", "\n").replace("##", "\n##").strip()
65
  except Exception as e:
66
  print(str(e))
67
  return False