pvanand commited on
Commit
940dd00
·
verified ·
1 Parent(s): 1b607c4

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +15 -12
main.py CHANGED
@@ -135,32 +135,35 @@ def json_from_text(text):
135
  """
136
  Extracts JSON from text using regex and fuzzy JSON loading.
137
  """
138
- match = re.search(r'\{[\s\S]*\}', text)
139
- if match:
140
- json_out = match.group(0)
141
- else:
142
- json_out = text
143
  try:
144
- # Using fuzzy json loader
145
- return loads(json_out)
146
- except Exception:
147
- # Using JSON fixer/ Fixes even half json/ Remove if you need an exception
148
- fix_json = JSONFixer()
149
- return loads(fix_json.fix(json_out).line)
150
-
 
 
 
 
151
  def generate_topics(user_input, num_topics, previous_queries):
152
  prompt = prompt_topics.format(user_input=user_input, num_topics=num_topics)
153
  response_topics = together_response(prompt, model=llm_default_medium, SysPrompt=SysPromptList, temperature=1)
154
  subtopics = json_from_text(response_topics)
155
  return subtopics
156
 
 
157
  def generate_subtopics(main_task,user_input,num_topics,excluded_topics):
 
 
158
  excluded_topics = ",".join(excluded_topics)
159
  prompt = prompt_subtopics.format(main_task = main_task,user_input=user_input, num_topics=num_topics, excluded_topics=excluded_topics)
160
  response_topics = together_response(prompt, model=llm_default_medium, SysPrompt=SysPromptList, temperature=1)
161
  subtopics = json_from_text(response_topics)
162
  return subtopics
163
 
 
164
  def generate_report(topic, description):
165
  prompt = f"""create a detailed report on: {topic} by following the instructions: {description}"""
166
  md_report = together_response(prompt, model = llm_default_medium, SysPrompt = SysPromptMdOffline)
 
135
  """
136
  Extracts JSON from text using regex and fuzzy JSON loading.
137
  """
 
 
 
 
 
138
  try:
139
+ return json.loads(text)
140
+ except:
141
+ match = re.search(r'\{[\s\S]*\}', text)
142
+ if match:
143
+ json_out = match.group(0)
144
+ else:
145
+ json_out = text
146
+ # Use Fuzzy JSON loading
147
+ return loads(json_out)
148
+
149
+ @retry(tries=3, delay=0.5)
150
  def generate_topics(user_input, num_topics, previous_queries):
151
  prompt = prompt_topics.format(user_input=user_input, num_topics=num_topics)
152
  response_topics = together_response(prompt, model=llm_default_medium, SysPrompt=SysPromptList, temperature=1)
153
  subtopics = json_from_text(response_topics)
154
  return subtopics
155
 
156
+ @retry(tries=3, delay=0.5)
157
  def generate_subtopics(main_task,user_input,num_topics,excluded_topics):
158
+ print("trying")
159
+ 1/0
160
  excluded_topics = ",".join(excluded_topics)
161
  prompt = prompt_subtopics.format(main_task = main_task,user_input=user_input, num_topics=num_topics, excluded_topics=excluded_topics)
162
  response_topics = together_response(prompt, model=llm_default_medium, SysPrompt=SysPromptList, temperature=1)
163
  subtopics = json_from_text(response_topics)
164
  return subtopics
165
 
166
+ @retry(tries=3, delay=0.5)
167
  def generate_report(topic, description):
168
  prompt = f"""create a detailed report on: {topic} by following the instructions: {description}"""
169
  md_report = together_response(prompt, model = llm_default_medium, SysPrompt = SysPromptMdOffline)