Summarize Document Smart Rule

What is wrong with this Smart Rule?

I try to auto-summarize a text document if it starts with LM, LL or IIP, but not even the plain option seems working.

The prompt is the same as my default summarize promt in DT/DTTG. Could be interesting to have an Summarize option in the Smart Rule actions.

BTW, no log generated.

I see LM Studio processing the input and answering, but nothing happens at DT side.

It’s just a Chat - Query action, it’s not able to perform actions on its own. Its result can be used via the Query Response placeholder.

Christian, call me st*pid, but I cannot find it or the way to do it.

Did it thanks to integrated help AI and Gemini Pro.

I had to create an intermediate custom field, but now is working. I still need to add some filter conditions but it is done.

on performSmartRule(theRecords)
    tell application id "DNtp"
        repeat with theRecord in theRecords
            -- Retrieve custom metadata attached to the record
            set theMetaData to custom meta data of theRecord
            
            -- Prevent null reference exceptions if no metadata exists
            if theMetaData is not missing value then
                try
                    -- Read the property populated by the previous Smart Rule action
                    set theSummary to mdchatresponse of theMetaData
                    
                    -- Validate the summary text before creating a new record
                    if theSummary is not missing value and theSummary is not "" then
                        set originalName to name of theRecord as string
                        
                        -- Opcional: puedes quitar & ".md" si prefieres que no se vea la extensión en el título
                        set theName to originalName & " (Resumen).md"
                        
                        -- Extract the DEVONthink item link and format it as a Markdown hyperlink
                        set theRefURL to reference URL of theRecord
                        set markdownLink to return & return & "---" & return & "**Documento original:** [" & originalName & "](" & theRefURL & ")"
                        
                        -- Append the hyperlink to the LLM response
                        set finalContent to theSummary & markdownLink
                        
                        -- Instantiate the new markdown record using 'plain text' for raw Markdown source
                        create record with {name:theName, type:markdown, plain text:finalContent} in (parent 1 of theRecord)
                    end if
                on error
                    log message "Key 'mdchatresponse' not found in metadata for: " & (name of theRecord as string)
                end try
            else
                log message "No custom metadata found for: " & (name of theRecord as string)
            end if
        end repeat
    end tell
end performSmartRule

This is actually not necessary, just use the actions Set Script Input and Script with Input/Output instead of custom metadata and the Apply Script action. See for example the default Append Chat response to annotation batch processing configuration.

2 Likes