function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Michael Machado 22Michael Machado 22 

Einstein Language Is now Beta - Feedback Forum

EINSTEIN LANGUAGE IS BETA!
We're excited to announce Einstein Language, a powerful set of new APIs that allow developers of all skill levels to integrate natural language processing into their applications. Developers can now leverage two new APIs, Einstein Sentiment and Einstein Intent, to unlock powerful insights within text.
 
EINSTEIN LANGUAGE
Build smarter apps with natural language processing.
• Einstein Sentiment (Beta) allows developers to classify the sentiment of text into positive, negative, and neutral classes.
• Einstein Intent (Beta) is a customizable natural language processing service that allows developers to categorize unstructured text into user defined labels to better understand and prioritize customers’ needs across channels. 
 
• Einstein Language Technical Docs: https://metamind.readme.io/docs/intro-to-einstein-language

Please use this forum to provide feedback, success stories, and service questions.

-Einstein.ai Team
Siva Ramesh 1Siva Ramesh 1
I have been trying to use the Intent Web Service and I am able to get a 200 and Response when I POST from cURL and SOAPUI. However, when I construct the request body in APEX and POST am getting a Error - 400 which is a generic BAD request response. I have inspected the requests from cURL and my Apex anonymous code and both are identical. Not sure why I am getting this error. With limited error message details (since Language is still in Beta) am unable to proceed. Any pointers will be highly appreciated!! Below are screenshots from requestbin -

POST from Salesforce -

request Bin for Salesforce Post

POST from cURL -

User-added image
Michael Machado 22Michael Machado 22
Hi Siva.  We are working to resolve this integration issue with APEX and will provide feedback shortly. Thank you for bringing this issue to our attention.

-Michael
Aarthy KumaravelAarthy Kumaravel
Hi Michael, even I'm unable to make successfull API callouts for Einstein. Could you please let us know when the issue will be resolved?
Thanks!
Michael Machado 22Michael Machado 22
Can you please share the error response you are receiving and an anonymous version of your API call?
 
Siva Ramesh 1Siva Ramesh 1
Am getting a 400 status code - Bad Request Exception as my http Response. Below is the code am using to generate the sample http Request from the Developer Console (Execute Anonymous Window) -

 // Instantiate a new http object
    
    

    Http h = new Http();
    
     // Instantiate a new HTTP request
    HttpRequest req = new HttpRequest();
    //req.setEndpoint('https://api.einstein.ai/v2/language/intent?');
    req.setMethod('POST');
    // Send the request, and return a response
    String contentBoundary =  HttpFormBuilder.WriteBoundary();
 
    String modelId = 'K6GSMOQKDQDJCMNL4FQF44OQSQ'; //insert your model Id
    String sampleId= 'test';
   String token = //  Insert the token here
  
  req.setEndpoint('https://api.einstein.ai/v2/language/intent');

    
     
   String content = 'how is my package being shipped?';
   String contentType = '';//'\nContent-Type: text/plain\nContent-Transfer-Encoding: gzip';
   
// assemble the body payload
    String headerValue = '----' + contentBoundary  + contentType+ '\nContent-Disposition: form-data; name="modelId";\n\n'  + modelId + '\n';
    String body =  '----' + contentBoundary +contentType+ '\nContent-Disposition: form-data; name="document";\n\n'  + content  + '\n';
    String bodySample = '----' + contentBoundary + '\nContent-Disposition: form-data; name="sampleId";\n\n'  + 'Test'  + '\n';
    String footer ='----'+ contentBoundary + '--' ;
    String bodyPayload = headerValue + body + footer; 


     String authorizationHeader = 'Bearer ' + token;
     //EncodingUtil.base64Encode(headerValue);
     req.setHeader('Content-Type', 'multipart/form-data; boundary=' + '--'+ contentBoundary);
     req.setHeader('Authorization', authorizationHeader);
     req.setHeader('Cache-Control', 'no-cache');
    //if the request and response for your REST call is JSON, use the code below.
     req.setHeader('accept', '*/*');
     req.setHeader('Compressed', 'true');
    // system.debug('the body of the request is '+bodyPayLoad);
     
     //req.setHeader('Accept', '*/*');
    req.setBody(bodyPayload);
    system.debug('request is'+req.getBody());
    HttpResponse res = h.send(req);
    system.debug('the response is '+ res.getBody());
Michael Machado 22Michael Machado 22
Siva- Are you using the docs java examples to help you format- These can be referenced for Einstein Language too but need to be updated w/ new V2 parameters for language - https://metamind.readme.io/docs/code-samples-and-learning-resources
Siva Ramesh 1Siva Ramesh 1
I appreciate your quick response! Which example are you referring to? When I inspect the http request packet - the request am generating through my code is identical to the request generated by cURL. Am not sure as to why it is returning me a 400.
Michael Machado 22Michael Machado 22
Can you try again? We just made a recent change.
Abhishek Sharma 74Abhishek Sharma 74
@Siva / @Aarthy  - the above code has few missing blocks. could you please try using the API example that we have created:  https://github.com/MetaMind/apex-utils. Passing the appropriate parameters (token, modelId etc) to Language.intent() would serve the purpose. You can use apex-utils for calling other APIs as well. Please let me know if this doesn't helps. 
Siva Ramesh 1Siva Ramesh 1
@Abhishek, I made modifications per your utils class and it works like a charm. Really appreciate your help!!
Abhishek Sharma 74Abhishek Sharma 74
cool, glad to know that.