tests:each image to Markdown

This commit is contained in:
lovebird 2025-04-24 16:28:41 +02:00
parent 55c5c9c4a5
commit 6da561b780
97 changed files with 278 additions and 5 deletions

View File

@ -741,6 +741,29 @@
"!**/node_modules/**"
],
"outputCapture": "std"
},
{
"type": "node",
"request": "launch",
"name": "each:image",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/dist-in/main.js",
"args": [
"--router2=openai",
"--model=meta-llama/llama-3.2-90b-vision-instruct",
"--prompt=./tests/pdf/prompt_manual.md",
"--each=./tests/pdf/780/*.jpg", // Note: Glob pattern passed directly
"--mode=completion",
"--preferences=none",
"--dst=./tests/pdf/sako_manual.md",
"--filters=code",
"--append=concat"
],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"outputCapture": "std"
}
]
}

View File

@ -1,6 +1,7 @@
import { ChatCompletionToolRunnerParams } from 'openai/lib/ChatCompletionRunner';
import { ChatCompletionMessageParam } from 'openai/resources/index.mjs';
import { IKBotTask } from '@polymech/ai-tools';
export declare const default_sort: (files: string[]) => string[];
type ProcessRunResult = string | boolean | Record<string, unknown> | null;
/**
* Complete options by setting up defaults, validating inputs, and initializing required components

File diff suppressed because one or more lines are too long

28
packages/kbot/dist-in/utils/merge.d.ts vendored Normal file
View File

@ -0,0 +1,28 @@
/**
* Appends new content to existing content.
*
* @param existingContent - The original content string.
* @param newContent - The content string to append.
* @returns The combined string with new content appended.
*/
export declare function concat(existingContent: string, newContent: string): string;
/**
* Merges new content into existing content.
* For now, this simply concatenates with a newline separator.
* TODO: Implement more sophisticated merging logic if needed (e.g., JSON merge).
*
* @param existingContent - The original content string.
* @param newContent - The content string to merge/append.
* @returns The combined string.
*/
export declare function merge(existingContent: string, newContent: string): string;
/**
* Writes content to a destination file, handling append/merge logic if the file exists.
*
* @param dstPath - The absolute path to the destination file.
* @param content - The content to write.
* @param appendMode - Optional mode ('concat' or 'merge') to handle existing files.
* @param logger - Optional logger instance conforming to SimpleLogger.
* @returns The final content written to the file or the original content if read fails.
*/
export declare function writeOrAppend(dstPath: string, content: string, appendMode?: 'concat' | 'merge'): string;

View File

@ -0,0 +1,54 @@
import { sync as exists } from '@polymech/fs/exists';
import { sync as read } from '@polymech/fs/read';
import { sync as write } from '@polymech/fs/write';
/**
* Appends new content to existing content.
*
* @param existingContent - The original content string.
* @param newContent - The content string to append.
* @returns The combined string with new content appended.
*/
export function concat(existingContent, newContent) {
return existingContent + '\n\n' + newContent + '\n';
}
/**
* Merges new content into existing content.
* For now, this simply concatenates with a newline separator.
* TODO: Implement more sophisticated merging logic if needed (e.g., JSON merge).
*
* @param existingContent - The original content string.
* @param newContent - The content string to merge/append.
* @returns The combined string.
*/
export function merge(existingContent, newContent) {
// Placeholder: Simple concatenation
// Potential future implementation: Detect JSON/YAML and perform structured merge
return existingContent + '\n' + newContent;
}
/**
* Writes content to a destination file, handling append/merge logic if the file exists.
*
* @param dstPath - The absolute path to the destination file.
* @param content - The content to write.
* @param appendMode - Optional mode ('concat' or 'merge') to handle existing files.
* @param logger - Optional logger instance conforming to SimpleLogger.
* @returns The final content written to the file or the original content if read fails.
*/
export function writeOrAppend(dstPath, content, appendMode) {
let finalContent = content;
if (exists(dstPath) && appendMode) {
const existingContentBuffer = read(dstPath); // Read returns Buffer | undefined
if (existingContentBuffer) { // Check if read was successful
const existingContent = existingContentBuffer.toString();
if (appendMode === 'concat') {
finalContent = concat(existingContent, content);
}
else if (appendMode === 'merge') {
finalContent = merge(existingContent, content); // Using placeholder merge for now
}
}
}
write(dstPath, finalContent);
return finalContent;
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVyZ2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbHMvbWVyZ2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLElBQUksSUFBSSxNQUFNLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQTtBQUNwRC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SxDQUFDO2dCQUNsQyxZQUFZLEdBQUcsS0FBSyxDQUFDLGVBQWUsRUFBRSxPQUFPLENBQUMsQ0FBQyxDQUFDLDBDQUEwQztZQUM1RixDQUFDO1FBQ0gsQ0FBQztJQUNILENBQUM7SUFDRCxLQUFLLENBQUMsT0FBTyxFQUFFLFlBQVksQ0FBQyxDQUFBO0lBQzVCLE9BQU8sWUFBWSxDQUFBO0FBQ3JCLENBQUMifQ==

View File

@ -28,6 +28,24 @@ import { runAssistant } from './run-assistant.js'
import { all } from '../models/index.js'
import { getLogger } from '../index.js'
export const default_sort = (files: string[]): string[] => {
const getSortableParts = (filename: string) => {
const baseName = path.parse(filename).name;
const match = baseName.match(/^(\d+)_?(.*)$/); // Match leading numbers
const numPart = match ? parseInt(match[1], 10) : NaN;
const textPart = match ? match[2] : baseName; // Extract text part
return { numPart, textPart };
}
return files.sort((a, b) => {
const { numPart: aNum, textPart: aText } = getSortableParts(a)
const { numPart: bNum, textPart: bText } = getSortableParts(b)
if (!isNaN(aNum) && !isNaN(bNum)) {
return aNum - bNum || aText.localeCompare(bText, undefined, { numeric: true, sensitivity: 'base' })
}
return aText.localeCompare(bText, undefined, { numeric: true, sensitivity: 'base' })
})
}
type ProcessRunResult = string | boolean | Record<string, unknown> | null;
@ -293,8 +311,10 @@ export const run = async (opts: IKBotTask): Promise<ProcessRunResult[]> => {
} else if (exists(opts.each) && isFile(opts.each) && path.parse(opts.each).ext === '.json') {
items = read(opts.each, 'json') as [] || []
} else if (hasMagic(opts.each)) {
const info = pathInfoEx(forward_slash(path.resolve(resolve(opts.each))))
items = info.FILES
const info = pathInfoEx(forward_slash(path.resolve(resolve(opts.each))),false,{
absolute: true,
})
items = default_sort(info.FILES)
} else if (isFile(opts.each) && exists(opts.each)) {
items = [opts.each]
} else if (isString(opts.each)) {

View File

@ -0,0 +1,59 @@
import { sync as exists } from '@polymech/fs/exists'
import { sync as read } from '@polymech/fs/read'
import { sync as write } from '@polymech/fs/write'
/**
* Appends new content to existing content.
*
* @param existingContent - The original content string.
* @param newContent - The content string to append.
* @returns The combined string with new content appended.
*/
export function concat(existingContent: string, newContent: string): string {
return existingContent + '\n\n' + newContent + '\n'
}
/**
* Merges new content into existing content.
* For now, this simply concatenates with a newline separator.
* TODO: Implement more sophisticated merging logic if needed (e.g., JSON merge).
*
* @param existingContent - The original content string.
* @param newContent - The content string to merge/append.
* @returns The combined string.
*/
export function merge(existingContent: string, newContent: string): string {
// Placeholder: Simple concatenation
// Potential future implementation: Detect JSON/YAML and perform structured merge
return existingContent + '\n' + newContent;
}
/**
* Writes content to a destination file, handling append/merge logic if the file exists.
*
* @param dstPath - The absolute path to the destination file.
* @param content - The content to write.
* @param appendMode - Optional mode ('concat' or 'merge') to handle existing files.
* @param logger - Optional logger instance conforming to SimpleLogger.
* @returns The final content written to the file or the original content if read fails.
*/
export function writeOrAppend(
dstPath: string,
content: string,
appendMode?: 'concat' | 'merge'
): string {
let finalContent = content;
if (exists(dstPath) && appendMode) {
const existingContentBuffer = read(dstPath); // Read returns Buffer | undefined
if (existingContentBuffer) { // Check if read was successful
const existingContent = existingContentBuffer.toString();
if (appendMode === 'concat') {
finalContent = concat(existingContent, content);
} else if (appendMode === 'merge') {
finalContent = merge(existingContent, content); // Using placeholder merge for now
}
}
}
write(dstPath, finalContent)
return finalContent
}

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

View File

@ -0,0 +1,6 @@
kbot-d --router2=openai --model=google/gemini-2.5-pro-preview-03-25 \
--prompt=./tests/pdf/prompt.md \
--each=./tests/pdf/RS485-780/RS485-780-*.jpg \
--mode=completion --preferences=none \
--dst=./tests/pdf/sako.md \
--filters=code --append=concat

View File

@ -0,0 +1,6 @@
kbot-d --router2=openai --model=meta-llama/llama-3.2-90b-vision-instruct \
--prompt=./tests/pdf/prompt_manual.md \
--each=./tests/pdf/780/*.jpg \
--mode=completion --preferences=none \
--dst=./tests/pdf/sako_manual.md \
--filters=code --append=concat

View File

@ -0,0 +1,14 @@
Extract all Modbus read & write registers, as Markdown table. If none can be identified, abort and return message "No registers found" !!
## Columns
- type (read/write holding register/coil) as function code
- description
- address in Hex
- address in decimal
- if provided, parameter group
- Dont comment or explain, just return Markdown
- insert new lines before and after headers
- insert a descriptive chapter name, header level 3 with the page number

View File

@ -0,0 +1,28 @@
Extract all parameters, as Markdown tables, return "Skipping Number Page : Nothing found" if nothing has been found, otherwise use this layout and structure (only valid Markdown!!)
## Parameters
### Columns
- parameter
- description
- if provided, parameter group
- range
- default
- Dont comment or explain, just return Markdown
- insert new lines before and after headers
- insert a descriptive chapter name, header level 3 with the page number
## Error Codes
### Columns
- code
- description
- if provided, parameter group
- Dont comment or explain, just return Markdown
- insert new lines before and after headers
- insert a descriptive chapter name, header level 3 with the page number

View File

@ -0,0 +1,15 @@
No registers found
### Modbus Registers
| type | description | address (Hex) | address (dec) | parameter group |
| :--------------------- | :------------------------- | :------------ | :------------ | :-------------- |
| write holding register | P0-16 functional parameters | F010H | 61456 | P0 |
| write holding register | AC-08 functional parameters | AC08H | 44040 | AC |
No registers found
No registers found

View File