Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Scroll export button
scopecurrent
template-id0fa09813-8b86-460a-aa1d-ef450a80e9ce
quick-starttrue
add-onScroll PDF Exporter

Info

This Guide describes how to integrate ChatGPT with Wildix. 

Created: February 2023

Updated: January 2024

Permalink: https://wildix.atlassian.net/wiki/x/AQBxC

Table of Contents

Introduction

...

  1. Download the archivekite-xmpp-bot-master.zip
  2. Open the archive, navigate to /kite-xmpp-bot-master/app and open config.js with an editor of your choice 

    Replace the following values with your own:

    • domain: 'XXXXXX.wildixin.com' - domain name of the PBX
    • service: 'xmpps://XXXXXX.wildixin.com:443', - domain name of the PBX 
    • username: 'XXXX', - Kitebot user extension number, do not change it
    • password: 'XXXXXXXXXXXX' - Kitebot user password
    • authorization: 'Bearer sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - ChatGPT authorization token
    • organization: 'org-XXXXXXXXXXXXXXXXXXXXXXXXX', – ChatGPT organization ID
    • model: 'gpt-3.5-turbo', - this parameter specifies which GPT model to use for text generation. gpt-3.5-turbo point to the latest model version (e.g. gpt-3.5-turbo-0613). GPT-3.5 models can understand and generate natural language or code. It is the most capable and cost effective model in the GPT-3.5 family which can return up to 4096 tokens
    • temperature: 0.1, - this parameter controls the "creativity" of the generated text by specifying how much randomness should be introduced into the model's output
    • externalmaxtokens: 250, - response token limit for Kite users contacting the chatbot
    • internalmaxtokens: 500  - response token limit for internal users contacting the chatbot
    • systemcontent: 'Be a helpful assistant. Provide accurate but concise response.', - this parameter can be used as an instruction for the model. Define text style, tone, volume, formality, etc. here

  3. Upload the archive to the /home/admin/ directory using WinSCP or any alternative SFTP client

  4. Connect to the web terminal. Log in as the super user via the su command, password wildix
  5. Install nodejs: 

    Code Block
    apt-get install nodejs unzip


  6. Unzip the archive: 

    Code Block
    unzip /home/admin/kite-xmpp-bot-master.zip 


  7. Copy the chatbot folder to /mnt/backups

    Code Block
    cp -r ./kite-xmpp-bot-master /mnt/backups/


  8. Move the chatbot.service.txt file to the appropriate directory and enable chatbot as a service to run in the background, then start the service: 

    Code Block
    cp /mnt/backups/kite-xmpp-bot-master/chatbot.service.txt /etc/systemd/system/chatbot.service
    systemctl enable chatbot.service 
    systemctl daemon-reload
    systemctl start chatbot.service


  9. Verify that the chatbot is running by either running the ps command:

    Code Block
    ps aux | grep node


    Or simply send the bot a message 

...

Use case: to interact with ChatGPT via voice and have a response sent via TTS to the caller. Also contains a simple example of embedded prompt engineering in the Dialplan applications 6 & 7 where it checks whether or not the recognition result contains the word “price” then proceeds to add instructions for the ChatGPT API to respond in a short manner and only provide numerical value in the response when asked for a price of a particular item.

How-to:

...

 

How-to:

  1. Download the Dialplan dialplan_2024.01.29_11.24.09_testupgrade_6.05.20240119.1_2211000083f3.bkp
  2. Go to WMS Dialplan -> Dialplan rules 
  3. Click Import to add downloaded Dialpan Dialplan and click Apply



Image RemovedImage Added

Dialplan applications explained:

  1. Set STT & TTS language
  2. Set DIAL_OPTIONS -> g to continue Dialplan execution after the Speech to text application, this allows looping the Dialplan to potentially answer multiple questions

  3. Set PROMPT_ENGINEERING -> Be a helpful assistant. Provide accurate but concise response. - this parameter can be used as an instruction for the model. Define text style, tone, volume, formality, etc. here

  4. Speech to text application that plays the voice prompt and captures the user’s response converting it to text. An in-depth guide for the STT Dialplan application: Dialplan applications Admin Guide

  5. NoOp(${RECOGNITION_RESULT}) - a debug application that shows the result of speech recognition, can be safely removed

  6. Set(RECOGNITION_RESULT=${SHELL(echo "${RECOGNITION_RESULT}" | tr -d \'):0:-1}) - this sets the RECOGNITION_RESULT variable to the value of the RECOGNITION_RESULT channel variable, with any single quotes removed. The :0:-1 substring removes the newline character

...

  1. Set(

...

  1. CONVERSATION=${CONVERSATION} \n${CALLERID(name)} ${CALLERID(num)}: ${RECOGNITION_RESULT}

...

  1. )

...

  1. - creating a variable that stores the conversation between the user and ChatGPT

  2. Set(chatGPT=${SHELL(curl https://api.openai.com/v1/chat/completions -H "Content-Type: application/json" -H "Authorization: Bearer sk-

...

  1. XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -d '{ "model": "

...

  1. gpt-

...

  1. 3.5-turbo", "messages": [ {"role": "system", "

...

  1. content": "${

...

  1. PROMPT_

...

  1. ENGINEERING}"}, {"role": "user", "content": "${RECOGNITION_RESULT}"} ], "temperature": 0.

...

  1. 8, "max_tokens": 500 }' | tr -d "'()"):0:-1}) - this sends an HTTP request to the OpenAI ChatGPT API to generate a response based on the RECOGNITION_RESULT and PROMPT_ENGINEERING variables. The resulting JSON string is assigned to the

...

  1. ChatGPT variable.

...

  1. gpt-

...

  1. 3.5-

...

  1. turbo is the model name, you can learn more about ChatGPT models by watching the dedicated Tech talk webinar or in the OpenAI

...

  1. documentation. Replace Bearer sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your API token

  2. Set(

...

  1. result

...

  1. =${SHELL(echo "${

...

  1. chatGPT}" | grep -oP '(?<=

...

  1. content).*'):0:-

...

  1. 1}) - this extracts the response text from the

...

  1. chatGPT variable by using grep to search for the text following the

...

  1. “content“ field.

  2. Play sound -> ${result}. End of response. - this uses the text in the result variable to generate text to speech message and play back the response from chatGPT API to the caller, appending “End of response” to mark the end of response, which is something you can change to your preference

...

  1. Set(CONVERSATION=${CONVERSATION} \nChatGPT: ${result}) - this app add the AI’s response to the conversation variable created earlier

  2. System(echo "${CONVERSATION}" | mutt -F /etc/companies.d/0/Muttrc -s "ChatGPT ASR interaction" test@test.com) - this app is used to email the conversation to an email address; replace test@test.com with the address you want it to send to. This is optional and can be safely removed without any impact to the STT part of the Dialplan


Example callweaver output for debug purposes: 

Code Block
-- Executing [s@GPTTurbo:1] NoOp("SIP/26861-00000005", "Executing 'Set': LANGUAGE() - en")
   -- Executing [s@GPTTurbo:1] NoOp("SIP/26861-00000005", "Executing 'Set': DIAL_OPTIONS - g")
   -- Executing [s@GPTTurbo:1] NoOp("SIP/26861-00000005", "Executing 'Set': PROMPT_ENGINEERING - Be a helpful assistant. Provide accurate but concise response.")
   -- Executing [s@GPTTurbo:1] NoOp("SIP/26861-00000005", "Executing 'Speech to text': question - "Ask your question", error message - "Didn't understand, please repeat", retries - 0, lenght - 10, silence - 3, save audio - "
no"")                                                                                                                                                                                                                           
   -- Executing [s@GPTTurbo:1] NoOp("SIP/26861-00000005", "Ask your question")
   -- Executing [s@GPTTurbo:1] Playback("SIP/26861-00000005", "/tmp/tts_b8b61b2a4e90ec49477453f8fd49a109")
   -- <SIP/26861-00000005> Playing '/tmp/tts_b8b61b2a4e90ec49477453f8fd49a109.slin' (language 'en')
   -- Executing [s@GPTTurbo:1] Record("SIP/26861-00000005", "/tmp/stt_7654.wav,3,10,ky")
   -- <SIP/26861-00000005> Playing 'beep.opus' (language 'en')
   -- Executing [s@GPTTurbo:1] NoOp("SIP/26861-00000005", "Recognition result: what does a 403 error code mean in voice over IP")
   -- Executing [s@GPTTurbo:1] NoOp("SIP/26861-00000005", "what does a 403 error code mean in voice over ip")
   -- Executing [s@GPTTurbo:1] Set("SIP/26861-00000005", "RECOGNITION_RESULT=what does a 403 error code mean in voice over ip")
   -- Executing [s@GPTTurbo:1] Set("SIP/26861-00000005", "CONVERSATION= \nKonstantin 26861: what does a 403 error code mean in voice over ip")
[Jan 29 11:37:00] ERROR[2107]: logger.c:2111 stderr_write_thread: STDERR:   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                Dload  Upload   Total   Spent    Left  Speed                                                                                                                                                   
100   969  100   689  100   280    449    182  0:00:01  0:00:01 --:--:--   632
   -- Executing [s@GPTTurbo:1] Set("SIP/26861-00000005", "chatGPT={
   --   "id": "chatcmpl-8mKEeyt70u4eXqKQ0w7pKmaf6kPQX",                                                                                                                                                                        
   --   "object": "chat.completion",                                                                                                                                                                                           
   --   "created": 1706528220,                                                                                                                                                                                                 
   --   "model": "gpt-3.5-turbo-0613",                                                                                                                                                                                         
   --   "choices": [                                                                                                                                                                                                           
   --     {                                                                                                                                                                                                                    
   --       "index": 0,                                                                                                                                                                                                        
   --       "message": {                                                                                                                                                                                                       
   --         "role": "assistant",                                                                                                                                                                                             
   --         "content": "The 403 error code in Voice over IP VoIP typically indicates a \"Forbidden\" error. This means that the server understood the request, but the user doesnt have permission to access the requested res
ource or perform the requested action."                                                                                                                                                                                         
   --       },                                                                                                                                                                                                                 
   --       "logprobs": null,                                                                                                                                                                                                  
   --       "finish_reason": "stop"                                                                                                                                                                                            
   --     }                                                                                                                                                                                                                    
   --   ],                                                                                                                                                                                                                     
   --   "usage": {                                                                                                                                                                                                             
   --     "prompt_tokens": 34,                                                                                                                                                                                                 
   --  Executing  [s@ChatGPT:1] NoOp("SIP/300-0000004a", "Ask your question")"completion_tokens": 48,              -- Executing [s@ChatGPT:1] Playback("SIP/300-0000004a", "/tmp/tts_594630b11a842dda50406c8ac9a89489")
[Feb 20 15:31:27] DEBUG[2743][C-00000049]: chan_sip.c:37758 handle_incoming: Webrtc device detected [0x2806858 -> 0x333c458], setting allow transparent SSRC
   -- <SIP/300-0000004a> Playing '/tmp/tts_594630b11a842dda50406c8ac9a89489.slin' (language 'en')
   -- Executing [s@ChatGPT:1] Record("SIP/300-0000004a", "/tmp/stt_6275.wav,3,10,y")
   -- <SIP/300-0000004a> Playing 'beep.opus' (language 'en')
[Feb 20 15:31:29] WARNING[3730058][C-00000049]: res_rtp_asterisk.c:3653 ast_rtp_write: res_rtp_asterisk, requested to send an RTCP FIR packet to the peer
 == Parsing '/etc/callweaver/res_ldap.conf': Found
   -- Executing [s@ChatGPT:1] NoOp("SIP/300-0000004a", "Recognition result: is it usually hot in the summer")
   -- Executing [s@ChatGPT:1] NoOp("SIP/300-0000004a", "is it usually hot in the summer")
   -- Executing [s@ChatGPT:1] Set("SIP/300-0000004a", "RECOGNITION_RESULT=is it usually hot in the summer")
   -- Executing [s@ChatGPT:1] ExecIf("SIP/300-0000004a", "0?Set(PROMPT_ENGINEERING=Only respond with price in numerical format.)")
   -- Executing [s@ChatGPT:1] Set("SIP/300-0000004a", "chatGPT={"id":"cmpl-6m2QbstaepooAETRb5bTxCYcODsbE","object":"text_completion","created":1676907097,"model":"text-davinci-003","choices":[{"text":"\n\nYes, it is usually
hot in the summer in many parts of the world. Temperatures can range from mild to extreme depending on the region.","index":0,"logprobs":null,"finish_reason":"stop"}],"usage":{"prompt_tokens":9,"completion_tokens":31,"total_t
okens":40}}")
   -- Executing [s@ChatGPT:1] Set("SIP/300-0000004a", "PrettyChatGPT={
   --  "id":   "cmpl-6m2QbstaepooAETRb5bTxCYcODsbE",
   --  "object":       "text_completion",
   --  "created":      1676907097,
   --  "model":        "text-davinci-003",
   --  "choices":      [{
   --                                                                                                                                                                              
   --     "total_tokens": 82                                                                                 "text": "\n\nYes, it is usually hot in the summer in many parts of the world. Temperatures can range from mild to extreme depending on the region.",
   --                                                 "index":        0,    --                  "logprobs":     null,    --                  "finish_reason":        "stop"
   --   },       }],       --  "usage":        {    --          "prompt_tokens":        9,                                                                                                                                                                       
   --   "system_fingerprint": null           --          "completion_tokens":    31,                                                                                                                                                                    
   -- }")                --          "total_tokens": 40                                                                                                                                                                                           
   -- Executing [s@GPTTurbo:1] --  }                                    Set("SIP/26861-00000005", "result=: The 403 error code in Voice over IP VoIP typically indicates a "Forbidden" error. This means that the server understood the request, but the user doesnt have
permission to access the requested resource or perform the requested action.")                                                                                                                                                 
   -- Executing [s@GPTTurbo:1] NoOp("SIP/26861-00000005", "Executing 'Playback': sound - "Start of response. : The 403 error code in Voice over IP VoIP typically indicates a \"Forbidden\" error. This means that the server un
derstood the -- }")                        request, but the user doesnt have permission to access the requested resource or perform the requested action.. End of response.", waitDigits - n, opts - ")                                                       
   -- Executing [s@GPTTurbo:1] Playback("SIP/26861-00000005", "/tmp/tts_be0f2125fbd29e48987821d9dc475480,")
   -- <SIP/26861-00000005> Playing '/tmp/tts_be0f2125fbd29e48987821d9dc475480.slin' (language 'en')
   -- Executing [s@GPTTurbo:1] Set("SIP/26861-00000005", "CONVERSATION= \nKonstantin 26861: what does a 403 error code mean in voice over ip \nChatGPT: : The 403 error code in Voice over IP VoIP typically indicates a "For
bidden" error. This means that the server understood the request, but the user doesnt have permission to access the requested resource or perform the requested action.")                                                       
    -- Executing [s@ChatGPTs@GPTTurbo:1] SetSystem("SIP/30026861-0000004a00000005", "result=Yes, it is usually hot in the summer in many parts of the world. Temperatures can range from mild to extreme depending on the region.")
   -- Executing [s@ChatGPT:1] NoOp("SIP/300-0000004a", "Executing 'Playback': sound - "Yes, it is usually hot in the summer in many parts of the world. Temperatures can range from mild to extreme depending on the region.. En
d of response.", waitDigits - n, opts - ")echo " \nKonstantin 26861: what does a 403 error code mean in voice over ip \nChatGPT: : The 403 error code in Voice over IP VoIP typically indicates a "Forbidd
en" error. This means that the server understood the request, but the user doesnt have permission to access the requested resource or perform the requested action." | mutt -F /etc/companies.d/0/Muttrc -s "ChatGPT ASR interact
ion" test@test.com")                                                                                                                                                                                                        -- Executing [s@ChatGPT:1] Playback("SIP/300-0000004a", "/tmp/tts_2b1d5b37ac3938881099308c2ba87718,")
   -- <SIP/300-0000004a> Playing Auto fallthrough, channel '/tmp/tts_2b1d5b37ac3938881099308c2ba87718.slin' (language 'en')SIP/26861-00000005' status is 'UNKNOWN'


Macrosuite divider macro
dividerTypetext
dividerWidth70
emoji{"id":"smile","name":"Smiling Face with Open Mouth and Smiling Eyes","short_names":["smile"],"colons":":smile:","emoticons":["C:","c:",":D",":-D"],"unified":"1f604","skin":null,"native":"😄"}
textColor#000000
dividerWeight2
labelPositionmiddle
textAlignmentcenter
iconColor#0052CC
fontSizemedium
textNot finding the help you need? Join the Facebook group to ask a question!
emojiEnabledfalse
dividerColor#DFE1E6
dividerIconbootstrap/CloudsFill

...