Skip to content

Commit

Permalink
Add anthropic
Browse files Browse the repository at this point in the history
  • Loading branch information
ClicShopping committed Jul 12, 2024
1 parent 8692334 commit 0664847
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ add fields mandatory for products attributes
Improve SEO GPT
Replace Gemma by Gemma2 for ollama
fix error products_attributes and check field
Add Anthopic Sonnet3.5,Opus, Haiku

--------------------
version 3.449
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ More information in the Wiki
#Functionnalities (some)
- B2B - B2C full functionalities
- GPT API integration
- Generative artificial Intelligence included with Gpt and Ollama
- Generative artificial Intelligence included with Gpt, Ollama and Anthropic
- Generative artificial products customers recommendations
- Generative artificial intelligence for All content (product,categories...)
- Generative artificial intelligence for SEO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
use LLPhant\OpenAIConfig;
use LLPhant\OllamaConfig;
use LLPhant\Chat\TokenUsage;

use LLPhant\AnthropicConfig;
use LLPhant\Chat\AnthropicChat;

use function defined;
use function is_null;
Expand Down Expand Up @@ -77,6 +78,9 @@ public static function getGptModel(): array
['id' => 'gpt-4o', 'text' => 'OpenAi gpt-4o'],
['id' => 'gemma:7b', 'text' => 'Ollama Gemma:7b'],
['id' => 'mistral:7b', 'text' => 'Ollama Mistral:7b'],
['id' => 'anth-sonnet', 'text' => 'Anthropic Claude Sonnet 3.5'],
['id' => 'anth-opus', 'text' => 'Anthropic Claude Opus'],
['id' => 'anth-haiku', 'text' => 'Anthropic Claude Haiku'],
];

return $array;
Expand Down Expand Up @@ -180,12 +184,60 @@ public static function getOpenAIChat(string $question, ?int $maxtoken = null, ?f
*/
public static function getOllamaChat(string $model = 'mistral:7b'): mixed
{

if (!empty(CLICSHOPPING_APP_CHATGPT_CH_MODEL)) {
$config = new OllamaConfig();
$config->model = $model;
$chat = new OllamaChat($config);

return $chat;
}


/**
* @param string $model
* @param int|null $maxtoken
* @param array|null $modelOptions
* @return array
*/
public static function getAnthropicChat(string $model, int|null $maxtoken = null, array|null $modelOptions = null): mixed
{
$api_key = CLICSHOPPING_APP_CHATGPT_CH_API_KEY_ANTHROPIC;
$chat = false;

if ($modelOptions === null) {
$modelOptions = [
'messages' => [
['role' => 'system',
'content' => 'You are an e-commerce expert in marketing.'
]
]
];
}
/*
// Perform the transformation if needed, e.g., extract contents from messages
$transformedMessages = array_map(function($message) {
return $message['content'];
}, $modelOptions['messages']);
// If transformation means a different structure, adapt accordingly
// For example, if you want to convert it to a dictionary:
$modelOptions['transformedMessages'] = $transformedMessages;
*/
if (is_null($maxtoken)) {
$maxtoken = (int)CLICSHOPPING_APP_CHATGPT_CH_MAX_TOKEN;
}


// Create a new AnthropicChat instance with the specified configuration

if (!empty(CLICSHOPPING_APP_CHATGPT_CH_API_KEY_ANTHROPIC)) {
if ($model = 'anth-sonnet') {
$chat = new AnthropicChat(new AnthropicConfig(AnthropicConfig::CLAUDE_3_5_SONNET, $maxtoken, $modelOptions, $api_key));
} elseif ($model = 'anth-opus') {
$chat = new AnthropicChat(new AnthropicConfig(AnthropicConfig::CLAUDE_3_OPUS, $maxtoken, $modelOptions, $api_key));
} else {
$chat = new AnthropicChat(new AnthropicConfig(AnthropicConfig::CLAUDE_3_HAIKU, $maxtoken, $modelOptions, $api_key));
}

return $chat;
} else {
return false;
Expand All @@ -205,6 +257,8 @@ private static function getChat(string $question, ?int $maxtoken = null, ?float
{
if (strpos(CLICSHOPPING_APP_CHATGPT_CH_MODEL, 'gpt') === 0) {
$client = self::getOpenAIChat($question, $maxtoken, $temperature, $engine, $max);
} elseif (strpos(CLICSHOPPING_APP_CHATGPT_CH_MODEL, 'anth') === 0) {
$client = self::getAnthropicChat(CLICSHOPPING_APP_CHATGPT_CH_MODEL, $maxtoken);
} else {
$client = self::getOllamaChat(CLICSHOPPING_APP_CHATGPT_CH_MODEL);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
*
* @copyright 2008 - https://www.clicshopping.org
* @Brand : ClicShoppingAI(TM) at Inpi all right Reserved
* @Licence GPL 2 & MIT
* @Info : https://www.clicshopping.org/forum/trademark/
*
*/

namespace ClicShopping\Apps\Configuration\ChatGpt\Module\ClicShoppingAdmin\Config\CH\Params;

use ClicShopping\OM\HTML;

class api_key_anthropic extends \ClicShopping\Apps\Configuration\ChatGpt\Module\ClicShoppingAdmin\Config\ConfigParamAbstract
{

public $default = '';
public ?int $sort_order = 33;
public bool $app_configured = true;

protected function init()
{
$this->title = $this->app->getDef('cfg_chatgpt_api_key_anthropic_title');
$this->description = $this->app->getDef('cfg_chatgpt_api_key_anthropic_description');
}

public function getInputField()
{
$value = $this->getInputValue();

$input = HTML::passwordField($this->key, $value, 'id="' . $this->key . '" autocomplete="off"');

return $input;
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cfg_chatgpt_api_key_title = Api Key
cfg_chatgpt_api_key_title = Api Key OpenAi
cfg_chatgpt_api_key_description = Please, insert the Api Key (https://platform.openai.com/account/api-keys)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cfg_chatgpt_api_key_anthropic_title = Anthropic Api Key
cfg_chatgpt_api_key_anthropic_description = Please, insert the Api Key (https://www.anthropic.com)
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cfg_chatgpt_api_key_title = Clef Api
cfg_chatgpt_api_key_title = Clef Api OpenAI
cfg_chatgpt_api_key_description = Veuillez insérer la clef API (https://platform.openai.com/account/api-keys)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cfg_chatgpt_api_key_anthropic_title = Clef Api Anthropic
cfg_chatgpt_api_key_anthropic_description = Veuillez insérer la clef API (https://www.anthropic.com)
1 change: 1 addition & 0 deletions install/Db/clicshopping.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1691,6 +1691,7 @@ INSERT INTO configuration VALUES(1742, 'Nombre de commentaires à analyser', 'CL
INSERT INTO configuration VALUES(1743, 'Souhaitez-vous installer ce module ?', 'MODULE_ADMIN_DASHBOARD_GPT_CHECK_API_APP_STATUS', 'True', 'Souhaitez-vous installer ce module ?', 6, 1, NULL, '2023-09-15 09:16:47', NULL, 'clic_cfg_set_boolean_value(array(\'True\', \'False\'))');
INSERT INTO configuration VALUES(1744, 'Select the width to display', 'MODULE_ADMIN_DASHBOARD_GPT_CHECK_API_APP_CONTENT_WIDTH', '12', 'Veuillez sélectionner un nombre entre 1 et 12', 6, 1, NULL, '2023-09-15 09:16:47', NULL, 'clic_cfg_set_content_module_width_pull_down');
INSERT INTO configuration VALUES(1745, 'Ordre de tri d\'affichage', 'MODULE_ADMIN_DASHBOARD_GPT_CHECK_API_APP_SORT_ORDER', '2', 'Ordre de tri pour l\'affichage (Le plus petit nombre est montré en premier)', 6, 2, NULL, '2023-09-15 09:16:47', NULL, '');
INSERT INTO configuration VALUES(1746, 'Clef Api Anthropic', 'CLICSHOPPING_APP_CHATGPT_CH_ANTHROPIC_API_KEY', '', 'Veuillez insérer la clef API (https://www.anthropic.com)', 6, 0, NULL, '2023-02-22 17:17:04', NULL, NULL);


INSERT INTO configuration_group VALUES(1, 'Gestion de ma boutique', 'Informations générales sur la boutique.', 1, 1);
Expand Down
1 change: 1 addition & 0 deletions install/Db/clicshopping_en.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1691,6 +1691,7 @@ INSERT INTO configuration VALUES(1742, 'Reviews number to analyse', 'CLICSHOPPIN
INSERT INTO configuration VALUES(1743, 'Do you want to enable this Module ?', 'MODULE_ADMIN_DASHBOARD_GPT_CHECK_API_APP_STATUS', 'True', 'Do you want to enable this Module ?', 6, 1, NULL, '2023-09-15 09:16:47', NULL, 'clic_cfg_set_boolean_value(array(\'True\', \'False\'))');
INSERT INTO configuration VALUES(1744, 'Select the width to display', 'MODULE_ADMIN_DASHBOARD_GPT_CHECK_API_APP_CONTENT_WIDTH', '12', 'Select a number between 1 to 12', 6, 1, NULL, '2023-09-15 09:16:47', NULL, 'clic_cfg_set_content_module_width_pull_down');
INSERT INTO configuration VALUES(1745, 'Sort Order', 'MODULE_ADMIN_DASHBOARD_GPT_CHECK_API_APP_SORT_ORDER', '2', 'Sort order of display. Lowest is displayed first.', 6, 2, NULL, '2023-09-15 09:16:47', NULL, '');
INSERT INTO configuration VALUES(1746, 'Anthropic api key', 'CLICSHOPPING_APP_CHATGPT_CH_ANTHROPIC_API_KEY', '', 'Please insert the api key (https://www.anthropic.com)', 6, 0, NULL, '2023-02-22 17:17:04', NULL, NULL);


INSERT INTO configuration_group VALUES(1, 'Store Setup', 'General Information on the Store.', 1, 1);
Expand Down

0 comments on commit 0664847

Please sign in to comment.