Created
February 18, 2023 19:37
-
-
Save shanwixcode/422d50916c0e7aaa743a367b107da4f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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