Delete HuggingFaceAPI.cls
Browse files- HuggingFaceAPI.cls +0 -40
HuggingFaceAPI.cls
DELETED
|
@@ -1,40 +0,0 @@
|
|
| 1 |
-
public class HuggingFaceAPI {
|
| 2 |
-
private static final String API_URL = 'http://your-flask-api-url/query'; // Change to your Flask API URL
|
| 3 |
-
|
| 4 |
-
// Method to make the HTTP request to Hugging Face API
|
| 5 |
-
public static String queryHuggingFace(String query) {
|
| 6 |
-
HttpRequest req = new HttpRequest();
|
| 7 |
-
req.setEndpoint(API_URL);
|
| 8 |
-
req.setMethod('POST');
|
| 9 |
-
req.setHeader('Content-Type', 'application/json');
|
| 10 |
-
|
| 11 |
-
// Prepare the JSON body
|
| 12 |
-
String jsonBody = '{"query": "' + query + '"}';
|
| 13 |
-
req.setBody(jsonBody);
|
| 14 |
-
|
| 15 |
-
Http http = new Http();
|
| 16 |
-
HttpResponse res = http.send(req);
|
| 17 |
-
|
| 18 |
-
// Check if the response is successful
|
| 19 |
-
if (res.getStatusCode() == 200) {
|
| 20 |
-
// Parse the JSON response
|
| 21 |
-
Map<String, Object> responseMap = (Map<String, Object>)JSON.deserializeUntyped(res.getBody());
|
| 22 |
-
String answer = (String)responseMap.get('answer');
|
| 23 |
-
return answer;
|
| 24 |
-
} else {
|
| 25 |
-
System.debug('Error: ' + res.getStatusCode() + ' ' + res.getStatus());
|
| 26 |
-
return 'Error: Could not fetch answer from Hugging Face model.';
|
| 27 |
-
}
|
| 28 |
-
}
|
| 29 |
-
|
| 30 |
-
// Method to log query in Salesforce
|
| 31 |
-
public static void logQuery(String userId, String query, String answer, String documentLink, Decimal confidenceScore) {
|
| 32 |
-
Chat_Query_Log__c newLog = new Chat_Query_Log__c();
|
| 33 |
-
newLog.User__c = userId;
|
| 34 |
-
newLog.Query__c = query;
|
| 35 |
-
newLog.Answer__c = answer;
|
| 36 |
-
newLog.Confidence_Score__c = confidenceScore;
|
| 37 |
-
newLog.Document_Link__c = documentLink;
|
| 38 |
-
insert newLog;
|
| 39 |
-
}
|
| 40 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|