Skip to content

Commit

Permalink
UI and GenAI
Browse files Browse the repository at this point in the history
  • Loading branch information
goulven authored and goulven committed Jan 2, 2025
1 parent 34dcb53 commit b8f2208
Show file tree
Hide file tree
Showing 13 changed files with 434 additions and 458 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.open4goods.commons.exceptions.AggregationSkipException;
import org.open4goods.commons.exceptions.InvalidParameterException;
import org.open4goods.commons.exceptions.ResourceNotFoundException;
import org.open4goods.commons.model.TopPage;
import org.open4goods.commons.model.AiSourcedPage;
import org.open4goods.commons.model.constants.RolesConstants;
import org.open4goods.commons.services.VerticalsConfigService;
import org.open4goods.commons.services.ai.GenAiService;
Expand Down Expand Up @@ -66,7 +66,7 @@ public String prompt(@RequestParam(defaultValue = "test") String key,

@GetMapping("/page/generate")
@Operation(summary="Generate a page")
public TopPage prompt(@RequestParam(defaultValue = "test") String key,
public AiSourcedPage prompt(@RequestParam(defaultValue = "test") String key,
String question,
String vertical,
String id,
Expand All @@ -75,7 +75,7 @@ public TopPage prompt(@RequestParam(defaultValue = "test") String key,

VerticalConfig vc = verticalsConfigService.getConfigById(vertical);

TopPage ret = pageGenService.generatePage(vc, question, id, question, title);
AiSourcedPage ret = pageGenService.generatePage(vc, question, id, question, title);

return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.open4goods.commons.dao.ProductRepository;
import org.open4goods.commons.exceptions.ResourceNotFoundException;
import org.open4goods.commons.model.AiReview;
import org.open4goods.commons.model.TopPage;
import org.open4goods.commons.model.AiSourcedPage;
import org.open4goods.commons.model.product.Product;
import org.open4goods.commons.services.VerticalsConfigService;
import org.open4goods.commons.services.ai.GenAiService;
Expand Down Expand Up @@ -51,21 +51,20 @@ public PageGenerationService( GenAiService aiService, VerticalsConfigService ver
* @throws ResourceNotFoundException
* @throws IOException
*/
public TopPage generatePage(VerticalConfig vConf, String question, String id, String language, String title) throws JsonParseException, JsonMappingException, ResourceNotFoundException, IOException {
public AiSourcedPage generatePage(VerticalConfig vConf, String question, String id, String language, String title) throws JsonParseException, JsonMappingException, ResourceNotFoundException, IOException {

Map<String,Object> context = new HashMap<>();

// Templates context feeding
context.put("VERTICAL_NAME", (vConf.getI18n().get("fr").getVerticalHomeTitle()));
context.put("QUESTION", question);


// AI Prompting
PromptResponse<CallResponseSpec> response = aiService.prompt("perplexity-top-page-generation", context);

System.out.println(response.getRaw());

TopPage page = new TopPage();
AiSourcedPage page = new AiSourcedPage();
page.setId(id);
page.setLanguage(language);
page.setQuestion(question);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void onProduct(Product data, VerticalConfig vConf) {


/**
* The data score is the number of score that are not virtuals
* The data score is the number of scores that are not virtuals
* @param map
* @return
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void onProduct(Product data, VerticalConfig vConf) {
private Double generateEcoScore(Map<String, Score> scores, VerticalConfig vConf) throws ValidationException {


double va = 0.0;
double ecoscoreVal = 0.0;
for (String config : vConf.getImpactScoreConfig().getCriteriasPonderation().keySet()) {
Score score = scores.get(config);

Expand All @@ -66,10 +66,10 @@ private Double generateEcoScore(Map<String, Score> scores, VerticalConfig vConf)


// Taking on the relativ
va += score. getRelativ().getValue() * Double.valueOf(vConf.getImpactScoreConfig().getCriteriasPonderation().get(config));
ecoscoreVal += score. getRelativ().getValue() * Double.valueOf(vConf.getImpactScoreConfig().getCriteriasPonderation().get(config));
}

return va;
return ecoscoreVal;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* POJO Content for a page that presents tops, best, ..
*/
@Document(indexName = "vertical-pages", createIndex = true, writeTypeHint = WriteTypeHint.FALSE)
public class TopPage {
public class AiSourcedPage {


@Id
Expand All @@ -28,17 +28,19 @@ public class TopPage {
private String title;

/***
* description of the article
* question this article must answers
*/
@Field(index = true, store = false, type = FieldType.Text)
private String description;
private String question;


/***
* question this article must answers
* description of the article
*/
@Field(index = true, store = false, type = FieldType.Text)
private String question;
private String description;


/** Conseils **/

@Field(index = true, store = false, type = FieldType.Text)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.open4goods.commons.store.repository.elastic;

import org.open4goods.commons.model.TopPage;
import org.open4goods.commons.model.AiSourcedPage;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

public interface VerticalPagesRepository extends ElasticsearchRepository<TopPage, String> {
public interface VerticalPagesRepository extends ElasticsearchRepository<AiSourcedPage, String> {

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.open4goods.ui.controllers.ui.pages;

import org.open4goods.ui.config.yml.UiConfig;
import org.open4goods.commons.config.yml.ui.VerticalConfig;
import org.open4goods.commons.services.VerticalsConfigService;
import org.open4goods.ui.controllers.ui.UiService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -27,11 +28,10 @@ public class EcoscoreController implements SitemapExposedController{

private static final Logger LOGGER = LoggerFactory.getLogger(EcoscoreController.class);
private @Autowired UiService uiService;
// The siteConfig
private final UiConfig config;
private @Autowired VerticalsConfigService verticalsConfigService;


public EcoscoreController(UiConfig config) {
this.config = config;
public EcoscoreController() {
}


Expand All @@ -46,6 +46,12 @@ public SitemapEntry getExposedUrls() {
public ModelAndView api(final HttpServletRequest request) {
ModelAndView ret = uiService.defaultModelAndView(("ecoscore"), request);
ret.addObject("page","évaluation environnementale");


VerticalConfig verticalConfig = verticalsConfigService.getConfigById("tv");
ret.addObject("impactscore",verticalConfig .getImpactScoreConfig());
ret.addObject("verticalConfig",verticalConfig);

return ret;
}

Expand Down
83 changes: 79 additions & 4 deletions ui/src/main/resources/static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,92 @@ CUSTOM
Xwiki css
**************************************************/
/** Xwiki box **/
.box {
min-height: 20px;

.box, .plainmessage, fieldset.xwikimessage {
min-height: 20px;
padding: 19px;
margin-bottom: 20px;
background-color: #fafafa;
border: 1px solid #e8e8e8;
border-radius: 4px;
border-radius: 7px;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.05);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.05);
overflow-x: auto;
}
}

.box blockquote, .plainmessage blockquote, fieldset.xwikimessage blockquote {
border-color: #ddd;
border-color: rgba(0, 0, 0, 0.15);
}

.box > *:last-child, .box > .xwiki-metadata-container > *:last-child {
margin-bottom: 0;
}

.plainmessage {
background-repeat: no-repeat;
}

.successmessage {
color: #3c763d;
background-color: #e5f3df;
border-color: #dbeccc;
border-color: #077537;
}

.successmessage hr {
border-top-color: #cee5ba;
}

.successmessage .alert-link {
color: #2b542c;
}

.errormessage {
color: #a94442;
background-color: #f8ecec;
border-color: #f1d9dd;
border-color: #ca302c;
}

.errormessage hr {
border-top-color: #eac7cd;
}

.errormessage .alert-link {
color: #843534;
}

.warningmessage {
color: #8a6d3b;
background-color: #fcf8e3;
border-color: #faebcc;
border-color: #f0ad4e;
}

.warningmessage hr {
border-top-color: #f7e1b5;
}

.warningmessage .alert-link {
color: #66512c;
}

.infomessage {
color: #31708f;
background-color: #e1f1f9;
border-color: #c3ebf3;
border-color: #2f70a7;
}

.infomessage hr {
border-top-color: #aee4ef;
}

.infomessage .alert-link {
color: #245269;
}



/** legacy bootsrap 3 jumbotron **/
Expand Down
7 changes: 4 additions & 3 deletions ui/src/main/resources/templates/default/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
<meta name="twitter:title" th:content="#{index.title}">
<meta name="twitter:description" th:content="#{index.meta.description}">
<meta name="twitter:image" th:content="${url} + 'assets/img/brand/light.svg'">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" integrity="sha512-c42qTSw/wPZ3/5LBzD+Bw5f7bSF2oxou6wEb+I/lqeaKV5FDIfMvvRp772y4jcJLKuGUOpbJMdg/BTl50fJYAw==" crossorigin="anonymous" referrerpolicy="no-referrer" />


<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" media="print" onload="this.media='all'">

<meta name="google-site-verification" content="I2wSyJnnRSjrLjadtNgFzHHmtSN8DPbjhPePTkQNhp4" />
</head>

Expand Down Expand Up @@ -494,7 +495,7 @@ <h3 id=opendata class="h5 card-title mt-3">Comparateur ouvert</h3>
<script src="/vendor/@popperjs/core/dist/umd/popper.min.js"></script>
<script src="/webjars/bootstrap/js/bootstrap.min.js"></script>
<script src="/webjars/jquery/jquery.min.js"></script>

<script src="/vendor/countup.js/dist/countUp.umd.js"></script>

<script src="/vendor/headroom.js/dist/headroom.min.js"></script>
<script src="/vendor/smooth-scroll/dist/smooth-scroll.polyfills.min.js"></script>
Expand Down
Loading

0 comments on commit b8f2208

Please sign in to comment.