ChatGPT and CB code autoaction

1 year 2 months ago #332765 by activha
ChatGPT and CB code autoaction was created by activha
Hello
I am testing chatgpt and would like to integrate it in a CB code autoaction.
It works fine when using the code in a single php file to display the result but I cannot get a code autoaction to work.

I use this :
include_once(JPATH_ROOT . '/ahatools/activations/assets/OpenAi.php');
include_once(JPATH_ROOT . '/ahatools/activations/assets/Url.php');
use \Orhanerday\OpenAi\OpenAi;
use \Orhanerday\OpenAi\Url;
$open_ai_key = 'xxxxxxxxx';

//in$open_ai_key = getenv('OPENAI_API_KEY');
$open_ai = new OpenAi($open_ai_key);

$prompt = 'Quelle est la capitale de paris ?';

$complete = $open_ai->completion([
   'model' => 'text-davinci-003',
   'prompt' => $prompt,
   'temperature' => 0.9,
   'max_tokens' => 200,
   'frequency_penalty' => 0,
   'presence_penalty' => 0.6,
]);
$responseJson = json_decode($complete, true);
$response = $responseJson['choices'][0]['text'];

Where the API used is this one : github.com/orhanerday/open-ai

Is there an issue using namespace in code autoactions ?

thanks for your help

Please Log in to join the conversation.

1 year 2 months ago #332766 by krileon
Replied by krileon on topic ChatGPT and CB code autoaction

Is there an issue using namespace in code autoactions ?

Yes, namespaces must be at the top of a PHP file. This isn't a limitation of CB Auto Actions, but is just how PHP works. Your options are to have a PHP file that you include yourself that has all your code in it so you can just use entirely native PHP or use full namespaced functions/class. Example as follows.

FROM: new OpenAi
TO: new \Orhanerday\OpenAi\OpenAi


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

1 year 2 months ago #332771 by activha
Replied by activha on topic ChatGPT and CB code autoaction
Ok will use outside code that's easier
Thanks

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.204 seconds

Facebook Twitter LinkedIn