Last active
November 11, 2023 15:25
-
-
Save zuzannamj/b3c1571b18ddc7f2fffc7de0dca2029a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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