heymenn commited on
Commit
69dc23d
·
verified ·
1 Parent(s): 08096d0

Update src/services/processor.py

Browse files
Files changed (1) hide show
  1. src/services/processor.py +60 -1
src/services/processor.py CHANGED
@@ -215,4 +215,63 @@ def select_technologies(problem_technology_list):
215
 
216
  if best_set is None:
217
  return set()
218
- return set(best_set)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
 
216
  if best_set is None:
217
  return set()
218
+ return set(best_set)
219
+
220
+
221
+ def search_prior_art(technologies_input: list, data: str, type: str) -> json:
222
+ """
223
+ Searches for prior art patents online that solve a given technical problem
224
+ using a set of specified technologies, leveraging the Gemini model's search capabilities.
225
+ """
226
+
227
+ technology_titles = [tech['title'] for tech in technologies_input]
228
+
229
+ if type == "problem":
230
+ prompt = f"Find prior art patents or research paper online that address the technical problem: '{data}'. " \
231
+
232
+ elif type == "constraints":
233
+ prompt = f"Find prior art patents or research paper online that address those constraints: '{data}'. " \
234
+
235
+ prompt += f"Using any combination of the following technologies: {', '.join(technology_titles)}. " \
236
+ f"Specifically look for patents that integrate multiple of these technologies. " \
237
+ f"Indicate for each document found what technologies is used inside of it from the provided list"
238
+
239
+ client,config = set_gemini()
240
+
241
+ response = client.models.generate_content(
242
+ model="gemini-2.5-flash",
243
+ contents=prompt,
244
+ config=config,
245
+ )
246
+
247
+ return response
248
+
249
+ def add_citations_and_collect_uris(response):
250
+ try:
251
+ print(response)
252
+ text = response.text
253
+ supports = response.candidates[0].grounding_metadata.grounding_supports
254
+ chunks = response.candidates[0].grounding_metadata.grounding_chunks
255
+
256
+ sorted_supports = sorted(supports, key=lambda s: s.segment.end_index, reverse=True)
257
+
258
+ uris_added = set()
259
+
260
+ for support in sorted_supports:
261
+ end_index = support.segment.end_index
262
+ if support.grounding_chunk_indices:
263
+ citation_links = []
264
+ for i in support.grounding_chunk_indices:
265
+ if i < len(chunks):
266
+ uri = chunks[i].web.uri
267
+ # Add URI only if not already in text or collected
268
+ if uri not in text and uri not in uris_added:
269
+ citation_links.append(f"[{i + 1}]({uri})")
270
+ uris_added.add(uri)
271
+ if citation_links:
272
+ citation_string = ", ".join(citation_links)
273
+ text = text[:end_index] + citation_string + text[end_index:]
274
+ except Exception as e:
275
+ print(f"Error : {e}")
276
+
277
+ return {"content": text,"uris": list(uris_added)}