Integration chatgpt with wix Error

Question:
i installed chatgpt - npm by npm in wix

Product:
Wix Editor

What are you trying to achieve:
[i want to use chatgpt 4 with my site so i send a question and recive a answear]

What have you already tried:
i tried to excute the code in backend and also it is didn’t work

Additional information:
but i have a problem which appear as following
Cannot find module ‘fs’ in ‘gpt-3-encoder’

my code

import { ChatGPTAPI } from ‘chatgpt’;
export async function sendMessageGpt() {
const api = new ChatGPTAPI({
apiKey:apiKey
});
const res = await api.sendMessage(“hello i am here how can you help me”).then(result => {
console.log(result);
}).catch(error => {
console.error(error);
});
console.log(res);
}
$w.onReady(async function () {
let res = await sendMessageGpt();
console.log(res);
});

if anyone try chatgpt with another library please share it with me
thank you all

1 Like

Thank you! I am looking for the same thing, integrating ChatGPT with NPM, because I have already achieved it with fetch, but in this way I am still having problems. If I manage to solve it, I will let you know and write to you.

1 Like

here the solution

1 Like

I was looking for this thank you i want to add my own live chat bot to know customer issues this will surely help me run my store greatly understanding customers problem and to maximize the sales. Thank you :blush::blush:

1 Like

try this method

const axios = require(‘axios’);
export function chat() {

axios({
        method: 'post',
        url: 'https://api.openai.com/v1/embeddings',
        headers: {
            "Authorization": "Bearer use-token",
            "Content-Type": "application/json"
        },
        data: {
            "input": "The food was delicious and the waiter...",
            "model": "text-embedding-ada-002"
        }
    })
    .then(function (response) {
        console.log(response);
    })
    .catch(function (error) {
        console.log(error);
    });

}