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 ¶
- func BuildAnalysisSystemPrompt(database, language string, snapshot *schema.Snapshot) string
- func BuildAnalysisUserPrompt(sql, resultBlob, focus string) string
- func BuildErrorExplanationPrompt(database, language string, snapshot *schema.Snapshot) string
- func BuildErrorUserPrompt(sql, errMsg string) string
- func BuildReviewSystemPrompt(database, language string, snapshot *schema.Snapshot) string
- func BuildReviewUserPrompt(sql, focus string) string
- func BuildSystemPrompt(database, language string, snapshot *schema.Snapshot) string
- type Client
- type Message
- type ModelInfo
- type Role
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildAnalysisSystemPrompt ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.