Code: Select all
function openRouterApiRequest() {
var apiKey = "****";
// var imageUrl = 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg';
var imageUrl = "https://drive.google.com/file/d/11178UwHmPb2TAnYCyxFOKXlPh-vSPecv/view?usp=sharing";
var apiEndpoint = 'https://openrouter.ai/api/v1/chat/completions';
var payload = {
"model": "meta-llama/llama-4-maverick",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "What is in this image?"
},
{
"type": "image_url",
"image_url": {
"url": imageUrl
}
}
]
}
]
};
var options = {
'method': 'post',
'headers': {
'Authorization': 'Bearer ' + apiKey,
'Content-Type': 'application/json'
},
'payload': JSON.stringify(payload),
'muteHttpExceptions': true // To get the response even if the request fails
};
var response = UrlFetchApp.fetch(apiEndpoint, options);
var responseCode = response.getResponseCode();
var responseBody = response.getContentText();
// Handle the response as needed
Logger.log('Response Code: ' + responseCode);
Logger.log('Response Body: ' + responseBody);
// You might want to parse the responseBody if it's JSON
try {
var jsonResponse = JSON.parse(responseBody);
Logger.log(jsonResponse);
} catch (e) {
Logger.log('Failed to parse response as JSON: ' + e.message);
}
}
< /code>
Wenn ich es ankomme: < /p>
var imageUrl = 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg';
< /code>
Die Ausgabe enthält:{model=meta-llama/llama-4-maverick, created=1.744144885E9, system_fingerprint=, choices=[{finish_reason=stop, native_finish_reason=stop, index=0.0, logprobs=null, message={content=The image depicts a serene landscape featuring a wooden boardwalk or path that traverses through a lush grassy field. The boardwalk, constructed from weathered wooden planks, is flanked by tall grasses on both sides and appears to be slightly elevated above the surrounding terrain.
Wenn ich den Sharable-Link probiere: https://drive.google.com/file/d/11178uW ... specv/view? error","code":502,"metadata":{"raw":"error, status code: 500, status: , message: invalid character 'I' looking for beginning of value, body: ","provider_name":"Novita"}},"user_id":"user_2i6MRzMhAMlWPTYRLTP5uRwhSyx"}
Es scheint, dass dies nicht durch die LLM lesbar ist. Gibt es eine Möglichkeit, es lesbar zu machen?