generated from axonivy-market/market-product
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
69d1c13
commit b52600e
Showing
9 changed files
with
420 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
vertexai-google-demo/src/com/axonivy/managedBean/GeminiDataBean2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package com.axonivy.managedBean; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.annotation.PostConstruct; | ||
import javax.faces.bean.ManagedBean; | ||
import javax.faces.bean.ViewScoped; | ||
|
||
import org.apache.commons.lang3.ObjectUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.primefaces.event.FilesUploadEvent; | ||
import org.primefaces.model.file.UploadedFile; | ||
import org.primefaces.model.file.UploadedFiles; | ||
|
||
import com.axonivy.connector.vertexai.entities.*; | ||
import com.axonivy.connector.vertexai.service.GeminiDataRequestService; | ||
import com.axonivy.connector.vertexai.service.GeminiDataRequestService2; | ||
|
||
import ch.ivyteam.ivy.environment.Ivy; | ||
|
||
@ManagedBean | ||
@ViewScoped | ||
public class GeminiDataBean2 { | ||
private String inputtedMessage; | ||
private Model model; | ||
private List<Conversation> conversations; | ||
private GeminiDataRequestService2 geminiDataRequestService2 = new GeminiDataRequestService2(); | ||
|
||
private UploadedFiles files; | ||
private List<String> base64Images; | ||
|
||
@PostConstruct | ||
public void init() { | ||
base64Images = new ArrayList<>(); | ||
conversations = new ArrayList<>(); | ||
geminiDataRequestService2.cleanData(); | ||
} | ||
|
||
public void onSendRequest() throws Exception { | ||
handleFilesUpload(); | ||
conversations = geminiDataRequestService2.sendRequestToGemini(inputtedMessage, base64Images, model); | ||
inputtedMessage = StringUtils.EMPTY; | ||
} | ||
|
||
public void onCleanText() { | ||
init(); | ||
geminiDataRequestService2.cleanData(); | ||
base64Images = new ArrayList<>(); | ||
} | ||
|
||
public void handleFilesUpload() { | ||
if (files != null) { | ||
for (UploadedFile file : files.getFiles()) { | ||
try (InputStream input = file.getInputStream()) { | ||
base64Images.add(java.util.Base64.getEncoder().encodeToString(input.readAllBytes())); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public Model[] onSelectModel() { | ||
return Model.values(); | ||
} | ||
|
||
public String getInputtedMessage() { | ||
return inputtedMessage; | ||
} | ||
|
||
public void setInputtedMessage(String inputtedMessage) { | ||
this.inputtedMessage = inputtedMessage; | ||
} | ||
|
||
public Model getModel() { | ||
return model; | ||
} | ||
|
||
public void setModel(Model model) { | ||
this.model = model; | ||
} | ||
|
||
public List<Conversation> getConversations() { | ||
return conversations; | ||
} | ||
|
||
public void setConversations(List<Conversation> conversations) { | ||
this.conversations = conversations; | ||
} | ||
|
||
public UploadedFiles getFiles() { | ||
return files; | ||
} | ||
|
||
public void setFiles(UploadedFiles files) { | ||
this.files = files; | ||
} | ||
|
||
public List<String> getBase64Images() { | ||
return base64Images; | ||
} | ||
|
||
public void setBase64Images(List<String> base64Images) { | ||
this.base64Images = base64Images; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
.../com/axonivy/connector/vertexai/vertexai/google/demo/chatWithAi2/chatWithAi2.rddescriptor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<richDialogDescriptor> | ||
<property> | ||
<name>viewTechnology</name> | ||
<value>JSF</value> | ||
</property> | ||
</richDialogDescriptor> |
57 changes: 57 additions & 0 deletions
57
.../src_hd/com/axonivy/connector/vertexai/vertexai/google/demo/chatWithAi2/chatWithAi2.xhtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<html xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:f="http://xmlns.jcp.org/jsf/core" | ||
xmlns:h="http://xmlns.jcp.org/jsf/html" | ||
xmlns:ui="http://xmlns.jcp.org/jsf/facelets" | ||
xmlns:ic="http://ivyteam.ch/jsf/component" | ||
xmlns:p="http://primefaces.org/ui" | ||
xmlns:pe="http://primefaces.org/ui/extensions"> | ||
<h:body> | ||
<ui:composition template="/layouts/basic-10.xhtml"> | ||
<ui:param name="managedBean" value="#{geminiDataBean2}" /> | ||
<ui:define name="title">ChatWithAi</ui:define> | ||
<ui:define name="content"> | ||
<h3>AI Chat</h3> | ||
<h:form id="form" enctype="multipart/form-data"> | ||
<div> | ||
<p:outputLabel for="option" value="Model" /> | ||
<p:selectOneMenu id="option" value="#{managedBean.model}"> | ||
<f:selectItems value="#{managedBean.onSelectModel()}" var="type" | ||
itemLabel="#{type.getName()}" itemValue="#{type}" /> | ||
</p:selectOneMenu> | ||
</div> | ||
<p:panelGrid columns="1" layout="grid" | ||
styleClass="ui-panelgrid-blank ui-fluid"> | ||
<ui:repeat var="conversation" value="#{managedBean.conversations}"> | ||
<p:panel rendered="#{conversation.role == 'user'}"> | ||
<h:outputText value="#{conversation.role}" | ||
style="font-weight:bold;" /> | ||
<h:outputText value="#{conversation.text}" escape="false" | ||
style="white-space: pre-line; display:block; margin-bottom:20px;" /> | ||
</p:panel> | ||
|
||
<p:panel rendered="#{conversation.role == 'model'}"> | ||
<h:outputText value="#{conversation.role}" | ||
style="font-weight:bold; color: red" /> | ||
<h:outputText value="#{conversation.text}" | ||
style="white-space: pre-line; display:block; margin-bottom:20px;" /> | ||
</p:panel> | ||
</ui:repeat> | ||
<p:inputTextarea widgetVar="editor" id="editor" | ||
value="#{managedBean.inputtedMessage}" height="150" | ||
style="margin-bottom:10px" placeholder="How can I help you today?"> | ||
</p:inputTextarea> | ||
</p:panelGrid> | ||
<br /> | ||
<div class="command-btns"> | ||
<p:fileUpload value="#{managedBean.files}" mode="simple" listener="#{managedBean.dandleFilesUpload()}" | ||
skinSimple="true" multiple="true"/> | ||
<p:commandButton id="refresh" value="refresh" update="form" | ||
actionListener="#{managedBean.onCleanText()}" icon="pi pi-refresh" /> | ||
<p:commandButton id="proceed" value="send" update="form" | ||
actionListener="#{managedBean.onSendRequest()}" icon="pi pi-check" /> | ||
</div> | ||
</h:form> | ||
</ui:define> | ||
</ui:composition> | ||
</h:body> | ||
</html> |
2 changes: 2 additions & 0 deletions
2
.../com/axonivy/connector/vertexai/vertexai/google/demo/chatWithAi2/chatWithAi2Data.ivyClass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
chatWithAi2Data #class | ||
com.axonivy.connector.vertexai.vertexai.google.demo.chatWithAi2 #namespace |
44 changes: 44 additions & 0 deletions
44
...com/axonivy/connector/vertexai/vertexai/google/demo/chatWithAi2/chatWithAi2Process.p.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"format" : "10.0.0", | ||
"id" : "18FC83D4B4D20E99", | ||
"kind" : "HTML_DIALOG", | ||
"config" : { | ||
"data" : "com.axonivy.connector.vertexai.vertexai.google.demo.chatWithAi2.chatWithAi2Data" | ||
}, | ||
"elements" : [ { | ||
"id" : "f0", | ||
"type" : "HtmlDialogStart", | ||
"name" : "start()", | ||
"config" : { | ||
"callSignature" : "start", | ||
"guid" : "18FC83D4B501EC7A" | ||
}, | ||
"visual" : { | ||
"at" : { "x" : 96, "y" : 64 } | ||
}, | ||
"connect" : { "id" : "f2", "to" : "f1" } | ||
}, { | ||
"id" : "f1", | ||
"type" : "HtmlDialogEnd", | ||
"visual" : { | ||
"at" : { "x" : 224, "y" : 64 } | ||
} | ||
}, { | ||
"id" : "f3", | ||
"type" : "HtmlDialogEventStart", | ||
"name" : "close", | ||
"config" : { | ||
"guid" : "18FC83D4B8371B51" | ||
}, | ||
"visual" : { | ||
"at" : { "x" : 96, "y" : 160 } | ||
}, | ||
"connect" : { "id" : "f5", "to" : "f4" } | ||
}, { | ||
"id" : "f4", | ||
"type" : "HtmlDialogExit", | ||
"visual" : { | ||
"at" : { "x" : 224, "y" : 160 } | ||
} | ||
} ] | ||
} |
Oops, something went wrong.