dolibarr 22.0.5
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 'textgeneration' => 'gpt-3.5-turbo', // a lot of text transformation like: 'textgenerationemail', 'textgenerationwebpage', 'textgeneration', 'texttranslation', 'textsummarize'
74 'imagegeneration' => 'dall-e-3',
75 'audiogeneration' => 'tts-1',
76 'videogeneration' => 'na',
77 'transcription' => 'whisper-1', // audio to text
78 'translation' => 'whisper-1', // audio to text into another language
79 ),
80 'groq' => array(
81 'label' => 'Groq',
82 'url' => 'https://api.groq.com/openai/',
83 'textgeneration' => 'mixtral-8x7b-32768', // 'llama3-8b-8192', 'gemma-7b-it'
84 'imagegeneration' => 'na',
85 'audiogeneration' => 'na',
86 'videogeneration' => 'na',
87 'transcription' => 'na',
88 'translation' => 'na',
89 ),
90 'mistral' => array(
91 'label' => 'Mistral',
92 'url' => 'https://api.mistral.ai/v1/',
93 'textgeneration' => 'open-mistral-7b',
94 'imagegeneration' => 'na',
95 'audiogeneration' => 'na',
96 'videogeneration' => 'na',
97 'transcription' => 'na',
98 'translation' => 'na',
99 ),
100 'custom' => array(
101 'label' => 'Custom',
102 'url' => 'https://domainofapi.com/v1/',
103 'textgeneration' => 'tinyllama-1.1b',
104 'imagegeneration' => 'mixtral-8x7b-32768',
105 'audiogeneration' => 'mixtral-8x7b-32768',
106 'videogeneration' => 'na',
107 'transcription' => 'mixtral-8x7b-32768',
108 'translation' => 'mixtral-8x7b-32768',
109 )
110 //'gemini' => array(
111 // 'label' => 'Gemini',
112 //)
113 );
114
115 return $arrayofai;
116}
117
118
119
120
127{
128 $arrayforaisummarize = array(
129 //'20_w' => 'SummarizeTwentyWords',
130 '50_w' => 'SummarizeFiftyWords',
131 '100_w' => 'SummarizeHundredWords',
132 '200_w' => 'SummarizeTwoHundredWords',
133 '1_p' => 'SummarizeOneParagraphs',
134 '2_p' => 'SummarizeTwoParagraphs',
135 '25_pc' => 'SummarizeTwentyFivePercent',
136 '50_pc' => 'SummarizeFiftyPercent',
137 '75_pc' => 'SummarizeSeventyFivePercent'
138 );
139
140 return $arrayforaisummarize;
141}
142
149{
150 $arrayforaierephrasestyle = array(
151 'professional' => 'RephraseStyleProfessional',
152 'humouristic' => 'RephraseStyleHumouristic'
153 );
154
155 return $arrayforaierephrasestyle;
156}
157
164{
165 global $langs, $conf;
166
167 $langs->load("agenda");
168
169 $h = 0;
170 $head = array();
171
172 $head[$h][0] = dol_buildpath("/ai/admin/setup.php", 1);
173 $head[$h][1] = $langs->trans("Settings");
174 $head[$h][2] = 'settings';
175 $h++;
176
177 $head[$h][0] = dol_buildpath("/ai/admin/custom_prompt.php", 1);
178 $head[$h][1] = $langs->trans("CustomPrompt");
179 $head[$h][2] = 'custom';
180 $h++;
181
182 /*
183 $head[$h][0] = dol_buildpath("/ai/admin/myobject_extrafields.php", 1);
184 $head[$h][1] = $langs->trans("ExtraFields");
185 $head[$h][2] = 'myobject_extrafields';
186 $h++;
187 */
188
189 // Show more tabs from modules
190 // Entries must be declared in modules descriptor with line
191 //$this->tabs = array(
192 // 'entity:+tabname:Title:@ai:/ai/mypage.php?id=__ID__'
193 //); // to add new tab
194 //$this->tabs = array(
195 // 'entity:-tabname:Title:@ai:/ai/mypage.php?id=__ID__'
196 //); // to remove a tab
197 complete_head_from_modules($conf, $langs, null, $head, $h, 'ai@ai');
198
199 complete_head_from_modules($conf, $langs, null, $head, $h, 'ai@ai', 'remove');
200
201 return $head;
202}
getListOfAIFeatures()
Prepare admin pages header.
Definition ai.lib.php:34
aiAdminPrepareHead()
Prepare admin pages header.
Definition ai.lib.php:163
getListOfAIServices()
Get list of available ai services.
Definition ai.lib.php:64
getListForAIRephraseStyle()
Get list for AI style of writing.
Definition ai.lib.php:148
getListForAISummarize()
Get list for AI summarize.
Definition ai.lib.php:126
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).
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79