Class: LLMUtilityAI
Defined in: packages/agentos/src/cognition/nlp/ai_utilities/LLMUtilityAI.ts:105
Interface
IUtilityAI Defines the contract for a comprehensive Utility AI service.
Implements
Constructors
Constructor
new LLMUtilityAI(
utilityId?):LLMUtilityAI
Defined in: packages/agentos/src/cognition/nlp/ai_utilities/LLMUtilityAI.ts:111
Parameters
utilityId?
string
Returns
LLMUtilityAI
Properties
utilityId
readonlyutilityId:string
Defined in: packages/agentos/src/cognition/nlp/ai_utilities/LLMUtilityAI.ts:106
Implementation of
Methods
analyzeSentiment()
analyzeSentiment(
text,options?):Promise<SentimentResult>
Defined in: packages/agentos/src/cognition/nlp/ai_utilities/LLMUtilityAI.ts:479
Parameters
text
string
options?
Returns
Promise<SentimentResult>
Implementation of
calculateReadability()
calculateReadability(
text,options):Promise<ReadabilityResult>
Defined in: packages/agentos/src/cognition/nlp/ai_utilities/LLMUtilityAI.ts:665
Parameters
text
string
options
Returns
Promise<ReadabilityResult>
Implementation of
IUtilityAI.calculateReadability
calculateSimilarity()
calculateSimilarity(
text1,text2,options?):Promise<number>
Defined in: packages/agentos/src/cognition/nlp/ai_utilities/LLMUtilityAI.ts:594
Parameters
text1
string
text2
string
options?
Returns
Promise<number>
Implementation of
IUtilityAI.calculateSimilarity
checkHealth()
checkHealth():
Promise<{dependencies?:object[];details?:any;isHealthy:boolean; }>
Defined in: packages/agentos/src/cognition/nlp/ai_utilities/LLMUtilityAI.ts:791
Returns
Promise<{ dependencies?: object[]; details?: any; isHealthy: boolean; }>
Implementation of
classifyText()
classifyText(
textToClassify,options):Promise<ClassificationResult>
Defined in: packages/agentos/src/cognition/nlp/ai_utilities/LLMUtilityAI.ts:399
Parameters
textToClassify
string
options
Returns
Promise<ClassificationResult>
Implementation of
detectLanguage()
detectLanguage(
text,options?):Promise<LanguageDetectionResult[]>
Defined in: packages/agentos/src/cognition/nlp/ai_utilities/LLMUtilityAI.ts:526
Parameters
text
string
options?
Returns
Promise<LanguageDetectionResult[]>
Implementation of
extractKeywords()
extractKeywords(
textToAnalyze,options?):Promise<string[]>
Defined in: packages/agentos/src/cognition/nlp/ai_utilities/LLMUtilityAI.ts:455
Parameters
textToAnalyze
string
options?
Returns
Promise<string[]>
Implementation of
generateNGrams()
generateNGrams(
tokens,options):Promise<Record<number,string[][]>>
Defined in: packages/agentos/src/cognition/nlp/ai_utilities/LLMUtilityAI.ts:645
Parameters
tokens
string[]
options
Returns
Promise<Record<number, string[][]>>
Implementation of
initialize()
initialize(
config):Promise<void>
Defined in: packages/agentos/src/cognition/nlp/ai_utilities/LLMUtilityAI.ts:115
Parameters
config
Returns
Promise<void>
Implementation of
loadTrainedModel()
loadTrainedModel():
Promise<{message?:string;success:boolean; }>
Defined in: packages/agentos/src/cognition/nlp/ai_utilities/LLMUtilityAI.ts:819
Returns
Promise<{ message?: string; success: boolean; }>
Implementation of
normalizeText()
normalizeText(
text,options?):Promise<string>
Defined in: packages/agentos/src/cognition/nlp/ai_utilities/LLMUtilityAI.ts:621
Parameters
text
string
options?
Returns
Promise<string>
Implementation of
parseJsonSafe()
parseJsonSafe<
T>(jsonString,options?):Promise<T|null>
Defined in: packages/agentos/src/cognition/nlp/ai_utilities/LLMUtilityAI.ts:321
The JSON the text holds, read as StatisticalUtilityAI reads it (parseReplyJson: the text as it is, else inside
the first Markdown code fence it holds, backticks inside a sentence opening none, with a language tag or none and
with words before or after it, up to the first later line that starts with as many backticks as opened the fence or
more), then a check against targetSchema with Ajv when given, as StatisticalUtilityAI checks it: the standard
formats checked, a keyword or a format Ajv does not know passed over, and a value coerced to the type its schema
names where it can (targetSchemaChecks). With attemptFixWithLLM, a text that fails either is sent for repair,
up to maxRepairAttempts times (1 unless it is a whole number of 1 or more), each repair on the text the last one
answered, whose answer is read the same way, on llmModelIdForFix (else jsonFixerModelId, else defaultModelId)
and llmProviderIdForFix (else defaultProviderId). A repair request names targetSchema when given, and the
schema's errors when the text parsed and failed it. Answers null when no repair parses and passes the schema, or
a repair call fails. No text can pass a targetSchema that Ajv cannot compile, that takes the draft-07
meta-schema's $id or that is marked $async: the call answers null at once, with a warning, and asks for no
repair.
Type Parameters
T
T = any
Parameters
jsonString
string
options?
Returns
Promise<T | null>
Implementation of
saveTrainedModel()
saveTrainedModel():
Promise<{message?:string;pathOrStoreId?:string;success:boolean; }>
Defined in: packages/agentos/src/cognition/nlp/ai_utilities/LLMUtilityAI.ts:816
Returns
Promise<{ message?: string; pathOrStoreId?: string; success: boolean; }>
Implementation of
shutdown()
shutdown():
Promise<void>
Defined in: packages/agentos/src/cognition/nlp/ai_utilities/LLMUtilityAI.ts:823
Returns
Promise<void>
Implementation of
stemTokens()
stemTokens(
tokens,_options?):Promise<string[]>
Defined in: packages/agentos/src/cognition/nlp/ai_utilities/LLMUtilityAI.ts:588
Parameters
tokens
string[]
_options?
Returns
Promise<string[]>
Implementation of
summarize()
summarize(
textToSummarize,options?):Promise<string>
Defined in: packages/agentos/src/cognition/nlp/ai_utilities/LLMUtilityAI.ts:267
Parameters
textToSummarize
string
options?
Returns
Promise<string>
Implementation of
summarizeConversationHistory()
summarizeConversationHistory(
messages,targetTokenCount,modelInfo,preserveImportantMessages?):Promise<{finalTokenCount:number;messagesSummarized:number;originalTokenCount:number;summaryMessages:ConversationMessage[]; }>
Defined in: packages/agentos/src/cognition/nlp/ai_utilities/LLMUtilityAI.ts:717
Summarizes conversation history to fit within token constraints, attempting to preserve key information.
Parameters
messages
readonly ConversationMessage[]
The array of conversation messages to summarize.
targetTokenCount
number
The desired maximum token count for the summary.
modelInfo
Readonly<ModelTargetInfo>
Information about the model for which the summary is being prepared.
preserveImportantMessages?
boolean
If true, attempt to identify and keep important messages verbatim.
Returns
Promise<{ finalTokenCount: number; messagesSummarized: number; originalTokenCount: number; summaryMessages: ConversationMessage[]; }>
A summary (which might be a single system message or a condensed list of messages), and metadata about the summarization.
Implementation of
IPromptEngineUtilityAI.summarizeConversationHistory
summarizeRAGContext()
summarizeRAGContext(
context,targetTokenCount,modelInfo,preserveSourceAttribution?):Promise<{finalTokenCount:number;originalTokenCount:number;preservedSources?:string[];summary:string; }>
Defined in: packages/agentos/src/cognition/nlp/ai_utilities/LLMUtilityAI.ts:762
Summarizes retrieved RAG context to fit token limits, ideally preserving source attribution if possible.
Parameters
context
The RAG context to summarize.
string | readonly object[]
targetTokenCount
number
The desired maximum token count for the summarized context.
modelInfo
Readonly<ModelTargetInfo>
Information about the model.
preserveSourceAttribution?
boolean
If true, attempt to retain source information in the summary.
Returns
Promise<{ finalTokenCount: number; originalTokenCount: number; preservedSources?: string[]; summary: string; }>
The summarized text and metadata.
Implementation of
IPromptEngineUtilityAI.summarizeRAGContext
tokenize()
tokenize(
text,options?):Promise<string[]>
Defined in: packages/agentos/src/cognition/nlp/ai_utilities/LLMUtilityAI.ts:559
Parameters
text
string
options?
Returns
Promise<string[]>
Implementation of
trainModel()
trainModel():
Promise<{message?:string;modelId?:string;success:boolean; }>
Defined in: packages/agentos/src/cognition/nlp/ai_utilities/LLMUtilityAI.ts:813
Returns
Promise<{ message?: string; modelId?: string; success: boolean; }>