repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
lmstudio.js
github_2023
lmstudio-ai
typescript
KVConfigSchematics.scoped
public scoped<TScopeKey extends string>( scopeKey: TScopeKey, ): KVConfigSchematics< TKVFieldValueTypeLibraryMap, { [TKey in keyof TKVConfigSchema & string as TKey extends `${TScopeKey}.${infer RInnerKey}` ? RInnerKey : never]: TKVConfigSchema[TKey]; } > { const newFields =...
/** * Get a subset of the config schema with a specific scope. */
https://github.com/lmstudio-ai/lmstudio.js/blob/22f2871aa123f65384f3b4ee2b9e3aae924f4e09/packages/lms-kv-config/src/KVConfig.ts#L541-L558
22f2871aa123f65384f3b4ee2b9e3aae924f4e09
lmstudio.js
github_2023
lmstudio-ai
typescript
KVConfigSchematics.flattenBaseKey
public flattenBaseKey() { const newFields = new Map<string, KVConcreteFieldSchema>(); for (const field of this.fields.values()) { newFields.set(field.fullKey, field); } return new KVConfigSchematics(this.valueTypeLibrary, newFields); }
/** * Combine baseKey into the fields. Effectively removes the baseKey. */
https://github.com/lmstudio-ai/lmstudio.js/blob/22f2871aa123f65384f3b4ee2b9e3aae924f4e09/packages/lms-kv-config/src/KVConfig.ts#L584-L590
22f2871aa123f65384f3b4ee2b9e3aae924f4e09
lmstudio.js
github_2023
lmstudio-ai
typescript
KVConfigSchematics.parse
public parse(config: KVConfig): ParsedKVConfig<TKVConfigSchema> { return ParsedKVConfig[createParsedKVConfig](this.parseToMap(config)); }
/** * Parse the given config to a ParsedKVConfig. **Will throw** if the config does not satisfy the * schema. */
https://github.com/lmstudio-ai/lmstudio.js/blob/22f2871aa123f65384f3b4ee2b9e3aae924f4e09/packages/lms-kv-config/src/KVConfig.ts#L620-L622
22f2871aa123f65384f3b4ee2b9e3aae924f4e09
lmstudio.js
github_2023
lmstudio-ai
typescript
KVConfigSchematics.buildFullConfig
public buildFullConfig(valuesRecord: { [TKey in keyof TKVConfigSchema & string]?: TKVConfigSchema[TKey]["type"]; }): KVConfig { return { fields: Array.from(this.fields.entries()).map(([key, field]) => { const value = this.parseField(field, valuesRecord[key]); return { key: field.fullKey,...
/** * Builds a full KV config from the given values record. **Will throw** if any of the values are * missing or do not satisfy the schema. */
https://github.com/lmstudio-ai/lmstudio.js/blob/22f2871aa123f65384f3b4ee2b9e3aae924f4e09/packages/lms-kv-config/src/KVConfig.ts#L632-L641
22f2871aa123f65384f3b4ee2b9e3aae924f4e09
lmstudio.js
github_2023
lmstudio-ai
typescript
KVConfigSchematics.buildPartialConfig
public buildPartialConfig(valuesRecord: { [TKey in keyof TKVConfigSchema & string]?: TKVConfigSchema[TKey]["type"] | undefined; }): KVConfig { return { fields: Object.entries(valuesRecord) .filter(([_key, value]) => value !== undefined) .map(([key, value]) => { const field = th...
/** * Builds a partial KV config from the given values record. Will leave holes in the config if the * values are missing. **Will throw** if any of the values do not satisfy the schema. */
https://github.com/lmstudio-ai/lmstudio.js/blob/22f2871aa123f65384f3b4ee2b9e3aae924f4e09/packages/lms-kv-config/src/KVConfig.ts#L647-L658
22f2871aa123f65384f3b4ee2b9e3aae924f4e09
lmstudio.js
github_2023
lmstudio-ai
typescript
KVConfigSchematics.getLenientZodSchema
public getLenientZodSchema(): ZodSchema<KVConfig> { if (this.lenientZodSchema !== undefined) { return this.lenientZodSchema; } this.lenientZodSchema = this.makeLenientZodSchema(); return this.lenientZodSchema; }
/** * Makes a zod schema that parses a KVConfig which only allows fields with correct keys and types * through. * * Will filter out any fields that are not in the schema. */
https://github.com/lmstudio-ai/lmstudio.js/blob/22f2871aa123f65384f3b4ee2b9e3aae924f4e09/packages/lms-kv-config/src/KVConfig.ts#L739-L745
22f2871aa123f65384f3b4ee2b9e3aae924f4e09
lmstudio.js
github_2023
lmstudio-ai
typescript
KVConfigSchematics.filterConfig
public filterConfig( config: KVConfig, additionalFilter?: ConfigFieldFilter<TKVFieldValueTypeLibraryMap>, ): KVConfig { const fullKeyMap = this.getFullKeyMap(); return { fields: config.fields.filter(configField => { const field = fullKeyMap.get(configField.key); if (field === und...
/** * Given a KVConfig, filter it to only include fields that are in the schematics. */
https://github.com/lmstudio-ai/lmstudio.js/blob/22f2871aa123f65384f3b4ee2b9e3aae924f4e09/packages/lms-kv-config/src/KVConfig.ts#L789-L809
22f2871aa123f65384f3b4ee2b9e3aae924f4e09
lmstudio.js
github_2023
lmstudio-ai
typescript
KVConfigSchematics.filterStack
public filterStack(stack: KVConfigStack): KVConfigStack { return { layers: stack.layers.map(layer => ({ layerName: layer.layerName, config: this.filterConfig(layer.config), })), }; }
/** * Given a KVConfigStack, filter it to only include fields that are in the schematics. */
https://github.com/lmstudio-ai/lmstudio.js/blob/22f2871aa123f65384f3b4ee2b9e3aae924f4e09/packages/lms-kv-config/src/KVConfig.ts#L814-L821
22f2871aa123f65384f3b4ee2b9e3aae924f4e09
lmstudio.js
github_2023
lmstudio-ai
typescript
KVConfigSchematics.filterFullKeys
public filterFullKeys(keys: ReadonlyArray<string>): Array<string> { const fullKeyMap = this.getFullKeyMap(); return keys.filter(key => fullKeyMap.has(key)); }
/** * Given a list of keys, filter it to only include keys that are in the schematics. */
https://github.com/lmstudio-ai/lmstudio.js/blob/22f2871aa123f65384f3b4ee2b9e3aae924f4e09/packages/lms-kv-config/src/KVConfig.ts#L851-L854
22f2871aa123f65384f3b4ee2b9e3aae924f4e09
lmstudio.js
github_2023
lmstudio-ai
typescript
KVConfigSchematics.configEffectiveEquals
public configEffectiveEquals(a: KVConfig, b: KVConfig) { const aMap = kvConfigToMap(a); const bMap = kvConfigToMap(b); for (const field of this.fields.values()) { const aValue = aMap.get(field.fullKey); const bValue = bMap.get(field.fullKey); if (aValue === undefined) { if (bValue...
/** * Compares two KV config. Compare with "effective equals". Only compare fields in the schematics. * Does not apply defaults. */
https://github.com/lmstudio-ai/lmstudio.js/blob/22f2871aa123f65384f3b4ee2b9e3aae924f4e09/packages/lms-kv-config/src/KVConfig.ts#L860-L884
22f2871aa123f65384f3b4ee2b9e3aae924f4e09
lmstudio.js
github_2023
lmstudio-ai
typescript
KVConfigSchematics.fieldEffectiveEquals
public fieldEffectiveEquals<TKey extends keyof TKVConfigSchema & string>( key: TKey, a: TKVConfigSchema[TKey]["type"], b: TKVConfigSchema[TKey]["type"], ) { const field = this.obtainField(key); return this.valueTypeLibrary.effectiveEquals(field.valueTypeKey, field.valueTypeParams, a, b); }
/** * Compares two KV config field. Compare with "effective equals". Can only compare fields in the * schematics. */
https://github.com/lmstudio-ai/lmstudio.js/blob/22f2871aa123f65384f3b4ee2b9e3aae924f4e09/packages/lms-kv-config/src/KVConfig.ts#L890-L897
22f2871aa123f65384f3b4ee2b9e3aae924f4e09
lmstudio.js
github_2023
lmstudio-ai
typescript
KVConfigSchematics.apply
public apply(target: KVConfig, patch: KVConfig) { const filteredPatch = this.filterConfig(patch); return collapseKVStackRaw([target, filteredPatch]); }
/** * Apply config in patch to target. Only apply fields that are in the schematics. */
https://github.com/lmstudio-ai/lmstudio.js/blob/22f2871aa123f65384f3b4ee2b9e3aae924f4e09/packages/lms-kv-config/src/KVConfig.ts#L950-L953
22f2871aa123f65384f3b4ee2b9e3aae924f4e09
lmstudio.js
github_2023
lmstudio-ai
typescript
KVConfigSchematics.unApply
public unApply(target: KVConfig, patch: KVConfig) { const filteredPatch = this.filterConfig(patch); const patchMap = kvConfigToMap(filteredPatch); const newMap = new Map(kvConfigToMap(target)); const fullKeyMap = this.getFullKeyMap(); for (const [key, value] of patchMap.entries()) { const fiel...
/** * Tries to un-apply the patch from the target. Will only un-apply fields that are in the * schematics. * * If the value in the target is not effective equal to the value in the patch, it will not be * removed. */
https://github.com/lmstudio-ai/lmstudio.js/blob/22f2871aa123f65384f3b4ee2b9e3aae924f4e09/packages/lms-kv-config/src/KVConfig.ts#L962-L988
22f2871aa123f65384f3b4ee2b9e3aae924f4e09
lmstudio.js
github_2023
lmstudio-ai
typescript
KVConfigSchematics.iterateFieldsOfConfig
public *iterateFieldsOfConfig(config: KVConfig): Generator<[string, any]> { const fullKeyMap = this.getFullKeyMap(); for (const { key, value } of config.fields) { const field = fullKeyMap.get(key); if (field !== undefined) { yield [key, value]; } } }
/** * Given a KVConfig, iterate through all the fields that are in the schematics. Keys will be full * keys. */
https://github.com/lmstudio-ai/lmstudio.js/blob/22f2871aa123f65384f3b4ee2b9e3aae924f4e09/packages/lms-kv-config/src/KVConfig.ts#L994-L1002
22f2871aa123f65384f3b4ee2b9e3aae924f4e09
lmstudio.js
github_2023
lmstudio-ai
typescript
KVConfigSchematics.fullKeys
public *fullKeys(): Generator<string> { const fullKeyMap = this.getFullKeyMap(); for (const key of fullKeyMap.keys()) { yield key; } }
/** * Given a KVConfig, iterate through all the fields that are in the schematics. */
https://github.com/lmstudio-ai/lmstudio.js/blob/22f2871aa123f65384f3b4ee2b9e3aae924f4e09/packages/lms-kv-config/src/KVConfig.ts#L1007-L1012
22f2871aa123f65384f3b4ee2b9e3aae924f4e09
lmstudio.js
github_2023
lmstudio-ai
typescript
KVConfigSchematics.effectiveCompareConfig
public effectiveCompareConfig( a: KVConfig, b: KVConfig, opts: { fieldFilter?: ConfigFieldFilter<TKVFieldValueTypeLibraryMap>; } = {}, ): { onlyInA: Array<string>; onlyInB: Array<string>; inBothButDifferent: Array<string> } { const { fieldFilter } = opts; const aMap = kvConfigToMap(a); ...
/** * Effectively compare two KV config, and return full keys of fields that are different. */
https://github.com/lmstudio-ai/lmstudio.js/blob/22f2871aa123f65384f3b4ee2b9e3aae924f4e09/packages/lms-kv-config/src/KVConfig.ts#L1017-L1067
22f2871aa123f65384f3b4ee2b9e3aae924f4e09
lmstudio.js
github_2023
lmstudio-ai
typescript
quoteString
function quoteString(str: string | undefined, empty?: string) { if (str === undefined || str === "") { return empty ?? '""'; } return JSON.stringify(str); }
/** * Quote a string. */
https://github.com/lmstudio-ai/lmstudio.js/blob/22f2871aa123f65384f3b4ee2b9e3aae924f4e09/packages/lms-kv-config/src/valueTypes.ts#L29-L34
22f2871aa123f65384f3b4ee2b9e3aae924f4e09
lmstudio.js
github_2023
lmstudio-ai
typescript
quoteStringWithManualEscape
function quoteStringWithManualEscape(str: string | undefined, empty?: string) { return quoteString(str?.replace(/\\n/g, "\n"), empty); }
/** * Quote a string that may include manual escape. (i.e. newlines represented with "\\n") */
https://github.com/lmstudio-ai/lmstudio.js/blob/22f2871aa123f65384f3b4ee2b9e3aae924f4e09/packages/lms-kv-config/src/valueTypes.ts#L39-L41
22f2871aa123f65384f3b4ee2b9e3aae924f4e09
lmstudio.js
github_2023
lmstudio-ai
typescript
failOk
function failOk<T>(schema: ZodSchema<T>): ZodSchema<T | undefined> { return z.any().transform(val => (schema.safeParse(val).success ? val : undefined)); }
/** * Makes a Zod schema that turns a failed parse into an `undefined`. */
https://github.com/lmstudio-ai/lmstudio.js/blob/22f2871aa123f65384f3b4ee2b9e3aae924f4e09/packages/lms-shared-types/src/Error.ts#L18-L20
22f2871aa123f65384f3b4ee2b9e3aae924f4e09
lmstudio.js
github_2023
lmstudio-ai
typescript
printDownloadedModels
async function printDownloadedModels() { const downloadedModels = await client.system.listDownloadedModels(); console.log("Downloaded Models:"); if (downloadedModels.length === 0) { console.log(" No models downloaded. Get some in LM Studio."); process.exit(0); } // Limit to printing 5 models for...
// ---------- Functions ----------
https://github.com/lmstudio-ai/lmstudio.js/blob/22f2871aa123f65384f3b4ee2b9e3aae924f4e09/scaffolds/node-typescript/src/index.ts#L11-L27
22f2871aa123f65384f3b4ee2b9e3aae924f4e09
ecctrl
github_2023
pmndrs
typescript
getMovingDirection
const getMovingDirection = (forward: boolean, backward: boolean, leftward: boolean, rightward: boolean, pivot: THREE.Object3D) : number | null => { if (!forward && !backward && !leftward && !rightward) return null; if (forward && leftward) return pivot.rotation.y + Math.PI / 4; if (forward && rightward)...
// Retrieve current moving direction of the character
https://github.com/pmndrs/ecctrl/blob/8b35a75284d2eb29aae430aa7c4f26a17f788aab/src/Ecctrl.tsx#L33-L48
8b35a75284d2eb29aae430aa7c4f26a17f788aab
ecctrl
github_2023
pmndrs
typescript
useIsInsideKeyboardControls
function useIsInsideKeyboardControls() { try { return !!useKeyboardControls() } catch { return false } }
/** * Check if inside keyboardcontrols */
https://github.com/pmndrs/ecctrl/blob/8b35a75284d2eb29aae430aa7c4f26a17f788aab/src/Ecctrl.tsx#L452-L458
8b35a75284d2eb29aae430aa7c4f26a17f788aab
ecctrl
github_2023
pmndrs
typescript
autoBalanceCharacter
const autoBalanceCharacter = () => { // Match body component to character model rotation on Y bodyFacingVec.set(0, 0, 1).applyQuaternion(quat(characterRef.current.rotation())) bodyBalanceVec.set(0, 1, 0).applyQuaternion(quat(characterRef.current.rotation())) bodyBalanceVecOnX.set(0, bodyBalanceVec.y, b...
/** * Character auto balance function */
https://github.com/pmndrs/ecctrl/blob/8b35a75284d2eb29aae430aa7c4f26a17f788aab/src/Ecctrl.tsx#L786-L825
8b35a75284d2eb29aae430aa7c4f26a17f788aab
ecctrl
github_2023
pmndrs
typescript
sleepCharacter
const sleepCharacter = () => { if (characterRef.current) { if (document.visibilityState === "hidden") { characterRef.current.sleep() } else { setTimeout(() => { characterRef.current.wakeUp() }, wakeUpDelay) } } }
/** * Character sleep function */
https://github.com/pmndrs/ecctrl/blob/8b35a75284d2eb29aae430aa7c4f26a17f788aab/src/Ecctrl.tsx#L830-L840
8b35a75284d2eb29aae430aa7c4f26a17f788aab
ecctrl
github_2023
pmndrs
typescript
pointToMove
const pointToMove = (delta: number, slopeAngle: number, movingObjectVelocity: THREE.Vector3, functionKeyDown: boolean) => { const moveToPoint = getMoveToPoint().moveToPoint; if (moveToPoint) { pointToPoint.set(moveToPoint.x - currentPos.x, 0, moveToPoint.z - currentPos.z) crossVector.crossVectors(po...
/** * Point-to-move function */
https://github.com/pmndrs/ecctrl/blob/8b35a75284d2eb29aae430aa7c4f26a17f788aab/src/Ecctrl.tsx#L845-L867
8b35a75284d2eb29aae430aa7c4f26a17f788aab
ecctrl
github_2023
pmndrs
typescript
rotateCamera
const rotateCamera = (x: number, y: number) => { pivot.rotation.y += y; followCam.rotation.x = Math.min( Math.max(followCam.rotation.x + x, camLowLimit), camUpLimit ); };
/** * Rotate camera function */
https://github.com/pmndrs/ecctrl/blob/8b35a75284d2eb29aae430aa7c4f26a17f788aab/src/Ecctrl.tsx#L872-L878
8b35a75284d2eb29aae430aa7c4f26a17f788aab
ecctrl
github_2023
pmndrs
typescript
rotateCharacterOnY
const rotateCharacterOnY = (rad: number) => { modelEuler.y += rad; };
/** * Rotate character on Y function */
https://github.com/pmndrs/ecctrl/blob/8b35a75284d2eb29aae430aa7c4f26a17f788aab/src/Ecctrl.tsx#L883-L885
8b35a75284d2eb29aae430aa7c4f26a17f788aab
ecctrl
github_2023
pmndrs
typescript
onTouchEnd
const onTouchEnd = (e: TouchEvent) => { // Reset animations api.start({ topRotationX: 0, topRotationY: 0, basePositionX: 0, basePositionY: 0, }) // Reset joystick store values resetJoystick() }
// Touch end function
https://github.com/pmndrs/ecctrl/blob/8b35a75284d2eb29aae430aa7c4f26a17f788aab/src/EcctrlJoystick.tsx#L87-L98
8b35a75284d2eb29aae430aa7c4f26a17f788aab
ecctrl
github_2023
pmndrs
typescript
onWindowResize
const onWindowResize = () => { setWindowSize({ innerHeight: window.innerHeight, innerWidth: window.innerWidth }) }
// Reset window size function
https://github.com/pmndrs/ecctrl/blob/8b35a75284d2eb29aae430aa7c4f26a17f788aab/src/EcctrlJoystick.tsx#L101-L103
8b35a75284d2eb29aae430aa7c4f26a17f788aab
ecctrl
github_2023
pmndrs
typescript
onDocumentMouseMove
const onDocumentMouseMove = (e: MouseEvent) => { if (document.pointerLockElement || isMouseDown) { pivot.rotation.y -= e.movementX * 0.002 * camMoveSpeed; const vy = followCam.rotation.x + e.movementY * 0.002 * camMoveSpeed; cameraDistance = followCam.position.length(); if (vy >= camLowLim...
// Rapier ray setup (optional)
https://github.com/pmndrs/ecctrl/blob/8b35a75284d2eb29aae430aa7c4f26a17f788aab/src/hooks/useFollowCam.tsx#L65-L79
8b35a75284d2eb29aae430aa7c4f26a17f788aab
ecctrl
github_2023
pmndrs
typescript
onDocumentMouseWheel
const onDocumentMouseWheel = (e: Event) => { const vz = originZDis.current - (e as WheelEvent).deltaY * 0.002 * camZoomSpeed; const vy = followCam.rotation.x; if (vz >= camMaxDis && vz <= camMinDis) { originZDis.current = vz; followCam.position.z = originZDis.current * Math.cos(-vy); foll...
// Mouse scroll event
https://github.com/pmndrs/ecctrl/blob/8b35a75284d2eb29aae430aa7c4f26a17f788aab/src/hooks/useFollowCam.tsx#L82-L92
8b35a75284d2eb29aae430aa7c4f26a17f788aab
ecctrl
github_2023
pmndrs
typescript
onTouchEnd
const onTouchEnd = (e: TouchEvent) => { previousTouch1 = null previousTouch2 = null }
/** * Touch events */
https://github.com/pmndrs/ecctrl/blob/8b35a75284d2eb29aae430aa7c4f26a17f788aab/src/hooks/useFollowCam.tsx#L98-L101
8b35a75284d2eb29aae430aa7c4f26a17f788aab
ecctrl
github_2023
pmndrs
typescript
onTouchMove
const onTouchMove = (e: TouchEvent) => { // prevent swipe to navigate gesture e.preventDefault(); e.stopImmediatePropagation(); const touch1 = e.targetTouches[0]; const touch2 = e.targetTouches[1]; // One finger touch to rotate camera if (previousTouch1 && !previousTouch2) { const to...
// Touch move event
https://github.com/pmndrs/ecctrl/blob/8b35a75284d2eb29aae430aa7c4f26a17f788aab/src/hooks/useFollowCam.tsx#L104-L152
8b35a75284d2eb29aae430aa7c4f26a17f788aab
ecctrl
github_2023
pmndrs
typescript
joystickCamMove
const joystickCamMove = (movementX: number, movementY: number) => { pivot.rotation.y -= movementX * 0.005 * camMoveSpeed * 5; const vy = followCam.rotation.x + movementY * 0.005 * camMoveSpeed * 5; cameraDistance = followCam.position.length(); if (vy >= camLowLimit && vy <= camUpLimit) { followC...
/** * Gamepad second joystick event */
https://github.com/pmndrs/ecctrl/blob/8b35a75284d2eb29aae430aa7c4f26a17f788aab/src/hooks/useFollowCam.tsx#L157-L168
8b35a75284d2eb29aae430aa7c4f26a17f788aab
ecctrl
github_2023
pmndrs
typescript
customTraverseAdd
function customTraverseAdd(object: THREE.Object3D) { // Chekc if the object's userData camExcludeCollision is true if (object.userData && object.userData.camExcludeCollision === true) { return; } // Check if the object is a Mesh, and is visible if ((object as THREE.Mesh).isMesh && (object as ...
/** * Custom traverse function */
https://github.com/pmndrs/ecctrl/blob/8b35a75284d2eb29aae430aa7c4f26a17f788aab/src/hooks/useFollowCam.tsx#L174-L189
8b35a75284d2eb29aae430aa7c4f26a17f788aab
ecctrl
github_2023
pmndrs
typescript
customTraverseRemove
function customTraverseRemove(object: THREE.Object3D) { intersectObjects.current = intersectObjects.current.filter( (item) => item.uuid !== object.uuid // Keep all items except the one to remove ); // Recursively traverse child objects object.children.forEach((child) => { customTraverseRemo...
// Remove intersect objects from camera collision array
https://github.com/pmndrs/ecctrl/blob/8b35a75284d2eb29aae430aa7c4f26a17f788aab/src/hooks/useFollowCam.tsx#L191-L200
8b35a75284d2eb29aae430aa7c4f26a17f788aab
ecctrl
github_2023
pmndrs
typescript
cameraCollisionDetect
const cameraCollisionDetect = (delta: number) => { // Update collision detect ray origin and pointing direction // Which is from pivot point to camera position cameraRayOrigin.copy(pivot.position); camera.getWorldPosition(cameraPosition); cameraRayDir.subVectors(cameraPosition, pivot.position); ...
/** * Camera collision detection function */
https://github.com/pmndrs/ecctrl/blob/8b35a75284d2eb29aae430aa7c4f26a17f788aab/src/hooks/useFollowCam.tsx#L205-L239
8b35a75284d2eb29aae430aa7c4f26a17f788aab
generative-ai-cdk-constructs
github_2023
awslabs
typescript
AmazonAuroraVectorStore.fromExistingAuroraVectorStore
public static fromExistingAuroraVectorStore( scope: Construct, id: string, props: ExistingAmazonAuroraVectorStoreProps, ): ExistingAmazonAuroraVectorStore { return new ExistingAmazonAuroraVectorStore(scope, id, props); }
/** * Creates an instance of AmazonAuroraVectorStore using existing Aurora Vector Store properties. * You need to provide your existing Aurora Vector Store properties * such as `databaseName`, `clusterIdentifier`, `vpc` where database is deployed, * `secret` containing username and password for authenticati...
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/amazonaurora/aurora-vector-store.ts#L456-L462
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
BedrockFoundationModel.asArn
asArn(construct: IConstruct): string { if (construct) { } return this.modelArn; }
/** * Returns the ARN of the foundation model in the following format: * `arn:${Partition}:bedrock:${Region}::foundation-model/${ResourceId}` */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/models.ts#L249-L253
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
BedrockFoundationModel.grantInvoke
public grantInvoke(grantee: IGrantable): Grant { const grant = Grant.addToPrincipal({ grantee: grantee, actions: ['bedrock:InvokeModel'], resourceArns: [this.invokableArn], }); return grant; }
/** * Gives the appropriate policies to invoke and use the Foundation Model in the stack region. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/models.ts#L264-L271
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
BedrockFoundationModel.grantInvokeAllRegions
public grantInvokeAllRegions(grantee: IGrantable): Grant { const invokableArn = Arn.format({ partition: Aws.PARTITION, service: 'bedrock', region: '*', account: '', resource: 'foundation-model', resourceName: this.modelId, arnFormat: ArnFormat.SLASH_RESOURCE_NAME, }); ...
/** * Gives the appropriate policies to invoke and use the Foundation Model in all regions. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/models.ts#L276-L292
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
ParentActionGroupSignature.constructor
constructor(public readonly value: string) {}
/** * Constructor should be used as a temporary solution when a new signature is supported * but its implementation in CDK hasn't been added yet. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/agents/action-group.ts#L37-L37
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
AgentActionGroup.userInput
public static userInput(enabled: boolean): AgentActionGroup { return new AgentActionGroup({ name: 'UserInputAction', enabled: enabled, parentActionGroupSignature: ParentActionGroupSignature.USER_INPUT, }); }
/** * Defines an action group that allows your agent to request the user for * additional information when trying to complete a task. * @param enabled Specifies whether the action group is available for the agent */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/agents/action-group.ts#L114-L120
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
AgentActionGroup.codeInterpreter
public static codeInterpreter(enabled: boolean): AgentActionGroup { return new AgentActionGroup({ name: 'CodeInterpreterAction', enabled: enabled, parentActionGroupSignature: ParentActionGroupSignature.CODE_INTERPRETER, }); }
/** * Defines an action group that allows your agent to request the user for * additional information when trying to complete a task. * @param enabled Specifies whether the action group is available for the agent */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/agents/action-group.ts#L127-L133
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
AgentActionGroup._render
public _render(): CfnAgent.AgentActionGroupProperty { return { actionGroupExecutor: this.executor?._render(), actionGroupName: this.name, actionGroupState: this.enabled ? 'ENABLED' : 'DISABLED', apiSchema: this.apiSchema?._render(), description: this.description, functionSchema: ...
/** * Format as CFN properties * * @internal This is an internal core function and should not be called directly. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/agents/action-group.ts#L202-L213
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
AgentAlias.fromAttributes
public static fromAttributes(scope: Construct, id: string, attrs: AgentAliasAttributes): IAgentAlias { class Import extends AgentAliasBase { public readonly agent = attrs.agent; public readonly aliasId = attrs.aliasId; public readonly aliasName = attrs.aliasName; public readonly aliasArn = S...
/** * Brings an Agent Alias from an existing one created outside of CDK. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/agents/agent-alias.ts#L189-L202
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
AgentAlias.constructor
constructor(scope: Construct, id: string, props: AgentAliasProps) { super(scope, id); // ------------------------------------------------------ // Set properties or defaults // ------------------------------------------------------ this.aliasName = props.aliasName ?? 'latest'; this.agent = prop...
// ------------------------------------------------------
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/agents/agent-alias.ts#L215-L245
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Agent.fromAgentAttrs
public static fromAgentAttrs(scope: Construct, id: string, attrs: AgentAttributes): IAgent { class Import extends AgentBase { public readonly agentArn = attrs.agentArn; public readonly agentId = Arn.split(attrs.agentArn, ArnFormat.SLASH_RESOURCE_NAME).resourceName!; public readonly role = iam.Role...
/** * Static Method for importing an existing Bedrock Agent. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/agents/agent.ts#L217-L229
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Agent.constructor
constructor(scope: Construct, id: string, props: AgentProps) { super(scope, id); // ------------------------------------------------------ // Set properties and defaults // ------------------------------------------------------ this.name = props.name ?? generatePhysicalNameV2(this, 'bedrock-a...
// ------------------------------------------------------
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/agents/agent.ts#L335-L453
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Agent.addKnowledgeBase
public addKnowledgeBase(knowledgeBase: IKnowledgeBase) { // Do some checks validation.throwIfInvalid(this.validateKnowledgeBase, knowledgeBase); // Add it to the array this.knowledgeBases.push(knowledgeBase); // Add the appropriate Permissions to query the Knowledge Base knowledgeBase.grantQuery...
/** * Add knowledge base to the agent. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/agents/agent.ts#L461-L468
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Agent.addGuardrail
public addGuardrail(guardrail: IGuardrail) { // Do some checks validation.throwIfInvalid(this.validateGuardrail, guardrail); // Add it to the construct this.guardrail = guardrail; // Handle permissions guardrail.grantApply(this.role); }
/** * Add guardrail to the agent. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/agents/agent.ts#L473-L480
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Agent.addActionGroup
public addActionGroup(actionGroup: AgentActionGroup) { // Do some checks validation.throwIfInvalid(this.validateActionGroup, actionGroup); // Add it to the array this.actionGroups.push(actionGroup); // Handle permissions to invoke the lambda function actionGroup.executor?.lambdaFunction?.grantIn...
/** * Add an action group to the agent. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/agents/agent.ts#L485-L497
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Agent.addActionGroups
public addActionGroups(...actionGroups: AgentActionGroup[]) { actionGroups.forEach(ag => this.addActionGroup(ag)); }
/** * Add multiple action groups to the agent. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/agents/agent.ts#L502-L504
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Agent.renderGuardrail
private renderGuardrail(): bedrock.CfnAgent.GuardrailConfigurationProperty | undefined { return this.guardrail ? { guardrailIdentifier: this.guardrail.guardrailId, guardrailVersion: this.guardrail.guardrailVersion, } : undefined; }
/** * Render the guardrail configuration. * * @internal This is an internal core function and should not be called directly. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/agents/agent.ts#L514-L521
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Agent.renderKnowledgeBases
private renderKnowledgeBases(): bedrock.CfnAgent.AgentKnowledgeBaseProperty[] { const knowledgeBaseAssociationsCfn: bedrock.CfnAgent.AgentKnowledgeBaseProperty[] = []; // Build the associations in the CFN format this.knowledgeBases.forEach(kb => { knowledgeBaseAssociationsCfn.push({ knowledgeB...
/** * Render the knowledge base associations. * * @internal This is an internal core function and should not be called directly. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/agents/agent.ts#L528-L540
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Agent.renderActionGroups
private renderActionGroups(): bedrock.CfnAgent.AgentActionGroupProperty[] { const actionGroupsCfn: bedrock.CfnAgent.AgentActionGroupProperty[] = []; // Build the associations in the CFN format this.actionGroups.forEach(ag => { actionGroupsCfn.push(ag._render()); }); return actionGroupsCfn; }
/** * Render the action groups * * @internal This is an internal core function and should not be called directly. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/agents/agent.ts#L547-L554
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Agent.validateKnowledgeBaseAssocations
private validateKnowledgeBase = (knowledgeBase: IKnowledgeBase): string[] => { const MAX_LENGTH = 200; const description = knowledgeBase.instruction ?? knowledgeBase.description; const errors: string[] = []; // If at least one of the previous has been defined if (description) { errors.push( ...
/** * Checks if the KB Associations are valid * * @internal This is an internal core function and should not be called directly. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/agents/agent.ts
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
ActionGroupExecutor.fromlambdaFunction
public static fromlambdaFunction(lambdaFunction: IFunction): ActionGroupExecutor { return new ActionGroupExecutor(lambdaFunction, undefined); }
/** * Defines an action group with a Lambda function containing the business logic. * @param lambdaFunction - Lambda function to be called by the action group. * @see https://docs.aws.amazon.com/bedrock/latest/userguide/agents-lambda.html */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/agents/api-executor.ts#L41-L43
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
ActionGroupExecutor._render
public _render(): bedrock.CfnAgent.ActionGroupExecutorProperty { return { customControl: this.customControl, lambda: this.lambdaFunction?.functionArn, }; }
/** * Format as CFN properties * * @internal This is an internal core function and should not be called directly. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/agents/api-executor.ts#L58-L63
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
InlineApiSchema._render
public _render(): CfnAgent.APISchemaProperty { return { payload: this.schema, }; }
/** * @internal This is an internal core function and should not be called directly. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/agents/api-schema.ts#L83-L87
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
S3ApiSchema._render
public _render(): CfnAgent.APISchemaProperty { return { s3: { s3BucketName: this.location.bucketName, s3ObjectKey: this.location.objectKey, }, }; }
/** * @internal This is an internal core function and should not be called directly. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/agents/api-schema.ts#L103-L110
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
PromptOverrideConfiguration.withCustomParser
public static withCustomParser(props: CustomParserProps): PromptOverrideConfiguration { // Create new object return new PromptOverrideConfiguration(props); }
/** * Creates a PromptOverrideConfiguration with a custom Lambda parser function. * @param props Configuration including: * - `parser`: Lambda function to use as custom parser * - `steps`: prompt step configurations. At least one of the steps must make use of the custom parser. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/agents/prompt-override.ts#L151-L154
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
PromptOverrideConfiguration.constructor
private constructor(props: CustomParserProps) { // Validate props validation.throwIfInvalid(this.validateSteps, props.steps); if (props.parser) { validation.throwIfInvalid(this.validateCustomParser, props.steps); } this.parser = props.parser; this.steps = props.steps; }
/** * Create a new PromptOverrideConfiguration. * * @internal - This is marked as private so end users leverage it only through static methods */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/agents/prompt-override.ts#L183-L191
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
PromptOverrideConfiguration._render
public _render(): CfnAgent.PromptOverrideConfigurationProperty { return { overrideLambda: this.parser?.functionArn, promptConfigurations: this.steps?.map(step => ({ // prettier-ignore promptType: step.stepType, /** Maps stepEnabled (true → 'ENABLED', false → 'DISABL...
/** * Format as CfnAgent.PromptOverrideConfigurationProperty * * @internal This is an internal core function and should not be called directly. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/agents/prompt-override.ts#L198-L222
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
GuardrailVersion.fromGuardrailVersionAttributes
public static fromGuardrailVersionAttributes( scope: Construct, id: string, attrs: GuardrailVersionAttributes, ): IGuardrailVersion { class Import extends GuardrailVersionBase { public readonly guardrail = Guardrail.fromGuardrailAttributes(scope, `Guardrail-${id}`, { guardrailArn: attrs....
/** * Import a Guardrail Version from its attributes. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/guardrails/guardrail-version.ts#L109-L122
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
GuardrailVersion.constructor
constructor(scope: Construct, id: string, props: GuardrailVersionProps) { super(scope, id); this.guardrail = props.guardrail; // Compute hash from guardrail, to recreate the resource when guardrail has changed const hash = md5hash(props.guardrail.lastUpdated ?? 'Default'); this._resource = new Cfn...
/** * */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/guardrails/guardrail-version.ts#L134-L147
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Guardrail.fromGuardrailAttributes
public static fromGuardrailAttributes(scope: Construct, id: string, attrs: GuardrailAttributes): IGuardrail { class Import extends GuardrailBase { public readonly guardrailArn = attrs.guardrailArn; public readonly guardrailId = Arn.split(attrs.guardrailArn, ArnFormat.SLASH_RESOURCE_NAME).resourceName!; ...
/** * Import a guardrail given its attributes */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/guardrails/guardrails.ts#L217-L227
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Guardrail.fromCfnGuardrail
public static fromCfnGuardrail(cfnGuardrail: bedrock.CfnGuardrail): IGuardrail { return new (class extends GuardrailBase { public readonly guardrailArn = cfnGuardrail.attrGuardrailArn; public readonly guardrailId = cfnGuardrail.attrGuardrailId; public readonly guardrailVersion = cfnGuardrail.attrV...
/** * Import a low-level L1 Cfn Guardrail */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/guardrails/guardrails.ts#L232-L242
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Guardrail.addContentFilter
public addContentFilter(filter: filters.ContentFilter): void { this.contentFilters.push(filter); }
/** * Adds a content filter to the guardrail. * @param filter The content filter to add. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/guardrails/guardrails.ts#L370-L372
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Guardrail.addPIIFilter
public addPIIFilter(filter: filters.PIIFilter): void { this.piiFilters.push(filter); }
/** * Adds a PII filter to the guardrail. * @param filter The PII filter to add. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/guardrails/guardrails.ts#L378-L380
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Guardrail.addRegexFilter
public addRegexFilter(filter: filters.RegexFilter): void { this.regexFilters.push(filter); }
/** * Adds a regex filter to the guardrail. * @param filter The regex filter to add. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/guardrails/guardrails.ts#L386-L388
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Guardrail.addDeniedTopicFilter
public addDeniedTopicFilter(filter: filters.Topic): void { this.deniedTopics.push(filter); }
/** * Adds a denied topic filter to the guardrail. * @param filter The denied topic filter to add. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/guardrails/guardrails.ts#L394-L396
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Guardrail.addContextualGroundingFilter
public addContextualGroundingFilter(filter: filters.ContextualGroundingFilter): void { this.contextualGroundingFilters.push(filter); }
/** * Adds a contextual grounding filter to the guardrail. * @param filter The contextual grounding filter to add. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/guardrails/guardrails.ts#L402-L404
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Guardrail.addWordFilter
public addWordFilter(filter: string): void { this.wordFilters.push(filter); }
/** * Adds a word filter to the guardrail. * @param filter The word filter to add. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/guardrails/guardrails.ts#L410-L412
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Guardrail.addWordFilterFromFile
public addWordFilterFromFile(filePath: string): void { const fileContents = fs.readFileSync(filePath, 'utf8'); const words = fileContents.trim().split(','); for (const word of words) this.addWordFilter(word); }
/** * Adds a word filter to the guardrail. * @param filePath The location of the word filter file. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/guardrails/guardrails.ts#L418-L422
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Guardrail.addManagedWordListFilter
public addManagedWordListFilter(filter: filters.ManagedWordFilterType): void { this.managedWordListFilters.push(filter); }
/** * Adds a managed word list filter to the guardrail. * @param filter The managed word list filter to add. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/guardrails/guardrails.ts#L428-L430
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Guardrail.createVersion
public createVersion(description?: string): string { const cfnVersion = new bedrock.CfnGuardrailVersion(this, `GuardrailVersion-${this.hash.slice(0, 16)}`, { description: description, guardrailIdentifier: this.guardrailId, }); this.guardrailVersion = cfnVersion.attrVersion; return this.guar...
/** * Create a version for the guardrail. * @param description The description of the version. * @returns The guardrail version. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/guardrails/guardrails.ts#L437-L445
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Guardrail.generateCfnContentPolicyConfig
private generateCfnContentPolicyConfig(): IResolvable { return Lazy.any({ produce: () => { if (this.contentFilters.length > 0) { return { filtersConfig: this.contentFilters } as bedrock.CfnGuardrail.ContentPolicyConfigProperty; } else { return undefined; } }, ...
/** * Returns the content filters applied to the guardrail. This method defers the computation * to synth time. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/guardrails/guardrails.ts#L454-L464
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Guardrail.generateCfnTopicPolicy
private generateCfnTopicPolicy(): IResolvable { return Lazy.any({ produce: () => { if (this.deniedTopics.length > 0) { return { topicsConfig: this.deniedTopics.flatMap((topic: filters.Topic) => { return { definition: topic.definition, ...
/** * Returns the topic filters applied to the guardrail. This method defers the computation * to synth time. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/guardrails/guardrails.ts#L470-L489
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Guardrail.generateCfnContextualPolicyConfig
private generateCfnContextualPolicyConfig(): IResolvable { return Lazy.any({ produce: () => { if (this.contextualGroundingFilters.length > 0) { return { filtersConfig: this.contextualGroundingFilters.flatMap((filter: filters.ContextualGroundingFilter) => { return { ...
/** * Returns the contectual filters applied to the guardrail. This method defers the computation * to synth time. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/guardrails/guardrails.ts#L495-L512
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Guardrail.generateCfnWordPolicyConfig
private generateCfnWordPolicyConfig(): IResolvable { return Lazy.any({ produce: () => { if (this.wordFilters.length > 0 || this.managedWordListFilters.length > 0) { return { wordsConfig: this.generateCfnWordConfig(), managedWordListsConfig: this.generateCfnManagedWord...
/** * Returns the word config applied to the guardrail. This method defers the computation * to synth time. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/guardrails/guardrails.ts#L518-L531
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Guardrail.generateCfnWordConfig
private generateCfnWordConfig(): IResolvable { return Lazy.any( { produce: () => { return this.wordFilters.flatMap((word: string) => { return { text: word, } as bedrock.CfnGuardrail.WordConfigProperty; }); }, }, { omitEmptyA...
/** * Returns the word filters applied to the guardrail. This method defers the computation * to synth time. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/guardrails/guardrails.ts#L537-L550
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Guardrail.generateCfnManagedWordListsConfig
private generateCfnManagedWordListsConfig(): IResolvable { return Lazy.any( { produce: () => { return this.managedWordListFilters.flatMap((filter: filters.ManagedWordFilterType) => { return { type: filter.toString(), } as bedrock.CfnGuardrail.ManagedWord...
/** * Returns the word filters applied to the guardrail. This method defers the computation * to synth time. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/guardrails/guardrails.ts#L556-L569
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Guardrail.generateCfnSensitiveInformationPolicyConfig
private generateCfnSensitiveInformationPolicyConfig(): IResolvable { return Lazy.any( { produce: () => { if (this.regexFilters.length > 0 || this.piiFilters.length > 0) { return { regexesConfig: this.generateCfnRegexesConfig(), piiEntitiesConfig: this....
/** * Returns the sensitive information config applied to the guardrail. This method defers the computation * to synth time. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/guardrails/guardrails.ts#L575-L591
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Guardrail.generateCfnRegexesConfig
private generateCfnRegexesConfig(): IResolvable { return Lazy.any( { produce: () => { return this.regexFilters.flatMap((regex: filters.RegexFilter) => { return { name: regex.name, description: regex.description, pattern: regex.pattern, ...
/** * Returns the regex filters applied to the guardrail. This method defers the computation * to synth time. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/guardrails/guardrails.ts#L597-L613
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
Guardrail.generateCfnPiiEntitiesConfig
private generateCfnPiiEntitiesConfig(): IResolvable { return Lazy.any( { produce: () => { return this.piiFilters.flatMap((filter: filters.PIIFilter) => { return { type: filter.type, action: filter.action, } as bedrock.CfnGuardrail.PiiEntity...
/** * Returns the Pii filters applied to the guardrail. This method defers the computation * to synth time. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/guardrails/guardrails.ts#L619-L633
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
ApplicationInferenceProfile.fromApplicationInferenceProfileAttributes
public static fromApplicationInferenceProfileAttributes( scope: Construct, id: string, attrs: ApplicationInferenceProfileAttributes, ): IInferenceProfile { class Import extends InferenceProfileBase { public readonly inferenceProfileArn = attrs.inferenceProfileArn; public readonly inference...
/** * Import a ApplicationInferenceProfile given its attributes */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/inference-profiles/application-inference-profile.ts#L83-L96
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
ApplicationInferenceProfile.fromCfnApplicationInferenceProfile
public static fromCfnApplicationInferenceProfile( CfnApplicationInferenceProfile: bedrock.CfnApplicationInferenceProfile, ): IInferenceProfile { return new (class extends InferenceProfileBase { public readonly inferenceProfileArn = CfnApplicationInferenceProfile.attrInferenceProfileArn; public rea...
/** * Import a low-level L1 Cfn ApplicationInferenceProfile */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/inference-profiles/application-inference-profile.ts#L100-L108
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
ApplicationInferenceProfile.grantInvoke
public grantInvoke(grantee: IGrantable): Grant { // This method ensures the appropriate permissions are given // to use either the inference profile or the vanilla FM this.inferenceProfileModel.grantInvoke(grantee); // plus we add permissions to now invoke the application inference profile itself. ...
/** * Gives the appropriate policies to invoke and use the application inference profile. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/inference-profiles/application-inference-profile.ts#L187-L195
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
ApplicationInferenceProfile.grantProfileUsage
grantProfileUsage(grantee: IGrantable): Grant { const grant = Grant.addToPrincipal({ grantee: grantee, actions: ['bedrock:GetInferenceProfile', 'bedrock:InvokeModel'], resourceArns: [this.inferenceProfileArn], }); return grant; }
/** * Grants appropriate permissions to use the application inference profile (AIP). * Does not grant permissions to use the model/cross-region profile in the AIP. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/inference-profiles/application-inference-profile.ts#L201-L208
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
CrossRegionInferenceProfile.grantInvoke
public grantInvoke(grantee: IGrantable): Grant { // for CRIS, we need to provide permissions to invoke the model in all regions // where the inference profile can route requests this.inferenceProfileModel.grantInvokeAllRegions(grantee); // and we need to provide permissions to invoke the inference profi...
/** * Gives the appropriate policies to invoke and use the Foundation Model. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/inference-profiles/cross-region-inference-profile.ts#L139-L145
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
CrossRegionInferenceProfile.grantProfileUsage
grantProfileUsage(grantee: IGrantable): Grant { const grant = Grant.addToPrincipal({ grantee: grantee, actions: ['bedrock:GetInferenceProfile', 'bedrock:InvokeModel'], resourceArns: [this.inferenceProfileArn], }); return grant; }
/** * Grants appropriate permissions to use the cross-region inference profile. * Does not grant permissions to use the model in the profile. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/inference-profiles/cross-region-inference-profile.ts#L151-L158
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
KendraKnowledgeBase.fromKnowledgeBaseAttributes
public static fromKnowledgeBaseAttributes( scope: Construct, id: string, attrs: KendraKnowledgeBaseAttributes, ): IKendraKnowledgeBase { const stack = Stack.of(scope); class Import extends KendraKnowledgeBaseBase { public readonly role = iam.Role.fromRoleArn(this, `kb-${attrs.knowledgeBaseI...
// ------------------------------------------------------
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/knowledge-bases/kendra-knowledge-base.ts#L85-L106
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
VectorKnowledgeBase.fromKnowledgeBaseAttributes
public static fromKnowledgeBaseAttributes( scope: Construct, id: string, attrs: VectorKnowledgeBaseAttributes, ): IVectorKnowledgeBase { const stack = Stack.of(scope); class Import extends VectorKnowledgeBaseBase { public readonly role = iam.Role.fromRoleArn(this, `kb-${attrs.knowledgeBaseI...
// ------------------------------------------------------
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/knowledge-bases/vector-knowledge-base.ts#L276-L296
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
VectorKnowledgeBase.handleOpenSearchCollection
private handleOpenSearchCollection(props: VectorKnowledgeBaseProps): { vectorStore: VectorCollection; vectorStoreType: VectorStoreType; } { const vectorStore = props.vectorStore as VectorCollection; vectorStore.grantDataAccess(this.role); return { vectorStore: vectorStore, vectorStoreT...
/** * Handle VectorCollection type of VectorStore. * * @param props - The properties of the KnowledgeBase. * @returns The instance of VectorCollection, VectorStoreType. * @internal This is an internal core function and should not be called directly. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/knowledge-bases/vector-knowledge-base.ts#L613-L623
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
VectorKnowledgeBase.handlePineconeVectorStore
private handlePineconeVectorStore(props: VectorKnowledgeBaseProps): { vectorStore: PineconeVectorStore; vectorStoreType: VectorStoreType; } { const vectorStore = props.vectorStore as PineconeVectorStore; return { vectorStore: vectorStore, vectorStoreType: VectorStoreType.PINECONE, }; ...
/** * Handle PineconeVectorStore type of VectorStore. * * @param props - The properties of the KnowledgeBase. * @returns The instance of PineconeVectorStore, VectorStoreType. * @internal This is an internal core function and should not be called directly. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/knowledge-bases/vector-knowledge-base.ts#L632-L641
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
VectorKnowledgeBase.handleAmazonAuroraVectorStore
private handleAmazonAuroraVectorStore(props: VectorKnowledgeBaseProps): { vectorStore: AmazonAuroraVectorStore | ExistingAmazonAuroraVectorStore; vectorStoreType: VectorStoreType; } { const vectorStore = props.vectorStore instanceof ExistingAmazonAuroraVectorStore ? props.vectorStore ...
/** * Handle AmazonAuroraVectorStore type of VectorStore. * * @param props - The properties of the KnowledgeBase. * @returns The instance of AmazonAuroraVectorStore, VectorStoreType. * @internal This is an internal core function and should not be called directly. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/knowledge-bases/vector-knowledge-base.ts#L650-L662
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
VectorKnowledgeBase.handleOpenSearchDefaultVectorCollection
private handleOpenSearchDefaultVectorCollection(): { vectorStore: VectorCollection; vectorStoreType: VectorStoreType; } { const vectorStore = new VectorCollection(this, 'KBVectors'); vectorStore.grantDataAccess(this.role); return { vectorStore: vectorStore, vectorStoreType: VectorStore...
/** * Handle the default VectorStore type. * * @returns The instance of VectorCollection, VectorStoreType. * @internal This is an internal core function and should not be called directly. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/knowledge-bases/vector-knowledge-base.ts#L670-L680
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
VectorKnowledgeBase.associateToAgent
public associateToAgent(agent: Agent) { agent.addKnowledgeBase(this); }
/** * Associate knowledge base with an agent */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/knowledge-bases/vector-knowledge-base.ts#L685-L687
5613c3d7c1b49bb9b241c271c313109f217e1296
generative-ai-cdk-constructs
github_2023
awslabs
typescript
validateModel
function validateModel(foundationModel: BedrockFoundationModel) { if (!foundationModel.supportsKnowledgeBase) { throw new Error(`The model ${foundationModel} is not supported by Bedrock Knowledge Base.`); } }
/** * Validate that Bedrock Knowledge Base can use the selected model. * * @internal This is an internal core function and should not be called directly. */
https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/knowledge-bases/vector-knowledge-base.ts#L695-L699
5613c3d7c1b49bb9b241c271c313109f217e1296