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 :
Code:
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'];
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.