I am making a chrome extension that uses Chat GPT 3.5 and have coded a simple prompt to send to the API using openai api and returns a value in the console.
I have my code below and keep getting this error...
error:
code: null
message: "you must provide a model parameter"
param: null
type: "invalid_request_error"
event though i have a model parameter.
// Define the API key
const API_KEY = "API KEY";
// Define the endpoint URL
const endpointUrl = "https://api.openai.com/v1/chat/completions";
// Define the headers
const headers = {
"Content-Type": "application/json",
Authorization: `Bearer ${API_KEY}`,
};
// Define the maximum number of completions to return
const maxCompletions = 1;
// Define the prompt to send to the API
const prompt = {
model: "gpt-3.5-turbo",
prompt: "Hello, world!",
temperature: 0.5,
};
// Send a POST request to the endpoint with the prompt and headers
fetch(endpointUrl, {
method: "POST",
headers,
body: JSON.stringify({
prompt,
max_completions: maxCompletions,
}),
})
.then((response) => response.json())
.then((data) => {
// Log the response data to the console
console.log(data);
})
.catch((error) => {
console.error(error);
});