I have figured out how to connect to openai but I’m getting error 401.
See my code below, please help.
import wixSecretsBackend from ‘wix-secrets-backend’ ; import { fetch } from ‘wix-fetch’ ; export const askOpenAi = async () => { const { Configuration , OpenAIApi } = require ( “openai” ); const configuration = new Configuration ({ apiKey : wixSecretsBackend . getSecret ( “OpenAi” ),}); const openai = new OpenAIApi ( Configuration ); const prompt = input: What is human life expectancy in the United States? output:
const response = await openai . createCompletion ( “text-davinci-001” , { prompt : prompt , temperature : 0 , max_tokens : 100 , top_p : 1 , frequency_penalty : 0 , presence_penalty : 0 , stop : [ “input:” ],}); return response . data ;}