How I made a ChatGPT bot in Salebot and nothing happened


This article describes my introduction to ChatGPT at the API level and integration with the Salebot bot building platform.

I have been building bots in Salebot and Python for a long time, and I could not just pass by ChatGPT and its API (model GPT 3). But, while studying the API, I was carried further, it was impossible to stop at GPT 3. Here are the tasks I set myself:

Available functionality on ChatGPT:

  • Chat with a bot

  • Image generator according to our description

  • Picture editor according to our description

  • Similar Image Generator

Perhaps everything is interesting! You can chat with the robot and generate a picture, and I wonder how ChatGPT will edit the image according to the description.

I will try everything!😄 in Salebot.

Preparation

  1. We are registering for https://chat.openai.com.

  2. Getting API access keys https://beta.openai.com/account/api-keys.

  3. We also find docks there. https://platform.openai.com/docs/api-reference/introductionand learn the API.

  4. Create a new project in salebot.


Chat with a bot

IN API ChatGPT contains all the parameters we need:

All of them are on the screen and I think there is no need to list them, I will only note that here there is a choice of model and PL:

Porting all parameters to Salebot (Salebot API help):

  1. Let’s go to our Salebot project.

  2. Create a new block Primary Condition Check (light green).

This will be the bot menu

The menu will be displayed at the start of the bot or by command /menu

The menu will be displayed at the start of the bot or by command /menu

  1. Create another block Primary Condition Check.

Here we place the trigger condition: “Chat with a bot” and the initial text for the user:

Now when the user clicks Chat with a bot, it will go to that block. From there, we will write a request to the API.

The general outline of the project should look something like this:

Bot scheme in Salebot Funnel Builder

Bot scheme in Salebot Funnel Builder

  1. Create two Dialog State blocks, connect them as in the diagram above.

In the first block, I make a request to the API:

Request URL: https://api.openai.com/v1/completions

Stored Values: choices|0|text->text;

Request header: {"Content-Type": "application/json", "Accept": "application/json", "Authorization": "Bearer YOUR_API_KEY_HERE"}

json parameters: {"model": "text-davinci-003", "prompt": "#{question}", "max_tokens": 2000, "temperature": 1}

In the second block, we show the result: #{text}.

Let’s move on to testing:

I cheated a little by specifying different units of measurement.  Unfortunately, the bot did not consider this important and the answer was not correct.

I cheated a little by specifying different units of measurement. Unfortunately, the bot did not consider this important and the answer was not correct.

We exchange a couple of phrases with the bot, the bot solves the problem. So, everything works, I go further, to image generation.


Image generator according to our description

I duplicate 3 interconnected blocks from the diagram above.

In the launch condition I set the condition: think of a picture.

Watch API to generate an image:

And I substitute the parameters in the copied block:

Request URL: https://api.openai.com/v1/completions

Stored Values: data|0|url->picture_url;

Request header: {"Content-Type": "application/json", "Accept": "application/json", "Authorization": "Bearer YOUR_API_KEY_HERE"}

json parameters: {"prompt": "#{question}", "n": 1, "size": "512x512"}

In the second block in the attachment, I simply specify the URL of the image: picture_url.

Ready. Testing.

Worked out great! Further more difficult.


Picture editor according to our description

I’m already going to the usual ChatGPT API to the section Images->Create image editlook:

If I understood the meaning correctly, then here we transfer the picture and a description of what needs to be changed / added / removed on it, and the neural network corrects the image and returns the result.

Well, I do everything by analogy with the previous steps:

I copy the blocks and correct the request:

Request URL: https://api.openai.com/v1/images/edits

Stored Values: data|0|url->picture_url;

Request header: {"Content-Type": "application/json", "Accept": "application/json", "Authorization": "Bearer YOUR_API_KEY_HERE"}

json parameters: {"image": "#{image_url}", prompt:"#{question}", "n": 1, "size": "512x512"}

On testing, I get the following response:

{"error":{"code":null,"message":"Invalid Content-Type header (application/json), expected multipart/form-data. (HINT: If you're using curl, you can pass -H 'Content-Type: multipart/form-data')","param":null,"type":"invalid_request_error"}}

Ok, I change the title to multipart/form-data.

I’m testing. I get a response:

{"error":{"code":null,"message":"Additional properties are not allowed ('image' was unexpected)","param":null,"type":"invalid_request_error"}}

Further, which only settings and parameters did not try to change, I came across this or other errors.

Tried:

Transmit the image in “rb” mode, as mentioned in the reference. In different encodings, with and without headers, the result was the same. More precisely, it was not)

Tired, I switch to Python:

Here I get a normal response and a generated image.

I understand that there are no openai and os libraries in salebot, but I still try to push various options for this piece of code into salebot, but all to no avail.


Similar Image Generator

Since the principle of queries is similar to the previous one, there was no point in trying.


I got such results from my acquaintance with ChatGPT. Perhaps Salebot will implement support for the openai library in the future and this will simplify the work, but so far this has not happened.

I did not consider the option of integrations on the side, because I wanted a single-platform solution.

Who wants to feel the bot, posted in telegram: https://t.me/chatgpt_image_bot.

If you have any comments or ideas on this topic, please share in the comments. I will be glad to hear them!

In the next article I will tell you how I met a girl in ChatGPT.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *