this is a very specific questions so I am not sure if there is anyone that can answer, but I have to try anyway.
So the reddit tldr bot uses the Smmry API to summarize content. I am trying to make something similar. The problem is in the documentation it only shows URLs as a possible parameter. Does anyone know how I could just pass a string of text?
I tried emailing them but got no response.
The home page of Smmry lets you pass just text so I am sure you can do it, There is also an example in PHP but I have 0 knowledge of PHP. Here is their PHP example:
$text = "Your long text goes here...";
$ch = curl_init("https://api.smmry.com/&SM_API_KEY=X");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Expect:")); // See Note
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "sm_api_input=".$text);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$return = json_decode(curl_exec($ch), true);
curl_close($ch);
Here is the sample code I am using for the request in javascript. YOURKEY is a placeholder for the key each person gets.
const axios = require('axios')
axios.post('https://api.smmry.com?SM_API_KEY=YOURKEY', {
})
.then(function (response) {
console.log(response.data.sm_api_content);
})
.catch(function (error) {
console.log(error);
});
Pass the string you would like to summarize as a key=pair value as a single string.
The added headers mimic the example in the API docs.
const axios = require('axios');
const text = 'A very long text to summarize..';
axios.post(
'https://api.smmry.com?SM_API_KEY=YOURKEY',
`sm_api_input=${text}`,
{
headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
'Expect': '100-continue'
}
}
)
.then(function (response) {
console.log(response.data.sm_api_content);
})
.catch(function (error) {
console.log(error);
});