ChatGPT with saving user context

ChatGPT with saving user context

Hello, everyone!
I've encountered an obstacle on my way that I can't solve. I want to create a Zobot instance connected to ChatGPT. I want to chat with ChatGPT while saving previous user questions (context).

So, I have created a Zobot instance with codeless builder.
And I have created two deluge scripts (as a plug) inside a Zobot:
1) ChatGPT plug (Engine for sending and getting answer from ChatGPT url)

  1. // current user request
  2. if(session.containsKey("question"))
  3. {
  4. question = session.get("question").get("value");
  5. }
  6. // Array of previous user requests (context)
  7. if(session.containsKey("context"))
  8. {
  9. context = session.get("context").get("value");
  10. }
  11. token = "Bearer MY_TOKEN_HERE_IS_REMOVED";
  12. header = Map();
  13. header.put("Authorization",token);
  14. header.put("Content-Type","application/json");
  15. messages = List();
  16. // create array of previous user questions
  17. for each  questionItem in context
  18. {
  19. messages.add({"role":"user","content":questionItem});
  20. }
  21. // add to array last question
  22. messages.add({"role":"user","content":question});
  23. // create JSON to chat GPT request
  24. chatgpt = Collection();
  25. chatgpt = {"model":"gpt-3.5-turbo","messages":messages,"temperature":0.9,"max_tokens":500,"top_p":1,"frequency_penalty":0.0,"presence_penalty":0.6,"stop":{" Human:"," AI:"}};
  26. info chatgpt;
  27. params = Map();
  28. params.put(chatgpt);
  29. response = invokeurl
  30. [
  31. url :"https://api.openai.com/v1/chat/completions"
  32. type :POST
  33. parameters:params.toString()
  34. headers:header
  35. ];
  36. answer = response.get("choices").getJSON("message").get("content");
  37. response = Map();
  38. // first time there is no context
  39. if(context.size() > 0)
  40. {
  41. // next time pass input context
  42. response.put("fromChatContext",context);
  43. }
  44. response.put("answer",answer);
  45. info response;
  46. return response;
ChatGPT plug parameters:



Input question - is a last user question
Input context - is an array of previous user questions (when an user texts first time there is no context)
Output fromChatContext - just to pass a context array further.
Output answer - what ChatGPT is answered to a user question.

Okey, next goal is to collect a user questions and pass further to ChatGPT input (as a context)

2) CollectContextScript - to add a current user question to array of previous questions (context):

  1. // last user request
  2. if(session.containsKey("lastRequest"))
  3. {
  4. lastRequest = session.get("lastRequest").get("value");
  5. }
  6. // Array of previous user request (context)
  7. if(session.containsKey("previousContext"))
  8. {
  9. previousContext = session.get("previousContext").get("value");
  10. }
  11. outputContext = List();
  12. for each  contextItem in previousContext
  13. {
  14. outputContext.add(contextItem);
  15. }
  16. outputContext.add(lastRequest);
  17. info outputContext;
  18. response = Map();
  19. response.put("outputContext",outputContext);
  20. return response;
CollectContextScript parameters:



Input lastRequest - is a last user question
Input previousContext - is a current array of previous user questions
Output outputContext - is a current array previous user questions + a last user question

So, I tested each plug separately:

 

and collect script:



Then I have connected these two plugs inside a Zobot builder (including parameters):





But when I try to test Zobot, I got a fail in ChatGPT plug:



I can't debug a Zobot. I don't know why ChatGPT Deluge script is fails all time.
I tried to test ChatGPT plug separately with no context (when first message from an user) and with some context - it works fine. Help me, please.

Maybe someone knows how to reach my goal in a simplier way...

    Access your files securely from anywhere

        Zoho Developer Community




                                  Zoho Desk Resources

                                  • Desk Community Learning Series


                                  • Digest


                                  • Functions


                                  • Meetups


                                  • Kbase


                                  • Resources


                                  • Glossary


                                  • Desk Marketplace


                                  • MVP Corner


                                  • Word of the Day



                                      Zoho Marketing Automation


                                              Manage your brands on social media



                                                    Zoho TeamInbox Resources

                                                      Zoho DataPrep Resources



                                                        Zoho CRM Plus Resources

                                                          Zoho Books Resources


                                                            Zoho Subscriptions Resources

                                                              Zoho Projects Resources


                                                                Zoho Sprints Resources


                                                                  Qntrl Resources


                                                                    Zoho Creator Resources



                                                                        Zoho Campaigns Resources


                                                                          Zoho CRM Resources

                                                                          • CRM Community Learning Series

                                                                            CRM Community Learning Series


                                                                          • Kaizen

                                                                            Kaizen

                                                                          • Functions

                                                                            Functions

                                                                          • Meetups

                                                                            Meetups

                                                                          • Kbase

                                                                            Kbase

                                                                          • Resources

                                                                            Resources

                                                                          • Digest

                                                                            Digest

                                                                          • CRM Marketplace

                                                                            CRM Marketplace

                                                                          • MVP Corner

                                                                            MVP Corner





                                                                              Design. Discuss. Deliver.

                                                                              Create visually engaging stories with Zoho Show.

                                                                              Get Started Now