diff --git a/docs/templates/document-classifier.md b/docs/templates/document-classifier.md index fe92ec98..b316ff6b 100644 --- a/docs/templates/document-classifier.md +++ b/docs/templates/document-classifier.md @@ -3,79 +3,176 @@ slug: "/templates/document-classifier" description: "Use this template to build an AI-enabled document classification workflow." --- -# Document Classification using LLM Tasks in Orkes Conductor +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; +import Install from '@site/src/components/install.mdx'; -The process of manual document classification is a daunting task for organizations that costs them time and resources and often results in human errors. Manual document classification is not just time-consuming; it's a drain on resources that could be better utilized elsewhere. The cost of human hours dedicated to sifting through documents, identifying types, and categorizing them accurately is a significant burden. Not to mention the inherent risk of human error, which can lead to misclassifications, data discrepancies, and subsequent operational challenges. +# Document Classification -With Orkes templates, you can execute the workflow, and the workflow classifies the document with the power of AI tasks in Orkes Conductor. Orkes Conductor revolutionizes this landscape by automating the document classification process. Imagine a seamless workflow where documents are intelligently identified as images and then categorized with precision into predefined classes like W2, Driver's License, Paystub, Employment Verification Letter, or Mortgage Application—all without the need for manual intervention. +Manual document classification is a daunting and resource-draining task for organizations. It is time-consuming and prone to human error, which can result in misclassifications, data discrepancies, and operational challenges. -This not only accelerates the classification process but also eliminates the associated costs of manual labor. Orkes Conductor becomes the digital workforce, tirelessly and accurately managing document classification tasks, freeing up human resources for more strategic and value-driven activities. +With this template, you can streamline document classification by automating the process with the power of AI tasks in Orkes Conductor. This workflow identifies text-based PDF documents and classifies them into predefined categories such as W2, driver’s license, paystub, employment verification letter, or mortgage application–all without manual intervention. -In document management, where time is money and accuracy is paramount, this template emerges as the cost-effective, efficient solution organizations have longed for. +This template serves as a digital workforce, efficiently handling document classification processes with accuracy and consistency. -## Conductor features used +## Conductor features used -- [Workflows](https://orkes.io/content/core-concepts) -- [Switch Task](https://orkes.io/content/reference-docs/operators/switch) -- [Inline Task](https://orkes.io/content/reference-docs/system-tasks/inline) -- [Terminate Task](https://orkes.io/content/reference-docs/operators/terminate) -- [LLM Get Document Task](https://orkes.io/content/reference-docs/ai-tasks/llm-get-document) -- [LLM Text Complete Task](https://orkes.io/content/reference-docs/ai-tasks/llm-text-complete) -- [AI Prompt Template](https://orkes.io/content/reference-docs/ai-tasks/prompt-template) +This template utilizes the following Conductor features: + +* [Switch task](https://orkes.io/content/reference-docs/operators/switch) +* [Inline task](https://orkes.io/content/reference-docs/system-tasks/inline) +* [Terminate task](https://orkes.io/content/reference-docs/operators/terminate) +* [LLM Get Document task](https://orkes.io/content/reference-docs/ai-tasks/llm-get-document) +* [LLM Text Complete task](https://orkes.io/content/reference-docs/ai-tasks/llm-text-complete) +* [AI Prompt Template](https://orkes.io/content/developer-guides/creating-and-managing-gen-ai-prompt-templates) ## How to use the template -When you click **Import** in the workflow template explorer, you will be navigated to the workflow definition page, where you can see the workflow name as **document_classifier**. This template is free for you to use as is, or you can modify it for your specific use case. +1. Import the template +2. Understand the workflow logic +3. Set up AL/LLM integration +4. Create AI prompt +5. Modify the workflow template +6. Run workflow + +### Import the template + +**To import the template:** -Let's look at what this workflow does and how to run it! +1. Go to **Template Explorer** from the left navigation menu on your Conductor cluster. +2. In **Document Classifier**, select **Import**. +3. Rename the workflow and task names. For example, rename the workflow as *document_classifier_your_name*. +4. Select **Save**. + +The workflow is now imported and ready for use.
-### Workflow Logic +### Understand the workflow logic -The input parameters to this workflow are: +This section explains the workflow logic and how to execute it. -- **document_url** - The URL of the document file, which is to be classified by the workflow. +**Workflow inputs:** +- **document_url**–The URL of the document file to be classified using the workflow. -Here is an example of the payload that goes in as inputs to this workflow. +**Workflow logic:** -```json -{ -"document_url": "https://example.pdf" -} -``` +* The workflow begins with a [Switch task](https://orkes.io/content/reference-docs/operators/switch) that evaluates whether the input URL is a PDF using ECMAScript. The Switch task has two switch cases based on the input file type. + * **PDF**–The switch case to execute if the input file is PDF. + * **defaultCase**–The switch case to execute if the input is not a PDF. +* If the input file is not a PDF, the workflow moves to an [Inline task](https://orkes.io/content/reference-docs/system-tasks/inline), which generates an error message about the unsupported file type. The workflow is then terminated using a [Terminate task](https://orkes.io/content/reference-docs/operators/terminate), which returns an error message about the unsupported file type. +* If the input file is a PDF, the workflow moves to an [LLM Get Document task](https://orkes.io/content/reference-docs/ai-tasks/llm-get-document), which retrieves the content of the PDF document. +* Next, the [LLM Text Complete task](https://orkes.io/content/reference-docs/ai-tasks/llm-text-complete) classifies the document as a W2, driver's license, paystub, employment verification letter, or mortgage application. This task determines the file type using a [prompt template](https://orkes.io/content/developer-guides/creating-and-managing-gen-ai-prompt-templates) in Conductor. +* The final task is an [Inline task](https://orkes.io/content/reference-docs/system-tasks/inline) that extracts and formats the classification result based on the previous LLM Text Complete task’s output. It also returns a message indicating the category to which the document type has been classified. + +### Set up AI/LLM integration + +The LLM Text Complete task in the workflow classifies the document with the help of an LLM. This can be done by adding your preferred LLM integration in Conductor. -- The first step in the workflow is a [switch task](https://orkes.io/content/reference-docs/operators/switch) that evaluates whether the input URL is a PDF or not using an ECMAScript. The switch task has 2 switch cases: one for PDF, and the other is the default path that gets executed if the input file type does not match the PDF file type. +**To add an AI/LLM integration:** +1. Go to **Integrations** from the left navigation menu on your Conductor cluster. +2. Select **+ New integration**. +3. In **AI/LLM** section, choose your preferred LLM provider and select **+ Add**. +:::note +The configuration parameters vary depending on the AI/LLM platform being integrated. Refer to the [LLM integration guides](https://orkes.io/content/category/integrations/ai-llm) for more information. +::: -- The “PDF” switch case gets executed if the input file is a PDF. The workflow then moves onto an [LLM Get Document task](https://orkes.io/content/reference-docs/ai-tasks/llm-get-document) that retrieves the content of the PDF document. -- If the input file type is not a PDF, the default branch **defaultCase** gets executed. - - In the default case, it is passed on to an [Inline task](https://orkes.io/content/reference-docs/system-tasks/inline) that generates an error message on the unsupported file type. - - It is then passed on to a [Terminate task](https://orkes.io/content/reference-docs/operators/terminate) that terminates the workflow, displaying the error message mentioning the unsupported file type. -- The switch task is followed by an [LLM Text Complete task](https://orkes.io/content/reference-docs/ai-tasks/llm-text-complete), an AI task in Orkes Conductor that classifies the document into W2, Drivers License, Paystub, Employment Verification Letter, or Mortgage Application. The LLM Text complete task determines the file type with the help of a [prompt template](https://orkes.io/content/reference-docs/ai-tasks/prompt-template) that is created within Orkes Conductor itself. -- It is then followed by an [Inline task](https://orkes.io/content/reference-docs/system-tasks/inline) that extracts and formats the classification result based on the LLM text complete task’s output. It also generates a message on what the document is classified as. +4. Enter the API keys and other parameters based on the chosen LLM provider. +5. Select **Save**. + +The LLM integration is added. The next step is to add a specific model. + +**To add a model to your integration:** + +1. In the **Integrations** page, select the + button next to your newly-added integration. +2. Select **+ New model**. +3. Enter the **Model name** and **Description**. +4. Ensure that the **Active** toggle is switched on and select **Save**. + +The integration is now ready to use. The next step is creating an AI prompt template that classifies the documents using this integration. + +### Create AI prompt + +**To create an AI prompt:** + +1. Go to **Definitions** > **AI Prompts** from the left navigation menu on your Conductor cluster. +2. Select **+ Add AI prompt**. +3. In **Prompt Name**, enter a unique name for your prompt, such as _doc_classifier_prompt_yourname_. +4. In **Model(s)**, select the integration you added in the previous step. The UI drop-down lists the integration along with the model names. Make sure to choose the right one. +5. Enter a **Description** of what the prompt does. + + + +6. In **Prompt Template**, enter your prompt, which will classify the document into appropriate categories. For example: + -Of course, this is just a starting point. The power of the Conductor model is that you can customize this workflow (and any other ones!) to your needs. You can add additional steps to custom-tailor this workflow to best suit your business requirements. The possibilities are endless, and you can quickly build this workflow to do exactly what you want and, without any effort, scale it up as much as you want! +_We have a document that was scanned using OCR. The content is ${text}. You need to classify the document based on the provided OCR content. The document could be one of these: W2, Drivers License, Pay stub, Employment Verification Letter, or Mortgage Application. Suppose the provided content does not match with any of those documents. In that case, you must reply NO_MATCH, and in the following line, you must give a human-understandable message about the result and why that determination was made in under three sentences. If the provided content matches, return the values found, including the document type. If the social security number is part of the values, obfuscate the first five digits._ -### Workflow Invocation +Here, we have defined _${text}_ as a variable derived from the previous tasks' output. This will become clearer once we incorporate this prompt into the workflow. -You can invoke the workflow in many different ways. +7. Select **Save** > **Confirm save**. -#### REST +This saves your prompt template. Let’s modify the imported workflow with the newly added integration and AI prompt. -As with any workflow in Conductor, you can invoke it by calling the REST endpoint of the Conductor server and specifying the workflow name, version, and input data. +### Modify the workflow template -You can use the following API to start a workflow execution: +Before using this template, make the following updates to the imported workflow: + +1. Go back to your workflow definition, and in the **classify_using_llm** task, replace the following parameters: + + + +- In **LLM provider**, replace *dl-test-3* with your integrated LLM provider. +- In **Model**, replace *gpt-3.5-turbo* with your integrated model. +- In **Prompt template**, replace *doc_classifier_prompt* with your prompt. +- Add the **promptVariable** text parameter as _${get_document_task_ref.output.result}_. This is the output of **get_document_task** that retrieves the content of the PDF document. + +2. Select **Save** > **Confirm**. + +### Run the workflow + +You can run the workflow in different ways. + +