Upload bing.js
Browse files- pages/api/bing.js +50 -0
pages/api/bing.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import axios from "axios";
|
| 2 |
+
|
| 3 |
+
export const config = {
|
| 4 |
+
"name": "bing",
|
| 5 |
+
"url": "/api/bing",
|
| 6 |
+
"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.",
|
| 7 |
+
"query": "prompt",
|
| 8 |
+
"response": "text",
|
| 9 |
+
"testURL": "./api/bing?prompt=hello"
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
export default async function handler(req, res2) {
|
| 13 |
+
let prompt = req.query.prompt;
|
| 14 |
+
|
| 15 |
+
axios.post('https://niansuhai-bingo.hf.space/api/create', {
|
| 16 |
+
|
| 17 |
+
}).then((res) => {
|
| 18 |
+
axios.post('https://niansuhai-bingo.hf.space/api/sydney',{
|
| 19 |
+
...res.data, "invocationId": 0,
|
| 20 |
+
"conversationStyle": "Balanced",
|
| 21 |
+
"prompt": prompt,
|
| 22 |
+
"allowSearch": true,
|
| 23 |
+
"context": ""
|
| 24 |
+
}).then((res) => {
|
| 25 |
+
let jsonString = res.data
|
| 26 |
+
// console.log(jsonString)
|
| 27 |
+
// require('fs').writeFileSync('output.txt', jsonString)
|
| 28 |
+
// Define the regex pattern to match the desired text
|
| 29 |
+
const regexPattern = /"message":"(.*?)"/;
|
| 30 |
+
|
| 31 |
+
// Use the regex pattern to find matches in the JSON string
|
| 32 |
+
const matches = jsonString.match(regexPattern);
|
| 33 |
+
|
| 34 |
+
// Extract the matched text
|
| 35 |
+
const extractedText = matches ? matches[matches.length-1] : null;
|
| 36 |
+
|
| 37 |
+
function replaceUnicodeWithEmoji(inputString) {
|
| 38 |
+
return inputString.replace(/\\u([\d\w]{4})/gi, (match, grp) => {
|
| 39 |
+
return String.fromCharCode(parseInt(grp, 16));
|
| 40 |
+
});
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
const input = extractedText;
|
| 44 |
+
const output = replaceUnicodeWithEmoji(input);
|
| 45 |
+
console.log(output.split('\\n').join('\n'));
|
| 46 |
+
res2.status(200).json({ "status": "Success", "message": output.split('\\n').join('\n') }); // Output: Hello! How can I assist you today? 😊
|
| 47 |
+
|
| 48 |
+
})
|
| 49 |
+
})
|
| 50 |
+
}
|