oscerd opened a new pull request, #24982:
URL: https://github.com/apache/camel/pull/24982

   ## Description
   
   Fixes [CAMEL-24224](https://issues.apache.org/jira/browse/CAMEL-24224). Two 
defects in the Bedrock runtime producer.
   
   ### 1. Streaming metadata never captured for Claude/Nova
   
   `BedrockStreamHandler` extracted metadata only inside `if 
(parser.isFinalChunk(chunkJson))`. For Claude — and Nova, which reuses 
`ClaudeStreamParser` — `isFinalChunk` matches `message_stop`, but `stop_reason` 
and `usage` arrive on the earlier **`message_delta`** chunk. A chunk is never 
both, so the completion reason and token count were **always absent** for those 
families.
   
   The parsers were already correct (`ClaudeStreamParserTest` asserts 
extraction from a `message_delta` chunk) — only the handler's gating was wrong. 
Every chunk is now inspected and whatever metadata it carries is kept; parsers 
return `null` for chunks without it, so Titan/Llama/Mistral/Cohere (which 
report on their final chunk) are unaffected. The identical extraction in both 
handler variants is factored into one `applyChunkMetadata` method.
   
   ### 2. Inference profile ids and ARNs rejected
   
   `setResponseText` switched on the exact configured `modelId` with a throwing 
`default`. Bedrock also accepts **cross-region inference profile ids** (`us.` / 
`eu.` / `apac.` / `us-gov.` prefixed, e.g. 
`us.anthropic.claude-3-5-sonnet-20241022-v2:0`) and **inference-profile ARNs**, 
which address the same foundation model — these failed with `Unexpected model: 
…`, as did any model released after the hard-coded list.
   
   Now the underlying foundation-model id is resolved first (stripping the 
region prefix or ARN path), and ids that are still unlisted fall back to 
**family-prefix dispatch** (the response format is defined by the family, not 
the individual model). Non-text families — image, embedding, rerank, video, 
speech — still fail with a clear message rather than being parsed as text.
   
   ## Tests
   
   - `BedrockStreamHandlerMetadataTest` — asserts Claude metadata is captured 
from the **non-final** `message_delta` chunk (explicitly asserting 
`isFinalChunk` is false for it), that a realistic chunk sequence preserves it, 
and that Titan's final-chunk metadata still works.
   - `BedrockProducerModelIdTest` — plain ids, all four region prefixes, an 
inference-profile ARN, and a null id.
   
   All 13 pre-existing stream tests still pass. Note: this module has no 
`assertj-core` test dependency, so these follow the module's existing JUnit 
assertion style rather than adding a dependency for style alone.
   
   ## Backport
   
   Targeting 4.22.0 and 4.18.4 (the streaming/Converse code does not exist on 
4.14.x — will confirm before backporting).
   
   ---
   _Claude Code on behalf of oscerd_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to