dolibarr 23.0.3
ai.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2022 Alice Adminson <aadminson@example.com>
3 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26include_once DOL_DOCUMENT_ROOT.'/ai/class/ai.class.php';
27
28
35{
36 global $langs;
37
38 $arrayofaifeatures = array(
39 'textgenerationemail' => array('label' => $langs->trans('TextGeneration').' ('.$langs->trans("EmailContent").')', 'picto' => '', 'status' => 'dolibarr', 'function' => 'TEXT', 'placeholder' => Ai::AI_DEFAULT_PROMPT_FOR_EMAIL),
40 'textgenerationwebpage' => array('label' => $langs->trans('TextGeneration').' ('.$langs->trans("WebsitePage").')', 'picto' => '', 'status' => 'dolibarr', 'function' => 'TEXT', 'placeholder' => Ai::AI_DEFAULT_PROMPT_FOR_WEBPAGE),
41 'textgeneration' => array('label' => $langs->trans('TextGeneration').' ('.$langs->trans("Other").')', 'picto' => '', 'status' => 'notused', 'function' => 'TEXT'),
42
43 'texttranslation' => array('label' => $langs->trans('TextTranslation'), 'picto' => '', 'status'=>'dolibarr', 'function' => 'TEXT', 'placeholder' => Ai::AI_DEFAULT_PROMPT_FOR_TEXT_TRANSLATION),
44 'textsummarize' => array('label' => $langs->trans('TextSummarize'), 'picto' => '', 'status'=>'dolibarr', 'function' => 'TEXT', 'placeholder' => Ai::AI_DEFAULT_PROMPT_FOR_TEXT_SUMMARIZE),
45 'textrephrase' => array('label' => $langs->trans('TextRephraser'), 'picto' => '', 'status'=>'dolibarr', 'function' => 'TEXT', 'placeholder' => Ai::AI_DEFAULT_PROMPT_FOR_TEXT_REPHRASER),
46
47 'textgenerationextrafield' => array('label' => $langs->trans('TextGeneration').' ('.$langs->trans("ExtrafieldFiller").')', 'picto' => '', 'status'=>'dolibarr', 'function' => 'TEXT', 'placeholder' => Ai::AI_DEFAULT_PROMPT_FOR_EXTRAFIELD_FILLER),
48
49 'imagegeneration' => array('label' => 'ImageGeneration', 'picto' => '', 'status' => 'notused', 'function' => 'IMAGE'),
50 'videogeneration' => array('label' => 'VideoGeneration', 'picto' => '', 'status' => 'notused', 'function' => 'VIDEO'),
51 'audiogeneration' => array('label' => 'AudioGeneration', 'picto' => '', 'status' => 'notused', 'function' => 'AUDIO'),
52 'transcription' => array('label' => 'AudioTranscription', 'picto' => '', 'status' => 'notused', 'function' => 'TRANSCRIPT'),
53 'translation' => array('label' => 'AudioTranslation', 'picto' => '', 'status' => 'notused', 'function' => 'TRANSLATE')
54 );
55
56 return $arrayofaifeatures;
57}
58
65{
66 global $langs;
67
68 $arrayofai = array(
69 '-1' => array('label' => $langs->trans('SelectAService')),
70 'chatgpt' => array(
71 'label' => 'ChatGPT',
72 'url' => 'https://api.openai.com/v1/',
73 'setup' => 'https://platform.openai.com/account/api-keys',
74 'textgeneration' => 'gpt-4.1-turbo', // a lot of text transformation like: 'textgenerationemail', 'textgenerationwebpage', 'textgeneration', 'texttranslation', 'textsummarize'
75 'imagegeneration' => 'dall-e-3',
76 'audiogeneration' => 'tts-1',
77 'videogeneration' => 'na',
78 'transcription' => 'whisper-1', // audio to text
79 'translation' => 'whisper-1', // audio to text into another language
80 ),
81 'groq' => array(
82 'label' => 'Groq',
83 'url' => 'https://api.groq.com/openai/',
84 'setup' => 'https://platform.groq.com/signup',
85 'textgeneration' => 'mixtral-8x7b-32768', // 'llama3-8b-8192', 'gemma-7b-it'
86 'imagegeneration' => 'na',
87 'audiogeneration' => 'na',
88 'videogeneration' => 'na',
89 'transcription' => 'na',
90 'translation' => 'na',
91 ),
92 'mistral' => array(
93 'label' => 'Mistral',
94 'url' => 'https://api.mistral.ai/v1/',
95 'setup' => 'https://console.mistral.ai/',
96 'textgeneration' => 'open-mistral-7b',
97 'imagegeneration' => 'na',
98 'audiogeneration' => 'na',
99 'videogeneration' => 'na',
100 'transcription' => 'na',
101 'translation' => 'na',
102 ),
103 'custom' => array(
104 'label' => 'Custom',
105 'url' => 'https://domainofapi.com/v1/',
106 'setup' => 'Ask your AI provider how to get your API key',
107 'textgeneration' => 'tinyllama-1.1b',
108 'imagegeneration' => 'mixtral-8x7b-32768',
109 'audiogeneration' => 'mixtral-8x7b-32768',
110 'videogeneration' => 'na',
111 'transcription' => 'mixtral-8x7b-32768',
112 'translation' => 'mixtral-8x7b-32768',
113 )
114 //'gemini' => array(
115 // 'label' => 'Gemini',
116 //)
117 );
118
119 return $arrayofai;
120}
121
122
123
124
131{
132 $arrayforaisummarize = array(
133 //'20_w' => 'SummarizeTwentyWords',
134 '50_w' => 'SummarizeFiftyWords',
135 '100_w' => 'SummarizeHundredWords',
136 '200_w' => 'SummarizeTwoHundredWords',
137 '1_p' => 'SummarizeOneParagraphs',
138 '2_p' => 'SummarizeTwoParagraphs',
139 '25_pc' => 'SummarizeTwentyFivePercent',
140 '50_pc' => 'SummarizeFiftyPercent',
141 '75_pc' => 'SummarizeSeventyFivePercent'
142 );
143
144 return $arrayforaisummarize;
145}
146
153{
154 $arrayforaierephrasestyle = array(
155 'professional' => 'RephraseStyleProfessional',
156 'humouristic' => 'RephraseStyleHumouristic'
157 );
158
159 return $arrayforaierephrasestyle;
160}
161
168{
169 global $langs, $conf;
170
171 $langs->load("agenda");
172
173 $h = 0;
174 $head = array();
175
176 $head[$h][0] = dol_buildpath("/ai/admin/setup.php", 1);
177 $head[$h][1] = $langs->trans("Settings");
178 $head[$h][2] = 'settings';
179 $h++;
180
181 $head[$h][0] = dol_buildpath("/ai/admin/custom_prompt.php", 1);
182 $head[$h][1] = $langs->trans("CustomPrompt");
183 $head[$h][2] = 'custom';
184 $h++;
185
186 if (getDolGlobalString("MAIN_FEATURES_LEVEL") >= 2) {
187 $head[$h][0] = dol_buildpath("/ai/admin/server_mcp.php", 1);
188 $head[$h][1] = $langs->trans("MCPServer");
189 $head[$h][2] = 'servermcp';
190 $h++;
191 }
192
193 /*
194 $head[$h][0] = dol_buildpath("/ai/admin/myobject_extrafields.php", 1);
195 $head[$h][1] = $langs->trans("ExtraFields");
196 $head[$h][2] = 'myobject_extrafields';
197 $h++;
198 */
199
200 // Show more tabs from modules
201 // Entries must be declared in modules descriptor with line
202 //$this->tabs = array(
203 // 'entity:+tabname:Title:@ai:/ai/mypage.php?id=__ID__'
204 //); // to add new tab
205 //$this->tabs = array(
206 // 'entity:-tabname:Title:@ai:/ai/mypage.php?id=__ID__'
207 //); // to remove a tab
208 complete_head_from_modules($conf, $langs, null, $head, $h, 'ai@ai');
209
210 complete_head_from_modules($conf, $langs, null, $head, $h, 'ai@ai', 'remove');
211
212 return $head;
213}
getListOfAIFeatures()
Prepare admin pages header.
Definition ai.lib.php:34
aiAdminPrepareHead()
Prepare admin pages header.
Definition ai.lib.php:167
getListOfAIServices()
Get list of available ai services.
Definition ai.lib.php:64
getListForAIRephraseStyle()
Get list for AI style of writing.
Definition ai.lib.php:152
getListForAISummarize()
Get list for AI summarize.
Definition ai.lib.php:130
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.