bedrock

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package bedrock wraps AWS Bedrock so the rdq TUI can ask an LLM to translate natural language into SQL.

It uses the unified Converse API rather than InvokeModel so the same code path works for any text-capable model the user picks. Inference profiles are preferred over direct foundation models because they fail over across regions automatically.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildAnalysisSystemPrompt

func BuildAnalysisSystemPrompt(database, language string, snapshot *schema.Snapshot) string

BuildAnalysisSystemPrompt assembles the system message for result analysis. Schema is included so the model knows the data types and relationships behind the columns it is interpreting.

func BuildAnalysisUserPrompt

func BuildAnalysisUserPrompt(sql, resultBlob, focus string) string

BuildAnalysisUserPrompt formats the SQL + result JSON / CSV blob into a single user turn. resultBlob is expected to already be truncated by the caller if huge. focus is an optional natural-language hint about what the user wants the analysis to emphasise (e.g. "look for outliers", "is the distribution skewed?", "compare across regions"). When empty the model produces a balanced general overview.

func BuildErrorExplanationPrompt

func BuildErrorExplanationPrompt(database, language string, snapshot *schema.Snapshot) string

BuildErrorExplanationPrompt assembles the system message for the error analyst flow. snapshot may be nil; the schema section is omitted in that case so the prompt still renders. language directs the model to write its explanation in the user's preferred language.

func BuildErrorUserPrompt

func BuildErrorUserPrompt(sql, errMsg string) string

BuildErrorUserPrompt formats the SQL + error message into the single user turn we send to the model. Both fields are trimmed so the layout stays stable regardless of how the caller assembled them.

func BuildReviewSystemPrompt

func BuildReviewSystemPrompt(database, language string, snapshot *schema.Snapshot) string

BuildReviewSystemPrompt assembles the system message for SQL review. It reuses the database / language directives and embeds the schema so the reviewer can verify identifiers without guessing.

func BuildReviewUserPrompt

func BuildReviewUserPrompt(sql, focus string) string

BuildReviewUserPrompt is the user-side message. focus is an optional natural-language hint about what the user wants the review to emphasise (e.g. "performance", "join correctness", "indexes I should add"). When empty the model defaults to a balanced general review.

func BuildSystemPrompt

func BuildSystemPrompt(database, language string, snapshot *schema.Snapshot) string

BuildSystemPrompt assembles the system message sent to Bedrock. The database name and schema listing come from the live cluster so the model can resolve table and column references accurately. snapshot may be nil when the background fetch hasn't finished yet — in that case the prompt goes out without schema rather than panicking. language is appended as a natural-language directive so the assistant prefers the user's preferred tongue for any commentary it does emit.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client groups the two Bedrock SDK clients we need: the management client for listing models and the runtime client for actually invoking them.

func New

func New(cfg aws.Config) *Client

New constructs a Client from a resolved AWS config. The Bedrock service must be enabled in the configured region; the call is lazy so this function never fails.

func (*Client) Ask

func (c *Client) Ask(ctx context.Context, modelID, systemPrompt string, messages []Message) (string, error)

Ask sends a multi-turn conversation to the chosen model and returns the assistant's text response with markdown code fences stripped. The caller owns the conversation slice — pass an empty / nil slice for a brand-new session and append both the user prompt and the model's reply between calls to keep context across turns.

func (*Client) Explain

func (c *Client) Explain(ctx context.Context, modelID, systemPrompt string, messages []Message) (string, error)

Explain sends a multi-turn conversation and returns the raw text untouched, so the response can include markdown bullet lists and ```sql fenced examples for the error analysis viewport.

func (*Client) ListModels

func (c *Client) ListModels(ctx context.Context) ([]ModelInfo, error)

ListModels returns the inference profiles available in the configured region. Cross-region inference profiles (the "us." / "apac." prefixed entries) are preferred because they automatically fail over across regions, which is essential for high-traffic Claude usage. Falls back to foundation models if no profiles are returned.

type Message

type Message struct {
	Role Role
	Text string
}

Message is a single turn in a multi-turn conversation. Both Ask and Explain accept a slice of these to keep context across calls within a single TUI session.

type ModelInfo

type ModelInfo struct {
	ID          string // ARN or model identifier accepted by Converse
	Name        string // human-friendly label
	Description string
}

ModelInfo is a flattened, user-friendly view of an inference profile or foundation model entry.

type Role

type Role string

Role is the speaker of a single Message in a multi-turn conversation. Only User and Assistant are supported — system instructions are passed separately via the systemPrompt argument.

const (
	RoleUser      Role = "user"
	RoleAssistant Role = "assistant"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL