Methods
assert(condition, message)
The function is an assertion helper that throws an error if a condition is not met.
Parameters:
Name | Type | Description |
---|---|---|
condition |
number | The condition is a boolean expression that is being tested for truthiness. If the condition is false, an error will be thrown. |
message |
Object | The message parameter is an optional parameter that can be passed to the assert function. It is a string or any other data type that represents the error message that will be thrown if the condition parameter is false. If no message is provided, a default error message will be thrown. |
(async) countTokens(text) → {Promise.<number>}
The function counts the number of tokens in a given text using a basic heuristic.
Parameters:
Name | Type | Description |
---|---|---|
text |
string | The input text for which we want to count the number of tokens. |
- Source:
Returns:
The function countTokens
returns the total count of tokens in the input text
.
- Type
- Promise.<number>
dotProduct(arr1, arr2) → {number}
Computes the dot product between two arrays
Parameters:
Name | Type | Description |
---|---|---|
arr1 |
Array.<number> | First array |
arr2 |
Array.<number> | Second array |
- Source:
Returns:
- Dot product
- Type
- number
generateUniqueKey() → {string}
The function generates a unique key using the uuidv4 library.
- Source:
Returns:
a unique key generated using the uuidv4 function.
- Type
- string
isBalanced(str) → {boolean}
The function checks if a string of brackets is balanced, meaning each opening bracket has a corresponding closing bracket in the correct order.
Parameters:
Name | Type | Description |
---|---|---|
str |
string | The input string that needs to be checked for balanced parentheses, brackets, and curly braces. |
- Source:
Returns:
a boolean value. It returns true
if the input string str
has balanced parentheses,
square brackets, and curly braces, and false
otherwise.
- Type
- boolean
openDatabase(storeNameopt)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
storeName |
string |
<optional> |
- Source:
(async) optimizeContext(history, maxTokens) → {Promise.<Array.<{role: string, content: string}>>}
This function optimizes a chat history by removing duplicate system messages and limiting the total number of tokens in the optimized history.
Parameters:
Name | Type | Description |
---|---|---|
history |
Array.<{role: string, content: string}> | The |
maxTokens |
number | The |
- Source:
Returns:
an array of message objects that have been optimized based on their content length and the maximum token limit.
- Type
- Promise.<Array.<{role: string, content: string}>>
retrieveKeysAndContext(storeName) → {Promise.<Array.<{key: string, context: object}>>}
Retrieves the saved text from IndexedDB using the key.
Parameters:
Name | Type | Description |
---|---|---|
storeName |
string | The name of the object store. |
- Source:
Returns:
The list of keys and corresponding context.
- Type
- Promise.<Array.<{key: string, context: object}>>
retrieveText(storeName, key) → {Promise.<{context: object, text: string}>}
Retrieves the saved text from IndexedDB using the key.
Parameters:
Name | Type | Description |
---|---|---|
storeName |
string | The name of the object store. |
key |
string | The key under which the text is saved. |
- Source:
Returns:
The saved context and text.
- Type
- Promise.<{context: object, text: string}>
saveTextToIndexedDB(storeName, context, text) → {Promise.<string>}
Saves the text for later summarization using IndexedDB.
Parameters:
Name | Type | Description |
---|---|---|
storeName |
string | The name of the object store. |
context |
object | The context associated with the text. |
text |
string | The text to be saved. |
- Source:
Returns:
The key under which the text is saved.
- Type
- Promise.<string>
Type Definitions
BaseTool
Abstract base class for tools.
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
constructor |
function | The constructor function of the base tool. |
id |
string | The unique identifier for the tool. |
desc |
string | The description of the tool. |
args |
Object.<string, string> | Dictionary of arguments for the tool. |
resp |
Object.<string, string> | Response format of the tool. |
prompt |
function | Returns the tool information as a JSON string. |
config |
function | Returns the configuration object for the tool. |
keyConfig
Type:
- object
Properties:
Name | Type | Description |
---|---|---|
google |
Object | |
openai |
Object |
keyConfig
Type:
- object
Properties:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
keys |
object |
Properties
|
- Source:
maxTokens
Type:
- Object
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
max_tokens |
number |
<optional> |
|
temperature |
number |
<optional> |
- Source: