<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Leonardo ML Functional API Python examples in Artificial Intelligence Forum</title>
    <link>https://community.sap.com/t5/artificial-intelligence-forum/leonardo-ml-functional-api-python-examples/m-p/502012#M50</link>
    <description>&lt;P&gt;I have tried your snippet and modified it accordingly. PFB the snippet&lt;/P&gt;
  &lt;P&gt;import requests &lt;/P&gt;
  &lt;P&gt;import json &lt;/P&gt;
  &lt;P&gt;headers = { 'APIKey' : 'xyz', 'Accept' : 'application/json', 'content-type' : 'application/json' }&lt;/P&gt;
  &lt;P&gt; data = { 'options' : {"period":"12"},'texts':['1,2,3,4,5,6,7,8,9,10,11,12'] } &lt;/P&gt;
  &lt;P&gt;url = "https://sandbox.api.sap.com/ml/timeseriesforecast/inference_sync" &lt;/P&gt;
  &lt;P&gt;r = requests.post(url, data=json.dumps(data), headers=headers) &lt;/P&gt;
  &lt;P&gt;print(r.text)&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;Output:&lt;/P&gt;
  &lt;P&gt;{ "_id": "adb69b92-8f38-463c-aff4-54bae08a5637", "error": "Invalid request", "error_description": "This service requires at least 1 file or 1 text Please put your input into the \"files\" or \"text\" field of the POST request", "processed_time": "Thu, 19 Jul 2018 08:31:59 GMT", "request": { "files": null, "options": {}, "tenantName": "imgclassif-tech-user", "texts": [] }, "status": "FAILED", "status_code": 400, "tenantName": "imgclassif-tech-user" }&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;Please Help!!!!!&lt;/P&gt;</description>
    <pubDate>Thu, 19 Jul 2018 08:32:50 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2018-07-19T08:32:50Z</dc:date>
    <item>
      <title>Leonardo ML Functional API Python examples</title>
      <link>https://community.sap.com/t5/artificial-intelligence-forum/leonardo-ml-functional-api-python-examples/m-p/502010#M48</link>
      <description>&lt;P&gt;Could anyone please provide example API usage with Python? Currently the "&lt;EM&gt;Generate Code&lt;/EM&gt;" option displays examples in J&lt;EM&gt;avascript, Java, Swift, Curl, ABAP&lt;/EM&gt; and &lt;EM&gt;SAPUI5&lt;/EM&gt;. For example &lt;A target="_blank" href="https://answers.sap.com/questions/307248/need-python-3-code-snippet-to-call-sap-leonardo-ml.html"&gt;this answer&lt;/A&gt; describes using &lt;EM&gt;prodimgclassifier&lt;/EM&gt; and I would like to know ways to call other APIs such as time-series prediction, language translation etc.&lt;BR /&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2024 00:20:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/artificial-intelligence-forum/leonardo-ml-functional-api-python-examples/m-p/502010#M48</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2024-02-04T00:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Leonardo ML Functional API Python examples</title>
      <link>https://community.sap.com/t5/artificial-intelligence-forum/leonardo-ml-functional-api-python-examples/m-p/502011#M49</link>
      <description>&lt;P&gt;The link you provided makes this out to be a little more complicated than it needs to be. At it's core with any REST service, you need the url you want to retrieve, the headers you'd like to send along with it and in the case of a POST the data you want to send.&lt;/P&gt;
  &lt;P&gt;Here's an example for the &lt;A target="_blank" href="https://cloudintegration.hana.ondemand.com/shell/discover/contentpackage/SAPLeonardoMLFunctionalServices/api/timeseries_forecast_api?section=RESOURCE"&gt;Time Series Forecast API&lt;/A&gt; you mentioned. Assuming you have the requests library installed (if not, &lt;A target="_blank" href="http://docs.python-requests.org/en/master/user/install/"&gt;install it&lt;/A&gt;) all you have to do is specify the url, create the headers and data as a dict, and allow the requests library to take care of the post action for you.&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;import requests
import json

headers = {
    'APIKey' : 'your API Key',
    'Accept' : 'application/json',
    'content-type' : 'multipart/form-data'
    }

data = {
    'options' : 'string'
    }

url = "https://sandbox.api.sap.com/ml/timeseriesforecast/inference_sync"

resp = requests.post(url, data=json.dumps(data), headers=headers)
print(r.text)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Oct 2017 19:11:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/artificial-intelligence-forum/leonardo-ml-functional-api-python-examples/m-p/502011#M49</guid>
      <dc:creator>former_member492038</dc:creator>
      <dc:date>2017-10-06T19:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: Leonardo ML Functional API Python examples</title>
      <link>https://community.sap.com/t5/artificial-intelligence-forum/leonardo-ml-functional-api-python-examples/m-p/502012#M50</link>
      <description>&lt;P&gt;I have tried your snippet and modified it accordingly. PFB the snippet&lt;/P&gt;
  &lt;P&gt;import requests &lt;/P&gt;
  &lt;P&gt;import json &lt;/P&gt;
  &lt;P&gt;headers = { 'APIKey' : 'xyz', 'Accept' : 'application/json', 'content-type' : 'application/json' }&lt;/P&gt;
  &lt;P&gt; data = { 'options' : {"period":"12"},'texts':['1,2,3,4,5,6,7,8,9,10,11,12'] } &lt;/P&gt;
  &lt;P&gt;url = "https://sandbox.api.sap.com/ml/timeseriesforecast/inference_sync" &lt;/P&gt;
  &lt;P&gt;r = requests.post(url, data=json.dumps(data), headers=headers) &lt;/P&gt;
  &lt;P&gt;print(r.text)&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;Output:&lt;/P&gt;
  &lt;P&gt;{ "_id": "adb69b92-8f38-463c-aff4-54bae08a5637", "error": "Invalid request", "error_description": "This service requires at least 1 file or 1 text Please put your input into the \"files\" or \"text\" field of the POST request", "processed_time": "Thu, 19 Jul 2018 08:31:59 GMT", "request": { "files": null, "options": {}, "tenantName": "imgclassif-tech-user", "texts": [] }, "status": "FAILED", "status_code": 400, "tenantName": "imgclassif-tech-user" }&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;Please Help!!!!!&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jul 2018 08:32:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/artificial-intelligence-forum/leonardo-ml-functional-api-python-examples/m-p/502012#M50</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-07-19T08:32:50Z</dc:date>
    </item>
    <item>
      <title>Re: Leonardo ML Functional API Python examples</title>
      <link>https://community.sap.com/t5/artificial-intelligence-forum/leonardo-ml-functional-api-python-examples/m-p/502013#M51</link>
      <description>&lt;P&gt;Your request is being made with a `texts` parameter but the error message seems to suggest you should be sending `text`&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jul 2018 15:27:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/artificial-intelligence-forum/leonardo-ml-functional-api-python-examples/m-p/502013#M51</guid>
      <dc:creator>former_member492038</dc:creator>
      <dc:date>2018-07-19T15:27:47Z</dc:date>
    </item>
  </channel>
</rss>

