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)
- // current user request
- if(session.containsKey("question"))
- {
- question = session.get("question").get("value");
- }
- // Array of previous user requests (context)
- if(session.containsKey("context"))
- {
- context = session.get("context").get("value");
- }
- token = "Bearer MY_TOKEN_HERE_IS_REMOVED";
- header = Map();
- header.put("Authorization",token);
- header.put("Content-Type","application/json");
- messages = List();
- // create array of previous user questions
- for each questionItem in context
- {
- messages.add({"role":"user","content":questionItem});
- }
- // add to array last question
- messages.add({"role":"user","content":question});
- // create JSON to chat GPT request
- chatgpt = Collection();
- 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:"}};
- info chatgpt;
- params = Map();
- params.put(chatgpt);
- response = invokeurl
- [
- url :"https://api.openai.com/v1/chat/completions"
- type :POST
- parameters:params.toString()
- headers:header
- ];
- answer = response.get("choices").getJSON("message").get("content");
- response = Map();
- // first time there is no context
- if(context.size() > 0)
- {
- // next time pass input context
- response.put("fromChatContext",context);
- }
- response.put("answer",answer);
- info response;
- 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):
- // last user request
- if(session.containsKey("lastRequest"))
- {
- lastRequest = session.get("lastRequest").get("value");
- }
- // Array of previous user request (context)
- if(session.containsKey("previousContext"))
- {
- previousContext = session.get("previousContext").get("value");
- }
- outputContext = List();
- for each contextItem in previousContext
- {
- outputContext.add(contextItem);
- }
- outputContext.add(lastRequest);
- info outputContext;
- response = Map();
- response.put("outputContext",outputContext);
- 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...