raannakasturi commited on
Commit
62463b3
·
1 Parent(s): 5761f43

Refactor NLP processing functions to update provider lists and increase max retries

Browse files
Files changed (1) hide show
  1. nlp_processes.py +22 -25
nlp_processes.py CHANGED
@@ -1,5 +1,6 @@
1
  from g4f.client import Client
2
- from g4f.Provider import RetryProvider, Airforce, AmigoChat, Blackbox, ChatGptEs, Chatgpt4o, DarkAI, Liaobots, PollinationsAI, Jmuz
 
3
  import threading
4
 
5
  def generate_nlp_summary(temp_summary):
@@ -21,14 +22,13 @@ def generate_nlp_summary(temp_summary):
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
  provider=RetryProvider(
26
- providers=[ChatGptEs, Chatgpt4o, DarkAI, Liaobots, PollinationsAI, Jmuz],
27
- max_retries=6,
28
  ),
29
- )
30
- completion = client.chat.completions.create(
31
- model="gpt-4o",
32
  messages=[
33
  {"role": "system", "content": "You are a helpful research assistant for generating well-formatted summaries from scientific research papers."},
34
  {"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\"'}
@@ -58,14 +58,13 @@ def generate_nlp_mindmap(temp_summary):
58
  return completion.choices[0].message.content.replace("**", "").replace("\n\n", "\n").replace("\n \n", "\n").replace("##", "\n##").strip()
59
  except Exception as e:
60
  print(str(e))
61
- client = Client(
 
62
  provider=RetryProvider(
63
- providers=[ChatGptEs, Chatgpt4o, DarkAI, Liaobots, PollinationsAI, Jmuz],
64
- max_retries=6,
65
  ),
66
- )
67
- completion = client.chat.completions.create(
68
- model="gpt-4o",
69
  messages=[
70
  {"role": "system", "content": "You are a helpful research assistant for generating well-formatted mindmaps from scientific research papers."},
71
  {"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.'}
@@ -118,14 +117,13 @@ def fix_title(title):
118
  return completion.choices[0].message.content
119
  except Exception as e:
120
  print(str(e))
121
- client = Client(
 
122
  provider=RetryProvider(
123
- providers=[ChatGptEs, Chatgpt4o, DarkAI, Liaobots, PollinationsAI, Jmuz],
124
- max_retries=6,
125
  ),
126
- )
127
- completion = client.chat.completions.create(
128
- model="gpt-4o",
129
  messages=[
130
  {
131
  "role": "system",
@@ -199,14 +197,13 @@ def fix_citation(citation):
199
  return completion.choices[0].message.content
200
  except Exception as e:
201
  print(str(e))
202
- client = Client(
 
203
  provider=RetryProvider(
204
- providers=[ChatGptEs, Chatgpt4o, DarkAI, Liaobots, PollinationsAI, Jmuz],
205
- max_retries=6,
206
  ),
207
- )
208
- completion = client.chat.completions.create(
209
- model="gpt-4o",
210
  messages=[
211
  {
212
  "role": "system",
 
1
  from g4f.client import Client
2
+ from g4f.Provider import RetryProvider, Airforce, AmigoChat, Blackbox
3
+ from g4f import Provider
4
  import threading
5
 
6
  def generate_nlp_summary(temp_summary):
 
22
  return completion.choices[0].message.content.replace("**", "").replace("\n\n", "\n").replace("\n \n", "\n").replace("##", "\n##").strip()
23
  except Exception as e:
24
  print(str(e))
25
+ client = Client()
26
+ completion = client.chat.completions.create(
27
  provider=RetryProvider(
28
+ providers=[Provider.DDG, Provider.DarkAI, Provider.DeepInfraChat, Provider.PollinationsAI, Provider.RubiksAI, Provider.TeachAnything, Provider.Airforce],
29
+ max_retries=8,
30
  ),
31
+ model="llama-3.1-70b",
 
 
32
  messages=[
33
  {"role": "system", "content": "You are a helpful research assistant for generating well-formatted summaries from scientific research papers."},
34
  {"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\"'}
 
58
  return completion.choices[0].message.content.replace("**", "").replace("\n\n", "\n").replace("\n \n", "\n").replace("##", "\n##").strip()
59
  except Exception as e:
60
  print(str(e))
61
+ client = Client()
62
+ completion = client.chat.completions.create(
63
  provider=RetryProvider(
64
+ providers=[Provider.DDG, Provider.DarkAI, Provider.DeepInfraChat, Provider.PollinationsAI, Provider.RubiksAI, Provider.TeachAnything, Provider.Airforce],
65
+ max_retries=8,
66
  ),
67
+ model="llama-3.1-70b",
 
 
68
  messages=[
69
  {"role": "system", "content": "You are a helpful research assistant for generating well-formatted mindmaps from scientific research papers."},
70
  {"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.'}
 
117
  return completion.choices[0].message.content
118
  except Exception as e:
119
  print(str(e))
120
+ client = Client()
121
+ completion = client.chat.completions.create(
122
  provider=RetryProvider(
123
+ providers=[Provider.DDG, Provider.DarkAI, Provider.DeepInfraChat, Provider.PollinationsAI, Provider.RubiksAI, Provider.TeachAnything, Provider.Airforce],
124
+ max_retries=8,
125
  ),
126
+ model="llama-3.1-70b",
 
 
127
  messages=[
128
  {
129
  "role": "system",
 
197
  return completion.choices[0].message.content
198
  except Exception as e:
199
  print(str(e))
200
+ client = Client()
201
+ completion = client.chat.completions.create(
202
  provider=RetryProvider(
203
+ providers=[Provider.DDG, Provider.DarkAI, Provider.DeepInfraChat, Provider.PollinationsAI, Provider.RubiksAI, Provider.TeachAnything, Provider.Airforce],
204
+ max_retries=8,
205
  ),
206
+ model="llama-3.1-70b",
 
 
207
  messages=[
208
  {
209
  "role": "system",