I'm calling the openai api like so:
const response = await fetch("https://api.openai.com/v1/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization:
"Bearer ...,
},
body: JSON.stringify({
model: "...",
prompt: promptString,
}),
});
but my the request in my browser(copied as fetch) is something like
fetch("https://api.openai.com/v1/completions", {
"headers": {
"accept": "*/*",
"accept-language": "en-GB,en-US;q=0.9,en;q=0.8",
"authorization": "....",
"content-type": "application/json",
"sec-ch-ua": "\"Not.A/Brand\";v=\"8\", \"Chromium\";v=\"114\", \"Google Chrome\";v=\"114\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"macOS\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "cross-site"
},
"referrerPolicy": "no-referrer",
"body": "...",
"method": "POST",
"mode": "cors",
"credentials": "include"
});
This makes for a bad completion from openai; copying this as cURL with the headers yields a similar result. I'm running this script via a chrome extension if that's relevant.
I'm unable to understand the cause of these headers and how I can prevent them. Any insight would be appreciated. Likewise any insight on the cause of the bad completion would be appreciated as well!
Edit: I tried running this on nodejs for some similar results My code:
openai
.createCompletion({
model: `text-curie-001`,
// temperature: 0.1,
// top_p: 0,
// logprobs: 2,
prompt:
prompt,
})
.then((response) => {
console.log(response.data);
})
.catch((e) => console.error(e));
The headers here are:
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json",
"User-Agent": "OpenAI/NodeJS/3.3.0",
Authorization: "...",
"Content-Length": 145,
I'd speculate that it's due to the Content-Length
which gets added automatically.
Using fetch instead of the opeai package doesn't help either.