Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
sabarna17
Contributor
1,901

 

Untitled video - Made with Clipchamp (1).gif

Unleash the Power of GenAI Document information Extraction by CAP Plugin: CAP-DOX 

Got inspired from both of these SAP Challenges:

May Developer Challenge - SAP AI Services by @noravonthenen  

February Developer Challenge - CAP Plugins by @thomas_jung 

Preface:

The way we see, the interfaces and events with CAP applications are getting changed. It causes a huge leap of developments accelerators and framework capabilities by the Plugin Framework.

Now with the power of GenAI the Custom schema of Document Information Extraction Service by SAP AI is also in boom. POCs and tryouts are everywhere. Why not me? I have been closely observing this one for a longer time and the mission from SAP-Discovery-Get Started with Document Information Extraction and Generative AI is an awesome thing to get started with.

Here I share the journey of creating a custom plugin with minimum efforts with some exploratory things. Tried out Joule in SAP Build Code. Designed the worst UI5 layout. Got inspiration from the blog- Reusable components for CAP with cds-plugin by @daniel_schlachter and created a Custom Plugin for AI-DOX(Unofficial). And the reason for this is simple:

time is here, and the is now

 

Fantasy Flow:

The Plugin concept in CAP is awesome, and the idea here is to mitigate "How CAP-based custom framework works". Here is a concept of a new custom CAP plugin - CAP-DOX

It merges and bridges the SAP AI DOX service integration with the CAP application. CAP-DOX can be included in your CAP Project via configurations. Here is the CAP-DOX Fantasy-Flow-Diagram:

1. Upload your PDF document

2. Extract PDF with DOX

3. Update your tables with the extractions

Fantasy-Flow-Diagram:

Fantasy-Flow-Diagram-ezgif.com-video-to-gif-converter.gif

Making you Impatient with a bit of ChatPDF

The robust adaptation of GenAI in organizations is necessary. The idea of identifying a small repetitive low IQ task and assigning it to AI has been part of our journey for quite a long.

It's a very straight use case, which all the Enterprises are already adopting in their system. Langchain based RAG framework can understand the chat query from the user and extract the relevant information from the documents and reconstruct it for the User. This idea can help all the Company Contract designers and Lawyers to understand complex and big documents and take quick action.

And do you know if you want to implement something in Python, how many lines do you need to write? 

- The answer is 25

 

import requests
url = 'https://api.chatpdf.com/v1'
chatpdf_key = 'sec_777Xibue1OqnClJ8OT7qI8y71hwWvbpX'
files = [('file', ('file', open('my_pdf.pdf', 'rb'), 'application/octet-stream'))]
response = requests.post(url +'/sources/add-file', headers={'x-api-key': chatpdf_key}, files=files)
src_id = response.json()['sourceId']

if response.status_code == 200:
    print('Source ID:', src_id)
else:
    print('Status: ', response.status_code, '\n Error: ', response.text)

while 1:
    print('Ask a Question: ')
    x = input()
    data = {'sourceId': src_id,'messages': [{'role': "user",'content': x}]}
    headers = {'x-api-key': chatpdf_key,"Content-Type": "application/json"}
    response = requests.post(url + '/chats/message', headers=headers, json=data)

    if response.status_code == 200:
        print('Result:', response.json()['content'])
        print('--------------------------\n')
    else:
        print('Status: ', response.status_code, '\n Error: ', response.text)

 

How do I opt for this ChatPDF API key?

Please follow the documentation here: ChatPDF-API-Documentation 

RAG - Simplified background of ChatPDF:

sabarna17_1-1709667470250.png

Step 1: Whatever the chat you inject into the framework, it converts into vector embeddings.

Step 2: Then algorithms like Nearest Neighbors can be used to search for similar contents.

Step 3: Use of Completion API of your LLM to reconstruct findings in meaningful texts.

These generic ideas can be complex enough and require a deep level of data management as well. 

Enough of ChatPDF, What can I do in SAP BTP?

Now it's time to mix these.

Things to check out before we go to Actual Steps

1. Get your service activated - 

  • Business Application Studio
  • SAP Business AI - DOX Service

2. Create SAP AI DOX service instance with just ✌️ steps.

  • Goto BTP Subaccount and click Booster
    sabarna17_0-1717220223625.png
  • Then click on Start
    sabarna17_1-1717220394763.png

3. Now goto your SAP AI Business Services - DOX UI.
 

Spoiler
Your URL will look like - 
https://69e91dd6trial.us10-trial.doc.cloud.sap/ui/index.html?clientId=default#/invoiceviewer

I used to forget the URL for DOX-UI a lot. Then I started to save it in bookmarks or search it from history.
There is an easy hack. Goto your default_key.json which was created earlier while activating the service from Boosters, Then navigate to tenantuiurl.
sabarna17_0-1717221646101.png

 

4. Create a schema DOX. Here I am using the same what I have created as a part of SAP AI Service challenge.

sabarna17_1-1717221677024.png

 

Spoiler

Use Trial to Extract Information from Custom Documents with Generative AI and Document Information Extraction

How to create and activate a custom schema for custom documents
How to define the fields that you want to extract from a custom document
How to upload a custom document to the Document Information Extraction UI
How to get extraction results using the schema you’ve created and LLMs

https://developers.sap.com/tutorials/cp-aibus-dox-ui-gen-ai.html

5. Now let's fire up the BAS from SAP BTP Trial and create a CAP application. You can also use SAP Build Code here for your development. But, I shall keep it as a bit of Old School way.

 

Let's Roll

to set your application up. 

sabarna17_0-1717345862236.png

1. Create a CAP project cap_plugin_genai_dox_demo.

2. Update db>schema.cds file-

 

namespace genai_dox_recipe;

using { managed, cuid } from '@sap/cds/common';

entity Recipe : cuid, managed {
  @mandatory
  recipe_name  : String;
  @readonly
  portions: String;

  @mandatory
  pdf : Binary @Core.MediaType : 'pdf' @Core.ContentDisposition.Filename : fileName;
  fileName : String(80) default 'recipe.pdf';

  ingredients: Composition of many RecipeIngredients on ingredients.recipe.ID = $self.ID;

}

entity RecipeIngredients : cuid,managed {
  recipe  : Association to Recipe;
  @mandatory
  ingredients  : String;
  @readonly
  portions: String;

}

 

3. Update srv>service.cds file - 

 

using { genai_dox_recipe as my } from '../db/schema';

@path : '/service/genai_dox_recipe'
service genai_dox_recipe_srv 
{
    @odata.draft.enabled
    entity Recipe as projection on my.Recipe;
    @odata.draft.enabled
    entity RecipeIngredients as projection on my.RecipeIngredients;
}

 

4. In this section, we are going to configure a UI5 app.

* I have deleted the app folder and started fresh.

Goto View > Command Palette and then select Fiori: Open Application Generator and

- Choose the template List Report Page.

- In Data Source and Service Selection choose Data Source as Use a Local CAP Project

- Choose the application Data Source as below and click Next

sabarna17_1-1717347325728.png

- Then Choose the entity

sabarna17_2-1717347650702.png

- Project Attribute

Module Name: cap_plugin_genai_dox_demo

Title: CAP DOX Plugin Demo - GenAI based Extraction

sabarna17_3-1717347839801.png

-Fiori Launchpad Configurations 

Semantic Object: SO_FIORI

Action: RECIPE_LIBRARY

Title: Recipe Library

Subtitle: SAP BTP AI Service - DOX - GenAI

sabarna17_4-1717348164308.png

5. Click on Preview Application

sabarna17_0-1717348524749.png

You might get this error as me. Install the dependencies as suggested by the tool and proceed forward.

sabarna17_0-1717442389819.png

 

Creating no-code UI5 & Joule tryouts are in Part 2

 

Labels in this area