File size: 1,693 Bytes
cc9763d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
    //    console.log(jsonString)
    //    require('fs').writeFileSync('output.txt', jsonString)
       // Define the regex pattern to match the desired text
const regexPattern = /"message":"(.*?)"/;

// Use the regex pattern to find matches in the JSON string
const matches = jsonString.match(regexPattern);

// Extract the matched text
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') }); // Output: Hello! How can I assist you today? 😊

    })
})
}