Repository navigation
feat(go-models): add AWS Bedrock provider driver - #15166
Conversation
Implements the AWS Bedrock model provider for the Go API server, tracked under infiniflow#14736. Adds Converse and Converse-Stream chat plus foundation-model listing, with SigV4-signed requests over a hand-rolled net/http path that matches the existing provider pattern in internal/entity/models/. The API key is a JSON blob carrying auth_mode plus the mode-specific credential material, mirroring the Python LiteLLMBase dispatch at rag/llm/chat_model.py:1872. Three modes are supported: - access_key_secret: static AK/SK signed directly. - iam_role: STS AssumeRole using the default credential chain, then sign with the temporary credentials. - assume_role: default credential chain (IRSA, env, instance profile) used directly. Streaming uses the AWS vnd.amazon.eventstream binary framing decoded via aws-sdk-go-v2/aws/protocol/eventstream. A contentBlockDelta with text is forwarded as a chunk; the loop returns on messageStop and fails loudly if the stream ends before messageStop. Exception frames are surfaced verbatim so partial completions cannot masquerade as success. Wires the driver into internal/entity/models/factory.go and ships conf/models/bedrock.json with 15 chat-capable foundation models (Claude 3.x, Llama 3.1, Mistral, Nova, Cohere). Embedding, OCR, ASR, TTS, and Image2Text are intentionally out of scope for this PR and return the documented "no such method" sentinel. Tests cover key parsing (every auth_mode), region resolution, Converse request shaping (system extraction, role validation, multimodal rejection), URL building (default and override), HTTP happy path / error propagation, event-stream decoding, exception surfacing, truncation detection, and every no-such-method sentinel. The httptest server accepts any SigV4 signature rather than re-verifying it; SigV4 correctness is the SDK's responsibility.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds an AWS Bedrock ModelDriver: new provider config, SigV4-signed Converse and Converse-Stream implementations with credential/region resolution (access-key, IAM-role, assume-role), model listing, unsupported capability stubs, factory wiring, and comprehensive unit tests. ChangesBedrock Chat Provider Implementation
Sequence DiagramsequenceDiagram
participant Client
participant BedrockRuntime as Bedrock Runtime (converse/converse-stream)
participant STS as AWS STS (AssumeRole)
participant Control as Bedrock Control Plane (foundation-models)
Client->>STS: AssumeRole (when auth_mode=assume_role)
STS-->>Client: Temporary credentials
Client->>BedrockRuntime: POST /model/{id}/converse (SigV4-signed)
BedrockRuntime-->>Client: JSON response (content blocks)
Client->>BedrockRuntime: POST /model/{id}/converse-stream (SigV4-signed, event-stream)
BedrockRuntime-->>Client: Event-stream frames (contentBlockDelta / messageStop / exception)
Client->>Control: GET /foundation-models (SigV4-signed) [ListModels]
Control-->>Client: Catalog JSON (modelId list)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Hi @Haruko386 how are you? Could you please review this PR? |
|
Hi @jakearmstrong59, I wil review your code soon. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15166 +/- ##
=======================================
Coverage 93.12% 93.12%
=======================================
Files 10 10
Lines 713 713
Branches 116 116
=======================================
Hits 664 664
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
### What problem does this PR solve? Fixes #15542. AWS Bedrock support for the Go model provider layer was added in #15166, but embedding support was intentionally left out of scope and `BedrockModel.Embed(...)` still returned the `no such method` sentinel. This PR implements Bedrock text embeddings under the umbrella provider tracker #14736. ### What this PR includes - `internal/entity/models/bedrock.go`: implement `BedrockModel.Embed(...)` through Bedrock Runtime `InvokeModel` with existing SigV4 auth, region resolution, and runtime URL helpers. - Titan embeddings: supports `amazon.titan-embed-text-v1` and `amazon.titan-embed-text-v2:0`; v2 forwards `EmbeddingConfig.Dimension` as `dimensions` when provided, while v1 keeps the payload minimal. - Cohere embeddings: supports `cohere.embed-english-v3`, `cohere.embed-multilingual-v3`, and `cohere.embed-v4:0`; batches input texts and maps returned vectors to RAGFlow `EmbeddingData` in input order. - `conf/models/bedrock.json`: adds the `embedding` URL suffix (`invoke`) and Bedrock embedding model entries. - `internal/entity/models/bedrock_test.go`: adds unit tests for Titan, Cohere, typed Cohere responses, validation, empty input, unsupported models, and HTTP error propagation. Reference docs: - Bedrock InvokeModel API: https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html - Titan Text Embeddings: https://docs.aws.amazon.com/bedrock/latest/userguide/titan-embedding-models.html - Cohere Embed models on Bedrock: https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-embed.html ### Type of change - [x] New Feature (non-breaking change which adds functionality) ### How was this tested? - [x] `jq empty conf/models/bedrock.json` - [x] `git diff --check` - [x] `go test ./internal/entity/models/... -run Bedrock -count=1` - [x] `go test ./internal/entity/models/... -run '^$' -count=1` - [x] `go test ./internal/entity/models/... -run Bedrock -race -count=1` Note: `go test ./internal/entity/models/... -count=1` currently fails in unrelated existing Astraflow coverage (`TestAstraflowEmbedReturnsNoSuchMethod` panics in `internal/entity/models/astraflow.go`). The Bedrock-specific tests and compile-only package check pass.
Summary
Closes #15165.
Implements the AWS Bedrock model provider for the Go API server, tracked under #14736. Adds Converse + Converse-Stream chat and foundation-model listing, with SigV4 signing over a hand-rolled
net/httppath that matches the established pattern ininternal/entity/models/(no new directgo.moddeps).internal/entity/models/bedrock.go— driver: SigV4-signed Converse / Converse-Stream / ListModels, three auth modes,vnd.amazon.eventstreamdecoding, truncation detection.internal/entity/models/bedrock_test.go— 33 unit tests againsthttptest.Server.internal/entity/models/factory.go—case "bedrock":registration.conf/models/bedrock.json— 15 chat-capable foundation models (Claude 3.x, Llama 3.1, Mistral, Nova, Cohere).What's included
rag/llm/chat_model.py:1872): API key is a JSON blob carryingauth_mode:access_key_secret— staticbedrock_ak/bedrock_sksigned directly.iam_role— STSAssumeRoleagainstaws_role_arnusing the default credential chain, then sign with the temporary credentials.assume_role— default credential chain (IRSA, env, instance profile) used directly.POST https://bedrock-runtime.{region}.amazonaws.com/model/{modelId}/converse(sync chat)POST https://bedrock-runtime.{region}.amazonaws.com/model/{modelId}/converse-stream(streaming chat, event-stream framing)GET https://bedrock.{region}.amazonaws.com/foundation-models(catalog)contentBlockDeltatext frames are forwarded as chunks; loop exits onmessageStopand fails loudly if the stream ends before it.exception/errorframes surface upstream messages verbatim.APIConfig.Regionwins; falls back tobedrock_regionin the key blob. A misconfigured region fails fast with an explicit error.chat,models(and optionalasync_chat) inconf/models/bedrock.jsonare honoured; sensible AWS defaults apply when omitted, so on-prem VPC-endpoint operators can re-route.What's intentionally out of scope
Embedding, OCR (Textract), ASR (Transcribe), TTS (Polly), Image2Text, and balance return the documented
"no such method"sentinel. Each is a separate AWS service and will land in follow-on PRs alongside the relevantconf/models/bedrock.jsonentries — matching how Novita, NVIDIA, TogetherAI, and Replicate were rolled out method-by-method.Why hand-rolled SigV4 (no
bedrockruntime/bedrockSDK clients)internal/entity/models/which usesnet/httpdirectly.go.modentries — only sub-packages of already-pinned modules:aws/signer/v4(sub-package ofaws-sdk-go-v2),aws/protocol/eventstream(v1.7.6, transitively present), andservice/sts(v1.41.8, transitively present).go mod tidywill promote the two indirects to direct on first build.Test plan
go mod tidy— confirm onlyaws/protocol/eventstreamandservice/stsmove from indirect → direct.go build ./...— compiles cleanly.go vet ./...— no warnings.go test ./internal/entity/models/... -run Bedrock -race -count=1— 33 unit tests pass:auth_mode, unknown mode,access_key_secretrequires both AK and SK,iam_rolerequires ARN,assume_roleaccepts bare config.APIConfig.Region, falls back to key, fails when neither set.buildConverseRequest: system extraction, interleaved-system rejection, unsupported-role rejection, empty messages, only-system messages, multimodal-content rejection.ListModelsfilters emptymodelIdentries;CheckConnectionsurfaces a 403 from the catalog.messageStopterminator with[DONE]sentinel emission, exception-frame surfacing, truncation detection (EOF beforemessageStop), explicitstream=falserejection, nil-sender rejection.no such methodtest.var _ ModelDriver = (*BedrockModel)(nil)pins interface satisfaction.ragflow_cli,add provider 'bedrock',create provider 'bedrock' instance ...with eachauth_mode, run the chat / stream-chat / list-models commands from [Feature] Implement model providers of RAGFlow API server in Go #14736.Linked tracker
Tracked under #14736 (Implement model providers of RAGFlow API server in Go). Closes #15165.