Skip to content

Instantly share code, notes, and snippets.

@shanwixcode
Created February 18, 2023 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanwixcode/422d50916c0e7aaa743a367b107da4f7 to your computer and use it in GitHub Desktop.
Save shanwixcode/422d50916c0e7aaa743a367b107da4f7 to your computer and use it in GitHub Desktop.
import {fetch} from 'wix-fetch';
const key = "";
export async function initiate_gpt(user) {
const parameters = {
model: 'text-davinci-003',
prompt: 'You are a customer support agent for an online store selling women apparel. Please respond to customers reaching out with queries.',
max_tokens: 100,
n: 1,
temperature: 0.2,
user: user
};
return fetch("https://api.openai.com/v1/completions", {
"method": "post",
"headers": {
"Content-Type": "application/json",
"Authorization": 'Bearer ' + key
},
"body": JSON.stringify(parameters)
} )
.then( (httpResponse) => {
return httpResponse.json();
})
.then( (json) => {
return json;
})
.catch( (err) => {
return err;
});
}
export async function ask_gpt(text, user) {
const parameters = {
model: 'text-davinci-003',
prompt: text,
max_tokens: 100,
n: 1,
temperature: 0.2,
user: user
};
return fetch("https://api.openai.com/v1/completions", {
"method": "post",
"headers": {
"Content-Type": "application/json",
"Authorization": 'Bearer ' + key
},
"body": JSON.stringify(parameters)
} )
.then( (httpResponse) => {
return httpResponse.json();
})
.then( (json) => {
return json;
})
.catch( (err) => {
return err;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment