@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 66 lines 2.32 KB
Raw
1 import type * as bedrock from "@distilled.cloud/aws/bedrock-agent-runtime";
2 import * as Binding from "alchemy/Binding";
3 import type * as Effect from "effect/Effect";
4 import type { KnowledgeBase } from "./KnowledgeBase.ts";
5
6 /**
7 * The `RetrieveAndGenerate` request. The knowledge base is referenced inside
8 * `retrieveAndGenerateConfiguration.knowledgeBaseConfiguration.knowledgeBaseId`
9 * — pass the bound {@link KnowledgeBase}'s `knowledgeBaseId` there. The
10 * binding scopes IAM to the bound knowledge base and the bound generation
11 * models.
12 */
13 export interface RetrieveAndGenerateRequest extends bedrock.RetrieveAndGenerateRequest {}
14
15 /**
16 * Runtime binding for `bedrock-agent-runtime:RetrieveAndGenerate` — the fully
17 * managed RAG operation: retrieve relevant passages from a
18 * {@link KnowledgeBase} and generate a grounded answer with a foundation
19 * model in one call.
20 *
21 * Bind a knowledge base and one or more generation models inside a function
22 * runtime. The binding grants `bedrock:Retrieve` and
23 * `bedrock:RetrieveAndGenerate` scoped to the knowledge base, plus
24 * `bedrock:InvokeModel` scoped to the bound models (or all foundation models
25 * and cross-region inference profiles when none are named).
26 *
27 * ### Retrieving and Generating
28 * **Example:** One-Shot Grounded Answer
29 * ```typescript
30 * // init
31 * const rag = yield* Bedrock.RetrieveAndGenerate(
32 * knowledgeBase,
33 * "us.anthropic.claude-3-5-sonnet-20240620-v1:0",
34 * );
35 *
36 * // runtime
37 * const result = yield* rag({
38 * input: { text: "How do I rotate credentials?" },
39 * retrieveAndGenerateConfiguration: {
40 * type: "KNOWLEDGE_BASE",
41 * knowledgeBaseConfiguration: {
42 * knowledgeBaseId: yield* knowledgeBase.knowledgeBaseId,
43 * modelArn: "us.anthropic.claude-3-5-sonnet-20240620-v1:0",
44 * },
45 * },
46 * });
47 * const answer = result.output.text;
48 * ```
49 *
50 * @binding
51 */
52 export interface RetrieveAndGenerate extends Binding.Service<
53 RetrieveAndGenerate,
54 "AWS.Bedrock.RetrieveAndGenerate",
55 <K extends KnowledgeBase>(
56 knowledgeBase: K,
57 ...models: string[]
58 ) => Effect.Effect<
59 (
60 request: RetrieveAndGenerateRequest,
61 ) => Effect.Effect<bedrock.RetrieveAndGenerateResponse, bedrock.RetrieveAndGenerateError>
62 >
63 > {}
64 export const RetrieveAndGenerate = Binding.Service<RetrieveAndGenerate>(
65 "AWS.Bedrock.RetrieveAndGenerate",
66 );