lordrip commented on code in PR #19261: URL: https://github.com/apache/camel/pull/19261#discussion_r2362533001
########## components/camel-ai/camel-docling/src/main/java/org/apache/camel/component/docling/DoclingEndpoint.java: ########## @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.docling; + +import org.apache.camel.Category; +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriPath; +import org.apache.camel.support.DefaultEndpoint; + +/** + * Process documents using Docling library for parsing and conversion. + */ +@UriEndpoint(firstVersion = "4.15.0", scheme = "docling", + title = "Docling", + syntax = "docling:operationId", Review Comment: Just out of curiosity, is the `:operationId` needed in the syntax? Or is it possible to have it as a regular parameter and still be mandatory? ########## components/camel-ai/camel-docling/src/main/java/org/apache/camel/component/docling/DoclingEndpoint.java: ########## @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.docling; + +import org.apache.camel.Category; +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriPath; +import org.apache.camel.support.DefaultEndpoint; + +/** + * Process documents using Docling library for parsing and conversion. + */ +@UriEndpoint(firstVersion = "4.15.0", scheme = "docling", + title = "Docling", + syntax = "docling:operationId", + category = { Category.AI }, headersClass = DoclingHeaders.class) Review Comment: Is this `AI` only? I thought it performed OCR without a model. ########## components/camel-ai/camel-docling/src/main/docs/docling-component.adoc: ########## @@ -0,0 +1,216 @@ += Docling Component +:doctitle: Docling +:shortname: docling +:artifactid: camel-docling +:description: Process documents using Docling library for parsing and conversion. +:since: 4.15 +:supportlevel: Preview +:tabs-sync-option: +:component-header: Both producer and consumer are supported +//Manually maintained attributes +:group: AI +:camel-spring-boot-name: docling + +*Since Camel {since}* + +*{component-header}* + +The Docling component allows you to convert and process documents using https://github.com/DS4SD/docling[IBM's Docling AI document parser]. +Docling is a powerful Python library that can parse and convert various document formats including PDF, Word documents, PowerPoint presentations, and more into structured formats like Markdown, HTML, JSON, or plain text. + +Maven users will need to add the following dependency to their `pom.xml` for this component: + +[source,xml] +---- +<dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-docling</artifactId> + <version>x.x.x</version> + <!-- use the same version as your Camel core version --> +</dependency> +---- + +== Prerequisites + +Before using this component, you need to have Docling installed on your system. You can install it using pip: + +[source,bash] +---- +pip install docling +---- + +== URI format + +---- +docling:operation[?options] +---- + +Where `operation` represents the document processing operation to perform. + +=== Supported Operations + +The component supports the following operations: + +[width="100%",cols="2,4",options="header"] +|=== +| Operation | Description + +| `CONVERT_TO_MARKDOWN` +| Convert document to Markdown format (default) + +| `CONVERT_TO_HTML` +| Convert document to HTML format + +| `CONVERT_TO_JSON` +| Convert document to JSON format with structure information + +| `EXTRACT_TEXT` +| Extract plain text content from document + +| `EXTRACT_STRUCTURED_DATA` +| Extract structured data including tables and layout information + +|=== + +// component-configure options: START + +// component-configure options: END + +// component options: START +include::partial$component-configure-options.adoc[] +include::partial$component-endpoint-options.adoc[] +// component options: END + +// endpoint options: START + +// endpoint options: END + +// component headers: START +include::partial$component-endpoint-headers.adoc[] +// component headers: END + +== Usage + +=== Input Types + +The component accepts the following input types in the message body: + +- `String` - File path or document content +- `byte[]` - Binary document content +- `File` - File object +- `InputStream` - Input stream containing document data + +=== Output Behavior + +The component behavior depends on the `contentInBody` configuration option: + +- When `contentInBody=true` (default: false): The converted content is placed in the exchange body and the output file is automatically deleted +- When `contentInBody=false`: The file path to the generated output file is returned in the exchange body + +== Examples + +=== Basic document conversion to Markdown + +[source,java] +---- +from("file:///data/documents?include=.*\\.pdf") + .to("docling:CONVERT_TO_MARKDOWN") + .to("file:///data/output"); +---- + +=== Convert to HTML with content in body + +[source,java] +---- +from("file:///data/documents?include=.*\\.pdf") + .to("docling:CONVERT_TO_HTML?contentInBody=true") + .process(exchange -> { + String htmlContent = exchange.getIn().getBody(String.class); + // Process the HTML content + }); +---- + +=== Extract structured data from documents + +[source,java] +---- +from("file:///data/documents?include=.*\\.pdf") + .to("docling:EXTRACT_STRUCTURED_DATA?outputFormat=json&contentInBody=true") + .process(exchange -> { + String jsonData = exchange.getIn().getBody(String.class); + // Process the structured JSON data + }); +---- + +=== Convert with OCR disabled + +[source,java] +---- +from("file:///data/documents?include=.*\\.pdf") + .to("docling:CONVERT_TO_MARKDOWN?enableOCR=false") + .to("file:///data/output"); +---- + +=== Using headers to control processing + +[source,java] +---- +from("file:///data/documents?include=.*\\.pdf") + .setHeader("CamelDoclingOperation", constant(DoclingOperations.CONVERT_TO_HTML)) + .setHeader("CamelDoclingEnableOCR", constant(true)) + .setHeader("CamelDoclingOCRLanguage", constant("es")) + .to("docling:CONVERT_TO_MARKDOWN") // Operation will be overridden by header + .to("file:///data/output"); +---- + +=== Processing with custom arguments + +[source,java] +---- +from("file:///data/documents?include=.*\\.pdf") + .process(exchange -> { + List<String> customArgs = Arrays.asList("--verbose", "--preserve-tables"); + exchange.getIn().setHeader("CamelDoclingCustomArguments", customArgs); + }) + .to("docling:CONVERT_TO_MARKDOWN") + .to("file:///data/output"); +---- + +=== Content in body vs file path output + +[source,java] +---- +// Get content directly in body (file is automatically deleted) +from("file:///data/documents?include=.*\\.pdf") + .to("docling:CONVERT_TO_MARKDOWN?contentInBody=true") + .process(exchange -> { + String markdownContent = exchange.getIn().getBody(String.class); + log.info("Converted content: {}", markdownContent); + }); + +// Get file path (file is preserved) +from("file:///data/documents?include=.*\\.pdf") + .to("docling:CONVERT_TO_MARKDOWN?contentInBody=false") + .process(exchange -> { + String outputFilePath = exchange.getIn().getBody(String.class); + log.info("Output file saved at: {}", outputFilePath); + }); +---- Review Comment: Would it be possible to add some examples in `YAML` as well? <img width="300" alt="Pretty please" src="https://github.com/user-attachments/assets/99bb0b55-44cf-40a4-9d84-24a2fb520e05" /> ########## components/camel-ai/camel-docling/src/main/java/org/apache/camel/component/docling/DoclingComponent.java: ########## @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.docling; + +import java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.Endpoint; +import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.annotations.Component; +import org.apache.camel.support.DefaultComponent; + +/** + * Component for integrating with Docling document processing library. + */ +@Component("docling") +public class DoclingComponent extends DefaultComponent { + + @Metadata + DoclingConfiguration configuration; + + public DoclingComponent() { + this(null); + } + + public DoclingComponent(CamelContext context) { + super(context); + this.configuration = new DoclingConfiguration(); + } + + @Override + protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { + DoclingConfiguration config = this.configuration.copy(); + DoclingEndpoint endpoint = new DoclingEndpoint(uri, this, remaining, config); + setProperties(endpoint, parameters); + return endpoint; + } + + public DoclingConfiguration getConfiguration() { + return configuration; + } + + /** + * The configuration; Review Comment: It looks like this description is getting into the generated JSON. Is there an expanded version of this property and what it does? Also, this will be generated as a generic `key:value` pair in a graphical tool: ```json "configuration": { "index": 0, "kind": "property", "displayName": "Configuration", "group": "common", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.docling.DoclingConfiguration", "deprecated": false, "autowired": false, "secret": false, "description": "The configuration;" }, ``` If we have a better definition, it certainly will help with the configuration. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
