Skip to content

Commit

Permalink
add ai generated solution by openai
Browse files Browse the repository at this point in the history
  • Loading branch information
empiricompany committed Apr 26, 2024
1 parent d0cfd9f commit cb1a46a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
20 changes: 20 additions & 0 deletions app/code/community/MM/Ignition/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class MM_Ignition_Helper_Data extends Mage_Core_Helper_Abstract
const XML_PATH_THEME = 'dev/mm_ignition/theme';
const XML_PATH_EDITOR = 'dev/mm_ignition/editor';
const XML_PATH_OVERRIDE_CONFIG = 'dev/mm_ignition/override_config';
const XML_PATH_OPENAI_ENABLED = 'dev/mm_ignition/enable_openai';
const XML_PATH_OPENAI_KEY = 'dev/mm_ignition/openai_api_key';

/**
* Allowed keys for settings
Expand Down Expand Up @@ -134,4 +136,22 @@ public function setSessionConfig($key, $value)
Mage::getSingleton('core/session')->setIgnitionConfig($ignitionConfig);
}

/**
* Check if OpenAI is enabled
* @return bool
*/
public function isOpenAiEnabled()
{
return Mage::getStoreConfigFlag(self::XML_PATH_OPENAI_ENABLED);
}

/**
* Get OpenAI key
* @return string
*/
public function getOpenAiKey()
{
return Mage::getStoreConfig(self::XML_PATH_OPENAI_KEY);
}

}
15 changes: 14 additions & 1 deletion app/code/community/MM/Ignition/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Spatie\Ignition\Config\IgnitionConfig;
use Spatie\Ignition\Ignition;
use Spatie\Ignition\Solutions\OpenAi\OpenAiSolutionProvider;

class MM_Ignition_Model_Observer extends Mage_Core_Model_Observer
{
Expand Down Expand Up @@ -46,9 +47,21 @@ public function handleIgnitionException(Varien_Event_Observer $observer)
*/
protected function getIgnitionInstance()
{
return Ignition::make()
$_ignition = Ignition::make()
->setConfig($this->getIgnitionConfig())
->applicationPath(Mage::getBaseDir());

if ($this->getHelper()->isOpenAiEnabled() && !empty($this->getHelper()->getOpenAiKey())) {
$openAiKey = $this->getHelper()->getOpenAiKey();
$aiSolutionProvider = new OpenAiSolutionProvider($openAiKey);
$aiSolutionProvider->applicationType('OpenMage a fork of Magetno 1.9 (Generic Developer Documentation: https://devdocs-openmage.org/ NO mention Magento 1.x)');

$_ignition->addSolutionProviders([
$aiSolutionProvider,
]);
}

return $_ignition;
}

/**
Expand Down
22 changes: 22 additions & 0 deletions app/code/community/MM/Ignition/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</override_config>
<enable_openai>
<label>Enable OpenAI</label>
<comment>Enable OpenAI for code completion</comment>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>50</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</enable_openai>
<openai_api_key>
<label>OpenAI API Key</label>
<comment>API key for OpenAI</comment>
<frontend_type>password</frontend_type>
<sort_order>60</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<depends>
<enable_openai>1</enable_openai>
</depends>
</openai_api_key>
</fields>
</mm_ignition>
</groups>
Expand Down

0 comments on commit cb1a46a

Please sign in to comment.