Skip to content

Instantly share code, notes, and snippets.

@zuzannamj
Last active November 11, 2023 15:25
Show Gist options
  • Save zuzannamj/b3c1571b18ddc7f2fffc7de0dca2029a to your computer and use it in GitHub Desktop.
Save zuzannamj/b3c1571b18ddc7f2fffc7de0dca2029a to your computer and use it in GitHub Desktop.
<script runat = "server" >
Platform.Load("Core", "1");
try {
var interest = "dogs"; //add your interest
var contentType = 'application/json';
var headerNames = ["Authorization"];
var headerValues = ["Bearer xxxx"]; //add your key
var jsonBody = '{"model": "gpt-3.5-turbo","messages": [{"role": "user", "content": "Write a marketing email about ' + interest + '."}],"temperature": 0.5,"max_tokens": 100}'
var requestUrl = "https://api.openai.com/v1/chat/completions";
var request = HTTP.Post(requestUrl, contentType, jsonBody, headerNames, headerValues);
var respo = request.Response.toString();
var json = Platform.Function.ParseJSON(respo);
var content = json.choices[0].message.content;
Write(content); //prints the content of the email
} catch (error) {
}
</script>
@ojhamanvisafelite
Copy link

I am getting the "The remote server returned an error (429) Too many requests." after using the above code in code snippet and then using that code snippet in email template

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment