[LLM Object Generation][1/2] Leverage AI Lib's Generate Object instead of parsing strings #309
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.
Relates to:
Issue #148: JSON Parsing Reliability
Risks
Low. The changes are not yet leveraged in production code, so the risk is contained to internal testing and development environments. The new modular approach will eventually replace
generateObject
andgenerateObjectArray
but poses no immediate impact on existing functionality.Background
What does this PR do?
This PR refactors the
generateObject
function by introducing a modular approach to handle AI model generation and parsing. The update addresses issue #148, which details inconsistencies in JSON response formatting from the LLM. For instance, action values likeNONE
are inconsistently quoted, causing JSON parsing errors that disrupt program logic.This PR introduces provider-specific handlers within
generateObject
, allowing standardized JSON parsing for each model type and reducing the need for custom error-handling code. This is the first part of a two-stage update, with a follow-up PR to fully deprecategenerateObject
andgenerateObjectArray
in favor of this approach.What kind of change is this?
generateObject
and centralizes model-specific parsing logic.Documentation changes needed?
generateObject
design and the role of provider-specific handlers.Testing
Where should a reviewer start?
Review
generateObject
, which now routes requests throughhandleProvider
, using specific handlers (e.g.,handleOpenAI
,handleAnthropic
) that configure JSON response handling for each model. This centralizes parsing and prepares for structured output where supported.Detailed testing steps
generateObject
to confirm JSON parsing accuracy with new handlers.