Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test Code Samples
name: Smoke Test

on:
workflow_call:
Expand All @@ -9,12 +9,13 @@ env:
MINDEE_ACCOUNT_SE_TESTS: ${{ secrets.MINDEE_ACCOUNT_SE_TESTS }}
MINDEE_API_KEY_SE_TESTS: ${{ secrets.MINDEE_API_KEY_SE_TESTS }}
MINDEE_V2_API_KEY: ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }}
MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }}
MINDEE_V2_SE_TESTS_FAILURE_WEBHOOK_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FAILURE_WEBHOOK_ID }}
MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID }}
MINDEE_V2_SE_TESTS_CROP_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CROP_MODEL_ID }}
MINDEE_V2_SE_TESTS_OCR_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_OCR_MODEL_ID }}
MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID }}
MINDEE_V2_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }}
MINDEE_V2_SE_TESTS_BLANK_PDF_URL: ${{ secrets.MINDEE_V2_SE_TESTS_BLANK_PDF_URL }}
MINDEE_V2_CLASSIFICATION_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID }}
MINDEE_V2_CROP_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CROP_MODEL_ID }}
MINDEE_V2_FAILURE_WEBHOOK_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FAILURE_WEBHOOK_ID }}
MINDEE_V2_OCR_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_OCR_MODEL_ID }}
MINDEE_V2_SPLIT_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID }}

jobs:
test:
Expand Down Expand Up @@ -44,7 +45,7 @@ jobs:
env:
MINDEE_LOG_LEVEL: DEBUG
run: |
./spec/test_code_samples_v1.sh
./spec/test_code_samples_v1.sh ${{ secrets.MINDEE_ACCOUNT_SE_TESTS }} ${{ secrets.MINDEE_ENDPOINT_SE_TESTS }}

- name: Tests V2 code samples
env:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ on:
- cron: '0 0 * * *'

jobs:
test_code_samples:
uses: mindee/mindee-api-ruby/.github/workflows/_test-code-samples.yml@main
test-smoke:
uses: mindee/mindee-api-ruby/.github/workflows/_test-smoke.yml@main
secrets: inherit
8 changes: 4 additions & 4 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ on:
types: [ published ]

jobs:
publish_docs:
publish-docs:
uses: mindee/mindee-api-ruby/.github/workflows/_publish-docs.yml@main
secrets: inherit
publish_guide:
publish-guide:
uses: mindee/mindee-api-ruby/.github/workflows/_publish-guide.yml@main
needs: publish_docs
needs: publish-docs
secrets: inherit
publish_code:
publish-code:
uses: mindee/mindee-api-ruby/.github/workflows/_publish-code.yml@main
secrets: inherit
16 changes: 8 additions & 8 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ permissions:
pull-requests: read

jobs:
static_analysis:
static-analysis:
uses: ./.github/workflows/_static-analysis.yml
test_units:
test-units:
uses: ./.github/workflows/_test-units.yml
needs: static_analysis
needs: static-analysis
secrets: inherit
test_integrations:
test-integrations:
uses: ./.github/workflows/_test-integrations.yml
needs: test_units
needs: test-units
secrets: inherit
test_code_samples:
uses: ./.github/workflows/_test-code-samples.yml
needs: test_units
test-smoke:
uses: ./.github/workflows/_test-smoke.yml
needs: test-units
secrets: inherit
8 changes: 4 additions & 4 deletions .github/workflows/push-main-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ on:
- main

jobs:
static_analysis:
static-analysis:
uses: mindee/mindee-api-ruby/.github/workflows/_static-analysis.yml@main
test_units:
test-units:
uses: mindee/mindee-api-ruby/.github/workflows/_test-units.yml@main
needs: static_analysis
needs: static-analysis
secrets: inherit
tag:
uses: mindee/client-lib-actions/.github/workflows/tag-version.yml@main
needs: test_units
needs: test-units
release:
uses: mindee/client-lib-actions/.github/workflows/create-release.yml@main
needs: tag
Expand Down
4 changes: 2 additions & 2 deletions docs/code_samples/v2_extraction.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ model_id = 'MY_MODEL_ID'
mindee_client = Mindee::ClientV2.new(api_key: api_key)

# Set inference parameters
inference_params = {
extraction_params = {
# ID of the model, required.
model_id: model_id,

Expand All @@ -35,7 +35,7 @@ input_source = Mindee::Input::Source::PathInputSource.new(input_path)
response = mindee_client.enqueue_and_get_result(
Mindee::V2::Product::Extraction::Extraction,
input_source,
inference_params
extraction_params
)

# Print a brief summary of the parsed data
Expand Down
4 changes: 2 additions & 2 deletions docs/code_samples/v2_extraction_webhook.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ model_id = 'MY_MODEL_ID'
# Init a new client
mindee_client = Mindee::ClientV2.new(api_key: api_key)

inference_params = {
extraction_params = {
# ID of the model, required.
model_id: model_id,
# Add any number of webhook IDs here.
Expand All @@ -36,7 +36,7 @@ input_source = Mindee::Input::Source::PathInputSource.new(input_path)
response = mindee_client.enqueue(
Mindee::V2::Product::Extraction::Extraction,
input_source,
inference_params
extraction_params
)

# Print the job ID
Expand Down
53 changes: 7 additions & 46 deletions lib/mindee/client_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,27 @@ def initialize(api_key: '')
@mindee_api = Mindee::HTTP::MindeeApiV2.new(api_key: api_key)
end

# Retrieves an inference.
# @param inference_id [String]
# @return [Mindee::Parsing::V2::InferenceResponse]
def get_inference(inference_id)
@mindee_api.req_get_inference(inference_id)
end

# Retrieves a result from a given queue or URL to the result.
# @param product [Class<Mindee::V2::Product::BaseProduct>] The return class.
# @param resource [String] ID of the inference or URL to the result.
# @return [Mindee::Parsing::V2::BaseResponse]
# @return [Mindee::V2::Parsing::BaseResponse]
def get_result(product, resource)
@mindee_api.req_get_result(product, resource)
end

# Retrieves an inference from a given queue or URL to the job.
# @param job_id [String] ID of the job.
# @return [Mindee::Parsing::V2::JobResponse]
# @return [Mindee::V2::Parsing::JobResponse]
def get_job(job_id)
@mindee_api.req_get_job(job_id)
end

# Enqueue a document for async parsing.
# @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource]
# The source of the input document (local file or URL).
# @param params [Hash, InferenceParameters]
# @return [Mindee::Parsing::V2::JobResponse]
def enqueue_inference(input_source, params, disable_redundant_warnings: false)
unless disable_redundant_warnings
warn '[DEPRECATION] `enqueue_inference` is deprecated; use `enqueue` instead.', uplevel: 1
end
normalized_params = normalize_parameters(Input::InferenceParameters, params)
enqueue(Mindee::Parsing::V2::Inference, input_source, normalized_params)
end

# Enqueue a document for async parsing.
# @param product [Class<Mindee::V2::Product::BaseProduct>] The return class.
# @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource]
# The source of the input document (local file or URL).
# @param params [Hash, InferenceParameters] Parameters for the inference.
# @return [Mindee::Parsing::V2::JobResponse]
# @param params [Hash, Input::BaseParameters] Parameters for the inference.
# @return [Mindee::V2::Parsing::JobResponse]
def enqueue(
product,
input_source,
Expand All @@ -77,8 +57,8 @@ def enqueue(
# @param product [Class<Mindee::V2::Product::BaseProduct>] The return class.
# @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource]
# The source of the input document (local file or URL).
# @param params [Hash, InferenceParameters] Parameters for the inference.
# @return [Mindee::Parsing::Common::ApiResponse]
# @param params [Hash, Input::BaseParameters] Parameters for the inference.
# @return [Parsing::BaseResponse]
def enqueue_and_get_result(
product,
input_source,
Expand Down Expand Up @@ -130,26 +110,7 @@ def enqueue_and_get_result(
"Asynchronous parsing request timed out after #{sec_count} seconds"
end

# Enqueue a document for async parsing and automatically try to retrieve it.
# @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource]
# The source of the input document (local file or URL).
# @param params [Hash, InferenceParameters] Parameters for the inference.
# @return [Mindee::Parsing::V2::InferenceResponse]
def enqueue_and_get_inference(input_source, params, disable_redundant_warnings: false)
unless disable_redundant_warnings
warn '[DEPRECATION] `enqueue_and_get_inference` is deprecated; use `enqueue_and_get_result` instead.',
uplevel: 1
end

response = enqueue_and_get_result(Mindee::Parsing::V2::Inference, input_source, params)
unless response.is_a?(Mindee::Parsing::V2::InferenceResponse)
raise TypeError, "Invalid response type \"#{response.class}\""
end

response
end

# If needed, converts the parsing options provided as a hash into a proper InferenceParameters object.
# If needed, converts the parsing options provided as a hash into a proper BaseParameters subclass object.
# @param params [Hash, Class<BaseParameters>] Params.
# @return [BaseParameters]
def normalize_parameters(param_class, params)
Expand Down
8 changes: 4 additions & 4 deletions lib/mindee/errors/mindee_http_error_v2.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require_relative 'mindee_error'
require_relative '../parsing/v2/error_item'
require_relative '../v2/parsing/error_item'

module Mindee
module Errors
Expand All @@ -18,9 +18,9 @@ class MindeeHTTPErrorV2 < MindeeError
# @return [Array<ErrorItem>] A list of explicit error details.
attr_reader :errors

# @param http_error [Hash, Mindee::Parsing::V2::ErrorResponse]
# @param http_error [Hash, Mindee::V2::Parsing::ErrorResponse]
def initialize(http_error)
if http_error.is_a?(Parsing::V2::ErrorResponse)
if http_error.is_a?(V2::Parsing::ErrorResponse)
http_error = { 'detail' => http_error.detail,
'status' => http_error.status,
'title' => http_error.title,
Expand All @@ -33,7 +33,7 @@ def initialize(http_error)
@code = http_error['code']
@errors = if http_error.key?('errors')
http_error['errors'].map do |error|
Mindee::Parsing::V2::ErrorItem.new(error)
Mindee::V2::Parsing::ErrorItem.new(error)
end
else
[]
Expand Down
2 changes: 1 addition & 1 deletion lib/mindee/http/api_settings_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ApiSettingsV2
# V2 base URL default environment key name.
MINDEE_V2_BASE_URL_ENV_NAME = 'MINDEE_V2_BASE_URL'
# V2 base URL default value.
MINDEE_V2_BASE_URL_DEFAULT = 'https://api-v2.mindee.net/v2'
MINDEE_V2_BASE_URL_DEFAULT = 'https://api-v2.mindee.net'

# HTTP request timeout default environment key name.
MINDEE_V2_REQUEST_TIMEOUT_ENV_NAME = 'MINDEE_V2_REQUEST_TIMEOUT'
Expand Down
Loading
Loading