gpt4 book ai didi

node.js - 当我提取图像数据时,它没有从 duckduckgo api 显示

转载 作者:太空宇宙 更新时间:2023-11-03 23:22:23 25 4
gpt4 key购买 nike

我正在使用node.js、microsoft bot框架和duckduckgo api,我想根据我得到的asnwer文本和url的问题显示图像结果,但图像没有在我的机器人中显示。谢谢。我提供了下面的代码 imagescreenshot1 image2

if (session.userData.search === 'DuckDuckGo') {

request = require('request');
var url = "https://api.duckduckgo.com/?q=" + encodeURIComponent(messageText) + "&format=json&pretty=1";
console.log("data:", messageText);
request(url, function(err, response, body) {
if (err) console.log(err);
if (response.statusCode == 200) {
body = JSON.parse(body)
session.sendTyping();
console.log(body);
if (!_.isEmpty(body.AbstractText)) {
session.send(body.AbstractText);
session.send(body.Image);
} else if (!_.isEmpty(body.RelatedTopics[0])) {
session.send(body.RelatedTopics[0].Icon.URL);
session.send(body.RelatedTopics[0].Text);
session.send(body.RelatedTopics[0].Icon);
console.log("data1111" , body.RelatedTopics[0].Icon);
console.log("tubag:", body.RelatedTopics[1].Text);
/* session.send("Related Results");*/
/* builder.Prompts.send(body.RelatedTopics[1].Text)
builder.Prompts.text(session, body.RelatedTopics[2].Text)
builder.Prompts.text(session, body.RelatedTopics[3].Text)*/

} else {
session.send('https://duckduckgo.com/?q=%s', encodeURIComponent(messageText));
}

} else if (response.statusCode == 500) {
session.send("error: server error");

} else {
session.send("error: problem with request code: " + response.statusCode)

}
});

最佳答案

图像/图标的 URL 可能为空。如果没有提供图像 URL,则在此示例中机器人将不会制作或发送任何图像附件。

request = require('request');
var url = "https://api.duckduckgo.com/?q=" + encodeURIComponent(messageText) + "&format=json&pretty=1";
console.log("data:", messageText);
request(url, function(err, response, body) {
if (err) console.log(err);
if (response.statusCode == 200) {
body = JSON.parse(body)
session.sendTyping();
console.log(body);
if (!_.isEmpty(body.AbstractText)) {
session.send(body.AbstractText);
session.send(body.Image);
} else if (!_.isEmpty(body.RelatedTopics[0])) {
session.send(body.RelatedTopics[0].Icon.URL);
session.send(body.RelatedTopics[0].Text);
session.send(body.RelatedTopics[0].Icon);
console.log("data1111" , body.RelatedTopics[0].Icon);
console.log("tubag:", body.RelatedTopics[1].Text);
/* session.send("Related Results");*/
/* builder.Prompts.send(body.RelatedTopics[1].Text)
builder.Prompts.text(session, body.RelatedTopics[2].Text)
builder.Prompts.text(session, body.RelatedTopics[3].Text)*/

} else {
session.send('https://duckduckgo.com/?q=%s', encodeURIComponent(messageText));
}

} else if (response.statusCode == 500) {
session.send("error: server error");

} else {
session.send("error: problem with request code: " + response.statusCode)

}

关于node.js - 当我提取图像数据时,它没有从 duckduckgo api 显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48312807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com