Jump to content

ProcessChatGPT


robert
 Share

Recommended Posts

I couldn’t resist the hype and created a simple module using the ChatGPT API to process field values. You can find it on GitHub here:

https://github.com/robertweiss/ProcessChatGPT

ProcessChatGPT is triggered upon saving, if you select it in the save dropdown. It processes the value of a page field, which can be set in the module config, using ChatGPT. The processed value can be saved back to the same field or to another field on the same page, which can also be set in the module configuration. You can add commands to the value that will be prefixed to the source field content. This way, you can give ChatGPT hints on what to do with the text. For example, you could add ›Write a summary with a maximum of 400 characters of the following text:‹.

One of my clients is already using the module to summarise announcement texts for upcoming music events on their website (Let’s face it, nobody reads them anyway ?).

If anyone finds it useful, I would be happy to submit it to the official module list.

  • Like 14
Link to comment
Share on other sites

Nice. Does the module offer a UI under the admin tree? I'm asking because there are naming conventions for PW modules. And the prefix "Process" is usually reserved for modules that have a page associated under the admin tree. Like ProcessPageLister etc. You might want to consider renaming your module before submitting it to the directory.

  • Like 2
Link to comment
Share on other sites

Is it correct that I need to install dependencies via composer?

If so... fine. Got that.

Another thing: Is there some way to get debug infos if anything was posted or fetched from ChatGPT?
Just tried it and can't figure out if it's just ChatGPT that over capacity right now or me/the setup.

Link to comment
Share on other sites

Hm, I can't make it work. curl_getinfo($curl, CURLINFO_HTTP_CODE) in OpenAi.php returns 0. I can manually curl just fine, so it's not GPT. 

Edit: aha, curl_error($curl) gives 'SSL certificate problem: unable to get local issuer certificate'. ok, not exactly recommended, but as a quick fix CURLOPT_SSL_VERIFYPEER => false, or download curl cert and add it to php.ini

  • Like 1
Link to comment
Share on other sites

Sorry for not being clear. CURLOPT_SSL_VERIFYPEER is an option for curl that verify the peer's SSL certificate. When CURLOPT_SSL_VERIFYPEER is enabled, and the verification fails to prove that the certificate is authentic, the connection fails. When the option is zero, the peer certificate verification succeeds regardless. I added this in OpenAi.php, which is used to make HTTP requests to ChatGPT. We could use wireHttp class for that too. Disabling this option is not a way to go, so this was a quick fix to get the response from ChatGPT.
Regarding "ChatGPT is offline" error, I couldn't log into my account from my work PC yesterday but could log in from my home PC. It happens from time to time. Try from another computer.

Link to comment
Share on other sites

Thanks for all of your comments and suggestions. I renamed the module to PromptChatGPT (thank you @gornycreative for the input!). The renamed repo can be found here:

https://github.com/robertweiss/PromptChatGPT

Additionally, I have included the composer vendor folder by default, which seems to be a better and easier way to distribute modules. Thanks to @wbmnfktr for bringing this to my attention.

Regarding the curl/ssl errors, as you have already deduced, these seem to be linked to the external dependency https://github.com/orhanerday/open-ai. Therefore, if the issues you mentioned persist, we should consider creating a new Github issue there.

For easier debugging, I have added a ›test settings‹ option to to verify if ChatGPT responds correctly.

I have also included a new option to select templates that should include the dropdown option.

  • Like 3
Link to comment
Share on other sites

Hmm, this is weird. Does the error message already show up on the module config page or while saving a ›real‹ page and choosing ›Save + send to ChatGPT‹? For reference, the attached screenshot shows my feedback which works without errors.

 

Screenshot-20230322-1747.jpg

  • Like 1
Link to comment
Share on other sites

59 minutes ago, wbmnfktr said:

The new version looks good and while testing the settings worked out pretty well, I now get this error:

chatquota.png.55b687531ae19afc190082572a0ce464.png

I checked my account and quotas are fine. Even billing settings are enabled/set.

I meant I got this result, not the developer's result..

  • Like 1
Link to comment
Share on other sites

Ok, I created a new account at Open AI and generated a test API key, then I got the same error message as you. After adding a payment method, still no luck. But then I generated a new key AFTER adding the payment method, and now it works. Could you check if that works for you too?

  • Like 1
Link to comment
Share on other sites

Okay, I got a proper answer once I switched to an account with credits. Awesome.

{
    "request": {
        "model": "gpt-3.5-turbo",
        "messages": [
            {
                "role": "user",
                "content": "This is a test for ChatGPT. Do you hear me?"
            }
        ]
    },
    "response": {
        "id": "chatcmpl-...",
        "object": "chat.completion",
        "created": 1679504670,
        "model": "gpt-3.5-turbo-0301",
        "usage": {
            "prompt_tokens": 21,
            "completion_tokens": 18,
            "total_tokens": 39
        },
        "choices": [
            {
                "message": {
                    "role": "assistant",
                    "content": "\n\nYes, I can hear you loud and clear! How can I assist you today?"
                },
                "finish_reason": "stop",
                "index": 0
            }
        ]
    }
}

 

  • Like 2
Link to comment
Share on other sites

Ok... now we are talking!

Adding billing details is necessary and creating a new API key afterwards probably as well.
Did both and everything is up and running.

Just did a small test and generated a full article just by giving a topic and a predefined action in the settings.

Love it!

Additional note: just switched back to my primary account, created a new API key there and it works there as well.

  • Like 1
Link to comment
Share on other sites

FYI

So... this might be another hiccup or something but... after a few hours I tried to generate more content, yet... that was my feedback.

hickup.thumb.png.4b18606f1cd8c0ebcef82ed4b2c60f5a.png

Tried it a few few times. Like a warm-up for API, yet no success.

The key I used (double checked), was my most recent key I created, which worked just a few hours ago in several tries successfully.

Limits/Usage was all green (aka: totally fine). $120/month (with $0,00 in my account) - so that shouldn't be the problem, I guess. ¯\_(ツ)_/¯

usage.png.7af9d7c9c6553d816effddb97c8c22f5.png

I created another new API key... and tried again... and it worked out as planned.

Can't say more about what this was or what might have happened here.

Just as a feedback.

Link to comment
Share on other sites

  • 3 weeks later...

Can I throw another log onto this fire?

Today I installed a local instance of oobabooga and vicuna.

It looks like text-generation-webui has an API mode that can be set to listen for JSON prompt requests!

It would be great to either fork PromptGPT or develop an option to select alternative API endpoints, etc.

I used this tutorial to guide the install - with the exception I also needed to install NVIDIA CUDA toolkit to get access to CUDA cores from pytorch.

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...