-
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
0 parents
commit 986b812
Showing
13 changed files
with
303 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
Salesforce-MarkPrompt-Integration/main/default/aura/AskAI/AskAI.cmp
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,53 @@ | ||
<aura:component controller="ChatController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" > | ||
|
||
<aura:attribute name="messages" type="List" /> | ||
<aura:attribute name="newMessage" type="String" /> | ||
<aura:attribute name="isLoading" type="boolean" default="false"/> | ||
<div class="slds-box slds-theme_default"> | ||
<!--<div class="slds-form-element"> | ||
|
||
<aura:iteration items="{!v.messages}" var="message"> | ||
<li>{! message.role } : {! message.content }</li> | ||
</aura:iteration> | ||
</div>--> | ||
<div class="slds-chat"> | ||
<ul class="slds-chat-list"> | ||
<aura:iteration items="{!v.messages}" var="message"> | ||
<li class="slds-chat-listitem slds-m-bottom_small"> | ||
<aura:if isTrue="{! v.message.role == 'user' }"> | ||
<div class="slds-chat-message slds-chat-message_outbound"> | ||
<div class="slds-chat-message__text"> | ||
<span class="slds-chat-message__text slds-chat-message__text_outbound user-message">{! message.role } : {! message.content }</span> | ||
</div> | ||
</div> | ||
<aura:set attribute="else"> | ||
<div class="slds-chat-message slds-chat-message_inbound"> | ||
<div class="slds-chat-message__text"> | ||
<span class="slds-chat-message__text slds-chat-message__text_inbound bot-message"> {! message.role } : {! message.content }</span> | ||
</div> | ||
</div> | ||
</aura:set> | ||
</aura:if> | ||
</li> | ||
</aura:iteration> | ||
</ul> | ||
</div> | ||
|
||
<aura:if isTrue="{! v.isLoading }"> | ||
<div class="exampleHolder"> | ||
<lightning:spinner alternativeText="Loading" size="small" /> | ||
</div> | ||
</aura:if> | ||
|
||
<div class="slds-grid slds-grid_align-spread slds-p-top_medium"> | ||
<div class="slds-col slds-size_10-of-12"> | ||
<lightning:input label="Type your message" value="{! v.newMessage }" placeholder="type your Question here" /> | ||
</div> | ||
<div class="slds-col slds-size_2-of-12 slds-text-align_right slds-align-middle slds-p-top_medium"> | ||
<lightning:button variant="brand" label="Send" title="Send" onclick="{! c.sendMessage }" /> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
|
||
</aura:component> |
5 changes: 5 additions & 0 deletions
5
Salesforce-MarkPrompt-Integration/main/default/aura/AskAI/AskAI.cmp-meta.xml
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,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<AuraDefinitionBundle xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>59.0</apiVersion> | ||
<description>A Lightning Component Bundle</description> | ||
</AuraDefinitionBundle> |
18 changes: 18 additions & 0 deletions
18
Salesforce-MarkPrompt-Integration/main/default/aura/AskAI/AskAI.css
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,18 @@ | ||
.THIS.user-message { | ||
text-align: right; | ||
margin-bottom: 0.5; | ||
} | ||
|
||
.THIS.bot-message { | ||
text-align: left; | ||
margin-bottom: 0.5; | ||
} | ||
|
||
.THIS.exampleHolder{ | ||
position: relative; | ||
display: inline-block; | ||
margin-left: 15px; | ||
width: 55px; | ||
vertical-align: middle; | ||
white-space: nowrap; | ||
} |
30 changes: 30 additions & 0 deletions
30
Salesforce-MarkPrompt-Integration/main/default/aura/AskAI/AskAIController.js
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,30 @@ | ||
({ | ||
sendMessage: function (component, event, helper) { | ||
var userMessage = component.get("v.newMessage"); | ||
console.log('userMessage'+userMessage); | ||
var messages = component.get("v.messages"); | ||
console.log('messages'+messages); | ||
messages.push({ role: "user", content: userMessage }); | ||
component.set("v.messages", messages); | ||
console.log('messages1'+JSON.stringify(messages)); | ||
component.set("v.isLoading",true); | ||
// Call the Apex method to get the API response | ||
var action = component.get("c.getChatResponse"); | ||
action.setParams({ userMessage : JSON.stringify(messages) }); | ||
|
||
action.setCallback(this, function (response) { | ||
if (response.getState() === "SUCCESS") { | ||
var apiResponse = response.getReturnValue(); | ||
messages.push({ role: "assistant", content: apiResponse }); | ||
component.set("v.messages", messages); | ||
console.log(JSON.stringify(apiResponse)); | ||
component.set("v.isLoading",false); | ||
} | ||
else{ | ||
component.set("v.isLoading",false); | ||
} | ||
}); | ||
component.set("v.newMessage",""); | ||
$A.enqueueAction(action); | ||
} | ||
}) |
20 changes: 20 additions & 0 deletions
20
Salesforce-MarkPrompt-Integration/main/default/aura/Train_MarkPrompt/Train_MarkPrompt.cmp
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,20 @@ | ||
<aura:component controller="MarkPrompt" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global"> | ||
<aura:attribute name="FileList" type="Object" /> | ||
<aura:attribute name="isLoading" type="boolean" default="false"/> | ||
<div class="slds-box slds-theme_default"> | ||
<div class="slds-form-element"> | ||
<label class="slds-form-element__label" for="file">Attachment</label> | ||
<div class="slds-form-element__control"> | ||
<lightning:input name="file" type="file" files="{!v.FileList}" aura:id="fileInput" accept=".txt, .zip" onchange="{!c.handleFilesChange}" /> | ||
</div> | ||
</div> | ||
<div class="slds-m-top_medium"> | ||
<lightning:button label="Submit" variant="brand" onclick="{!c.uploadFileHandler}" /> | ||
</div> | ||
<aura:if isTrue="{! v.isLoading }"> | ||
<div class="exampleHolder"> | ||
<lightning:spinner alternativeText="Loading" size="small" /> | ||
</div> | ||
</aura:if> | ||
</div> | ||
</aura:component> |
5 changes: 5 additions & 0 deletions
5
...e-MarkPrompt-Integration/main/default/aura/Train_MarkPrompt/Train_MarkPrompt.cmp-meta.xml
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,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<AuraDefinitionBundle xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>59.0</apiVersion> | ||
<description>A Lightning Component Bundle</description> | ||
</AuraDefinitionBundle> |
16 changes: 16 additions & 0 deletions
16
...e-MarkPrompt-Integration/main/default/aura/Train_MarkPrompt/Train_MarkPromptController.js
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,16 @@ | ||
({ | ||
handleFilesChange: function(component, event, helper) { | ||
var files = event.getSource().get("v.files"); | ||
component.set("v.FileList", files[0]); | ||
console.log(files.length + ' files !!'); | ||
}, | ||
|
||
uploadFileHandler: function(component, event, helper) { | ||
var file = component.get("v.FileList"); | ||
console.log('uploadfileHandler'+file); | ||
if (file) { | ||
component.set("v.isLoading",true); | ||
helper.uploadFileHelper(component, file); | ||
} | ||
} | ||
}) |
48 changes: 48 additions & 0 deletions
48
...force-MarkPrompt-Integration/main/default/aura/Train_MarkPrompt/Train_MarkPromptHelper.js
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,48 @@ | ||
({ | ||
uploadFileHelper: function(component, file) { | ||
var reader = new FileReader(); | ||
reader.onload = $A.getCallback(function() { | ||
var base64 = reader.result.match(/,(.*)$/)[1]; | ||
var fileName = file.name; | ||
var fileType = file.type; | ||
var fileData = file.toString(); | ||
console.log('txt-----'+fileData); | ||
console.log('Name and type '+fileName+'------'+fileType); | ||
var action = component.get("c.uploadFile"); | ||
action.setParams({ | ||
base64Data: base64, | ||
fileName: fileName, | ||
fileType: fileType, | ||
fileData: fileData | ||
}); | ||
|
||
action.setCallback(this, function(response) { | ||
var state = response.getState(); | ||
|
||
if (state === 'SUCCESS') { | ||
console.log("success"); | ||
|
||
console.log('res '+JSON.stringify(response.getReturnValue())); | ||
var jsonString = response.getReturnValue(); | ||
var jsonObject = JSON.parse(jsonString); | ||
console.log(JSON.stringify(response.getReturnValue()).length); | ||
component.set("v.isLoading",false); | ||
if(jsonObject.status == "ok"){ | ||
alert("Success: " + jsonObject.message); | ||
} | ||
else{ | ||
alert("Error uploading the file: " + jsonObject.message); | ||
} | ||
|
||
} else { | ||
alert("Error uploading the file: " + response.getError()[0].message); | ||
|
||
} | ||
|
||
}); | ||
|
||
$A.enqueueAction(action); | ||
}); | ||
reader.readAsDataURL(file); | ||
} | ||
}) |
30 changes: 30 additions & 0 deletions
30
Salesforce-MarkPrompt-Integration/main/default/classes/ChatController.cls
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,30 @@ | ||
public with sharing class ChatController { | ||
|
||
public class messageData { | ||
public String role; | ||
public String content; | ||
} | ||
|
||
@AuraEnabled | ||
public static String getChatResponse(String userMessage) { | ||
String endpoint = 'https://api.markprompt.com/v1/chat'; | ||
String token = 'ZmxnkPHLuRBQkUXkyf4a0z2UbBlf5O4D'; // change token | ||
String requestBody = '{ "messages": ' + userMessage + ', "model": "gpt-4","projectKey":"sk_test_DIvPRkylZxa9MuctLquFfX2Fcm2qhpQ2"}'; //change development key here | ||
|
||
HttpRequest request = new HttpRequest(); | ||
request.setEndpoint(endpoint); | ||
request.setMethod('POST'); | ||
request.setHeader('Authorization', 'Bearer ' + token); | ||
request.setHeader('Content-Type', 'application/json'); | ||
request.setBody(requestBody); | ||
|
||
Http http = new Http(); | ||
HttpResponse response = http.send(request); | ||
|
||
if (response.getStatusCode() == 200) { | ||
return response.getBody(); | ||
} else { | ||
return 'Error: ' + response.getStatus(); | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
Salesforce-MarkPrompt-Integration/main/default/classes/ChatController.cls-meta.xml
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,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>59.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
62 changes: 62 additions & 0 deletions
62
Salesforce-MarkPrompt-Integration/main/default/classes/MarkPrompt.cls
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,62 @@ | ||
public class MarkPrompt { | ||
|
||
public class Request { | ||
public List<FileData> files; | ||
} | ||
|
||
public class FileData { | ||
public String path; | ||
public String content; | ||
} | ||
|
||
@AuraEnabled | ||
public static string uploadFile(String base64Data, String fileName, String fileType, string fileData) { | ||
try { | ||
string trainURL = 'https://api.markprompt.com/v1/train'; | ||
string accessToken = 'ZmxnkPHLuRBQkUXkyf4a0z2UbBlf5O4D'; // Change Token | ||
|
||
Http http = new Http(); | ||
HttpRequest requestTrain = new HttpRequest(); | ||
requestTrain.setMethod('POST'); | ||
requestTrain.setEndpoint(trainURL); | ||
requestTrain.setHeader('Accept', 'application/json'); | ||
requestTrain.setHeader('Authorization', 'Bearer ' + accessToken); | ||
|
||
if(fileName.endsWith('.zip')){ | ||
Blob fileBlob = EncodingUtil.base64Decode(base64Data); | ||
requestTrain.setHeader('content-Type', 'application/zip'); | ||
requestTrain.setBodyAsBlob(fileBlob); | ||
} | ||
Else{ | ||
if(fileName.endsWith('.txt')){ | ||
MarkPrompt.Request request = new MarkPrompt.Request(); | ||
request.files = new List<MarkPrompt.FileData>(); | ||
MarkPrompt.FileData obj = new MarkPrompt.FileData(); | ||
obj.path=fileName; | ||
obj.content=fileData; | ||
request.files.add(obj); | ||
string requestBody = JSON.serialize(request); | ||
requestTrain.setHeader('content-Type', 'application/json'); | ||
requestTrain.setBody(requestBody); | ||
} | ||
} | ||
HttpResponse responseTrain = http.send(requestTrain); | ||
|
||
if (responseTrain.getStatusCode() == 200) { | ||
|
||
system.debug('########'+JSON.serializePretty(responseTrain.getBody())); | ||
|
||
|
||
} else { | ||
|
||
System.debug('API call failed with status code: ' + responseTrain.getStatusCode()); | ||
|
||
} | ||
return responseTrain.getBody(); | ||
//insert content; | ||
} catch (Exception e) { | ||
throw new AuraHandledException('Error uploading the file: ' + e.getMessage()); | ||
|
||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
Salesforce-MarkPrompt-Integration/main/default/classes/MarkPrompt.cls-meta.xml
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,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>59.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
6 changes: 6 additions & 0 deletions
6
...rce-MarkPrompt-Integration/main/default/remoteSiteSettings/MarkPrompt.remoteSite-meta.xml
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,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<RemoteSiteSetting xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<disableProtocolSecurity>false</disableProtocolSecurity> | ||
<isActive>true</isActive> | ||
<url>https://api.markprompt.com</url> | ||
</RemoteSiteSetting> |