|
import axios from "axios"; |
|
|
|
export const config = { |
|
"name": "bing", |
|
"url": "/api/bing", |
|
"description": "Get response from Bing. Bing is a very powerful AI that can do a lot of things. It have access to real time internet! It can provide you with the latest news, weather, and more.", |
|
"query": "prompt", |
|
"response": "text", |
|
"testURL": "./api/bing?prompt=hello" |
|
} |
|
|
|
export default async function handler(req, res2) { |
|
let prompt = req.query.prompt; |
|
|
|
axios.post('https://niansuhai-bingo.hf.space/api/create', { |
|
|
|
}).then((res) => { |
|
axios.post('https://niansuhai-bingo.hf.space/api/sydney',{ |
|
...res.data, "invocationId": 0, |
|
"conversationStyle": "Balanced", |
|
"prompt": prompt, |
|
"allowSearch": true, |
|
"context": "" |
|
}).then((res) => { |
|
let jsonString = res.data |
|
|
|
|
|
|
|
const regexPattern = /"message":"(.*?)"/; |
|
|
|
|
|
const matches = jsonString.match(regexPattern); |
|
|
|
|
|
const extractedText = matches ? matches[matches.length-1] : null; |
|
|
|
function replaceUnicodeWithEmoji(inputString) { |
|
return inputString.replace(/\\u([\d\w]{4})/gi, (match, grp) => { |
|
return String.fromCharCode(parseInt(grp, 16)); |
|
}); |
|
} |
|
|
|
const input = extractedText; |
|
const output = replaceUnicodeWithEmoji(input); |
|
console.log(output.split('\\n').join('\n')); |
|
res2.status(200).json({ "status": "Success", "message": output.split('\\n').join('\n') }); |
|
|
|
}) |
|
}) |
|
} |