|
Krotos Modules 3
|
take a user text query and return 4 assets that can be loaded as an ambience preset More...
#include <TextToAssets.h>
Classes | |
| struct | Data |
| struct | Layer |
| class | Listener |
| Listener for the TextToAssets module. More... | |
| struct | TTPAsset |
Public Member Functions | |
| TextToAssets () | |
| ~TextToAssets () | |
| std::tuple< String, std::array< TTPAsset, 4 > > | findPresetFiles (String searchTerm) |
| find 4 assets suitable for the given query | |
| std::vector< float > | rankify (const std::vector< float > &x) const |
| output the rank of each vector element | |
| bool | processFileList (Array< File > &filesToProcess) |
| processes a file list to create text embeddings | |
| bool | appendDataToEmbeddingsFile () |
| appends data to the main embeddings file | |
| virtual File | createFilePath (String filename) |
| creates the path for the embeddings file | |
| bool | isUCSValid (String catID) |
| check UCS CatID is valid | |
| void | setClaudeApiKey (const String &key) |
| Set the encrypted API key string for the Claude API. | |
| void | addListener (Listener *listener) |
| void | removeListener (Listener *listener) |
| bool | isAvailable () |
| Returns the status of the file processing. | |
| bool | isStrictMode () |
| Returns if "Strict Mode" is enabled (default: disabled). | |
| void | setStrictMode (bool isStrictMode) |
| Sets whether "Strict Mode" is enabled or disabled (default: disabled). | |
Static Public Member Functions | |
| static void | searchForTagAndProperty (ValueTree &root, Identifier tag, Identifier property, String newSample, Identifier target) |
| this will add a sample that comes from ttp to the corresponding core egine but it also update the xypad labels with the assets proposed, | |
| static void | updateTabLabel (ValueTree &root, int index, const String &label) |
| This function searches for a specific TABLABEL by index within the CUSTOMDATA node and updates its text. | |
| static void | updateCoreEngineParamValue (ValueTree &tree, const var &coreEngineID, const var ¶mID, const String &value) |
| update a CoreEngine PARAM value | |
| static std::unique_ptr< XmlElement > | getInitTTPData () |
| xml for automated preset generation | |
Protected Member Functions | |
| virtual void | calculateEmbeddingsForFile (const File &file) |
| create text embeddings file for the given file | |
| virtual bool | isModelFileAvailable () const |
| Returns whether there is a model file available for use, in order to generate embeddings. | |
Protected Attributes | |
| bool | m_modelFileAvailable {false} |
| bool | m_synchronousUpdates {false} |
Private Member Functions | |
| void | addBiasToLayers (const String &query, std::vector< Layer > &layers) |
| add a non-zero bias to layers that match certain keywords | |
| StringArray | parseAnthropicResponse (std::unique_ptr< InputStream > &stream) |
| parse Anthropic API response and return results in a StringArray | |
| StringArray | getLLMLayers (std::unique_ptr< InputStream > &stream) |
| returns a StringArray of preset layer names generated by an LLM | |
| StringArray | anthropicAPICall (String query) |
| send query to an LLM using the anthropic API | |
| std::vector< float > | calculateLLMLayerScores (const std::vector< Layer > &layers, const StringArray &generatedLayerNames) |
| return similarity scores for layers based on the LLM generated layer names | |
| float | dot (const std::vector< float > &a, const std::vector< float > &b) const |
| return dot product between a and b | |
| void | normalise (std::vector< float > &x) const |
| L2 normalise the input vector. | |
| std::vector< float > | getVectorScores (String catID, const std::vector< float > &x) const |
| return vector scores between query embedding and dataset embeddings | |
| std::tuple< String, StringArray > | preprocessQuery (String query) const |
| return preprocessed query and exclude tags | |
| std::vector< std::pair< float, int > > | topk (std::vector< std::pair< float, int > > data, int topk) const |
| return topk elements | |
| std::vector< float > | calculateReciprocalRankFusion (const std::vector< float > &scores1, const std::vector< float > &scores2, float k=2.0f, float alpha=0.5f) const |
| calculate the reciprocal rank fusion for scores1 and scores2 | |
| bool | matchesCategory (const String &catID, StringArray tags) const |
| check if UCS catID matches one of our target tags | |
| void | clear () |
| clears internal data | |
| void | run () override |
| run thread | |
| void | loadFileEmbeddings () |
| will load embeddings data from file to all modules that need it | |
| bool | readFromFile (File file) |
| load embeddings from file | |
| String | sanitizeString (String text) |
| removes digits and underscores from a string | |
| String | capitalize (const String &text) |
| make first letter of string upper case and the rest lower case | |
| void | loadPresetLayers () |
| load preset layers from json stored as binary data | |
| void | loadQueryEmbeddings () |
| load quer embeddings from json stored as binary data | |
| std::tuple< String, String > | findClosestAmbienceCatID (const String &query, const std::vector< float > &queryEmbedding) |
| search for closest match to query | |
| std::vector< int > | argsort (const std::vector< float > &x) const |
| returns the indices that would sort the vector. | |
| bool | containsKeyword (const String &text, const StringArray &keywords) |
| returns true if the text contains any keyword in keywords. | |
| void | maskLayersContainingTag (String tag, std::vector< Layer > &layers) |
| set layer.isValid to false for layers containing tag. | |
| void | excludeLayers (const StringArray &excludeList, std::vector< Layer > &layers) |
| uses the contents of exclude list to set some preset layers as invalid if certain keywords are detected. | |
| std::tuple< float, int, bool > | findLayer (const std::vector< float > &queryEmbedding, const std::vector< float > &presetEmbedding, const std::vector< Layer > &layers, const std::vector< float > &layerScoresLLM) |
| find a relevant preset layer | |
| std::tuple< String, float > | findAsset (const Layer &layer) |
| find a relevant asset for a given preset layer | |
| void | notifyAvailabilityStatus (bool isAvailable) |
| Update TTA availability status and notify listeners. TTA should not available whilst file processing is taking place. | |
| void | notifyProgressUpdate (const int processedFiles, const int totalFiles, const String &estimatedTimeRemaining) |
| Notifies listeners of the progress of the current file processing operation. | |
Private Attributes | |
| std::unique_ptr< BM25 > | m_bm25 |
| std::vector< String > | m_bm25Corpus |
| std::unordered_map< String, std::vector< Data > > | m_datasetMap |
| std::unordered_map< String, std::vector< std::size_t > > | m_datasetIDMap |
| std::map< String, int > | m_assetCounter |
| StringArray | m_samplePaths |
| StringArray | m_sampleFilenames |
| bool | m_shouldSave = true |
| SentenceTransformer | m_sentenceTransformer |
| SharedResourcePointer< UniversalCategorySystem > | m_UCS |
| CriticalSection | m_cs |
| bool | m_ttaAvailable {true} |
| std::vector< std::pair< String, std::vector< float > > > | m_queryEmbeddings |
| std::unordered_map< String, std::vector< Layer > > | m_layersMap |
| String | m_claudeApiKeyEncrypted |
| ListenerList< Listener > | m_listeners |
| AsyncListenerUpdater< Listener > | m_statusUpdater |
| AsyncListenerUpdater< Listener > | m_progressUpdater |
| bool | m_strictMode {false} |
take a user text query and return 4 assets that can be loaded as an ambience preset
| krotos::TextToAssets::TextToAssets | ( | ) |
Constructor.
| krotos::TextToAssets::~TextToAssets | ( | ) |
Destructor.
|
private |
add a non-zero bias to layers that match certain keywords
| void krotos::TextToAssets::addListener | ( | Listener * | listener | ) |
Registers a listener for callbacks when the TTA status changes.
|
private |
send query to an LLM using the anthropic API
| query | the user query |
| bool krotos::TextToAssets::appendDataToEmbeddingsFile | ( | ) |
appends data to the main embeddings file
|
private |
returns the indices that would sort the vector.
|
protectedvirtual |
create text embeddings file for the given file
|
private |
return similarity scores for layers based on the LLM generated layer names
|
private |
calculate the reciprocal rank fusion for scores1 and scores2
|
private |
make first letter of string upper case and the rest lower case
| text | The text to process |
|
private |
clears internal data
|
private |
returns true if the text contains any keyword in keywords.
|
virtual |
creates the path for the embeddings file
|
private |
return dot product between a and b
|
private |
uses the contents of exclude list to set some preset layers as invalid if certain keywords are detected.
|
private |
find a relevant asset for a given preset layer
| layer | The preset layer |
|
private |
search for closest match to query
| query | The user query as a string |
| queryEmbedding | The user query sbert embedding |
|
private |
find a relevant preset layer
| queryEmbedding | The user query sbert embedding |
| presetEmbedding | The cumulative sbert embedding for selected preset layers |
| layers | The available preset layers |
| layerScoresLLM | The scores each layer received from matching against the generated LLM layer names |
| std::tuple< String, std::array< TTPAsset, 4 > > krotos::TextToAssets::findPresetFiles | ( | String | searchTerm | ) |
find 4 assets suitable for the given query
| searchTerm | The user query |
|
static |
xml for automated preset generation
|
private |
returns a StringArray of preset layer names generated by an LLM
|
private |
return vector scores between query embedding and dataset embeddings
|
inline |
Returns the status of the file processing.
|
inlineprotectedvirtual |
Returns whether there is a model file available for use, in order to generate embeddings.
|
inline |
Returns if "Strict Mode" is enabled (default: disabled).
Strict mode disables bias in layer selection, potentially reducing output likelihood. When disabled (default), T2P uses bias towards expected keywords in base content. When enabled, it uses original generation settings without keyword bias.
| bool krotos::TextToAssets::isUCSValid | ( | String | catID | ) |
check UCS CatID is valid
|
private |
will load embeddings data from file to all modules that need it
|
private |
load preset layers from json stored as binary data
|
private |
load quer embeddings from json stored as binary data
|
private |
set layer.isValid to false for layers containing tag.
|
private |
check if UCS catID matches one of our target tags
|
private |
L2 normalise the input vector.
|
private |
Update TTA availability status and notify listeners. TTA should not available whilst file processing is taking place.
| isAvailable | True if TTA is available |
|
private |
Notifies listeners of the progress of the current file processing operation.
| processedFiles | The number of files that have been processed so far |
| totalFiles | The total number of files to be processed in the job |
| estimatedTimeRemaining | The estimated time until file processing completion, in a human readable string format, using RelativeTime::getDescription |
|
private |
parse Anthropic API response and return results in a StringArray
|
private |
return preprocessed query and exclude tags
| bool krotos::TextToAssets::processFileList | ( | Array< File > & | filesToProcess | ) |
processes a file list to create text embeddings
| file | list to process |
| std::vector< float > krotos::TextToAssets::rankify | ( | const std::vector< float > & | x | ) | const |
output the rank of each vector element
| x | The vector of elements to find ranks for |
|
private |
load embeddings from file
| void krotos::TextToAssets::removeListener | ( | Listener * | listener | ) |
Deregisters a listener.
|
overrideprivate |
run thread
|
private |
removes digits and underscores from a string
| text | The text to process |
|
static |
this will add a sample that comes from ttp to the corresponding core egine but it also update the xypad labels with the assets proposed,
| root | the preset root value tree, |
| tag | the tag uder which the property exists, |
| the | ptoperty to update |
| newSample | the sample from ttp |
| target | the target to update ( core engie or xy pad in this case) |
|
inline |
Set the encrypted API key string for the Claude API.
| key | The encrypted API key, represented as a 256-character hexadecimal string with the IV prepended as the first 32 characters and the remaining 224 characters as the ciphertext. |
|
inline |
Sets whether "Strict Mode" is enabled or disabled (default: disabled).
Strict mode disables bias in layer selection, potentially reducing output likelihood. When disabled (default), T2P uses bias towards expected keywords in base content. When enabled, it uses original generation settings without keyword bias.
|
private |
return topk elements
|
static |
update a CoreEngine PARAM value
|
static |
This function searches for a specific TABLABEL by index within the CUSTOMDATA node and updates its text.
| root | The preset root value tree. |
| index | The index of the TABLABEL to update. |
| label | The new label text for the TABLABEL. |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
protected |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
protected |
|
private |
|
private |