@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 83 lines 2.97 KB
Raw
1 import type * as bedrock from "@distilled.cloud/aws/bedrock-runtime";
2 import * as Binding from "alchemy/Binding";
3 import type * as Effect from "effect/Effect";
4
5 /**
6 * The `Converse` request with the binding-injected `modelId` made optional:
7 * it defaults to the first bound model id and may be overridden per call
8 * with any of the bound model ids.
9 */
10 export interface ConverseRequest extends Omit<bedrock.ConverseRequest, "modelId"> {
11 /**
12 * The model to run inference on for this call. Must be one of the model
13 * ids the binding was created with (IAM is scoped to exactly those).
14 * @default the first bound model id
15 */
16 modelId?: string;
17 }
18
19 /**
20 * Runtime binding for `bedrock-runtime:Converse` — Amazon Bedrock's unified
21 * messages API that works across all conversational foundation models.
22 *
23 * Bind one or more model references inside a function runtime to get a
24 * callable that sends messages to the model. The binding grants the function
25 * `bedrock:InvokeModel` scoped to exactly the bound models. A model reference
26 * may be a foundation-model id, a cross-region inference profile id (e.g.
27 * `us.amazon.nova-micro-v1:0`), or a full Bedrock ARN (application inference
28 * profile, imported model, prompt version, ...).
29 *
30 * Model access is an account entitlement — enable the model in the Bedrock
31 * console (Model access) before invoking, otherwise calls fail with
32 * `AccessDeniedException`. Many newer models are only invocable through a
33 * cross-region inference profile id, not their bare foundation-model id.
34 *
35 * ### Conversing with a Model
36 * **Example:** Send a Single Prompt
37 * ```typescript
38 * // init
39 * const converse = yield* Bedrock.Converse("us.amazon.nova-micro-v1:0");
40 *
41 * // runtime
42 * const result = yield* converse({
43 * messages: [{ role: "user", content: [{ text: "Say hello." }] }],
44 * inferenceConfig: { maxTokens: 64 },
45 * });
46 * const text = result.output.message.content[0]?.text;
47 * ```
48 *
49 * **Example:** Bind Multiple Models and Pick Per Call
50 * ```typescript
51 * const converse = yield* Bedrock.Converse(
52 * "us.amazon.nova-micro-v1:0",
53 * "us.anthropic.claude-sonnet-4-20250514-v1:0",
54 * );
55 *
56 * const result = yield* converse({
57 * modelId: "us.anthropic.claude-sonnet-4-20250514-v1:0",
58 * messages: [{ role: "user", content: [{ text: "Summarize this." }] }],
59 * });
60 * ```
61 *
62 * **Example:** System Prompt and Inference Config
63 * ```typescript
64 * const result = yield* converse({
65 * system: [{ text: "You answer in exactly one word." }],
66 * messages: [{ role: "user", content: [{ text: "What color is the sky?" }] }],
67 * inferenceConfig: { maxTokens: 16, temperature: 0 },
68 * });
69 * ```
70 *
71 * @binding
72 */
73 export interface Converse extends Binding.Service<
74 Converse,
75 "AWS.Bedrock.Converse",
76 (
77 model: string,
78 ...additionalModels: string[]
79 ) => Effect.Effect<
80 (request: ConverseRequest) => Effect.Effect<bedrock.ConverseResponse, bedrock.ConverseError>
81 >
82 > {}
83 export const Converse = Binding.Service<Converse>("AWS.Bedrock.Converse");