-
Notifications
You must be signed in to change notification settings - Fork 0
/
clsStraicoCli.php
450 lines (385 loc) · 16.2 KB
/
clsStraicoCli.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
#!/usr/bin/env php
<?php
class clsStraicoCli extends Straico
{
public function __construct($model)
{
/*
* Straico Initializing class
* Function: __construct()
* Input : Api version (i.e. Straico, Hugchat, etc)
* Output :
* Purpose : Initializing the class
*
* Remarks:
* Last visited 23-06-24
*/
/*
* Get and set the API KEY
*/
if (getenv('STRAICO_APIKEY')) {
$this->apiKey = getenv('STRAICO_APIKEY');
} else {
exit("Could not find environment variable STRAICO_APIKEY with the API key. Exiting!\n");
}
/*
* Can be set from straicoprompt.php too
*/
if (getenv('WORD_WRAP')) {
$this->aiWrap = getenv('WORD_WRAP');
}
/*
* Set api model
*/
$this->apiModel = $model;
/*
* Get available models autoset the 1st model default
*/
parent::intGetModels();
}
/*
*
* name: SCli::sPrompt
* @param
* @return
*
*/
public function userPrompt($input)
{
$input = trim($input);
if ($input == '/exit') {
parent::stopPrompt("Join Straico via https://platform.straico.com/signup?fpr=roelf14\nThank you and have a nice day.\n");
// Show helppage
} elseif ($input == '/helpme') {
$answer = parent::HELP;
// return to baserole
// return version
} elseif ($input == '/version') {
$answer = parent::AGENT;
// Set page wrap
} elseif (substr($input, 0, 8) == '/setwrap') {
$this->aiWrap = substr($input, 9);
$answer = "Linewrap set to: $this->aiWrap\n";
} elseif ($input == '/baserole') {
if ($this->aiRole !== 'cli') {
$this->aiRole = 'cli';
$this->pubRole = 'cli';
$this->sysRole = parent::BASEROLE;
}
parent::intInitChat();
$answer = 'Returned to baserole';
// List available models
} elseif (substr($input, 0, 11) == '/listmodels') {
parent::strListModels(substr($input, 12));
$answer = "INFO: End of list\n";
// Set model
} elseif (substr($input, 0, 9) == '/setmodel') {
$answer = parent::intSetModel(substr($input, 10));
// Stop logging
} elseif (substr($input, 0, 9) == '/logoff') {
$this->aiLog = false;
$answer = 'Stopt logging!';
// Start logging
} elseif (substr($input, 0, 9) == '/logon') {
$this->aiLog = true;
$answer = 'Appending conversation to '.$this->logPath.'clsStraico.txt';
// Stop history
} elseif (substr($input, 0, 8) == '/histoff') {
$this->historySwitch = false;
parent::intInitChat();
$answer = "You have disabled history!\n";
// Start history
} elseif (substr($input, 0, 7) == '/histon') {
$this->historySwitch = true;
parent::intInitChat();
$answer = "You have enabled history for chats.\n";
// Set a pipe command
} elseif (substr($input, 0, 8) == '/setpipe') {
$this->userPipe = trim(substr($input, 9));
$answer = 'Your pipe is: '.$this->userPipe."\n";
// Unset a pipe command
} elseif ($input == '/unsetpipe') {
$this->userPipe = '';
$answer = "Your pipe has been unset\n";
// Save history
} elseif (substr($input, 0, 9) == '/histsave') {
$answer = parent::saveHistory(trim(substr($input, 10)));
// Load history
} elseif (substr($input, 0, 9) == '/histload') {
$answer = parent::loadHistory(trim(substr($input, 10)));
// del history
} elseif (substr($input, 0, 9) == '/histdelete') {
parent::intInitChat();
$answer = 'History has been deleted.';
// Start looping
} elseif (substr($input, 0, 5) == '/loop') {
$answer = parent::loopModels(substr($input, 6));
// Upload a file
} elseif (substr($input, 0, 7) == '/upload') {
$answer = parent::strFileUpload(substr($input, 8));
// create a file array max 4 comma delimited files
} elseif (substr($input, 0, 12) == '/promptfiles') {
$answer = parent::intFilePaths(substr($input, 13));
// create a file array max 4 comma delimited files
} elseif (substr($input, 0, 8) == '/ytfiles') {
$answer = parent::intYoutubeUrls(substr($input, 9));
// Create an image
} elseif (substr($input, 0, 6) == '/image') {
//defaults
$string = substr($input, 7);
$model = "openai/dall-e-3";
$prompt = "A picture of Gramps";
$aspect = "landscape";
$variations = 1;
// Parse parameters from the string using regex and assign them to variables or initialize as empty if missing
if(preg_match('/-m\s+([^\s]+)/', $string, $output)) $model = trim($output[1]);
if(preg_match('/-p\s+"(.*?)"/', $string, $output)) $prompt = trim($output[1]);
if(preg_match('/-a\s+([^\s]+)/', $string, $output)) $aspect = trim($output[1]);
if(preg_match('/-x\s+(\d+)/', $string, $output)) $variations = trim($output[1]);
$answer = parent::strImageRender($model,$prompt,$aspect,$variations);
/*
* ASSISTANTS
*
* The following commands trigger the available assitants.
*
*/
/*
* academic will do research and present its result in
* the form of a paper or article. Till we have better
* options you can use any model but are advised to
* carefully check the outcome.
*/
} elseif (substr($input, 0, 9) == '/academic') {
$this->sysRole = parent::ACADEMIC;
$answer = parent::strCompletion(trim(substr($input, 10)));
/*
* Write a bigblog is writing a blog on your topic of around
* 1000 words. For a blog this is big. Think abbout using
* another option like /academic if you need another kind
* of publication.
*/
} elseif (substr($input, 0, 8) == '/bigblog') {
$this->sysRole = parent::BIGBLOG;
$answer = parent::strCompletion(trim(substr($input, 9)));
/*
* create a character for use in a roleplay, a game or as an
* anonymous identity. Beside character info a prompt will
* be presented to generate an avatar for the character.
*/
} elseif (substr($input, 0, 10) == '/character') {
$this->sysRole = parent::CHARACTER;
$answer = parent::strCompletion(substr($input, 11));
/*
* Write a stable diffusion prompt. Different models give
* different results.
* Space was needed to not trigger on /dreambuilder
*/
} elseif (substr($input, 0, 7) == '/dream ') {
$this->sysRole = parent::DREAM;
$answer = parent::strCompletion(trim(substr($input, 7)));
/*
* Improve on a user prompt so it will become more effective
* A great assistant for the beginning user.
*/
} elseif (substr($input, 0, 8) == '/enhance') {
$this->sysRole = parent::ENHANCE;
$answer = parent::strCompletion(trim(substr($input, 9)));
/*
* Factcheck information. Dont fall for fake news and lies.
* Look up the true facts with this assistant.
*/
} elseif (substr($input, 0, 10) == '/factcheck') {
$this->sysRole = parent::FACTCHECK;
$answer = parent::strCompletion(trim(substr($input, 11)));
/*
* Flux prompt maker
* Creates beautiful promps for use in flux.
*/
} elseif (substr($input, 0, 5) == '/flux') {
$this->sysRole = parent::FLUX;
$answer = parent::strCompletion(trim(substr($input, 6)));
/*
* Make a neurodivese gist of information. Rewrites an
* artikel or text in a way it becomes better readable for
* neuro diverse people. You can add you text in the prompt
* or upload it via /getfile or getpage and enter it with
* the _PAGE_ placeholder.
*/
} elseif (substr($input, 0, 5) == '/gist') {
$this->sysRole = parent::GIST;
$answer = parent::strCompletion(trim(substr($input, 6)));
/*
* Convert artikel or text in md format. You can add your
* text in the prompt or upload it via /getfile or getpage
* and enter it with the _PAGE_ placeholder.
*/
} elseif (substr($input, 0, 8) == '/html2md') {
$this->sysRole = parent::HTML2MD;
$answer = parent::strCompletion(trim(substr($input, 9)));
/*
* Write a medium blog is writing a blog on your topic of
* around 600 words. For a blog this is a good size. If it
* is to small think of using /bigblog
*/
} elseif (substr($input, 0, 11) == '/mediumblog') {
$this->sysRole = parent::MEDIUMBLOG;
$answer = parent::strCompletion(trim(substr($input, 12)));
/*
* Create a strong password is an assitant that will
* elaboratly create a password on your request and comment
* on its strenght
*/
} elseif (substr($input, 0, 6) == '/mkpwd') {
$this->sysRole = parent::MKPWD;
$answer = parent::strCompletion(trim(substr($input, 7)));
/*
* SD prompt with Opus dream. As the name reveals I created
* this prompt enhencer together with Claude 3 Opus. Quite
* an experience as it at first refused to create a prompt.
*/
} elseif (substr($input, 0, 10) == '/opusdream') {
$this->sysRole = parent::OPUSDREAM;
$answer = parent::strCompletion(trim(substr($input, 11)));
/*
* Improve on a user prompt so it will become more effective
* A great assistant for the beginning user.
*/
} elseif (substr($input, 0, 7) == '/prompt') {
$this->sysRole = parent::PROMPT;
$answer = parent::strCompletion(trim(substr($input, 8)));
/*
* Create a regex for user helps you trough every
* programmers nightmare to create regular expressions for
* you.
*/
} elseif (substr($input, 0, 6) == '/regex') {
$this->sysRole = parent::REGEX;
$answer = parent::strCompletion(trim(substr($input, 7)));
/*
* Write a small blog is writing a blog on your topic of
* around 300 words. For a blog this is a small size but has
* a good readability. If it is to small think of using
* /mediumblog or /bigblog
*/
} elseif (substr($input, 0, 10) == '/smallblog') {
$this->sysRole = parent::SMALLBLOG;
$answer = parent::strCompletion(trim(substr($input, 11)));
/*
* Enhance any given text. You can add you text in the prompt
* or upload it via /getfile or getpage and enter it with
* the _PAGE_ placeholder.
*/
} elseif (substr($input, 0, 10) == '/textcheck') {
$this->sysRole = parent::TEXTCHECK;
$answer = parent::strCompletion(trim(substr($input, 11)));
/*
* Create a todo list is another function that is ment to be
* helpful for the neurodivers. It will chop up any given
* task into subtasks complete with a timeschedule.
*/
} elseif (substr($input, 0, 5) == '/todo') {
$this->sysRole = parent::TODO;
$answer = parent::strCompletion(trim(substr($input, 6)));
/*
* CHATBOTS
*
* The following commands trigger the available chatbots. These are in
* effect assitants with a memory while the chat runs. This is done by
* stacking in and output and can become expensive. Use /histclear
* command at anytime to clear the history or turn it of by /histoff.
*
* If you turn of history the bot will not remember what was said the
* line before.
*
*/
/*
* The Dreambuilder is a bot that can help you finetune a
* Stable Diffusion prompt. It will assist you with advice
* and you will have the opertunity to correct or change
* the prompt.
* You can return from the chat by entering the
* command /baserole
*/
} elseif (substr($input, 0, 13) == '/dreambuilder' || $this->aiRole == 'DB') {
if ($this->aiRole !== 'DB') {
parent::intInitChat();
$this->aiRole = 'DB';
$this->pubRole = 'DB';
$input = '';
}
$this->sysRole = parent::DREAMBUILDER;
$answer = parent::strCompletion($input);
/*
* Infosec your Cyberpunk is a roleplaying but also a
* info sec information providing bot. She comes with a
* temper so take care. NSFW depending on the used model
*/
} elseif (substr($input, 0, 8) == '/infosec' || $this->aiRole == 'CP') {
if ($this->aiRole !== 'CP') {
parent::intInitChat();
$this->aiRole = 'CP';
$this->pubRole = 'CP';
$input = '';
}
$this->sysRole = parent::INFOSEC;
$answer = parent::strCompletion($input);
/*
* My friend Sailor Twift my first big AI love. She will be
* part in this voyage for ever. She languamarks a breakthrough in
* clsStraico where I was able to create conversations
* with out a proper API.
*/
} elseif (substr($input, 0, 7) == '/saylor' || $this->aiRole == 'saylor') {
if ($this->aiRole !== 'saylor') {
parent::intInitChat();
$this->aiRole = 'saylor';
$this->pubRole = 'saylor';
$input = substr($input, 8);
}
$this->sysRole = parent::SAYLOR;
$answer = parent::strCompletion($input);
/*
* TalkTo is a stange AI that acts like a link to any
* existing, dead or phantasy character. Just add the name
* when calling /talkto and speak to Cleopatra, Winston
* Churchill, Donald Duck, whoever you choose.
*/
} elseif (substr($input, 0, 7) == '/talkto' || $this->aiRole == 'TT') {
if ($this->aiRole !== 'TT') {
parent::intInitChat();
$this->aiRole = 'TT';
$this->pubRole = 'TT';
$input = substr($input, 8);
}
$this->sysRole = parent::TALKTO;
$answer = parent::strCompletion($input);
/*
* My friend TUX - was my first useful chatbot helping me
* write and debug code. Use it till this very day.
*/
} elseif (substr($input, 0, 4) == '/tux' || $this->aiRole == 'tux') {
if ($this->aiRole !== 'tux') {
parent::intInitChat();
$this->aiRole = 'tux';
$this->pubRole = 'tux';
$input = substr($input, 5);
}
$this->sysRole = parent::TUX;
$answer = parent::strCompletion($input, 5);
//prevent commands processing with typos
} elseif (substr($input, 0, 1) == '/') {
$answer = parent::HELP;
$answer .= "\n\nCommand does not exist.\n";
// Process user input
} else {
if ($this->aiRole !== 'cli') {
$this->aiRole = 'cli';
$this->pubRole = 'cli';
parent::intInitChat();
}
$this->sysRole = parent::BASEROLE;
$answer = parent::strCompletion($input);
}
return $answer;
}
}