Advertisement
Guest User

google sheets AI

a guest
Feb 6th, 2024
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. function openai(cellContent, modelo, systemprompt) {
  2. var url = 'https://api.openai.com/v1/chat/completions';
  3. var headers = {
  4. "Content-Type": "application/json",
  5. "Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  6. };
  7.  
  8. var data = {
  9. "model": modelo,
  10. "messages": [
  11. {
  12. "role": "system",
  13. "content": systemprompt
  14. },
  15. {
  16. "role": "user",
  17. "content": cellContent // Or replace this with your actual question
  18. }
  19. ]
  20. };
  21.  
  22. var options = {
  23. "method" : "post",
  24. "headers": headers,
  25. "payload" : JSON.stringify(data)
  26. };
  27.  
  28. var response = UrlFetchApp.fetch(url, options);
  29. var json = JSON.parse(response.getContentText());
  30.  
  31. return json.choices[0].message.content; // This will return the answer from GPT-3.5-turbo
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement