-
Notifications
You must be signed in to change notification settings - Fork 0
Demos 1171 UI path #541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dustbuster
wants to merge
12
commits into
main
Choose a base branch
from
DEMOS-1171-UI-path
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Demos 1171 UI path #541
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bc95044
Adds demo of connecting to UiPath Document Understanding
james-becwar-cms 8f55ff5
fix line endings
james-becwar-cms 9871564
Fix another line ending
james-becwar-cms 2539b62
fix .env example
james-becwar-cms f068906
Yet another
james-becwar-cms 1585fca
Merge branch 'main' into DEMOS-1169
dustbuster 9a03a6f
DEMOS-1171: added a file logger
dustbuster a57b25b
DEMOS-1171: some refactoring for sep of concerns
dustbuster 247425f
Merge branch 'main' into DEMOS-1171-UI-path
dustbuster 0c8096c
DEMOS-1171: Added some separation of concerns
dustbuster 145caf3
DEMOS-1171: added expontial back off to be cheaper
dustbuster cfc09ad
DEMOS-1171: pre-type scripting
dustbuster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| node_modules/ | ||
| .env | ||
| .venv/ | ||
| uipath.log | ||
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,29 @@ | ||
| import axios from "axios"; | ||
| import { | ||
| duPost, | ||
| UIPATH_BASE_URL, | ||
| getExtractorGuid, | ||
| getProjectId, | ||
| } from "./uipathClient.js"; | ||
|
|
||
| export async function extractDoc(token, docId) { | ||
| const extract = await axios.post( | ||
| `https://govcloud.uipath.us:443/${process.env.EXTRACTOR_GUID}/du_/api/framework/projects/${process.env.ZERO_PROJECT_ID}/extractors/generative_extractor/extraction/start?api-version=1.0`, | ||
| { | ||
| documentId: docId, | ||
| pageRange: null, | ||
| prompts: [ | ||
| { | ||
| id: "State", | ||
| question: "What state is this 1115 waver for?", | ||
| fieldType: "Text", | ||
| multiValued: false, | ||
| }, | ||
| ], | ||
| configuration: null, | ||
| }, | ||
| { | ||
| headers: { | ||
| Authorization: `Bearer ${token}`, | ||
| }, | ||
| } | ||
| ); | ||
| const extractorGuid = getExtractorGuid(); // NOTE: Zoe might make her own. So we may need to query here to get the right GUID | ||
| const projectId = getProjectId(); | ||
| const url = `${UIPATH_BASE_URL}:443/${extractorGuid}/du_/api/framework/projects/${projectId}/extractors/generative_extractor/extraction/start`; | ||
|
|
||
| const extract = await duPost(url, token, { | ||
| documentId: docId, | ||
| pageRange: null, | ||
| prompts: activeQuestionBlobs, | ||
| configuration: null, | ||
| }); | ||
| return extract.data.resultUrl; | ||
| } | ||
|
|
||
| const activeQuestionBlobs = [ | ||
| { | ||
| id: "State", | ||
| question: "What state is this 1115 waver for?", | ||
| fieldType: "Text", | ||
| multiValued: false, | ||
| }, | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import fs from "fs"; | ||
| import path from "path"; | ||
|
|
||
| const DEFAULT_LOG_PATH = "uipath.log"; | ||
|
|
||
| function ensureParentDir(logPath) { | ||
| const dir = path.dirname(logPath); | ||
| if (dir && dir !== ".") { | ||
| fs.mkdirSync(dir, { recursive: true }); | ||
| } | ||
| } | ||
|
|
||
| export function createLogFile(logPath = DEFAULT_LOG_PATH, { overwrite = false } = {}) { | ||
| ensureParentDir(logPath); | ||
| if (overwrite || !fs.existsSync(logPath)) { | ||
| fs.writeFileSync(logPath, ""); | ||
| } | ||
| return logPath; | ||
| } | ||
|
|
||
| export function appendToLog(message, logPath = DEFAULT_LOG_PATH) { | ||
| ensureParentDir(logPath); | ||
| const output = typeof message === "string" ? message : JSON.stringify(message); | ||
| fs.appendFileSync(logPath, output + "\n"); | ||
| } | ||
|
|
||
| export function log(message, logPath = DEFAULT_LOG_PATH) { | ||
| console.log(message); | ||
| appendToLog(message, logPath); | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import axios from "axios"; | ||
|
|
||
| export const UIPATH_BASE_URL = "https://govcloud.uipath.us"; | ||
| export const UIPATH_TENANT = "globalalliant/Dev"; | ||
| export const UIPATH_API_VERSION = "1.0"; | ||
|
|
||
| export function getProjectId() { | ||
| const projectId = process.env.ZERO_PROJECT_ID; | ||
| if (!projectId) { | ||
| throw new Error("Missing ZERO_PROJECT_ID in environment."); | ||
| } | ||
| return projectId; | ||
| } | ||
|
|
||
| // Basically the model it's using, may want different models for differnt files. | ||
| // May need to request to checj the differeent extractors. | ||
| export function getExtractorGuid() { | ||
| const extractorGuid = process.env.EXTRACTOR_GUID; | ||
| if (!extractorGuid) { | ||
| throw new Error("Missing EXTRACTOR_GUID in environment."); | ||
| } | ||
| return extractorGuid; | ||
| } | ||
|
|
||
| // duPost == Document Understanding POST | ||
| export function duPost(url, token, data, options = {}) { | ||
| const { params = {}, headers = {}, ...rest } = options; | ||
|
|
||
| return axios.post(url, data, { | ||
| headers: { | ||
| Authorization: `Bearer ${token}`, | ||
| ...headers, | ||
| }, | ||
| params: { | ||
| "api-version": UIPATH_API_VERSION, | ||
| ...params, | ||
| }, | ||
| ...rest, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,36 @@ | ||
| import axios from "axios"; | ||
| import fs from "fs"; | ||
| import FormData from "form-data"; | ||
| import { log } from "./logFile.js"; | ||
| import { duPost, UIPATH_BASE_URL, UIPATH_TENANT, getProjectId } from "./uipathClient.js"; | ||
|
|
||
| export async function uploadDocument(token, fileName) { | ||
| const projectId = getProjectId(); | ||
| const url = `${UIPATH_BASE_URL}/${UIPATH_TENANT}/du_/api/framework/projects/${projectId}/digitization/start`; | ||
|
|
||
| export async function uploadDocument(token,fileName) { | ||
| const formData = new FormData(); | ||
| formData.append( | ||
| "file", | ||
| fs.createReadStream(fileName), | ||
| fileName | ||
| ); | ||
|
|
||
| const doc = await axios.post( | ||
| `https://govcloud.uipath.us/globalalliant/Dev/du_/api/framework/projects/${process.env.ZERO_PROJECT_ID}/digitization/start?api-version=1.0`, | ||
| formData, | ||
| { | ||
| formData.append("file", fs.createReadStream(fileName), fileName); | ||
|
|
||
| try { | ||
| const doc = await duPost(url, token, formData, { | ||
| headers: { | ||
| "Content-Type": "multipart/form-data", // Important for file uploads | ||
| // form-data requires its own headers so axios can set boundaries | ||
| ...formData.getHeaders(), | ||
| "x-uipath-page-range": "All", | ||
| Authorization: `Bearer ${token}`, | ||
| }, | ||
| onUploadProgress: (progressEvent) => { | ||
| // Optional: Track upload progress | ||
| const percentCompleted = Math.round( | ||
| (progressEvent.loaded * 100) / progressEvent.total | ||
| ); | ||
| console.log(`Upload progress: ${percentCompleted}%`); | ||
| const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total); | ||
| log(`Upload progress: ${percentCompleted}%`); | ||
| }, | ||
| } | ||
| ); | ||
| }); | ||
|
|
||
| return doc.data.documentId; | ||
| return doc?.data?.documentId || doc?.data; | ||
| } catch (error) { | ||
| log(`Error uploading document: ${error.message}`); | ||
| if (error.response?.data) { | ||
| log(`Upload error response: ${JSON.stringify(error.response.data)}`); | ||
| } | ||
| throw error; | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think UIPath charges for the fetch of the status, so this might not be saving any money. It will also increase the average polling overhead from 500ms to between 2.5 seconds to 15 seconds.