Lucas ARRIESSE commited on
Commit
2a7f67c
·
1 Parent(s): 6edfd36

Prepare FTO

Browse files
prompts/private/fto_topics.txt ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <role> You are a patent committee expert.</role>
2
+ <task>
3
+ You are tasked with giving a list of topics to investigate for freedom-to-operate from a given idea.
4
+ You will be given an idea and you need to list all the topics or concepts that should be explored in a FTO analysis to make sure the idea is exploitable.
5
+ Please give at most the 8 most important ideas or concepts to explore.
6
+ </task>
7
+
8
+ <idea>
9
+ **Here is the idea:**
10
+ ## Problem description
11
+ {{problem_description}}
12
+
13
+ ## Solution description
14
+ {{solution_description}}
15
+ </idea>
16
+
17
+ <response_format>
18
+ Reply in JSON using the following schema:
19
+ {{response_schema}}
20
+
21
+ Here's an example response:
22
+ {
23
+ "topics": [
24
+ "Topic 1",
25
+ "Topic 2",
26
+ "Topic 3",
27
+ "Topic 4"
28
+ ]
29
+ }
30
+ </response_format>
static/index.html CHANGED
@@ -373,6 +373,7 @@
373
  </textarea>
374
  </div>
375
  <div class="card-actions justify-end mt-6">
 
376
  <button id="refine-btn" class="btn btn-primary">Refine draft</button>
377
  </div>
378
  </div>
 
373
  </textarea>
374
  </div>
375
  <div class="card-actions justify-end mt-6">
376
+ <button id="fto-analysis-btn" class="btn btn-warning">Perform FTO on draft</button>
377
  <button id="refine-btn" class="btn btn-primary">Refine draft</button>
378
  </div>
379
  </div>
static/js/app.js CHANGED
@@ -3,8 +3,7 @@ import {
3
  toggleElementsEnabled, toggleContainersVisibility, showLoadingOverlay, hideLoadingOverlay, populateSelect,
4
  populateCheckboxDropdown, populateDaisyDropdown, extractTableData, switchTab, enableTabSwitching, debounceAutoCategoryCount,
5
  bindTabs, checkPrivateLLMInfoAvailable, moveSolutionToDrafts, buildSolutionSubCategories, handleDraftRefine, renderDraftUI, populateLLMModelSelect,
6
- displayFullAssessment, handleSaveConfigFields, handleLoadConfigFields,
7
- handleClearConfig
8
  } from "./ui.js";
9
  import { postWithSSE } from "./sse.js";
10
 
@@ -1053,10 +1052,6 @@ document.addEventListener('DOMContentLoaded', function () {
1053
  boostrapWorkflow(1);
1054
  });
1055
 
1056
- // Events des boutons pour le drafting de solutions
1057
- const refineBtn = document.getElementById('refine-btn');
1058
- refineBtn.addEventListener('click', handleDraftRefine);
1059
-
1060
  // render l'ui de draft vide
1061
  renderDraftUI();
1062
 
@@ -1097,4 +1092,8 @@ document.getElementById('settings-fetch-models').addEventListener('click', _ =>
1097
  // button to open full assessment modal
1098
  document.getElementById('read-assessment-button').addEventListener('click', _ => {
1099
  displayFullAssessment();
1100
- });
 
 
 
 
 
3
  toggleElementsEnabled, toggleContainersVisibility, showLoadingOverlay, hideLoadingOverlay, populateSelect,
4
  populateCheckboxDropdown, populateDaisyDropdown, extractTableData, switchTab, enableTabSwitching, debounceAutoCategoryCount,
5
  bindTabs, checkPrivateLLMInfoAvailable, moveSolutionToDrafts, buildSolutionSubCategories, handleDraftRefine, renderDraftUI, populateLLMModelSelect,
6
+ displayFullAssessment, handleSaveConfigFields, handleLoadConfigFields, handleFTOAnalysis, handleClearConfig
 
7
  } from "./ui.js";
8
  import { postWithSSE } from "./sse.js";
9
 
 
1052
  boostrapWorkflow(1);
1053
  });
1054
 
 
 
 
 
1055
  // render l'ui de draft vide
1056
  renderDraftUI();
1057
 
 
1092
  // button to open full assessment modal
1093
  document.getElementById('read-assessment-button').addEventListener('click', _ => {
1094
  displayFullAssessment();
1095
+ });
1096
+
1097
+ // Events des boutons pour le drafting de solutions
1098
+ document.getElementById('refine-btn').addEventListener('click', handleDraftRefine);
1099
+ document.getElementById('fto-analysis-btn').addEventListener('click', handleFTOAnalysis);
static/js/gen.js CHANGED
@@ -31,7 +31,7 @@ export async function retrieveTemplate(task) {
31
  * Lance un deep search sur le serveur pour les topics donnés.
32
  * @param {Array} topics
33
  */
34
- async function performDeepSearch(topics) {
35
  const response = await fetch('/solutions/search_prior_art', {
36
  method: 'POST',
37
  headers: { 'Content-Type': 'application/json' },
@@ -81,8 +81,10 @@ export async function generateCompletion(providerUrl, modelName, apiKey, message
81
  }
82
  }
83
 
 
 
84
  /**
85
- * Genère une completion avec le LLM specifié
86
  * @param {String} providerUrl - URL du provider du LLM
87
  * @param {String} modelName - Nom du modèle à appeler
88
  * @param {String} apiKey - API key a utiliser
@@ -90,6 +92,7 @@ export async function generateCompletion(providerUrl, modelName, apiKey, message
90
  * @param {Object} schema - Zod schema to use for structured generation
91
  * @param {Number} temperature - Température à utiliser pour la génération
92
  */
 
93
  export async function generateStructuredCompletion(providerUrl, modelName, apiKey, messages, schema, temperature = 0.5) {
94
  const genEndpoint = providerUrl + "/chat/completions";
95
  try {
@@ -239,4 +242,24 @@ export async function refineSolution(providerUrl, modelName, apiKey, solution, i
239
  newSolution.solution_description = refined_idea;
240
 
241
  return newSolution;
242
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  * Lance un deep search sur le serveur pour les topics donnés.
32
  * @param {Array} topics
33
  */
34
+ export async function performDeepSearch(topics) {
35
  const response = await fetch('/solutions/search_prior_art', {
36
  method: 'POST',
37
  headers: { 'Content-Type': 'application/json' },
 
81
  }
82
  }
83
 
84
+
85
+
86
  /**
87
+ * Genère une completion structurée avec le LLM specifié
88
  * @param {String} providerUrl - URL du provider du LLM
89
  * @param {String} modelName - Nom du modèle à appeler
90
  * @param {String} apiKey - API key a utiliser
 
92
  * @param {Object} schema - Zod schema to use for structured generation
93
  * @param {Number} temperature - Température à utiliser pour la génération
94
  */
95
+ //TODO: Find the correct args to constrain the LLM to the json schema instead of enforcing json correct parsing
96
  export async function generateStructuredCompletion(providerUrl, modelName, apiKey, messages, schema, temperature = 0.5) {
97
  const genEndpoint = providerUrl + "/chat/completions";
98
  try {
 
242
  newSolution.solution_description = refined_idea;
243
 
244
  return newSolution;
245
+ }
246
+
247
+ // JS schema for FTO analysis topic extraction
248
+ const FTOAnalysisTopicsSchema = zod.object({
249
+ topics: zod.array(zod.string())
250
+ });
251
+
252
+ export async function getFtoAnalysisTopics(providerUrl, modelName, apiKey, idea) {
253
+ const template = await retrieveTemplate("fto_topics");
254
+
255
+ const structured_template = formatTemplate(template, {
256
+ "problem_description": idea.problem_description,
257
+ "solution_description": idea.solution_description,
258
+ "response_schema": zod.toJSONSchema(FTOAnalysisTopicsSchema),
259
+ });
260
+
261
+ const topics = await generateStructuredCompletion(providerUrl, modelName, apiKey, [{ role: "user", content: structured_template }], FTOAnalysisTopicsSchema);
262
+
263
+ return topics;
264
+ }
265
+
static/js/ui.js CHANGED
@@ -1,5 +1,5 @@
1
  import { marked } from 'https://cdnjs.cloudflare.com/ajax/libs/marked/16.1.1/lib/marked.esm.js';
2
- import { assessSolution, getModelList, refineSolution } from "./gen.js"
3
  import { clearConfig, loadConfig, saveConfig } from "./persistence.js";
4
 
5
  // =============================================================================
@@ -508,6 +508,7 @@ export function moveSolutionToDrafts(solution) {
508
 
509
  // push the solution to the draft history
510
  draftHistory.push({
 
511
  solution: solution,
512
  insights: insights,
513
  assessment_full: response.assessment_full,
@@ -637,6 +638,7 @@ export function handleDraftRefine() {
637
  const newInsights = result.assessedResult.extracted_info.insights.map((e, idx, __) => ({ id: idx, text: e, checked: false }));
638
 
639
  draftHistory.push({
 
640
  solution: result.refinedSolution,
641
  insights: newInsights,
642
  assessment_full: result.assessedResult.assessment_full,
@@ -665,6 +667,27 @@ function jumpToDraft(index) {
665
  }
666
  }
667
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
668
  /**
669
  * Displays the whole idea evaluation.
670
  */
 
1
  import { marked } from 'https://cdnjs.cloudflare.com/ajax/libs/marked/16.1.1/lib/marked.esm.js';
2
+ import { assessSolution, getModelList, refineSolution, getFtoAnalysisTopics, performDeepSearch } from "./gen.js"
3
  import { clearConfig, loadConfig, saveConfig } from "./persistence.js";
4
 
5
  // =============================================================================
 
508
 
509
  // push the solution to the draft history
510
  draftHistory.push({
511
+ type: "draft",
512
  solution: solution,
513
  insights: insights,
514
  assessment_full: response.assessment_full,
 
638
  const newInsights = result.assessedResult.extracted_info.insights.map((e, idx, __) => ({ id: idx, text: e, checked: false }));
639
 
640
  draftHistory.push({
641
+ type: "draft",
642
  solution: result.refinedSolution,
643
  insights: newInsights,
644
  assessment_full: result.assessedResult.assessment_full,
 
667
  }
668
  }
669
 
670
+ export function handleFTOAnalysis() {
671
+ const { providerUrl, providerToken, providerModel } = getConfigFields();
672
+ const currentState = draftHistory[draftCurrentIndex];
673
+
674
+ console.log("Launching FTO analysis");
675
+
676
+ showLoadingOverlay("Starting FTO analysis ...");
677
+
678
+ getFtoAnalysisTopics(providerUrl, providerModel, providerToken, currentState.solution)
679
+ .then(a => {
680
+ showLoadingOverlay("Performing FTO analysis ...");
681
+ performDeepSearch(a.topics)
682
+ .then((info) => {
683
+ console.log(info);
684
+ hideLoadingOverlay();
685
+ });
686
+ })
687
+ .catch(e => alert("Failed to perform FTO analysis: " + e))
688
+ .finally(() => hideLoadingOverlay());
689
+ }
690
+
691
  /**
692
  * Displays the whole idea evaluation.
693
  */