I am doing a basic implementation for my first time. I found this tutorial online. I’ve integrated code with nSo errors, however when I attempt to ask a question I am being returned the following error from the Google console.
xhr.js:162 Refused to set unsafe header “User-Agent”
zone.js:2707
SERVICE.TS
import { Injectable } from ‘@angular/core’;
import { Configuration, OpenAIApi } from ‘openai’;
@Injectable({
providedIn: ‘root’
})
export class OpenaiService {
private openai: OpenAIApi;
configuration = new Configuration({
apiKey: ‘sk-MYKEYHERE’
});
constructor() {
this.openai = new OpenAIApi(this.configuration);
}
generateText(prompt: string):Promise<string | undefined>{
return this.openai.createCompletion({
model: “text-davinci-003”,
prompt: prompt,
max_tokens: 256
}).then(response => {
return response.data.choices[0].text;
}).catch(error=>{
return ‘’;
});
}
}