iterator tests
This commit is contained in:
parent
50d9c8d6da
commit
f99022bd6f
2
packages/kbot/dist-in/async-iterator.d.ts
vendored
2
packages/kbot/dist-in/async-iterator.d.ts
vendored
@ -50,5 +50,7 @@ export interface TransformWithOptionsInput {
|
||||
onTransformed?: OnTransformedCallback;
|
||||
kbotOptions?: Partial<IKBotTask>;
|
||||
}
|
||||
export declare const defaultOnTransform: OnTransformCallback;
|
||||
export declare const defaultOnTransformed: OnTransformedCallback;
|
||||
export declare function transformObjectWithOptions(obj: Record<string, any>, transform: AsyncTransformer, options: TransformWithOptionsInput): Promise<void>;
|
||||
export declare const defaultOptions: (options?: Partial<TransformOptions>) => TransformOptions;
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -35,6 +35,8 @@
|
||||
"test:web": "vitest run tests/unit/web.test.ts",
|
||||
"test:web:crwl": "vitest run tests/unit/web/crwl.test.ts",
|
||||
"test:files": "vitest run tests/unit/files.test.ts",
|
||||
"test:async-iterator": "vitest run tests/unit/core/async-iterator.test.ts",
|
||||
"test:iterator": "vitest run tests/unit/core/iterator.test.ts",
|
||||
"test:research": "vitest run tests/unit/research.test.ts",
|
||||
"test:core": "vitest run tests/unit/core",
|
||||
"test:core:watch": "vitest watch tests/unit/core",
|
||||
|
||||
@ -200,8 +200,8 @@ export interface TransformWithOptionsInput {
|
||||
}
|
||||
|
||||
// Default no-op implementations for the new callbacks
|
||||
const defaultOnTransform: OnTransformCallback = async (_, value) => value;
|
||||
const defaultOnTransformed: OnTransformedCallback = async (_, transformedValue) => transformedValue;
|
||||
export const defaultOnTransform: OnTransformCallback = async (_, value) => value;
|
||||
export const defaultOnTransformed: OnTransformedCallback = async (_, transformedValue) => transformedValue;
|
||||
|
||||
export async function transformObjectWithOptions(
|
||||
obj: Record<string, any>,
|
||||
|
||||
@ -4,54 +4,54 @@
|
||||
{
|
||||
"id": "f1",
|
||||
"name": "apple",
|
||||
"description": "A deliciously juicy fruit that bursts with natural sweetness and offers a satisfying crunch, making every bite a refreshing and energizing treat for your senses.",
|
||||
"description": "\"Plump, juicy, and irresistibly crunchy, this luscious fruit bursts with sweetness, its tender flesh and golden skin a perfect harmony of texture and taste.\"",
|
||||
"details": {
|
||||
"color": "red",
|
||||
"origin": "Worldwide",
|
||||
"nutrition": "Rich in fiber and vitamin C, which supports healthy digestion and promotes regular bowel movements. Vitamin C boosts the immune system, aids in collagen production, and helps protect cells from oxidative damage."
|
||||
"nutrition": "\"Rich in fiber and vitamin C, this food supports healthy digestion, boosts the immune system, and helps protect against cell damage and inflammation, promoting overall well-being and antioxidant defenses.\""
|
||||
},
|
||||
"marketingName": "Orchard Bliss"
|
||||
"marketingName": "Here are a few suggestions for a more appealing marketing name:\n\n1. **CoreDelight**: This name plays on the idea of the apple's core and sounds delightful and appealing.\n2. **Appleaura**: This name combines \"apple\" with \"aura,\" suggesting a vibrant and healthy glow.\n3. **Harvest Bite**: This name evokes the idea of biting into a fresh, juicy apple, with \"Harvest\" implying a natural and wholesome product.\n4. **Autumn Crunch**: This name captures the essence of the apple season, with \"Crunch\" emphasizing the satisfying texture of biting into a crisp apple.\n5. **Pomium**: This name comes from the Latin word for apple, \"pomum,\" giving it a sleek and modern sound.\n\nWhich one do you like best? Or do you have any specific preferences (e.g., play on words, alliteration, etc.)?"
|
||||
},
|
||||
{
|
||||
"id": "f2",
|
||||
"name": "banana",
|
||||
"description": "A vibrant, sun-kissed tropical fruit with a smooth golden skin, juicy flesh bursting with sweet, tangy flavor, and an irresistibly refreshing aroma that captures the essence of summer.",
|
||||
"description": "\"Vibrant and juicy, the sunshine-hued tropical fruit bursts with sweet flavor, its bright yellow skin inviting you to indulge in a taste of exotic paradise.\"",
|
||||
"details": {
|
||||
"color": "yellow",
|
||||
"origin": "Southeast Asia",
|
||||
"nutrition": "High in potassium, which helps regulate blood pressure, supports proper muscle and nerve function, and aids in maintaining fluid balance in the body, contributing to overall cardiovascular and muscular health."
|
||||
"nutrition": "\"High in potassium, supporting healthy blood pressure, promoting strong bone health, and aiding in muscle recovery, this food helps maintain overall cardiovascular and muscular well-being naturally.\""
|
||||
},
|
||||
"marketingName": "Golden Tropic Delight"
|
||||
"marketingName": "Here are some options:\n\n1. **Bananator**: A playful name that sounds fun and energetic.\n2. **YellowGenie**: This name evokes the idea of a magical genie that grants wishes, with a nod to the bright yellow color of a banana.\n3. **BananaBuzz**: This name creates a buzz around the product and suggests excitement and energy.\n4. **PeelPro**: A clever name that references the banana peel, with a professional twist.\n5. **SunnySpeak**: This name conveys a sense of happiness and warmth, with a nod to the sunny yellow color of a banana.\n\nWhich one do you like best? Or would you like me to come up with more options?"
|
||||
}
|
||||
],
|
||||
"vegetables": [
|
||||
{
|
||||
"id": "v1",
|
||||
"name": "carrot",
|
||||
"description": "A vibrant, nutrient-packed orange root vegetable with a crisp texture and sweet, earthy flavor, often enjoyed fresh, roasted, or blended into nourishing soups and juices.",
|
||||
"description": "\"Vibrant and succulent, the orange root vegetable boasts a sweet, earthy flavor and crunchy texture, its juicy sweetness bursting with every delightful bite of this nutritious treasure.\"",
|
||||
"details": {
|
||||
"color": "orange",
|
||||
"origin": "Eurasia",
|
||||
"nutrition": "Supports sharp vision by protecting eye cells from oxidative stress, reduces risk of age-related macular degeneration, and helps maintain retinal health for overall improved eye function and long-term visual clarity."
|
||||
"nutrition": "Supports eye health, helping to prevent age-related macular degeneration and reduce the risk of cataracts. Rich in antioxidants, it also protects against blue light damage and promotes healthy retina function."
|
||||
},
|
||||
"marketingName": "Golden Crunch"
|
||||
"marketingName": "Here are some options:\n\n1. **SunsetBoost**: evokes the idea of a healthy, vibrant orange color and a boost of energy.\n2. **Orange Bliss**: conveys a sense of happiness and satisfaction, associated with a tasty and nutritious snack.\n3. **BetaBoost**: highlights the scientific name for carrot, Beta vulgaris, and adds a modern, energetic twist.\n4. **Carrotium**: a playful, catchy name that sounds like a fun, healthy treat.\n5. **Harvest Delight**: suggests a connection to nature, harvest time, and the delight of enjoying a crunchy, tasty snack.\n\nWhich one do you like best? Or would you like me to come up with more options?"
|
||||
},
|
||||
{
|
||||
"id": "v2",
|
||||
"name": "broccoli",
|
||||
"description": "A vibrant green, nutrient-packed cruciferous vegetable known for its crisp texture and subtle peppery flavor, rich in vitamins, minerals, and powerful antioxidants promoting overall health.",
|
||||
"description": "\"A vibrant, emerald-green cruciferous superstar, bursting with nutrients and flavor, with tightly packed florets and a sturdy stem, adding a nutritious twist to any meal.\"",
|
||||
"details": {
|
||||
"color": "green",
|
||||
"origin": "Italy",
|
||||
"nutrition": "Rich in vitamins K and C, this supports strong immune function, promotes healthy blood clotting, and enhances collagen production for skin health. Together, they also help reduce inflammation and support bone strength."
|
||||
"nutrition": "\"High in vitamins K and C, supporting bone health, immune function, and antioxidant defenses. Vitamin K promotes blood clotting, while vitamin C boosts collagen production and protects against cell damage.\""
|
||||
},
|
||||
"marketingName": "Emerald Crown Veggie"
|
||||
"marketingName": "Here are some options:\n\n1. **BroccoBoost**: Suggests a boost of energy and nutrition from the broccoli.\n2. **GreenGenie**: Evokes the idea of a magical, healthy solution.\n3. **Broccoli Bliss**: Conveys a sense of happiness and well-being associated with consuming broccoli.\n4. **VeggieVitality**: Emphasizes the product's vitality and health benefits.\n5. **BroccoPower**: Positions broccoli as a powerful, nutritious food.\n\nWhich one do you like best? Or would you like me to come up with more options?"
|
||||
}
|
||||
]
|
||||
},
|
||||
"metadata": {
|
||||
"lastUpdated": "2023-04-15",
|
||||
"source": "Foods Database",
|
||||
"description": "A vibrant assortment of fresh, colorful fruits and crisp vegetables, featuring a diverse selection of popular, nutrient-rich produce perfect for healthy snacks, delicious recipes, and vibrant meals."
|
||||
"description": "\"Vibrant medley of everyday favorites, featuring a colorful assortment of juicy fruits and crisp vegetables, carefully curated to showcase nature's bounty in all its delicious and nutritious glory.\""
|
||||
}
|
||||
}
|
||||
@ -7,7 +7,7 @@
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "Intro Chapter",
|
||||
"value": "\"Chapter 1: Overview\"",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
@ -40,7 +40,7 @@
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "The document introduces topics related to AI and Markdown processing.",
|
||||
"value": "The document introduces topics on AI and Markdown processing.",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
@ -74,7 +74,7 @@
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "Background Overview",
|
||||
"value": "\"1.1: Background Overview\"",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 5,
|
||||
@ -107,7 +107,7 @@
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "Markdown has an interesting history that we will explore.",
|
||||
"value": "The history of Markdown is interesting and warrants background information.",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 7,
|
||||
@ -141,7 +141,7 @@
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "\"Early Days\"",
|
||||
"value": "\"1.1.1: Origins\"",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 9,
|
||||
@ -174,7 +174,7 @@
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "Early days are described in the details provided.",
|
||||
"value": "Early days are described in the following details.",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 11,
|
||||
@ -208,7 +208,7 @@
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "Methodology Overview",
|
||||
"value": "\"Chapter 2: Methods\"",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 13,
|
||||
@ -241,7 +241,7 @@
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "This chapter describes the employed methods.",
|
||||
"value": "This chapter describes the methods employed.",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 15,
|
||||
@ -275,7 +275,7 @@
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "\"Markdown Parsing\"",
|
||||
"value": "\"2.1: Markdown Parsing\"",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 17,
|
||||
@ -308,7 +308,7 @@
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "User preferences indicate a focus on concise and direct responses.",
|
||||
"value": "It appears the text you provided is incomplete. Please provide the full paragraph for summarization.",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 19,
|
||||
@ -340,7 +340,7 @@
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "The paragraph consists only of an empty conjunction and lacks meaningful content.",
|
||||
"value": "The text consists solely of the word \"and.\"",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 19,
|
||||
@ -372,7 +372,7 @@
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "To manage Markdown formatting.",
|
||||
"value": "To process Markdown.",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 19,
|
||||
@ -406,7 +406,7 @@
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "Content Transformation",
|
||||
"value": "\"Content Transformation\"",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 21,
|
||||
@ -439,7 +439,7 @@
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "The process entails navigating the AST and implementing LLM transformations.",
|
||||
"value": "The process entails navigating the AST to implement LLM transformations.",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 23,
|
||||
@ -473,7 +473,7 @@
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "Data Representation",
|
||||
"value": "\"Chapter 3: Data Formats\"",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 25,
|
||||
@ -506,7 +506,7 @@
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "The table includes three headers and various data cells, highlighting important content in one cell.",
|
||||
"value": "The table contains three rows of data across three headers.",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 27,
|
||||
@ -539,7 +539,7 @@
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "The table displays sample data with transformable cells.",
|
||||
"value": "The table displays sample data, with each cell available for transformation.",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 33,
|
||||
@ -573,7 +573,7 @@
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "Structured Output Analysis",
|
||||
"value": "\"Chapter 4: Structured Output Analysis\"",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 35,
|
||||
@ -606,7 +606,7 @@
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "The text mentions sunny weather, making it ideal for a park walk.",
|
||||
"value": "The section analyzes keywords and sentiment from positive weather-related text.",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 37,
|
||||
@ -633,7 +633,18 @@
|
||||
"offset": 1193
|
||||
}
|
||||
},
|
||||
"tempId": "analyze-me"
|
||||
"manualAnalysisResult": {
|
||||
"keywords": [
|
||||
"section",
|
||||
"analyzes",
|
||||
"keywords",
|
||||
"sentiment",
|
||||
"positive",
|
||||
"weather-related",
|
||||
"text"
|
||||
],
|
||||
"sentiment": "positive"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "heading",
|
||||
@ -641,7 +652,7 @@
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "Final Thoughts",
|
||||
"value": "\"Conclusion\"",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 39,
|
||||
@ -674,7 +685,7 @@
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "A summary of the key findings is presented in the concluding paragraph.",
|
||||
"value": "A summary of the main findings is presented in the concluding paragraph.",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 41,
|
||||
|
||||
@ -1,37 +1,37 @@
|
||||
# Intro Chapter
|
||||
# "Chapter 1: Overview"
|
||||
|
||||
The document introduces topics related to AI and Markdown processing.
|
||||
The document introduces topics on AI and Markdown processing.
|
||||
|
||||
## Background Overview
|
||||
## "1.1: Background Overview"
|
||||
|
||||
Markdown has an interesting history that we will explore.
|
||||
The history of Markdown is interesting and warrants background information.
|
||||
|
||||
### "Early Days"
|
||||
### "1.1.1: Origins"
|
||||
|
||||
Early days are described in the details provided.
|
||||
Early days are described in the following details.
|
||||
|
||||
# Methodology Overview
|
||||
# "Chapter 2: Methods"
|
||||
|
||||
This chapter describes the employed methods.
|
||||
This chapter describes the methods employed.
|
||||
|
||||
## "Markdown Parsing"
|
||||
## "2.1: Markdown Parsing"
|
||||
|
||||
User preferences indicate a focus on concise and direct responses.`unified`The paragraph consists only of an empty conjunction and lacks meaningful content.`remark-parse`To manage Markdown formatting.
|
||||
It appears the text you provided is incomplete. Please provide the full paragraph for summarization.`unified`The text consists solely of the word "and."`remark-parse`To process Markdown.
|
||||
|
||||
## Content Transformation
|
||||
## "Content Transformation"
|
||||
|
||||
The process entails navigating the AST and implementing LLM transformations.
|
||||
The process entails navigating the AST to implement LLM transformations.
|
||||
|
||||
# Data Representation
|
||||
# "Chapter 3: Data Formats"
|
||||
|
||||
The table includes three headers and various data cells, highlighting important content in one cell.
|
||||
The table contains three rows of data across three headers.
|
||||
|
||||
The table displays sample data with transformable cells.
|
||||
The table displays sample data, with each cell available for transformation.
|
||||
|
||||
# Structured Output Analysis
|
||||
# "Chapter 4: Structured Output Analysis"
|
||||
|
||||
The text mentions sunny weather, making it ideal for a park walk.
|
||||
The section analyzes keywords and sentiment from positive weather-related text.
|
||||
|
||||
# Final Thoughts
|
||||
# "Conclusion"
|
||||
|
||||
A summary of the key findings is presented in the concluding paragraph.
|
||||
A summary of the main findings is presented in the concluding paragraph.
|
||||
|
||||
@ -9,7 +9,9 @@ import {
|
||||
ErrorCallback,
|
||||
FilterCallback,
|
||||
INetworkOptions,
|
||||
DEFAULT_NETWORK_OPTIONS
|
||||
DEFAULT_NETWORK_OPTIONS,
|
||||
defaultOnTransform,
|
||||
defaultOnTransformed
|
||||
} from '../../../src/async-iterator'
|
||||
|
||||
// Helper function to manually transform paths in the test data based on mockFilterCallback and mockTransform
|
||||
@ -310,7 +312,9 @@ describe('async-iterator', () => {
|
||||
'$.items[*].name',
|
||||
networkOptions,
|
||||
mockErrorCallback,
|
||||
mockFilterCallback
|
||||
mockFilterCallback,
|
||||
defaultOnTransform,
|
||||
defaultOnTransformed
|
||||
)
|
||||
|
||||
// Should not throw errors and object should remain empty
|
||||
@ -326,7 +330,9 @@ describe('async-iterator', () => {
|
||||
'',
|
||||
networkOptions,
|
||||
mockErrorCallback,
|
||||
mockFilterCallback
|
||||
mockFilterCallback,
|
||||
defaultOnTransform,
|
||||
defaultOnTransformed
|
||||
)
|
||||
|
||||
// Should not transform anything with empty path
|
||||
@ -486,7 +492,9 @@ describe('async-iterator', () => {
|
||||
'$[*].[name,description]', // JSONPath expression targeting name and description in array items
|
||||
networkOptions,
|
||||
mockErrorCallback,
|
||||
filter
|
||||
filter,
|
||||
defaultOnTransform,
|
||||
defaultOnTransformed
|
||||
)
|
||||
|
||||
// Verify the actual function works as expected with arrays
|
||||
@ -513,7 +521,9 @@ describe('async-iterator', () => {
|
||||
path,
|
||||
networkOptions,
|
||||
mockErrorCallback,
|
||||
mockFilterCallback
|
||||
mockFilterCallback,
|
||||
defaultOnTransform,
|
||||
defaultOnTransformed
|
||||
)
|
||||
|
||||
expect(testObj.items[0].description).toBe('A FRUIT')
|
||||
@ -533,7 +543,9 @@ describe('async-iterator', () => {
|
||||
path,
|
||||
networkOptions,
|
||||
mockErrorCallback,
|
||||
mockFilterCallback
|
||||
mockFilterCallback,
|
||||
defaultOnTransform,
|
||||
defaultOnTransformed
|
||||
)
|
||||
|
||||
expect(testObj.items[0].description).toBe('A FRUIT')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user