@promptbook/core 0.105.0-6 → 0.105.0-8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.es.js +987 -30
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/commitments/NOTE/NOTE.d.ts +2 -2
- package/esm/typings/src/commitments/USE_SEARCH_ENGINE/USE_SEARCH_ENGINE.d.ts +6 -0
- package/esm/typings/src/commitments/index.d.ts +1 -1
- package/esm/typings/src/llm-providers/agent/Agent.d.ts +1 -0
- package/esm/typings/src/llm-providers/agent/AgentOptions.d.ts +7 -0
- package/esm/typings/src/llm-providers/agent/RemoteAgentOptions.d.ts +1 -1
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +987 -30
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -27,7 +27,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
|
|
|
27
27
|
* @generated
|
|
28
28
|
* @see https://github.com/webgptorg/promptbook
|
|
29
29
|
*/
|
|
30
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.105.0-
|
|
30
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.105.0-8';
|
|
31
31
|
/**
|
|
32
32
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
33
33
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -8525,6 +8525,698 @@ function $getCurrentDate() {
|
|
|
8525
8525
|
return new Date().toISOString();
|
|
8526
8526
|
}
|
|
8527
8527
|
|
|
8528
|
+
/**
|
|
8529
|
+
* Creates human-readable hash
|
|
8530
|
+
*
|
|
8531
|
+
* @public exported from `@promptbook/utils`
|
|
8532
|
+
*/
|
|
8533
|
+
async function linguisticHash(input) {
|
|
8534
|
+
const hash = computeHash(input);
|
|
8535
|
+
// Use parts of the hash to select words
|
|
8536
|
+
// SHA256 is 64 hex characters
|
|
8537
|
+
// We use different slices of the hash to ensure variety even with small changes in input
|
|
8538
|
+
const part1 = parseInt(hash.substring(0, 10), 16);
|
|
8539
|
+
const part2 = parseInt(hash.substring(10, 20), 16);
|
|
8540
|
+
const part3 = parseInt(hash.substring(20, 30), 16);
|
|
8541
|
+
const adjective = ADJECTIVES[part1 % ADJECTIVES.length];
|
|
8542
|
+
const noun = NOUNS[part2 % NOUNS.length];
|
|
8543
|
+
const verb = VERBS[part3 % VERBS.length];
|
|
8544
|
+
return `${capitalize(adjective)} ${noun.toLowerCase()} ${verb.toLowerCase()}`;
|
|
8545
|
+
}
|
|
8546
|
+
const ADJECTIVES = [
|
|
8547
|
+
'red',
|
|
8548
|
+
'blue',
|
|
8549
|
+
'green',
|
|
8550
|
+
'yellow',
|
|
8551
|
+
'quick',
|
|
8552
|
+
'slow',
|
|
8553
|
+
'bright',
|
|
8554
|
+
'dark',
|
|
8555
|
+
'happy',
|
|
8556
|
+
'sad',
|
|
8557
|
+
'brave',
|
|
8558
|
+
'calm',
|
|
8559
|
+
'clever',
|
|
8560
|
+
'eager',
|
|
8561
|
+
'fancy',
|
|
8562
|
+
'grand',
|
|
8563
|
+
'jolly',
|
|
8564
|
+
'kind',
|
|
8565
|
+
'lucky',
|
|
8566
|
+
'nice',
|
|
8567
|
+
'proud',
|
|
8568
|
+
'silly',
|
|
8569
|
+
'wise',
|
|
8570
|
+
'young',
|
|
8571
|
+
'old',
|
|
8572
|
+
'big',
|
|
8573
|
+
'small',
|
|
8574
|
+
'fast',
|
|
8575
|
+
'shiny',
|
|
8576
|
+
'wild',
|
|
8577
|
+
'silent',
|
|
8578
|
+
'loud',
|
|
8579
|
+
'soft',
|
|
8580
|
+
'hard',
|
|
8581
|
+
'warm',
|
|
8582
|
+
'cold',
|
|
8583
|
+
'sweet',
|
|
8584
|
+
'sour',
|
|
8585
|
+
'bitter',
|
|
8586
|
+
'salty',
|
|
8587
|
+
'rich',
|
|
8588
|
+
'poor',
|
|
8589
|
+
'heavy',
|
|
8590
|
+
'light',
|
|
8591
|
+
'strong',
|
|
8592
|
+
'weak',
|
|
8593
|
+
'smooth',
|
|
8594
|
+
'rough',
|
|
8595
|
+
'clean',
|
|
8596
|
+
'dirty',
|
|
8597
|
+
'fresh',
|
|
8598
|
+
'stale',
|
|
8599
|
+
'sharp',
|
|
8600
|
+
'blunt',
|
|
8601
|
+
'thick',
|
|
8602
|
+
'thin',
|
|
8603
|
+
'wide',
|
|
8604
|
+
'narrow',
|
|
8605
|
+
'deep',
|
|
8606
|
+
'shallow',
|
|
8607
|
+
'mighty',
|
|
8608
|
+
'gentle',
|
|
8609
|
+
'fierce',
|
|
8610
|
+
'vibrant',
|
|
8611
|
+
'dusty',
|
|
8612
|
+
'golden',
|
|
8613
|
+
'silver',
|
|
8614
|
+
'frozen',
|
|
8615
|
+
'burning',
|
|
8616
|
+
'ancient',
|
|
8617
|
+
'modern',
|
|
8618
|
+
'hidden',
|
|
8619
|
+
'lost',
|
|
8620
|
+
'found',
|
|
8621
|
+
'magic',
|
|
8622
|
+
'mystic',
|
|
8623
|
+
'cosmic',
|
|
8624
|
+
'stellar',
|
|
8625
|
+
'lunar',
|
|
8626
|
+
'solar',
|
|
8627
|
+
'misty',
|
|
8628
|
+
'foggy',
|
|
8629
|
+
'stormy',
|
|
8630
|
+
'sunny',
|
|
8631
|
+
'windy',
|
|
8632
|
+
'quiet',
|
|
8633
|
+
'noisy',
|
|
8634
|
+
'peaceful',
|
|
8635
|
+
'busy',
|
|
8636
|
+
'empty',
|
|
8637
|
+
'full',
|
|
8638
|
+
'round',
|
|
8639
|
+
'square',
|
|
8640
|
+
'flat',
|
|
8641
|
+
'curved',
|
|
8642
|
+
'tiny',
|
|
8643
|
+
'huge',
|
|
8644
|
+
'giant',
|
|
8645
|
+
'little',
|
|
8646
|
+
'short',
|
|
8647
|
+
'long',
|
|
8648
|
+
'near',
|
|
8649
|
+
'distant',
|
|
8650
|
+
'inner',
|
|
8651
|
+
'outer',
|
|
8652
|
+
'patient',
|
|
8653
|
+
'steady',
|
|
8654
|
+
'noble',
|
|
8655
|
+
'pure',
|
|
8656
|
+
'graceful',
|
|
8657
|
+
'honest',
|
|
8658
|
+
'simple',
|
|
8659
|
+
'complex',
|
|
8660
|
+
'active',
|
|
8661
|
+
'passive',
|
|
8662
|
+
'vivid',
|
|
8663
|
+
'pale',
|
|
8664
|
+
'loyal',
|
|
8665
|
+
'true',
|
|
8666
|
+
'false',
|
|
8667
|
+
'fair',
|
|
8668
|
+
'clear',
|
|
8669
|
+
'murky',
|
|
8670
|
+
'vast',
|
|
8671
|
+
'slick',
|
|
8672
|
+
'slippery',
|
|
8673
|
+
'sticky',
|
|
8674
|
+
'dull',
|
|
8675
|
+
'keen',
|
|
8676
|
+
'broad',
|
|
8677
|
+
'slim',
|
|
8678
|
+
'slender',
|
|
8679
|
+
'fat',
|
|
8680
|
+
'lean',
|
|
8681
|
+
'stiff',
|
|
8682
|
+
'flexible',
|
|
8683
|
+
'rigid',
|
|
8684
|
+
'elastic',
|
|
8685
|
+
'tough',
|
|
8686
|
+
'brittle',
|
|
8687
|
+
'fragile',
|
|
8688
|
+
'solid',
|
|
8689
|
+
'liquid',
|
|
8690
|
+
'gaseous',
|
|
8691
|
+
'airy',
|
|
8692
|
+
'weighty',
|
|
8693
|
+
'buoyant',
|
|
8694
|
+
'dense',
|
|
8695
|
+
'sparse',
|
|
8696
|
+
'hollow',
|
|
8697
|
+
'stuffed',
|
|
8698
|
+
'crowded',
|
|
8699
|
+
'lonely',
|
|
8700
|
+
'social',
|
|
8701
|
+
'private',
|
|
8702
|
+
'public',
|
|
8703
|
+
'secret',
|
|
8704
|
+
'famous',
|
|
8705
|
+
'certain',
|
|
8706
|
+
'vague',
|
|
8707
|
+
'plain',
|
|
8708
|
+
'easy',
|
|
8709
|
+
'tame',
|
|
8710
|
+
'mild',
|
|
8711
|
+
'hot',
|
|
8712
|
+
'cool',
|
|
8713
|
+
'dry',
|
|
8714
|
+
'wet',
|
|
8715
|
+
'damp',
|
|
8716
|
+
'moist',
|
|
8717
|
+
'soaked',
|
|
8718
|
+
'parched',
|
|
8719
|
+
'hungry',
|
|
8720
|
+
'thirsty',
|
|
8721
|
+
'sleepy',
|
|
8722
|
+
'awake',
|
|
8723
|
+
'tired',
|
|
8724
|
+
'lazy',
|
|
8725
|
+
'idle',
|
|
8726
|
+
'swift',
|
|
8727
|
+
'rapid',
|
|
8728
|
+
'unstable',
|
|
8729
|
+
'shaky',
|
|
8730
|
+
'firm',
|
|
8731
|
+
'bold',
|
|
8732
|
+
'timid',
|
|
8733
|
+
'brave',
|
|
8734
|
+
'cowardly',
|
|
8735
|
+
'smart',
|
|
8736
|
+
'dumb',
|
|
8737
|
+
'foolish',
|
|
8738
|
+
'mean',
|
|
8739
|
+
'rude',
|
|
8740
|
+
'tasty',
|
|
8741
|
+
'bland',
|
|
8742
|
+
'arctic',
|
|
8743
|
+
'tropical',
|
|
8744
|
+
'deserted',
|
|
8745
|
+
'urban',
|
|
8746
|
+
'rural',
|
|
8747
|
+
'local',
|
|
8748
|
+
'global',
|
|
8749
|
+
'digital',
|
|
8750
|
+
'analog',
|
|
8751
|
+
'virtual',
|
|
8752
|
+
'real',
|
|
8753
|
+
'fake',
|
|
8754
|
+
'natural',
|
|
8755
|
+
'artificial',
|
|
8756
|
+
'living',
|
|
8757
|
+
'dead',
|
|
8758
|
+
'broken',
|
|
8759
|
+
'fixed',
|
|
8760
|
+
'new',
|
|
8761
|
+
'worn',
|
|
8762
|
+
'neat',
|
|
8763
|
+
'messy',
|
|
8764
|
+
'brave',
|
|
8765
|
+
'fearful',
|
|
8766
|
+
'proud',
|
|
8767
|
+
'humble',
|
|
8768
|
+
'greedy',
|
|
8769
|
+
'generous',
|
|
8770
|
+
'calm',
|
|
8771
|
+
'angry',
|
|
8772
|
+
'happy',
|
|
8773
|
+
'sad',
|
|
8774
|
+
'excited',
|
|
8775
|
+
'bored',
|
|
8776
|
+
'strange',
|
|
8777
|
+
'normal',
|
|
8778
|
+
'odd',
|
|
8779
|
+
'even',
|
|
8780
|
+
'rare',
|
|
8781
|
+
'common',
|
|
8782
|
+
'unique',
|
|
8783
|
+
'plain',
|
|
8784
|
+
'fancy',
|
|
8785
|
+
'basic',
|
|
8786
|
+
'prime',
|
|
8787
|
+
'super',
|
|
8788
|
+
'mega',
|
|
8789
|
+
'ultra',
|
|
8790
|
+
'micro',
|
|
8791
|
+
'nano',
|
|
8792
|
+
'macro',
|
|
8793
|
+
'mini',
|
|
8794
|
+
];
|
|
8795
|
+
const NOUNS = [
|
|
8796
|
+
'apple',
|
|
8797
|
+
'sky',
|
|
8798
|
+
'tree',
|
|
8799
|
+
'fox',
|
|
8800
|
+
'cat',
|
|
8801
|
+
'bird',
|
|
8802
|
+
'dog',
|
|
8803
|
+
'river',
|
|
8804
|
+
'mountain',
|
|
8805
|
+
'forest',
|
|
8806
|
+
'ocean',
|
|
8807
|
+
'star',
|
|
8808
|
+
'moon',
|
|
8809
|
+
'sun',
|
|
8810
|
+
'cloud',
|
|
8811
|
+
'flower',
|
|
8812
|
+
'leaf',
|
|
8813
|
+
'stone',
|
|
8814
|
+
'wind',
|
|
8815
|
+
'rain',
|
|
8816
|
+
'fire',
|
|
8817
|
+
'ice',
|
|
8818
|
+
'book',
|
|
8819
|
+
'dream',
|
|
8820
|
+
'song',
|
|
8821
|
+
'road',
|
|
8822
|
+
'gate',
|
|
8823
|
+
'key',
|
|
8824
|
+
'lamp',
|
|
8825
|
+
'map',
|
|
8826
|
+
'house',
|
|
8827
|
+
'city',
|
|
8828
|
+
'bridge',
|
|
8829
|
+
'field',
|
|
8830
|
+
'garden',
|
|
8831
|
+
'lake',
|
|
8832
|
+
'beach',
|
|
8833
|
+
'island',
|
|
8834
|
+
'valley',
|
|
8835
|
+
'desert',
|
|
8836
|
+
'world',
|
|
8837
|
+
'spirit',
|
|
8838
|
+
'heart',
|
|
8839
|
+
'mind',
|
|
8840
|
+
'soul',
|
|
8841
|
+
'life',
|
|
8842
|
+
'time',
|
|
8843
|
+
'space',
|
|
8844
|
+
'light',
|
|
8845
|
+
'shadow',
|
|
8846
|
+
'sound',
|
|
8847
|
+
'music',
|
|
8848
|
+
'voice',
|
|
8849
|
+
'word',
|
|
8850
|
+
'page',
|
|
8851
|
+
'story',
|
|
8852
|
+
'pearl',
|
|
8853
|
+
'gold',
|
|
8854
|
+
'silver',
|
|
8855
|
+
'crystal',
|
|
8856
|
+
'diamond',
|
|
8857
|
+
'emerald',
|
|
8858
|
+
'ruby',
|
|
8859
|
+
'path',
|
|
8860
|
+
'trail',
|
|
8861
|
+
'peak',
|
|
8862
|
+
'shore',
|
|
8863
|
+
'wave',
|
|
8864
|
+
'tide',
|
|
8865
|
+
'flame',
|
|
8866
|
+
'spark',
|
|
8867
|
+
'beam',
|
|
8868
|
+
'ray',
|
|
8869
|
+
'seed',
|
|
8870
|
+
'root',
|
|
8871
|
+
'branch',
|
|
8872
|
+
'bloom',
|
|
8873
|
+
'thorn',
|
|
8874
|
+
'bark',
|
|
8875
|
+
'shell',
|
|
8876
|
+
'feather',
|
|
8877
|
+
'wing',
|
|
8878
|
+
'claw',
|
|
8879
|
+
'paw',
|
|
8880
|
+
'nest',
|
|
8881
|
+
'cave',
|
|
8882
|
+
'grove',
|
|
8883
|
+
'tower',
|
|
8884
|
+
'castle',
|
|
8885
|
+
'crown',
|
|
8886
|
+
'sword',
|
|
8887
|
+
'shield',
|
|
8888
|
+
'coin',
|
|
8889
|
+
'gem',
|
|
8890
|
+
'ring',
|
|
8891
|
+
'bell',
|
|
8892
|
+
'clock',
|
|
8893
|
+
'compass',
|
|
8894
|
+
'anchor',
|
|
8895
|
+
'torch',
|
|
8896
|
+
'flute',
|
|
8897
|
+
'harp',
|
|
8898
|
+
'drum',
|
|
8899
|
+
'lens',
|
|
8900
|
+
'glass',
|
|
8901
|
+
'sand',
|
|
8902
|
+
'dust',
|
|
8903
|
+
'mist',
|
|
8904
|
+
'dew',
|
|
8905
|
+
'dawn',
|
|
8906
|
+
'dusk',
|
|
8907
|
+
'night',
|
|
8908
|
+
'day',
|
|
8909
|
+
'year',
|
|
8910
|
+
'age',
|
|
8911
|
+
'bolt',
|
|
8912
|
+
'drop',
|
|
8913
|
+
'storm',
|
|
8914
|
+
'snow',
|
|
8915
|
+
'hail',
|
|
8916
|
+
'fog',
|
|
8917
|
+
'smoke',
|
|
8918
|
+
'vapor',
|
|
8919
|
+
'gas',
|
|
8920
|
+
'fluid',
|
|
8921
|
+
'liquid',
|
|
8922
|
+
'solid',
|
|
8923
|
+
'metal',
|
|
8924
|
+
'rock',
|
|
8925
|
+
'dirt',
|
|
8926
|
+
'clay',
|
|
8927
|
+
'sand',
|
|
8928
|
+
'salt',
|
|
8929
|
+
'sugar',
|
|
8930
|
+
'wood',
|
|
8931
|
+
'bone',
|
|
8932
|
+
'skin',
|
|
8933
|
+
'flesh',
|
|
8934
|
+
'blood',
|
|
8935
|
+
'cell',
|
|
8936
|
+
'atom',
|
|
8937
|
+
'pulse',
|
|
8938
|
+
'beat',
|
|
8939
|
+
'breath',
|
|
8940
|
+
'sigh',
|
|
8941
|
+
'name',
|
|
8942
|
+
'echo',
|
|
8943
|
+
'image',
|
|
8944
|
+
'vision',
|
|
8945
|
+
'thought',
|
|
8946
|
+
'idea',
|
|
8947
|
+
'plan',
|
|
8948
|
+
'goal',
|
|
8949
|
+
'wish',
|
|
8950
|
+
'hope',
|
|
8951
|
+
'fear',
|
|
8952
|
+
'joy',
|
|
8953
|
+
'love',
|
|
8954
|
+
'hate',
|
|
8955
|
+
'will',
|
|
8956
|
+
'power',
|
|
8957
|
+
'force',
|
|
8958
|
+
'energy',
|
|
8959
|
+
'motion',
|
|
8960
|
+
'speed',
|
|
8961
|
+
'place',
|
|
8962
|
+
'point',
|
|
8963
|
+
'line',
|
|
8964
|
+
'shape',
|
|
8965
|
+
'form',
|
|
8966
|
+
'size',
|
|
8967
|
+
'mass',
|
|
8968
|
+
'weight',
|
|
8969
|
+
'heat',
|
|
8970
|
+
'cold',
|
|
8971
|
+
'color',
|
|
8972
|
+
'tone',
|
|
8973
|
+
'pitch',
|
|
8974
|
+
'rhythm',
|
|
8975
|
+
'vibe',
|
|
8976
|
+
'mood',
|
|
8977
|
+
'state',
|
|
8978
|
+
'way',
|
|
8979
|
+
'step',
|
|
8980
|
+
'move',
|
|
8981
|
+
'turn',
|
|
8982
|
+
'fall',
|
|
8983
|
+
'rise',
|
|
8984
|
+
'jump',
|
|
8985
|
+
'leap',
|
|
8986
|
+
'run',
|
|
8987
|
+
'walk',
|
|
8988
|
+
'rest',
|
|
8989
|
+
'stay',
|
|
8990
|
+
'trip',
|
|
8991
|
+
'quest',
|
|
8992
|
+
'task',
|
|
8993
|
+
'work',
|
|
8994
|
+
'job',
|
|
8995
|
+
'play',
|
|
8996
|
+
'game',
|
|
8997
|
+
'sport',
|
|
8998
|
+
'art',
|
|
8999
|
+
'craft',
|
|
9000
|
+
'tool',
|
|
9001
|
+
'ship',
|
|
9002
|
+
'boat',
|
|
9003
|
+
'car',
|
|
9004
|
+
'bike',
|
|
9005
|
+
'train',
|
|
9006
|
+
'plane',
|
|
9007
|
+
'hub',
|
|
9008
|
+
'base',
|
|
9009
|
+
'core',
|
|
9010
|
+
'node',
|
|
9011
|
+
'link',
|
|
9012
|
+
'net',
|
|
9013
|
+
'web',
|
|
9014
|
+
'box',
|
|
9015
|
+
'bag',
|
|
9016
|
+
'jar',
|
|
9017
|
+
'cup',
|
|
9018
|
+
'bowl',
|
|
9019
|
+
'plate',
|
|
9020
|
+
'dish',
|
|
9021
|
+
'spoon',
|
|
9022
|
+
'fork',
|
|
9023
|
+
'knife',
|
|
9024
|
+
'pan',
|
|
9025
|
+
'pot',
|
|
9026
|
+
'bed',
|
|
9027
|
+
'desk',
|
|
9028
|
+
'chair',
|
|
9029
|
+
'door',
|
|
9030
|
+
'wall',
|
|
9031
|
+
'roof',
|
|
9032
|
+
'floor',
|
|
9033
|
+
];
|
|
9034
|
+
const VERBS = [
|
|
9035
|
+
'jumping',
|
|
9036
|
+
'dancing',
|
|
9037
|
+
'flying',
|
|
9038
|
+
'running',
|
|
9039
|
+
'singing',
|
|
9040
|
+
'shining',
|
|
9041
|
+
'growing',
|
|
9042
|
+
'flowing',
|
|
9043
|
+
'falling',
|
|
9044
|
+
'rising',
|
|
9045
|
+
'sleeping',
|
|
9046
|
+
'walking',
|
|
9047
|
+
'talking',
|
|
9048
|
+
'thinking',
|
|
9049
|
+
'dreaming',
|
|
9050
|
+
'looking',
|
|
9051
|
+
'feeling',
|
|
9052
|
+
'smiling',
|
|
9053
|
+
'laughing',
|
|
9054
|
+
'playing',
|
|
9055
|
+
'working',
|
|
9056
|
+
'resting',
|
|
9057
|
+
'moving',
|
|
9058
|
+
'staying',
|
|
9059
|
+
'beaming',
|
|
9060
|
+
'glowing',
|
|
9061
|
+
'sparkling',
|
|
9062
|
+
'waiting',
|
|
9063
|
+
'waking',
|
|
9064
|
+
'drifting',
|
|
9065
|
+
'spinning',
|
|
9066
|
+
'gliding',
|
|
9067
|
+
'soaring',
|
|
9068
|
+
'floating',
|
|
9069
|
+
'whispering',
|
|
9070
|
+
'calling',
|
|
9071
|
+
'seeking',
|
|
9072
|
+
'finding',
|
|
9073
|
+
'giving',
|
|
9074
|
+
'taking',
|
|
9075
|
+
'weaving',
|
|
9076
|
+
'building',
|
|
9077
|
+
'creating',
|
|
9078
|
+
'burning',
|
|
9079
|
+
'freezing',
|
|
9080
|
+
'melting',
|
|
9081
|
+
'breathing',
|
|
9082
|
+
'pulsing',
|
|
9083
|
+
'beating',
|
|
9084
|
+
'living',
|
|
9085
|
+
'learning',
|
|
9086
|
+
'knowing',
|
|
9087
|
+
'hidden',
|
|
9088
|
+
'shown',
|
|
9089
|
+
'broken',
|
|
9090
|
+
'mended',
|
|
9091
|
+
'lost',
|
|
9092
|
+
'found',
|
|
9093
|
+
'starting',
|
|
9094
|
+
'ending',
|
|
9095
|
+
'climbing',
|
|
9096
|
+
'diving',
|
|
9097
|
+
'swimming',
|
|
9098
|
+
'sailing',
|
|
9099
|
+
'rolling',
|
|
9100
|
+
'shaking',
|
|
9101
|
+
'turning',
|
|
9102
|
+
'shifting',
|
|
9103
|
+
'changing',
|
|
9104
|
+
'fading',
|
|
9105
|
+
'dying',
|
|
9106
|
+
'born',
|
|
9107
|
+
'humming',
|
|
9108
|
+
'crying',
|
|
9109
|
+
'racing',
|
|
9110
|
+
'creeping',
|
|
9111
|
+
'hiding',
|
|
9112
|
+
'watching',
|
|
9113
|
+
'hearing',
|
|
9114
|
+
'sensing',
|
|
9115
|
+
'longing',
|
|
9116
|
+
'hoping',
|
|
9117
|
+
'loving',
|
|
9118
|
+
'fearing',
|
|
9119
|
+
'wondering',
|
|
9120
|
+
'wandering',
|
|
9121
|
+
'traveling',
|
|
9122
|
+
'crossing',
|
|
9123
|
+
'meeting',
|
|
9124
|
+
'parting',
|
|
9125
|
+
'keeping',
|
|
9126
|
+
'sharing',
|
|
9127
|
+
'sparking',
|
|
9128
|
+
'flaming',
|
|
9129
|
+
'healing',
|
|
9130
|
+
'solving',
|
|
9131
|
+
'opening',
|
|
9132
|
+
'closing',
|
|
9133
|
+
'lifting',
|
|
9134
|
+
'pulling',
|
|
9135
|
+
'pushing',
|
|
9136
|
+
'holding',
|
|
9137
|
+
'tossing',
|
|
9138
|
+
'throwing',
|
|
9139
|
+
'catching',
|
|
9140
|
+
'fixing',
|
|
9141
|
+
'making',
|
|
9142
|
+
'doing',
|
|
9143
|
+
'seeing',
|
|
9144
|
+
'tasting',
|
|
9145
|
+
'smelling',
|
|
9146
|
+
'touching',
|
|
9147
|
+
'pacing',
|
|
9148
|
+
'hurrying',
|
|
9149
|
+
'pausing',
|
|
9150
|
+
'going',
|
|
9151
|
+
'coming',
|
|
9152
|
+
'leaving',
|
|
9153
|
+
'acting',
|
|
9154
|
+
'being',
|
|
9155
|
+
'seeming',
|
|
9156
|
+
'shrinking',
|
|
9157
|
+
'widening',
|
|
9158
|
+
'narrowing',
|
|
9159
|
+
'heating',
|
|
9160
|
+
'cooling',
|
|
9161
|
+
'drying',
|
|
9162
|
+
'wetting',
|
|
9163
|
+
'filling',
|
|
9164
|
+
'filling',
|
|
9165
|
+
'emptying',
|
|
9166
|
+
'letting',
|
|
9167
|
+
'gaining',
|
|
9168
|
+
'winning',
|
|
9169
|
+
'failing',
|
|
9170
|
+
'trying',
|
|
9171
|
+
'using',
|
|
9172
|
+
'getting',
|
|
9173
|
+
'showing',
|
|
9174
|
+
'hiding',
|
|
9175
|
+
'breaking',
|
|
9176
|
+
'fixing',
|
|
9177
|
+
'saving',
|
|
9178
|
+
'spending',
|
|
9179
|
+
'buying',
|
|
9180
|
+
'selling',
|
|
9181
|
+
'paying',
|
|
9182
|
+
'costing',
|
|
9183
|
+
'reaching',
|
|
9184
|
+
'missing',
|
|
9185
|
+
'hitting',
|
|
9186
|
+
'striking',
|
|
9187
|
+
'leading',
|
|
9188
|
+
'following',
|
|
9189
|
+
'helping',
|
|
9190
|
+
'serving',
|
|
9191
|
+
'teaching',
|
|
9192
|
+
'training',
|
|
9193
|
+
'coding',
|
|
9194
|
+
'writing',
|
|
9195
|
+
'reading',
|
|
9196
|
+
'drawing',
|
|
9197
|
+
'painting',
|
|
9198
|
+
'crafting',
|
|
9199
|
+
'shaping',
|
|
9200
|
+
'forming',
|
|
9201
|
+
'joining',
|
|
9202
|
+
'splitting',
|
|
9203
|
+
'sharing',
|
|
9204
|
+
'bonding',
|
|
9205
|
+
'healing',
|
|
9206
|
+
'harming',
|
|
9207
|
+
'protecting',
|
|
9208
|
+
'fighting',
|
|
9209
|
+
'defending',
|
|
9210
|
+
'attacking',
|
|
9211
|
+
'escaping',
|
|
9212
|
+
'catching',
|
|
9213
|
+
'trapping',
|
|
9214
|
+
'freeing',
|
|
9215
|
+
'binding',
|
|
9216
|
+
'weaving',
|
|
9217
|
+
'spinning',
|
|
9218
|
+
];
|
|
9219
|
+
|
|
8528
9220
|
/**
|
|
8529
9221
|
* Function parseNumber will parse number from string
|
|
8530
9222
|
*
|
|
@@ -8633,6 +9325,95 @@ function removeQuotes(text) {
|
|
|
8633
9325
|
return text;
|
|
8634
9326
|
}
|
|
8635
9327
|
|
|
9328
|
+
/**
|
|
9329
|
+
* Removes quotes and optional introduce text from a string
|
|
9330
|
+
*
|
|
9331
|
+
* Tip: This is very useful for post-processing of the result of the LLM model
|
|
9332
|
+
* Note: This function trims the text and removes whole introduce sentence if it is present
|
|
9333
|
+
* Note: There are two similar functions:
|
|
9334
|
+
* - `removeQuotes` which removes only bounding quotes
|
|
9335
|
+
* - `unwrapResult` which removes whole introduce sentence
|
|
9336
|
+
*
|
|
9337
|
+
* @param text optionally quoted text
|
|
9338
|
+
* @returns text without quotes
|
|
9339
|
+
* @public exported from `@promptbook/utils`
|
|
9340
|
+
*/
|
|
9341
|
+
function unwrapResult(text, options) {
|
|
9342
|
+
const { isTrimmed = true, isIntroduceSentenceRemoved = true } = options || {};
|
|
9343
|
+
let trimmedText = text;
|
|
9344
|
+
// Remove leading and trailing spaces and newlines
|
|
9345
|
+
if (isTrimmed) {
|
|
9346
|
+
trimmedText = spaceTrim$1(trimmedText);
|
|
9347
|
+
}
|
|
9348
|
+
let processedText = trimmedText;
|
|
9349
|
+
// Check for markdown code block
|
|
9350
|
+
const codeBlockRegex = /^```[a-z]*\n([\s\S]*?)\n```\s*$/;
|
|
9351
|
+
const codeBlockMatch = processedText.match(codeBlockRegex);
|
|
9352
|
+
if (codeBlockMatch && codeBlockMatch[1] !== undefined) {
|
|
9353
|
+
// Check if there's only one code block
|
|
9354
|
+
const codeBlockCount = (processedText.match(/```/g) || []).length / 2;
|
|
9355
|
+
if (codeBlockCount === 1) {
|
|
9356
|
+
return unwrapResult(codeBlockMatch[1], { isTrimmed: false, isIntroduceSentenceRemoved: false });
|
|
9357
|
+
}
|
|
9358
|
+
}
|
|
9359
|
+
if (isIntroduceSentenceRemoved) {
|
|
9360
|
+
const introduceSentenceRegex = /^[a-zěščřžýáíéúů:\s]*:\s*/i;
|
|
9361
|
+
if (introduceSentenceRegex.test(text)) {
|
|
9362
|
+
// Remove the introduce sentence and quotes by replacing it with an empty string
|
|
9363
|
+
processedText = processedText.replace(introduceSentenceRegex, '');
|
|
9364
|
+
}
|
|
9365
|
+
processedText = spaceTrim$1(processedText);
|
|
9366
|
+
// Check again for code block after removing introduce sentence
|
|
9367
|
+
const codeBlockMatch2 = processedText.match(codeBlockRegex);
|
|
9368
|
+
if (codeBlockMatch2 && codeBlockMatch2[1] !== undefined) {
|
|
9369
|
+
const codeBlockCount = (processedText.match(/```/g) || []).length / 2;
|
|
9370
|
+
if (codeBlockCount === 1) {
|
|
9371
|
+
return unwrapResult(codeBlockMatch2[1], { isTrimmed: false, isIntroduceSentenceRemoved: false });
|
|
9372
|
+
}
|
|
9373
|
+
}
|
|
9374
|
+
}
|
|
9375
|
+
if (processedText.length < 3) {
|
|
9376
|
+
return trimmedText;
|
|
9377
|
+
}
|
|
9378
|
+
if (processedText.includes('\n')) {
|
|
9379
|
+
return trimmedText;
|
|
9380
|
+
}
|
|
9381
|
+
// Remove the quotes by extracting the substring without the first and last characters
|
|
9382
|
+
const unquotedText = processedText.slice(1, -1);
|
|
9383
|
+
// Check if the text starts and ends with quotes
|
|
9384
|
+
if ([
|
|
9385
|
+
['"', '"'],
|
|
9386
|
+
["'", "'"],
|
|
9387
|
+
['`', '`'],
|
|
9388
|
+
['*', '*'],
|
|
9389
|
+
['_', '_'],
|
|
9390
|
+
['„', '“'],
|
|
9391
|
+
['«', '»'] /* <- QUOTES to config */,
|
|
9392
|
+
].some(([startQuote, endQuote]) => {
|
|
9393
|
+
if (!processedText.startsWith(startQuote)) {
|
|
9394
|
+
return false;
|
|
9395
|
+
}
|
|
9396
|
+
if (!processedText.endsWith(endQuote)) {
|
|
9397
|
+
return false;
|
|
9398
|
+
}
|
|
9399
|
+
if (unquotedText.includes(startQuote) && !unquotedText.includes(endQuote)) {
|
|
9400
|
+
return false;
|
|
9401
|
+
}
|
|
9402
|
+
if (!unquotedText.includes(startQuote) && unquotedText.includes(endQuote)) {
|
|
9403
|
+
return false;
|
|
9404
|
+
}
|
|
9405
|
+
return true;
|
|
9406
|
+
})) {
|
|
9407
|
+
return unwrapResult(unquotedText, { isTrimmed: false, isIntroduceSentenceRemoved: false });
|
|
9408
|
+
}
|
|
9409
|
+
else {
|
|
9410
|
+
return processedText;
|
|
9411
|
+
}
|
|
9412
|
+
}
|
|
9413
|
+
/**
|
|
9414
|
+
* TODO: [🧠] Should this also unwrap the (parenthesis)
|
|
9415
|
+
*/
|
|
9416
|
+
|
|
8636
9417
|
/**
|
|
8637
9418
|
* Checks if the given value is a valid JavaScript identifier name.
|
|
8638
9419
|
*
|
|
@@ -11317,6 +12098,46 @@ class UseMcpCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
11317
12098
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
11318
12099
|
*/
|
|
11319
12100
|
|
|
12101
|
+
/**
|
|
12102
|
+
* A search engine implementation that uses the SerpApi to fetch Google search results.
|
|
12103
|
+
*
|
|
12104
|
+
* @private <- TODO: !!!! Export via some package
|
|
12105
|
+
*/
|
|
12106
|
+
class SerpSearchEngine {
|
|
12107
|
+
get title() {
|
|
12108
|
+
return 'SerpApi Search Engine';
|
|
12109
|
+
}
|
|
12110
|
+
get description() {
|
|
12111
|
+
return 'Search engine that uses SerpApi to fetch Google search results';
|
|
12112
|
+
}
|
|
12113
|
+
checkConfiguration() {
|
|
12114
|
+
if (!process.env.SERP_API_KEY) {
|
|
12115
|
+
throw new Error('SERP_API_KEY is not configured');
|
|
12116
|
+
}
|
|
12117
|
+
}
|
|
12118
|
+
async search(query) {
|
|
12119
|
+
const apiKey = process.env.SERP_API_KEY;
|
|
12120
|
+
if (!apiKey) {
|
|
12121
|
+
throw new Error('SERP_API_KEY is not configured');
|
|
12122
|
+
}
|
|
12123
|
+
const url = new URL('https://serpapi.com/search');
|
|
12124
|
+
url.searchParams.set('q', query);
|
|
12125
|
+
url.searchParams.set('api_key', apiKey);
|
|
12126
|
+
url.searchParams.set('engine', 'google');
|
|
12127
|
+
const response = await fetch(url.toString());
|
|
12128
|
+
if (!response.ok) {
|
|
12129
|
+
const body = await response.text();
|
|
12130
|
+
throw new Error(`SerpApi failed with status ${response.status}: ${response.statusText}\n${body}`);
|
|
12131
|
+
}
|
|
12132
|
+
const data = (await response.json());
|
|
12133
|
+
return (data.organic_results || []).map((item) => ({
|
|
12134
|
+
title: item.title,
|
|
12135
|
+
url: item.link,
|
|
12136
|
+
snippet: item.snippet || '',
|
|
12137
|
+
}));
|
|
12138
|
+
}
|
|
12139
|
+
}
|
|
12140
|
+
|
|
11320
12141
|
/**
|
|
11321
12142
|
* USE SEARCH ENGINE commitment definition
|
|
11322
12143
|
*
|
|
@@ -11393,18 +12214,13 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
11393
12214
|
? existingTools
|
|
11394
12215
|
: [
|
|
11395
12216
|
...existingTools,
|
|
11396
|
-
{ type: 'web_search' },
|
|
11397
|
-
// <- Note: [🔰] This is just using simple native search tool by OpenAI @see https://platform.openai.com/docs/guides/tools-web-search
|
|
11398
|
-
// In future we will use proper MCP search tool:
|
|
11399
|
-
/*
|
|
11400
|
-
|
|
11401
12217
|
{
|
|
11402
12218
|
name: 'web_search',
|
|
11403
|
-
description: spaceTrim(`
|
|
11404
|
-
|
|
11405
|
-
|
|
11406
|
-
|
|
11407
|
-
|
|
12219
|
+
description: spaceTrim$1(`
|
|
12220
|
+
Search the internet for information.
|
|
12221
|
+
Use this tool when you need to find up-to-date information or facts that you don't know.
|
|
12222
|
+
${!content ? '' : `Search scope / instructions: ${content}`}
|
|
12223
|
+
`),
|
|
11408
12224
|
parameters: {
|
|
11409
12225
|
type: 'object',
|
|
11410
12226
|
properties: {
|
|
@@ -11416,7 +12232,6 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
11416
12232
|
required: ['query'],
|
|
11417
12233
|
},
|
|
11418
12234
|
},
|
|
11419
|
-
*/
|
|
11420
12235
|
];
|
|
11421
12236
|
// Return requirements with updated tools and metadata
|
|
11422
12237
|
return {
|
|
@@ -11428,6 +12243,33 @@ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
|
|
|
11428
12243
|
},
|
|
11429
12244
|
};
|
|
11430
12245
|
}
|
|
12246
|
+
/**
|
|
12247
|
+
* Gets the `web_search` tool function implementation.
|
|
12248
|
+
*/
|
|
12249
|
+
getToolFunctions() {
|
|
12250
|
+
return {
|
|
12251
|
+
async web_search(args) {
|
|
12252
|
+
console.log('!!!! [Tool] web_search called', { args });
|
|
12253
|
+
const { query } = args;
|
|
12254
|
+
if (!query) {
|
|
12255
|
+
throw new Error('Search query is required');
|
|
12256
|
+
}
|
|
12257
|
+
const searchEngine = new SerpSearchEngine();
|
|
12258
|
+
const results = await searchEngine.search(query);
|
|
12259
|
+
return spaceTrim$1((block) => `
|
|
12260
|
+
Search results for "${query}":
|
|
12261
|
+
|
|
12262
|
+
${block(results
|
|
12263
|
+
.map((result) => spaceTrim$1(`
|
|
12264
|
+
- **${result.title}**
|
|
12265
|
+
${result.url}
|
|
12266
|
+
${result.snippet}
|
|
12267
|
+
`))
|
|
12268
|
+
.join('\n\n'))}
|
|
12269
|
+
`);
|
|
12270
|
+
},
|
|
12271
|
+
};
|
|
12272
|
+
}
|
|
11431
12273
|
}
|
|
11432
12274
|
/**
|
|
11433
12275
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -11671,6 +12513,7 @@ const COMMITMENT_REGISTRY = [
|
|
|
11671
12513
|
new NoteCommitmentDefinition('NOTES'),
|
|
11672
12514
|
new NoteCommitmentDefinition('COMMENT'),
|
|
11673
12515
|
new NoteCommitmentDefinition('NONCE'),
|
|
12516
|
+
new NoteCommitmentDefinition('TODO'),
|
|
11674
12517
|
new GoalCommitmentDefinition('GOAL'),
|
|
11675
12518
|
new GoalCommitmentDefinition('GOALS'),
|
|
11676
12519
|
new InitialMessageCommitmentDefinition(),
|
|
@@ -17647,6 +18490,16 @@ function cacheLlmTools(llmTools, options = {}) {
|
|
|
17647
18490
|
}
|
|
17648
18491
|
}
|
|
17649
18492
|
}
|
|
18493
|
+
if (shouldCache && promptResult.toolCalls !== undefined) {
|
|
18494
|
+
// Note: Do not cache results that contain tool calls because they are dynamic and should be always fresh
|
|
18495
|
+
// For example, it doesn't make sense to cache the message 'What time is it? 3:30 pm' because when the question is asked another time, it can be a different time.
|
|
18496
|
+
shouldCache = false;
|
|
18497
|
+
if (isVerbose) {
|
|
18498
|
+
console.info('Not caching result that contains tool calls for key:', key, {
|
|
18499
|
+
toolCalls: promptResult.toolCalls,
|
|
18500
|
+
});
|
|
18501
|
+
}
|
|
18502
|
+
}
|
|
17650
18503
|
if (shouldCache) {
|
|
17651
18504
|
await storage.setItem(key, {
|
|
17652
18505
|
date: $getCurrentDate(),
|
|
@@ -20541,8 +21394,7 @@ AgentLlmExecutionTools.assistantCache = new Map();
|
|
|
20541
21394
|
* TODO: [🧠] Adding parameter substitution support (here or should be responsibility of the underlying LLM Tools)
|
|
20542
21395
|
*/
|
|
20543
21396
|
|
|
20544
|
-
var _Agent_instances, _Agent_selfLearnSamples;
|
|
20545
|
-
// !!!!! import { RemoteAgent } from './RemoteAgent'; // <- [💞] <- !!!!!
|
|
21397
|
+
var _Agent_instances, _Agent_selfLearnNonce, _Agent_selfLearnSamples, _Agent_selfLearnTeacher;
|
|
20546
21398
|
/**
|
|
20547
21399
|
* Represents one AI Agent
|
|
20548
21400
|
*
|
|
@@ -20612,6 +21464,7 @@ class Agent extends AgentLlmExecutionTools {
|
|
|
20612
21464
|
this.meta = {};
|
|
20613
21465
|
// TODO: [🐱🚀] Add `Agent` simple "mocked" learning by appending to agent source
|
|
20614
21466
|
// TODO: [🐱🚀] Add `Agent` learning by promptbookAgent
|
|
21467
|
+
this.teacherAgent = options.teacherAgent;
|
|
20615
21468
|
this.agentSource = agentSource;
|
|
20616
21469
|
this.agentSource.subscribe((source) => {
|
|
20617
21470
|
this.updateAgentSource(source);
|
|
@@ -20682,26 +21535,42 @@ class Agent extends AgentLlmExecutionTools {
|
|
|
20682
21535
|
if ((_a = modelRequirements.metadata) === null || _a === void 0 ? void 0 : _a.isClosed) {
|
|
20683
21536
|
return result;
|
|
20684
21537
|
}
|
|
20685
|
-
// TODO: !!!!!
|
|
21538
|
+
// TODO: !!!!! Return the answer and do the learning asynchronously
|
|
21539
|
+
// Note: [0] Asynchronously add nonce
|
|
21540
|
+
if (just(false)) {
|
|
21541
|
+
await __classPrivateFieldGet(this, _Agent_instances, "m", _Agent_selfLearnNonce).call(this);
|
|
21542
|
+
}
|
|
20686
21543
|
// Note: [1] Do the append of the samples
|
|
20687
|
-
__classPrivateFieldGet(this, _Agent_instances, "m", _Agent_selfLearnSamples).call(this, prompt, result);
|
|
20688
|
-
/*
|
|
20689
|
-
!!!!!
|
|
21544
|
+
await __classPrivateFieldGet(this, _Agent_instances, "m", _Agent_selfLearnSamples).call(this, prompt, result);
|
|
20690
21545
|
// Note: [2] Asynchronously call the teacher agent and invoke the silver link. When the teacher fails, keep just the samples
|
|
20691
|
-
this
|
|
20692
|
-
if (this.options.isVerbose) {
|
|
20693
|
-
|
|
20694
|
-
|
|
21546
|
+
await __classPrivateFieldGet(this, _Agent_instances, "m", _Agent_selfLearnTeacher).call(this, prompt, result).catch((error) => {
|
|
21547
|
+
// !!!!! if (this.options.isVerbose) {
|
|
21548
|
+
console.error(colors.bgCyan('[Self-learning]') + colors.red(' Failed to learn from teacher agent'));
|
|
21549
|
+
console.error(error);
|
|
21550
|
+
// }
|
|
20695
21551
|
});
|
|
20696
|
-
*/
|
|
20697
21552
|
return result;
|
|
20698
21553
|
}
|
|
20699
21554
|
}
|
|
20700
|
-
_Agent_instances = new WeakSet(),
|
|
21555
|
+
_Agent_instances = new WeakSet(), _Agent_selfLearnNonce =
|
|
21556
|
+
/**
|
|
21557
|
+
* Self-learning Step 0: Asynchronously with random timing add nonce to the agent source
|
|
21558
|
+
*/
|
|
21559
|
+
async function _Agent_selfLearnNonce() {
|
|
21560
|
+
await forTime(Math.random() * 5000);
|
|
21561
|
+
// <- TODO: [🕓] `await forRandom(...)`
|
|
21562
|
+
console.info(colors.bgCyan('[Self-learning]') + colors.cyan(' Nonce'));
|
|
21563
|
+
const nonce = `NONCE ${await linguisticHash(Math.random().toString())}`;
|
|
21564
|
+
// Append to the current source
|
|
21565
|
+
const currentSource = this.agentSource.value;
|
|
21566
|
+
const newSource = padBook(validateBook(spaceTrim$2(currentSource) + '\n\n---\n\n' + nonce));
|
|
21567
|
+
// <- TODO: [🈲] Use some object-based way how to append on book (with sections `---`)
|
|
21568
|
+
// Update the source (which will trigger the subscription and update the underlying tools)
|
|
21569
|
+
this.agentSource.next(newSource);
|
|
21570
|
+
}, _Agent_selfLearnSamples = function _Agent_selfLearnSamples(prompt, result) {
|
|
21571
|
+
console.info(colors.bgCyan('[Self-learning]') + colors.cyan(' Sampling'));
|
|
20701
21572
|
const learningExample = spaceTrim$2((block) => `
|
|
20702
21573
|
|
|
20703
|
-
---
|
|
20704
|
-
|
|
20705
21574
|
USER MESSAGE
|
|
20706
21575
|
${block(prompt.content)}
|
|
20707
21576
|
|
|
@@ -20711,9 +21580,80 @@ _Agent_instances = new WeakSet(), _Agent_selfLearnSamples = function _Agent_self
|
|
|
20711
21580
|
`);
|
|
20712
21581
|
// Append to the current source
|
|
20713
21582
|
const currentSource = this.agentSource.value;
|
|
20714
|
-
const newSource = padBook(validateBook(spaceTrim$2(currentSource) + '\n\n' + learningExample));
|
|
21583
|
+
const newSource = padBook(validateBook(spaceTrim$2(currentSource) + '\n\n---\n\n' + learningExample));
|
|
21584
|
+
// <- TODO: [🈲] Use some object-based way how to append on book (with sections `---`)
|
|
20715
21585
|
// Update the source (which will trigger the subscription and update the underlying tools)
|
|
20716
21586
|
this.agentSource.next(newSource);
|
|
21587
|
+
}, _Agent_selfLearnTeacher =
|
|
21588
|
+
/**
|
|
21589
|
+
* Self-learning Step 2: Asynchronously call the teacher agent and invoke the silver link
|
|
21590
|
+
*/
|
|
21591
|
+
async function _Agent_selfLearnTeacher(prompt, result) {
|
|
21592
|
+
// [1] Call the teacher agent // <- !!!!! Emojis
|
|
21593
|
+
if (this.teacherAgent === null) {
|
|
21594
|
+
return;
|
|
21595
|
+
}
|
|
21596
|
+
console.info(colors.bgCyan('[Self-learning]') + colors.cyan(' Teacher'));
|
|
21597
|
+
const teacherResult = await this.teacherAgent.callChatModel({
|
|
21598
|
+
title: 'Self-learning',
|
|
21599
|
+
modelRequirements: {
|
|
21600
|
+
modelVariant: 'CHAT',
|
|
21601
|
+
},
|
|
21602
|
+
// TODO: !!!! Use prompt notation
|
|
21603
|
+
content: spaceTrim$2((block) => `
|
|
21604
|
+
|
|
21605
|
+
You are a teacher agent helping another agent to learn from its interactions.
|
|
21606
|
+
|
|
21607
|
+
Here is your current client which you are teaching:
|
|
21608
|
+
|
|
21609
|
+
\`\`\`book
|
|
21610
|
+
${block(this.agentSource.value)}
|
|
21611
|
+
\`\`\`
|
|
21612
|
+
|
|
21613
|
+
**And here is the latest interaction:**
|
|
21614
|
+
|
|
21615
|
+
**User:**
|
|
21616
|
+
${block(prompt.content)}
|
|
21617
|
+
|
|
21618
|
+
**Agent:**
|
|
21619
|
+
${block(result.content)}
|
|
21620
|
+
|
|
21621
|
+
|
|
21622
|
+
**Rules:**
|
|
21623
|
+
|
|
21624
|
+
- Decide what the agent should learn from this interaction.
|
|
21625
|
+
- Append new commitments at the end of the agent source.
|
|
21626
|
+
- Do not modify the current agent source, just return new commitments (KNOWLEDGE, RULE, etc.).
|
|
21627
|
+
- If there is nothing new to learn, return empty book code block
|
|
21628
|
+
- Wrap the commitments in a book code block.
|
|
21629
|
+
- Do not explain anything, just return the commitments wrapped in a book code block.
|
|
21630
|
+
- Write the learned commitments in the same style and language as in the original agent source.
|
|
21631
|
+
|
|
21632
|
+
|
|
21633
|
+
This is how book code block looks like:
|
|
21634
|
+
|
|
21635
|
+
\`\`\`book
|
|
21636
|
+
KNOWLEDGE The sky is blue.
|
|
21637
|
+
RULE Always be polite.
|
|
21638
|
+
\`\`\`
|
|
21639
|
+
`),
|
|
21640
|
+
// pipelineUrl: 'https://github.com/webgptorg/promptbook/blob/main/prompts/self-learning.ptbk.md',
|
|
21641
|
+
// <- TODO: !!!! Remove and `pipelineUrl` for agent purposes
|
|
21642
|
+
parameters: {},
|
|
21643
|
+
});
|
|
21644
|
+
console.log('!!!! teacherResult', teacherResult);
|
|
21645
|
+
const teacherCommitments = unwrapResult(teacherResult.content);
|
|
21646
|
+
if (teacherCommitments === '') {
|
|
21647
|
+
console.info(colors.bgCyan('[Self-learning]') +
|
|
21648
|
+
colors.cyan(' Teacher agent did not provide new commitments to learn'));
|
|
21649
|
+
return;
|
|
21650
|
+
}
|
|
21651
|
+
// [2] Append to the current source
|
|
21652
|
+
const currentSource = this.agentSource.value;
|
|
21653
|
+
const newSource = padBook(validateBook(spaceTrim$2(currentSource) + '\n\n' + teacherCommitments));
|
|
21654
|
+
// <- TODO: [🈲] Use some object-based way how to append on book (with sections `---`)
|
|
21655
|
+
// [3] Update the source
|
|
21656
|
+
this.agentSource.next(newSource);
|
|
20717
21657
|
};
|
|
20718
21658
|
/**
|
|
20719
21659
|
* TODO: [🧠][😰]Agent is not working with the parameters, should it be?
|
|
@@ -20857,10 +21797,25 @@ function book(strings, ...values) {
|
|
|
20857
21797
|
*/
|
|
20858
21798
|
class RemoteAgent extends Agent {
|
|
20859
21799
|
static async connect(options) {
|
|
20860
|
-
|
|
20861
|
-
const profileResponse = await fetch(
|
|
21800
|
+
const agentProfileUrl = `${options.agentUrl}/api/profile`;
|
|
21801
|
+
const profileResponse = await fetch(agentProfileUrl);
|
|
20862
21802
|
// <- TODO: [🐱🚀] What about closed-source agents?
|
|
20863
21803
|
// <- TODO: [🐱🚀] Maybe use promptbookFetch
|
|
21804
|
+
if (!profileResponse.ok) {
|
|
21805
|
+
throw new Error(spaceTrim$2((block) => `
|
|
21806
|
+
Failed to fetch remote agent profile:
|
|
21807
|
+
|
|
21808
|
+
Agent URL:
|
|
21809
|
+
${options.agentUrl}
|
|
21810
|
+
|
|
21811
|
+
Agent Profile URL:
|
|
21812
|
+
${agentProfileUrl}
|
|
21813
|
+
|
|
21814
|
+
Http Error:
|
|
21815
|
+
${block(profileResponse.statusText)}
|
|
21816
|
+
|
|
21817
|
+
`));
|
|
21818
|
+
}
|
|
20864
21819
|
const profile = await profileResponse.json();
|
|
20865
21820
|
// Note: We are creating dummy agent source because we don't have the source from the remote agent
|
|
20866
21821
|
// But we populate the metadata from the profile
|
|
@@ -20887,6 +21842,7 @@ class RemoteAgent extends Agent {
|
|
|
20887
21842
|
*/
|
|
20888
21843
|
},
|
|
20889
21844
|
agentSource,
|
|
21845
|
+
teacherAgent: null, // <- Note:
|
|
20890
21846
|
});
|
|
20891
21847
|
remoteAgent._remoteAgentName = profile.agentName;
|
|
20892
21848
|
remoteAgent._remoteAgentHash = profile.agentHash;
|
|
@@ -22626,10 +23582,11 @@ function $generateBookBoilerplate(options) {
|
|
|
22626
23582
|
const agentSource = validateBook(spaceTrim$2((block) => `
|
|
22627
23583
|
${agentName}
|
|
22628
23584
|
|
|
22629
|
-
|
|
23585
|
+
|
|
22630
23586
|
PERSONA ${block(personaDescription)}
|
|
22631
23587
|
${block(initialRules.map((rule) => `RULE ${rule}`).join('\n'))}
|
|
22632
23588
|
`));
|
|
23589
|
+
// Note: `META COLOR ${color || PROMPTBOOK_COLOR.toHex()}` was removed for now
|
|
22633
23590
|
// Note: `META FONT Playfair Display, sans-serif` was removed for now
|
|
22634
23591
|
// <- TODO: [🈲] Simple and object-constructive way how to create new books
|
|
22635
23592
|
return agentSource;
|