Skip to content

feat(ai-service): introduce Provider Interface for LLM + OCR (Issue #…#685

Open
Richardkingz2019 wants to merge 1 commit into
Pulsefy:mainfrom
Richardkingz2019:feature/issue-615-provider-interface
Open

feat(ai-service): introduce Provider Interface for LLM + OCR (Issue #…#685
Richardkingz2019 wants to merge 1 commit into
Pulsefy:mainfrom
Richardkingz2019:feature/issue-615-provider-interface

Conversation

@Richardkingz2019

Copy link
Copy Markdown

…615)

Introduces a clean abstract contract and reference implementations for swapping LLM and OCR backends without changing route logic.

New package app/ai-service/services/providers/ with:

  • Abstract contracts: LLMProvider, OCRProvider and supporting dataclasses (LLMRequest/LLMResponse/OCRRequest/OCRProviderOutput) plus a hierarchy of ProviderError exceptions.
  • Reference implementations: OpenAIProvider, GroqProvider, FixtureLLMProvider (LLM side); TesseractOCRProvider, FixtureOCRProvider (OCR side).
  • LLMProviderRegistry and OCRProviderSelector helpers that resolve the right provider(s) for a request based on settings.
  • build_default_llm_registry / build_default_ocr_selector factory functions used by the verification services.

Refactored consumers:

  • services/humanitarian_verification.py routes all LLM calls through the registry. Circuit-breaker logic, prompt fallback and JSON parsing stay in the service because they are part of the verification policy. Legacy string-dispatch hooks (_provider_attempt_order / _call_provider / _get_model_for_provider / _call_openai / _call_groq / _call_test) are preserved so the existing test suite continues to work without modifications.
  • services/ocr.py keeps preprocessing + field detection in the service (these are policy decisions) and delegates the actual OCR engine call to the selected OCRProvider through _run_tesseract (which now routes to TesseractOCRProvider or FixtureOCRProvider).

Tests:

  • New tests/test_provider_interface.py pins the contract end-to-end: abstract type checks, exception hierarchy, reference providers, registry attempt order, selector logic, and a full route integration via /v1/ai/humanitarian/verify with a swapped registry.

closes #615

…ulsefy#615)

Introduces a clean abstract contract and reference implementations for
swapping LLM and OCR backends without changing route logic.

New package app/ai-service/services/providers/ with:
* Abstract contracts: LLMProvider, OCRProvider and supporting dataclasses
  (LLMRequest/LLMResponse/OCRRequest/OCRProviderOutput) plus a hierarchy
  of ProviderError exceptions.
* Reference implementations: OpenAIProvider, GroqProvider,
  FixtureLLMProvider (LLM side); TesseractOCRProvider, FixtureOCRProvider
  (OCR side).
* LLMProviderRegistry and OCRProviderSelector helpers that resolve the
  right provider(s) for a request based on settings.
* build_default_llm_registry / build_default_ocr_selector factory
  functions used by the verification services.

Refactored consumers:
* services/humanitarian_verification.py routes all LLM calls through
  the registry. Circuit-breaker logic, prompt fallback and JSON parsing
  stay in the service because they are part of the verification policy.
  Legacy string-dispatch hooks (_provider_attempt_order / _call_provider
  / _get_model_for_provider / _call_openai / _call_groq / _call_test)
  are preserved so the existing test suite continues to work without
  modifications.
* services/ocr.py keeps preprocessing + field detection in the service
  (these are policy decisions) and delegates the actual OCR engine call
  to the selected OCRProvider through _run_tesseract (which now routes
  to TesseractOCRProvider or FixtureOCRProvider).

Tests:
* New tests/test_provider_interface.py pins the contract end-to-end:
  abstract type checks, exception hierarchy, reference providers,
  registry attempt order, selector logic, and a full route integration
  via /v1/ai/humanitarian/verify with a swapped registry.
@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Cedarich's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jun 29, 2026

Copy link
Copy Markdown

@Richardkingz2019 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Cedarich

Copy link
Copy Markdown
Contributor

@Richardkingz2019 fix workflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provider Interface for LLM + OCR (Swap Without Refactors)

2 participants