repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | validateVectorIndex | function validateVectorIndex(vectorStore: any, vectorIndex: any, vectorField: any, indexName: any) {
if (!(vectorStore instanceof VectorCollection) && vectorIndex) {
throw new Error(
'If vectorStore is not of type VectorCollection, vectorIndex should not be provided ' +
'in KnowledgeBase construct.'... | /**
* Validate if VectorIndex was provided for a VectorStore of type
* other than `VectorCollection`.
*
* @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#L707-L726 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | validateIndexParameters | function validateIndexParameters(vectorIndex: VectorIndex, indexName: string, vectorField: string) {
if (vectorIndex.indexName !== 'bedrock-knowledge-base-default-index') {
if (vectorIndex.indexName !== indexName) {
throw new Error(
'Default value of indexName is `bedrock-knowledge-base-default-inde... | /**
* Validate that indexName and vectorField parameters are identical
* in KnowledgeBase construct if VectorIndex was created manually.
*
* By default we assign `vectorIndex` to `bedrock-knowledge-base-default-index`
* value and if user provides `vectorIndex` manually, we need to make sure
* they also provide it... | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/knowledge-bases/vector-knowledge-base.ts#L739-L762 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | getStorageConfiguration | function getStorageConfiguration(params: StorageConfiguration): any {
switch (params.vectorStoreType) {
case VectorStoreType.OPENSEARCH_SERVERLESS:
params.vectorStore = params.vectorStore as VectorCollection;
return {
type: VectorStoreType.OPENSEARCH_SERVERLESS,
opensearchServerlessCon... | /**
* Determine storage configuration based on vector store type.
*
* @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#L769-L822 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | ChatMessage.__render | public __render(): CfnPrompt.MessageProperty {
return {
role: this.role,
content: [
{
text: this.text,
},
],
};
} | /**
* Renders as Cfn Property
* @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/prompts/prompt-variant.ts#L112-L121 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | ToolChoice.specificTool | public static specificTool(toolName: string) {
return new ToolChoice(undefined, undefined, toolName);
} | /** The Model must request the specified tool. Only supported by some models like Anthropic Claude 3 models. */ | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/prompts/prompt-variant.ts#L135-L137 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | ToolChoice.__render | public __render(): CfnPrompt.ToolChoiceProperty {
return {
any: this.any,
auto: this.auto,
tool: this.tool ? { name: this.tool } : undefined,
};
} | /**
*
* @internal
*/ | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/prompts/prompt-variant.ts#L149-L155 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | Prompt.fromPromptAttributes | public static fromPromptAttributes(scope: Construct, id: string, attrs: PromptAttributes): IPrompt {
const formattedArn = Arn.split(attrs.promptArn, ArnFormat.SLASH_RESOURCE_NAME);
class Import extends PromptBase {
public readonly promptArn = attrs.promptArn;
public readonly promptId = formattedArn.... | // ------------------------------------------------------ | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/prompts/prompt.ts#L138-L148 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | Prompt.constructor | constructor(scope: Construct, id: string, props: PromptProps) {
super(scope, id);
// ------------------------------------------------------
// Set properties or defaults
// ------------------------------------------------------
this.promptName = props.promptName;
this.kmsKey = props.kmsKey;
... | // ------------------------------------------------------ | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/prompts/prompt.ts#L191-L230 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | Prompt.validatePromptName | private validatePromptName() {
const errors: string[] = [];
const matchesPattern = /^([0-9a-zA-Z][_-]?){1,100}$/.test(this.promptName);
if (!matchesPattern) {
errors.push(
'Valid characters are a-z, A-Z, 0-9, _ (underscore) and - (hyphen). And must not begin with a hyphen',
);
}
... | /**
* Validates whether the prompt name is valid according to the specification.
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-bedrock-prompt.html#cfn-bedrock-prompt-name
*/ | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/prompts/prompt.ts#L239-L252 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | Prompt.validatePromptVariants | private validatePromptVariants() {
const MAX_VARIANTS = 3;
const errors: string[] = [];
if (this.variants.length > MAX_VARIANTS) {
errors.push(
`Error: Too many variants specified. The maximum allowed is ${MAX_VARIANTS}, but you have provided ${this.variants.length} variants.`,
);
}
... | /**
* Validates whether the number of prompt variants is respected.
*/ | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/prompts/prompt.ts#L257-L266 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | Prompt.createVersion | public createVersion(description?: string): string {
const version = new bedrock.CfnPromptVersion(this, `PromptVersion-${this._hash}`, {
promptArn: this.promptArn,
description,
});
this.promptVersion = version.attrVersion;
return this.promptVersion;
} | /**
* Creates a prompt version, a static snapshot of your prompt that can be
* deployed to production.
*/ | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/prompts/prompt.ts#L275-L282 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | Prompt.addVariant | public addVariant(variant: PromptVariant) {
this.variants.push(variant);
} | /**
* Adds a prompt variant.
*/ | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/bedrock/prompts/prompt.ts#L287-L289 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | KendraGenAiIndex.fromAttrs | public static fromAttrs(scope: Construct, id: string, attrs: KendraGenAiIndexAttributes): IKendraGenAiIndex {
class Import extends KendraGenAiIndexBase {
public readonly role = attrs.role;
public readonly indexId = attrs.indexId;
public readonly indexArn = Stack.of(this).formatArn({
servic... | /**
* Import a guardrail given its attributes
*/ | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/kendra/gen-ai-index.ts#L162-L174 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | VectorCollection.metricAll | public static metricAll(metricName: string, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return new cloudwatch.Metric({
namespace: 'AWS/AOSS',
metricName,
statistic: 'Sum',
...props,
});
} | /**
* Return metrics for all vector collections.
*/ | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/opensearchserverless/vector-collection.ts#L254-L261 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | VectorCollection.metricAllSearchRequestCount | public static metricAllSearchRequestCount(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.metricAll('SearchRequestCount', props);
} | /**
* Metric for the total number of search requests across all collections.
*/ | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/opensearchserverless/vector-collection.ts#L266-L268 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | VectorCollection.metricAllIndexRequestCount | public static metricAllIndexRequestCount(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.metricAll('IndexRequestCount', props);
} | /**
* Metric for the total number of index requests across all collections.
*/ | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/opensearchserverless/vector-collection.ts#L273-L275 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | VectorCollection.metricAllSearchLatency | public static metricAllSearchLatency(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.metricAll('SearchLatency', {
statistic: 'Average',
...props,
});
} | /**
* Metric for average search latency across all collections.
*/ | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/opensearchserverless/vector-collection.ts#L280-L285 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | VectorCollection.fromCollectionAttributes | public static fromCollectionAttributes(
constructScope: Construct,
constructId: string,
attrs: VectorCollectionAttributes,
): IVectorCollection {
class Import extends VectorCollectionBase {
public readonly collectionArn = attrs.collectionArn;
public readonly collectionId = attrs.collection... | /**
* Import an existing collection using its attributes.
* @param constructScope The parent creating construct.
* @param constructId The construct's name.
* @param attrs The collection attributes to use.
*/ | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/opensearchserverless/vector-collection.ts#L293-L328 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | VectorCollection.grantDataAccess | grantDataAccess(grantee: iam.IRole) {
this.dataAccessPolicyDocument.push({
Rules: [
{
Resource: [`collection/${this.collectionName}`],
Permission: [
'aoss:DescribeCollectionItems',
'aoss:CreateCollectionItems',
'aoss:UpdateCollectionItems',
... | /**
* Grants the specified role access to data in the collection.
* @param grantee The role to grant access to.
*/ | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/cdk-lib/opensearchserverless/vector-collection.ts#L482-L512 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | BaseClass.updateEnvSuffix | protected updateEnvSuffix(props: BaseClassProps) {
let stage = '-dev';
if (props?.stage) {
stage = props.stage;
}
this.stage = stage;
} | //overwrite default env suffix | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/common/base-class/base-class.ts#L113-L119 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | BaseClass.updateConstructUsageMetricCode | protected updateConstructUsageMetricCode(props: BaseClassProps, scope: Construct, lambdaFunctions: lambda.DockerImageFunction[],
) {
const solutionId = `genai_cdk_${version}/${props.constructName}/${props.constructId}`;
if (lambdaFunctions
&& lambdaFunctions.length > 0) {
for (let lambdaFunctio... | /*
* update template description with construct usage metric and
* add AWS_SDK_UA_APP_ID to user agent on aws sdk.
*/ | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/common/base-class/base-class.ts#L125-L151 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | BaseClass.addObservabilityToConstruct | protected addObservabilityToConstruct(props: BaseClassProps) {
if (props.observability == false) {
this.enablexray = false;
this.lambdaTracing = lambda.Tracing.DISABLED;
this.fieldLogLevel = appsync.FieldLogLevel.NONE;
this.retention = logs.RetentionDays.TEN_YEARS;
};
} | // observability | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/common/base-class/base-class.ts#L154-L161 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | getRedisSubnetGroup | function getRedisSubnetGroup(scope: Construct, props: RedisProps): elasticache.CfnSubnetGroup {
let redisSubnetGroup = new elasticache.CfnSubnetGroup(scope, 'redisSubnetGroup', {
description: 'Redis subnet group',
subnetIds: props.subnetIds,
});
return redisSubnetGroup;
} | // get redis subnet group from existing vpc | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/common/helpers/redis-helper.ts#L96-L102 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | AossCwDashboard.constructor | constructor(scope: Construct, id: string, props: AossCwDashboardProps) {
super(scope, id);
this.dashboard = props.existingDashboard ?? new Dashboard(this, 'AossMetricsDashboard', {
dashboardName: props.dashboardName ?? 'AossMetricsDashboard',
});
} | /**
* Constructs a new instance of the AossCwDashboard class.
* @param {cdk.App} scope - represents the scope for all the resources.
* @param {string} id - this is a a scope-unique id.
* @param {AossCwDashboardProps} props - user provided props for the construct.
* @since 0.0.0
* @public
*/ | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/patterns/gen-ai/aws-aoss-cw-dashboard/index.ts#L101-L107 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | AossCwDashboard.addCollectionMonitoringbyAttributes | public addCollectionMonitoringbyAttributes(collectionName: string, collectionId: string, props: CollectionMonitoringProps) {
const period = props.period ?? Duration.hours(1);
const clientId = props.clientId ?? Aws.ACCOUNT_ID;
const dimensionMap = {
ClientId: clientId,
CollectionId: collectionI... | /* Provide metrics for a specific aoss collection
* @param {string} collectionName - Name of the aoss collection to monitor.
* @param {string} collectionId - Id of the aoss collection to monitor.
* @param {CollectionMonitoringProps} props - user provided props for monitoring.
*/ | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/patterns/gen-ai/aws-aoss-cw-dashboard/index.ts#L114-L252 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | AossCwDashboard.addCollectionMonitoringByCollection | public addCollectionMonitoringByCollection(collection: CfnCollection, props: CollectionMonitoringProps) {
this.addCollectionMonitoringbyAttributes(collection.name, collection.attrId, props);
} | /* Provide metrics for a specific aoss collection
* @param {string} collection - CfnCollection to monitor.
* @param {CollectionMonitoringProps} props - user provided props for monitoring.
*/ | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/patterns/gen-ai/aws-aoss-cw-dashboard/index.ts#L258-L262 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | AossCwDashboard.addIndexMonitoringByAtributes | public addIndexMonitoringByAtributes(
collectionName: string,
collectionId: string,
IndexName: string,
IndexId: string,
props: IndexMonitoringProps,
) {
const period = props.period ?? Duration.hours(1);
const clientId = props.clientId ?? Aws.ACCOUNT_ID;
const dimensionMap = {
C... | /* Provide metrics for a specific aoss index
* @param {string} collectionName - Name of the aoss collection to monitor.
* @param {string} collectionId - Id of the aoss collection to monitor.
* @param {string} IndexName - Name of the aoss index to monitor.
* @param {string} IndexId - Id of the aoss index to ... | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/patterns/gen-ai/aws-aoss-cw-dashboard/index.ts#L271-L373 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | BedrockCwDashboard.constructor | constructor(scope: Construct, id: string, props: BedrockCwDashboardProps = {}) {
super(scope, id);
this.dashboard = props.existingDashboard ?? new Dashboard(this, `BedrockMetricsDashboard${id}`, {
dashboardName: props.dashboardName ?? 'BedrockMetricsDashboard',
});
const cloudwatchDashboardURL =... | /**
* Constructs a new instance of the BedrockCwDashboard class.
* @param {cdk.App} scope - represents the scope for all the resources.
* @param {string} id - this is a a scope-unique id.
* @param {BedrockCwDashboardProps} props - user provided props for the construct.
* @since 0.0.0
* @public
*/ | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/patterns/gen-ai/aws-bedrock-cw-dashboard/index.ts#L111-L123 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | BedrockCwDashboard.addModelMonitoring | public addModelMonitoring(modelName: string, modelId: string, props: ModelMonitoringProps = {}) {
const period = props.period ?? Duration.hours(1);
const outputImageCountDimension = modelId + props.imageSize + props.bucketedStepSize;
const modelInputTokensMetric = new Metric({
namespace: 'AWS/Bedroc... | /* Provide metrics for a specific model id in Bedrock
* @param {string} modelName - Model name as it will appear in the dashboard row widget.
* @param {string} modelId - Bedrock model id as defined in https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html
* @param {ModelMonitoringProps} props - us... | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/patterns/gen-ai/aws-bedrock-cw-dashboard/index.ts#L130-L364 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | BedrockCwDashboard.addAllModelsMonitoring | public addAllModelsMonitoring(props: ModelMonitoringProps = {}) {
const period = props.period ?? Duration.hours(1);
// Metrics across all Model Ids
const inputTokensAllModelsMetric = new Metric({
namespace: 'AWS/Bedrock',
metricName: 'InputTokenCount',
statistic: Stats.SUM,
period:... | /* Add a new row to the dashboard providing metrics across all model ids in Bedrock
* @param {ModelMonitoringProps} props - user provided props for the monitoring.
*/ | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/patterns/gen-ai/aws-bedrock-cw-dashboard/index.ts#L369-L519 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | ContentGenerationAppSyncLambda.constructor | constructor(scope: Construct, id: string, props: ContentGenerationAppSyncLambdaProps) {
super(scope, id);
Annotations.of(scope).addWarningV2('@cdklabs/generative-ai-cdk-constructs:ContentGenerationAppSyncLambda.deprecation',
'This construct is deprecated and will not receive further support. It will be r... | /**
* Constructs a new instance of the ContentGenerationAppSyncLambda class.
* @param {cdk.App} scope - represents the scope for all the resources.
* @param {string} id - this is a a scope-unique id.
* @param {ContentGenerationAppSyncLambdaProps} props - user provided props for the construct.
* @since 0.... | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/patterns/gen-ai/aws-contentgen-appsync-lambda/index.ts#L159-L564 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | SageMakerInstanceType.of | public static of(instanceType: string): SageMakerInstanceType {
return new SageMakerInstanceType(instanceType);
} | /**
* Builds an InstanceType from a given string or token (such as a CfnParameter).
* @param instanceType An instance type as string
* @returns A strongly typed InstanceType
*/ | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/patterns/gen-ai/aws-model-deployment-sagemaker/sagemaker-instance-type.ts#L465-L467 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | SageMakerInstanceType.toString | public toString(): string {
return this.instanceTypeIdentifier;
} | /**
* Return the instance type as a string
* @returns The instance type as a string
*/ | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/patterns/gen-ai/aws-model-deployment-sagemaker/sagemaker-instance-type.ts#L483-L485 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | QaAppsyncOpensearch.constructor | constructor(scope: Construct, id: string, props: QaAppsyncOpensearchProps) {
super(scope, id);
Annotations.of(scope).addWarningV2('@cdklabs/generative-ai-cdk-constructs:QaAppsyncOpensearch.deprecation',
'This construct is deprecated and will not receive further support. It will be removed in the next rel... | /**
* Constructs a new instance of the RagAppsyncStepfnOpensearch class.
* @param {cdk.App} scope - represents the scope for all the resources.
* @param {string} id - this is a scope-unique id.
* @param {QaAppsyncOpensearchProps} props - user provided props for the construct.
* @since 0.0.0
* @public
... | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/patterns/gen-ai/aws-qa-appsync-opensearch/index.ts#L192-L636 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | RagAppsyncStepfnOpensearch.constructor | constructor(scope: Construct, id: string, props: RagAppsyncStepfnOpensearchProps) {
super(scope, id);
Annotations.of(scope).addWarningV2('@cdklabs/generative-ai-cdk-constructs:RagAppsyncStepfnOpensearch.deprecation',
'This construct is deprecated and will not receive further support. It will be removed i... | /**
* Constructs a new instance of the RagAppsyncStepfnOpensearch class.
* @param {cdk.App} scope - represents the scope for all the resources.
* @param {string} id - this is a scope-unique id.
* @param {RagAppsyncStepfnOpensearchProps} props - user provided props for the construct.
* @since 0.... | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/patterns/gen-ai/aws-rag-appsync-stepfn-opensearch/index.ts#L233-L918 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | SummarizationAppsyncStepfn.constructor | constructor(scope: Construct, id: string, props: SummarizationAppsyncStepfnProps) {
super(scope, id);
Annotations.of(scope).addWarningV2('@cdklabs/generative-ai-cdk-constructs:SummarizationAppsyncStepfn.deprecation',
'This construct is deprecated and will not receive further support. It will be removed i... | /**
* Constructs a new instance of the SummarizationAppsyncStepfn class.
* @param {Construct} scope - represents the scope for all the resources.
* @param {string} id - this is a a scope-unique id.
* @param {SummarizationAppsyncStepfnProps} props - user provided props for the construct.
* @sinc... | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/patterns/gen-ai/aws-summarization-appsync-stepfn/index.ts#L244-L887 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | TextToSql.constructor | constructor(scope: Construct, id: string, props: TextToSqlProps) {
super(scope, id);
Annotations.of(scope).addWarningV2('@cdklabs/generative-ai-cdk-constructs:TextToSql.deprecation',
'This construct is deprecated and will not receive further support. It will be removed in the next release of the library.... | /**
* Constructs a new instance of the TextToSql class.
* @param {Construct} scope - represents the scope for all the resources.
* @param {string} id - this is a a scope-unique id.
* @param {TextToSqlProps} props - user provided props for the construct.
* @since 0.0.0
* @public
*/ | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/src/patterns/gen-ai/aws-text-to-sql/index.ts#L251-L1080 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | t | const t = () => {
new JumpStartSageMakerEndpoint(JmpStrtTestStack, 'test', {
model: JumpStartModel.META_TEXTGENERATION_LLAMA_2_7B_F_2_0_2,
acceptEula: false, // should fail synth
instanceType: SageMakerInstanceType.ML_G5_2XLARGE,
endpointName: 'testendpoint',
});
}; | //wrapping code in a function, otherwise the error will not be caught and the assertion will fail. | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/test/patterns/gen-ai/aws-model-deployment-sagemaker/aws-sagemaker-jumpstart-endpoint.test.ts#L119-L126 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | t | const t = () => {
new JumpStartSageMakerEndpoint(JmpStrtTestStack, 'test2', {
model: JumpStartModel.META_TEXTGENERATION_LLAMA_2_7B_F_2_0_2,
acceptEula: true, // should succeed synth
instanceType: SageMakerInstanceType.ML_G5_2XLARGE,
endpointName: 'testendpoint',
});
}; | //wrapping code in a function, otherwise the error will not be caught and the assertion will fail. | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/test/patterns/gen-ai/aws-model-deployment-sagemaker/aws-sagemaker-jumpstart-endpoint.test.ts#L134-L141 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
generative-ai-cdk-constructs | github_2023 | awslabs | typescript | t | const t = () => {
new JumpStartSageMakerEndpoint(JmpStrtTestStack, 'test3', {
model: JumpStartModel.MODEL_DEPTH2IMG_STABLE_DIFFUSION_V1_5_CONTROLNET_1_0_0, // eula not defined
instanceType: SageMakerInstanceType.ML_G5_2XLARGE,
endpointName: 'testendpoint',
});
}; | //wrapping code in a function, otherwise the error will not be caught and the assertion will fail. | https://github.com/awslabs/generative-ai-cdk-constructs/blob/5613c3d7c1b49bb9b241c271c313109f217e1296/test/patterns/gen-ai/aws-model-deployment-sagemaker/aws-sagemaker-jumpstart-endpoint.test.ts#L149-L155 | 5613c3d7c1b49bb9b241c271c313109f217e1296 |
next-shared-cache | github_2023 | caching-tools | typescript | removeEntryFromHandlers | async function removeEntryFromHandlers(
handlers: Handler[],
key: string,
debug: boolean,
): Promise<void> {
if (debug) {
console.info(
'[CacheHandler] [method: %s] [key: %s] %s',
'delete',
key,
'Started deleting entry from Handlers.',
);
}
const operationsResults = await Pr... | /**
* Deletes an entry from all handlers.
*
* @param handlers - The list of handlers.
* @param key - The key to delete.
* @param debug - Whether to log debug messages.
*
* @returns A Promise that resolves when all handlers have finished deleting the entry.
*/ | https://github.com/caching-tools/next-shared-cache/blob/9144fc50d616df2393c04a95db06bbed9abdb6d0/packages/cache-handler/src/cache-handler.ts#L284-L325 | 9144fc50d616df2393c04a95db06bbed9abdb6d0 |
next-shared-cache | github_2023 | caching-tools | typescript | CacheHandler.name | static get name(): string {
if (CacheHandler.#cacheListLength === undefined) {
return '@neshca/cache-handler is not configured yet';
}
return `@neshca/cache-handler with ${CacheHandler.#cacheListLength} Handler${
CacheHandler.#cacheListLength > 1 ? 's' : ''
}`;
} | /**
* Provides a descriptive name for the CacheHandler class.
*
* The name includes the number of handlers and whether file system caching is used.
* If the cache handler is not configured yet, it will return a string indicating so.
*
* This property is primarily intended for debugging purposes
* a... | https://github.com/caching-tools/next-shared-cache/blob/9144fc50d616df2393c04a95db06bbed9abdb6d0/packages/cache-handler/src/cache-handler.ts#L359-L367 | 9144fc50d616df2393c04a95db06bbed9abdb6d0 |
next-shared-cache | github_2023 | caching-tools | typescript | CacheHandler.onCreation | static onCreation(onCreationHook: OnCreationHook): void {
CacheHandler.#onCreationHook = onCreationHook;
} | /**
* Registers a hook to be called during the creation of an CacheHandler instance.
* This method allows for custom cache configurations to be applied at the time of cache instantiation.
*
* The provided {@link OnCreationHook} function can perform initialization tasks, modify cache settings,
* or integr... | https://github.com/caching-tools/next-shared-cache/blob/9144fc50d616df2393c04a95db06bbed9abdb6d0/packages/cache-handler/src/cache-handler.ts#L569-L571 | 9144fc50d616df2393c04a95db06bbed9abdb6d0 |
next-shared-cache | github_2023 | caching-tools | typescript | CacheHandler.constructor | constructor(context: FileSystemCacheContext) {
CacheHandler.#context = context;
if (CacheHandler.#debug) {
console.info(
'[CacheHandler] %s',
'Instance created with provided context.',
);
}
} | /**
* Creates a new CacheHandler instance. Constructor is intended for internal use only.
*/ | https://github.com/caching-tools/next-shared-cache/blob/9144fc50d616df2393c04a95db06bbed9abdb6d0/packages/cache-handler/src/cache-handler.ts#L819-L828 | 9144fc50d616df2393c04a95db06bbed9abdb6d0 |
next-shared-cache | github_2023 | caching-tools | typescript | serializeArguments | function serializeArguments(object: object): string {
return JSON.stringify(object);
} | /**
* Serializes the given arguments into a string representation.
*
* @param object - The arguments to be serialized.
*
* @returns The serialized string representation of the arguments.
*/ | https://github.com/caching-tools/next-shared-cache/blob/9144fc50d616df2393c04a95db06bbed9abdb6d0/packages/cache-handler/src/functions/nesh-cache.ts#L78-L80 | 9144fc50d616df2393c04a95db06bbed9abdb6d0 |
next-shared-cache | github_2023 | caching-tools | typescript | serializeResult | function serializeResult(object: object): string {
return Buffer.from(JSON.stringify(object), 'utf-8').toString('base64');
} | /**
* Serializes the given object into a string representation.
*
* @param object - The object to be serialized.
*
* @returns The serialized string representation of the object.
*/ | https://github.com/caching-tools/next-shared-cache/blob/9144fc50d616df2393c04a95db06bbed9abdb6d0/packages/cache-handler/src/functions/nesh-cache.ts#L89-L91 | 9144fc50d616df2393c04a95db06bbed9abdb6d0 |
next-shared-cache | github_2023 | caching-tools | typescript | deserializeResult | function deserializeResult<T>(string: string): T {
return JSON.parse(Buffer.from(string, 'base64').toString('utf-8'));
} | /**
* Deserializes a string representation of an object into its original form.
*
* @param string - The string representation of the object.
*
* @returns The deserialized object.
*/ | https://github.com/caching-tools/next-shared-cache/blob/9144fc50d616df2393c04a95db06bbed9abdb6d0/packages/cache-handler/src/functions/nesh-cache.ts#L100-L102 | 9144fc50d616df2393c04a95db06bbed9abdb6d0 |
next-shared-cache | github_2023 | caching-tools | typescript | serializeArguments | function serializeArguments(object: object): string {
return JSON.stringify(object);
} | /**
* Serializes the given arguments into a string representation.
*
* @param object - The arguments to be serialized.
*
* @returns The serialized string representation of the arguments.
*/ | https://github.com/caching-tools/next-shared-cache/blob/9144fc50d616df2393c04a95db06bbed9abdb6d0/packages/cache-handler/src/functions/nesh-classic-cache.ts#L30-L32 | 9144fc50d616df2393c04a95db06bbed9abdb6d0 |
next-shared-cache | github_2023 | caching-tools | typescript | serializeResult | function serializeResult(object: object): string {
return Buffer.from(JSON.stringify(object), 'utf-8').toString('base64');
} | /**
* Serializes the given object into a string representation.
*
* @param object - The object to be serialized.
*
* @returns The serialized string representation of the object.
*/ | https://github.com/caching-tools/next-shared-cache/blob/9144fc50d616df2393c04a95db06bbed9abdb6d0/packages/cache-handler/src/functions/nesh-classic-cache.ts#L41-L43 | 9144fc50d616df2393c04a95db06bbed9abdb6d0 |
next-shared-cache | github_2023 | caching-tools | typescript | deserializeResult | function deserializeResult<T>(string: string): T {
return JSON.parse(Buffer.from(string, 'base64').toString('utf-8'));
} | /**
* Deserializes a string representation of an object into its original form.
*
* @param string - The string representation of the object.
*
* @returns The deserialized object.
*/ | https://github.com/caching-tools/next-shared-cache/blob/9144fc50d616df2393c04a95db06bbed9abdb6d0/packages/cache-handler/src/functions/nesh-classic-cache.ts#L52-L54 | 9144fc50d616df2393c04a95db06bbed9abdb6d0 |
wishful-search | github_2023 | hrishioa | typescript | MARKDOWN_TEMPLATE | const MARKDOWN_TEMPLATE = (inputObj: any, typespec: string, ddlExplanation: string | null, ddl: string | null, structuredDDL: string | null, objectToRow: string | null) =>
`# Automated Object Analysis
*All the key information in this file was generated by an LLM. Treat it as a starting point, don't ever run auto-genera... | // prettier-ignore | https://github.com/hrishioa/wishful-search/blob/593d5076d144b1db9d4a279c213d963371361ad5/src/auto-analyze.ts#L6-L59 | 593d5076d144b1db9d4a279c213d963371361ad5 |
wishful-search | github_2023 | hrishioa | typescript | LLMSearcheableDatabase.create | static async create<RowObject>(
strDDL: string,
dbName: string,
key: DBColumn,
objectToTabledRow: (rowObject: RowObject) => any[][],
sqljsWasmURL?: string,
) {
const sqljsOptions: {
locateFile?: (filename: string) => string;
} = {
locateFile: sqljsWasmURL ? () => sqljsWasmURL :... | /**
* Static factory function since we can't have async constructors.
* Creates a new database instance with own sqljs and tables.
* @param strDDL table definitions in SQL, .e.g. 'CREATE TABLE...'
* @param dbName Name of the database. Mainly for labelling.
* @param key The primary key of the entire datab... | https://github.com/hrishioa/wishful-search/blob/593d5076d144b1db9d4a279c213d963371361ad5/src/db.ts#L33-L60 | 593d5076d144b1db9d4a279c213d963371361ad5 |
wishful-search | github_2023 | hrishioa | typescript | LLMSearcheableDatabase.getTableNames | private getTableNames(): string[] {
const result = this.db.exec(
'SELECT name FROM sqlite_master WHERE type="table"',
);
if (!result || !result.length || !result[0])
throw new Error('No tables found in database');
const tableNames = result[0].values.flat() as string[];
return tableNames;... | /**
* Dynamically retrieve the list of tables from the database.
* TODO: See if it's better to just use the structured DDL.
* @returns
*/ | https://github.com/hrishioa/wishful-search/blob/593d5076d144b1db9d4a279c213d963371361ad5/src/db.ts#L87-L95 | 593d5076d144b1db9d4a279c213d963371361ad5 |
wishful-search | github_2023 | hrishioa | typescript | LLMSearcheableDatabase.getEnums | getEnums(column: DBColumn, sortByFrequency: boolean = false): string[] {
const query = sortByFrequency
? `SELECT ${column.column}, COUNT(${column.column}) as frequency
FROM ${column.table}
GROUP BY ${column.column}
ORDER BY frequency DESC;`
: `SELECT DISTINCT ${column.column} FROM ${column.t... | /**
* Retrieves the distinct values being stored in a column.
* @param column table name and column name.
* @param sortByFrequency sorts the returned values by most frequent first.
* @returns string array of distinct values in the column,
*/ | https://github.com/hrishioa/wishful-search/blob/593d5076d144b1db9d4a279c213d963371361ad5/src/db.ts#L103-L120 | 593d5076d144b1db9d4a279c213d963371361ad5 |
wishful-search | github_2023 | hrishioa | typescript | LLMSearcheableDatabase.rawQuery | rawQuery(query: string): string[] {
const prohibitedKeywords = [
'INSERT',
'UPDATE',
'DELETE',
'CREATE',
'ALTER',
'DROP',
'PRAGMA',
'BEGIN',
'COMMIT',
'ROLLBACK',
'REPLACE',
];
query = query.split(';')[0]!.trim();
for (const keyword of ... | /**
* Execute a raw search query against the database.
* @param query string query, must start with 'SELECT'
* @returns
*/ | https://github.com/hrishioa/wishful-search/blob/593d5076d144b1db9d4a279c213d963371361ad5/src/db.ts#L127-L162 | 593d5076d144b1db9d4a279c213d963371361ad5 |
wishful-search | github_2023 | hrishioa | typescript | LLMSearcheableDatabase.delete | delete(keys: string[]) {
const placeholders = keys.map((_) => '?').join(',');
const query = `DELETE FROM ${this.key.table} WHERE ${this.key.column} IN (${placeholders})`;
this.db.run(query, keys);
} | /**
* Delete specified keys from the database.
* @param keys
*/ | https://github.com/hrishioa/wishful-search/blob/593d5076d144b1db9d4a279c213d963371361ad5/src/db.ts#L195-L201 | 593d5076d144b1db9d4a279c213d963371361ad5 |
wishful-search | github_2023 | hrishioa | typescript | LLMSearcheableDatabase.insert | insert(
elements: RowObject[],
errorOnInvalidRows = false,
): InsertionErroredRow[] {
const rows = elements.map((object) => this.objectToTabledRow(object));
const validRows = rows.filter(
(row) => row.length === this.tableNames.length,
);
if (validRows.length !== rows.length && errorOn... | /**
* Insert elements into the database for searching.
* @param elements Array of elements
* @param errorOnInvalidRows Whether to throw an error and halt
* the entire db transaction when one object fails to insert.
* Otherwise, a list of errors in returned as an array.
* @returns List of failed object... | https://github.com/hrishioa/wishful-search/blob/593d5076d144b1db9d4a279c213d963371361ad5/src/db.ts#L211-L286 | 593d5076d144b1db9d4a279c213d963371361ad5 |
wishful-search | github_2023 | hrishioa | typescript | LLMSearcheableDatabase.clearDb | clearDb() {
this.db.close();
this.db = new this.sqljsSQL.Database();
this.db.run(this.strDDL);
} | /**
* Clear and reset the entire database completely.
*/ | https://github.com/hrishioa/wishful-search/blob/593d5076d144b1db9d4a279c213d963371361ad5/src/db.ts#L291-L295 | 593d5076d144b1db9d4a279c213d963371361ad5 |
wishful-search | github_2023 | hrishioa | typescript | WishfulSearchEngine.create | static async create<ElementType>(
name: string,
tables: DDLTable[],
primaryKey: DBColumn,
objectToTabledRow: (element: ElementType) => any[][],
llmConfig: LLMConfig,
callLLM: LLMCallFunc | null,
getKeyFromObject: ((element: ElementType) => string) | null,
saveHistory: boolean = true,
... | /**
* Creates and returns an instance of wishful search engine.
* @param name Name of the engine/db - for labelling.
* @param tables Structured table definitions. See generateSQLDDL
* for how this is used to create the final string DDL.
* @param primaryKey primary index of the entire database, to be used... | https://github.com/hrishioa/wishful-search/blob/593d5076d144b1db9d4a279c213d963371361ad5/src/search-engine.ts#L74-L111 | 593d5076d144b1db9d4a279c213d963371361ad5 |
wishful-search | github_2023 | hrishioa | typescript | WishfulSearchEngine.getQueryPrefix | private getQueryPrefix(complexQuery: boolean = false) {
if (complexQuery) return 'SELECT ';
return `SELECT ${this.primaryKey.column} FROM ${this.primaryKey.table}`;
} | /**
* The query prefix makes sure that the SQL being run is a
* SELECT query, and that it fetches the db primary key.
* @returns
*/ | https://github.com/hrishioa/wishful-search/blob/593d5076d144b1db9d4a279c213d963371361ad5/src/search-engine.ts#L138-L141 | 593d5076d144b1db9d4a279c213d963371361ad5 |
wishful-search | github_2023 | hrishioa | typescript | WishfulSearchEngine.computeEnums | private computeEnums() {
if (!this.enableDynamicEnums) return;
for (const table of this.tables) {
for (const column of table.columns.filter(
(column) => column.dynamicEnumSettings !== undefined,
)) {
const enums = this.db.getEnums(
{
table: table.name,
... | /**
* Finds the distinct values for each column as specified in the ddl.
* Also converts them into distinct examples, min-max for numbers and
* dates, and truncates by some fixed character limit if
* necessary.
* @returns
*/ | https://github.com/hrishioa/wishful-search/blob/593d5076d144b1db9d4a279c213d963371361ad5/src/search-engine.ts#L150-L239 | 593d5076d144b1db9d4a279c213d963371361ad5 |
wishful-search | github_2023 | hrishioa | typescript | WishfulSearchEngine.insert | insert(elements: ElementType[], errorOnInvalidData = false) {
const insertErrors = this.db.insert(elements, errorOnInvalidData);
this.computeEnums();
if (this.getKeyFromObject && this.elementDict) {
for (const element of elements) {
this.elementDict[this.getKeyFromObject(element)] = element;... | /**
* Inserts an array of elements into the db and indexes them for use.
* @param elements Array of elements.
* @param errorOnInvalidData Throw an exception and rollback the full
* insert if a single row fails.
* @returns A list of indices and errros for the objects that failed.
*/ | https://github.com/hrishioa/wishful-search/blob/593d5076d144b1db9d4a279c213d963371361ad5/src/search-engine.ts#L248-L263 | 593d5076d144b1db9d4a279c213d963371361ad5 |
wishful-search | github_2023 | hrishioa | typescript | WishfulSearchEngine.remove | remove(elementIds?: string[]) {
if (this.elementDict) {
if (elementIds)
for (const elementId of elementIds) delete this.elementDict[elementId];
else this.elementDict = {};
}
if (elementIds) return this.db.delete(elementIds);
else return this.db.clearDb();
} | /**
* Removes elements from the engine. Nukes the entire db if called
* without a list.
* @param elementIds (Optional) array of elements.
* @returns
*/ | https://github.com/hrishioa/wishful-search/blob/593d5076d144b1db9d4a279c213d963371361ad5/src/search-engine.ts#L271-L280 | 593d5076d144b1db9d4a279c213d963371361ad5 |
wishful-search | github_2023 | hrishioa | typescript | WishfulSearchEngine.generateSearchMessages | generateSearchMessages(question: string, complexQuery: boolean = false) {
if (this.saveHistory) this.latestIncompleteQuestion = question;
const queryPrefix = this.getQueryPrefix(complexQuery);
const messages = generateLLMMessages(
generateSQLDDL(this.tables, true),
question,
queryPrefix,... | /**
* Generates the search messages to the LLM based on the question.
* You can use this to retrieve a fully formatted prompt if you'd
* like to manipulate it or make your own calls.
* @param question A question from the user about the dataset.
* @returns List of OpenAI-structured messages to the LLM.
... | https://github.com/hrishioa/wishful-search/blob/593d5076d144b1db9d4a279c213d963371361ad5/src/search-engine.ts#L289-L309 | 593d5076d144b1db9d4a279c213d963371361ad5 |
wishful-search | github_2023 | hrishioa | typescript | WishfulSearchEngine.searchWithPartialQuery | searchWithPartialQuery(
partialQuery: string,
printQuery?: boolean,
complexQuery: boolean = false,
): RawResults | ElementType[] {
if (this.saveHistory && this.latestIncompleteQuestion)
this.history.push({
complexQuery,
question: this.latestIncompleteQuestion,
partialQuer... | /**
* Searches the engine if you have a partial query from the LLM.
* @param partialQuery A query (excluding the search prefix like
* 'SELECT id from elements ') to run against the db.
* @returns list of elements if getKeyFromObject is provided, else
* returns a list of keys.
*/ | https://github.com/hrishioa/wishful-search/blob/593d5076d144b1db9d4a279c213d963371361ad5/src/search-engine.ts#L322-L351 | 593d5076d144b1db9d4a279c213d963371361ad5 |
wishful-search | github_2023 | hrishioa | typescript | WishfulSearchEngine.getQueryFromLLM | async getQueryFromLLM(
messages: LLMCompatibleMessage[],
complexQuery: boolean = false,
) {
if (!this.callLLM)
throw new Error(
'No LLM call function provided. Use generateSearchMessages instead if you intent to make your own calls.',
);
let partialQuery = await this.callLLM(
... | /**
* Calls the LLM with generated search messages to get the partial query.
* Does some additional string processing as needed, to make sure we have a partial query.
* @param messages
* @returns
*/ | https://github.com/hrishioa/wishful-search/blob/593d5076d144b1db9d4a279c213d963371361ad5/src/search-engine.ts#L359-L413 | 593d5076d144b1db9d4a279c213d963371361ad5 |
wishful-search | github_2023 | hrishioa | typescript | WishfulSearchEngine.autoSearch | async autoSearch(
userQuestion: string,
toStringFunc: (element: ElementType) => string,
optimizationRounds: number,
successThreshold: number,
callLLM?: LLMCallFunc | null,
printQueries?: boolean,
verbose?: boolean,
currentQuestion?: string,
history?: AutoSearchHistoryElement[],
): ... | /**
* Runs more complex looping search until the best result is found.
* @param userQuestion The original user question.
* @param toStringFunc Function to stringify an element. Shorter is better, but include key fields.
* @param optimizationRounds Maximum number of rounds to optimize result.
* @param suc... | https://github.com/hrishioa/wishful-search/blob/593d5076d144b1db9d4a279c213d963371361ad5/src/search-engine.ts#L428-L621 | 593d5076d144b1db9d4a279c213d963371361ad5 |
wishful-search | github_2023 | hrishioa | typescript | WishfulSearchEngine.search | async search(
question: string,
verbose?: boolean,
reflectAndFix?: boolean,
): Promise<RawResults | ElementType[]> {
const messages = this.generateSearchMessages(question);
const partialQuery = await this.getQueryFromLLM(messages);
try {
const results = this.searchWithPartialQuery(part... | /**
* Full search function that generates the LLM messages, calls
* the LLM, and returns either a list of keys or elements depending
* on instantiating config.
* @param question Search question from the user.
* @param verbose Print more output to the console.
* @param reflectAndFix If the query fails,... | https://github.com/hrishioa/wishful-search/blob/593d5076d144b1db9d4a279c213d963371361ad5/src/search-engine.ts#L667-L692 | 593d5076d144b1db9d4a279c213d963371361ad5 |
wishful-search | github_2023 | hrishioa | typescript | WishfulSearchEngine.tryAndFixQuery | async tryAndFixQuery(
searchMessages: LLMCompatibleMessage[],
partialQuery: string,
err: any,
complexQuery: boolean = false,
verbose?: boolean,
) {
if (verbose)
console.error(
'Error in query ',
partialQuery,
' - reflecting and fixing error ',
err,
)... | /**
* Reflect errors back to the LLM and get a fixed query.
* @param searchMessages
* @param partialQuery
* @param err
* @param verbose
* @returns
*/ | https://github.com/hrishioa/wishful-search/blob/593d5076d144b1db9d4a279c213d963371361ad5/src/search-engine.ts#L702-L735 | 593d5076d144b1db9d4a279c213d963371361ad5 |
wishful-search | github_2023 | hrishioa | typescript | WishfulSearchEngine.attemptReflection | async attemptReflection(
searchMessages: LLMCompatibleMessage[],
partialQuery: string,
err: any,
complexQuery: boolean = false,
verbose?: boolean,
) {
const fixedPartialQuery = await this.tryAndFixQuery(
searchMessages,
partialQuery,
err,
complexQuery,
verbose,
... | /**
* Reflect errors back to the LLM and attempt a fix.
* @param searchMessages
* @param partialQuery
* @param err
* @param verbose
* @returns
*/ | https://github.com/hrishioa/wishful-search/blob/593d5076d144b1db9d4a279c213d963371361ad5/src/search-engine.ts#L745-L767 | 593d5076d144b1db9d4a279c213d963371361ad5 |
wishful-search | github_2023 | hrishioa | typescript | WishfulSearchEngine.autoGenerateFewShot | async autoGenerateFewShot(
smarterCallLLMFunc: LLMCallFunc,
fewShotQuestions: {
question: string;
clearHistory?: boolean;
}[],
noQuestionsWithZeroResults: boolean = false,
errorOnInvalidQuestions: boolean = false,
verbose: boolean = false,
complexQuery: boolean = false,
): Prom... | /**
* Generate few-shot examples using a smarter model,
* that can be auto-emdedded in the prompt.
* @param smarterCallLLMFunc adapter call function from a smarter model.
* @param fewShotQuestions some questions to generate responses for. For longer contexts, clear the history at some point to teach the mod... | https://github.com/hrishioa/wishful-search/blob/593d5076d144b1db9d4a279c213d963371361ad5/src/search-engine.ts#L778-L890 | 593d5076d144b1db9d4a279c213d963371361ad5 |
libro | github_2023 | weavefox | typescript | traverseDirectory | async function traverseDirectory(
dir: string,
transformPathFn: (filePath: string, resourcePath: string) => string,
): Promise<void> {
const files = await fsPromises.readdir(dir);
for (const file of files) {
const fullPath = path.join(dir, file);
const stat = await fsPromises.lstat(fullPath);
if (st... | // Recursively traverse the directory | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/apps/docs/dumi-plugin-deploy.ts#L12-L26 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | processFile | async function processFile(
filePath: string,
transformPathFn: (filePath: string, resourcePath: string) => string,
): Promise<void> {
let content = await fsPromises.readFile(filePath, 'utf8');
const regex = new RegExp(`${PREFIX_URL}([^\\s'"]+)`, 'g');
let match: RegExpExecArray | null;
let shouldWrite = fa... | // Process each file | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/apps/docs/dumi-plugin-deploy.ts#L29-L61 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | downloadResource | async function downloadResource(url, destination) {
try {
console.info('[deploy] downloading:', url);
const response = await axios({
url,
method: 'GET',
responseType: 'stream', // Ensures we get the response as a stream
headers: {
'User-Agent':
'Mozilla/5.0 (Windows N... | // Download the resource and save it locally | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/apps/docs/dumi-plugin-deploy.ts#L63-L97 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | NotebookDocumentContentProvider.provideEditorDocumentModelContent | async provideEditorDocumentModelContent(
uri: URI,
encoding?: string | undefined,
): Promise<string> {
const cell = await this.libroOpensumiService.getCellViewByUri(uri);
return cell?.model.value ?? '';
} | // } | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/archive/opensumi-module-libro/src/browser/notebook-document-content-provider.ts#L49-L55 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | NotebookDocumentContentProvider.provideEncoding | provideEncoding?(uri: URI): MaybePromise<string> {
const encoding = this.preferenceService.get<string>(
'files.encoding',
undefined,
uri.toString(),
getLanguageIdFromMonaco(uri)!,
);
return encoding || 'utf8';
} | // } | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/archive/opensumi-module-libro/src/browser/notebook-document-content-provider.ts#L82-L90 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | NotebookDocumentContentProvider.isAlwaysDirty | isAlwaysDirty?(uri: URI): MaybePromise<boolean> {
return false;
} | // } | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/archive/opensumi-module-libro/src/browser/notebook-document-content-provider.ts#L98-L100 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | NotebookDocumentContentProvider.disposeEvenDirty | disposeEvenDirty?(uri: URI): MaybePromise<boolean> {
return false;
} | // } | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/archive/opensumi-module-libro/src/browser/notebook-document-content-provider.ts#L107-L109 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LibroE2EditorContribution.canHandle | canHandle(mime: string): number {
// 代码编辑都使用opensumi编辑器
return 50 + 2;
} | // eslint-disable-next-line @typescript-eslint/no-unused-vars | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/archive/opensumi-module-libro/src/mana/editor/editor-contribution.ts#L40-L43 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LibroOpensumiEditor.uuid | get uuid(): string {
return this._uuid;
} | /**
* The uuid of this editor;
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/archive/opensumi-module-libro/src/mana/editor/opensumi-editor.ts#L291-L293 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LibroOpensumiEditor.model | get model(): IModel {
return this._model;
} | /**
* Returns a model for this editor.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/archive/opensumi-module-libro/src/mana/editor/opensumi-editor.ts#L302-L304 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LibroOpensumiEditor.onMimeTypeChanged | protected onMimeTypeChanged(): void {
const model = this.monacoEditor?.getModel();
model?.setLanguage('');
if (this.languageSpec && model) {
setModelLanguage(model, this.languageSpec.language);
}
} | /**
* Handles a mime type change.
* 切换语言
* cell 切换没走这里
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/archive/opensumi-module-libro/src/mana/editor/opensumi-editor.ts#L609-L615 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LibroOpensumiEditor.onCursorActivity | protected onCursorActivity(): void {
// Only add selections if the editor has focus. This avoids unwanted
// triggering of cursor activity due to collaborator actions.
if (this.hasFocus()) {
// const selections = this.getSelections();
// this.model.selections = selections;
}
} | /**
* Handles a cursor activity event.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/archive/opensumi-module-libro/src/mana/editor/opensumi-editor.ts#L625-L632 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LibroOpensumiEditor.getPositionForCoordinate | setOption = <K extends keyof LibroOpensumiEditorConfig>(
option: K,
value: LibroOpensumiEditorConfig[K],
) => {
if (value === null || value === undefined) {
return;
}
// if (option === 'theme') {
// this._config.theme = value as NonNullable<LibroE2EditorConfig['theme']>;
// this... | // eslint-disable-next-line @typescript-eslint/no-unused-vars | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/archive/opensumi-module-libro/src/mana/editor/opensumi-editor.ts | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LibroOpensumiEditor.disposed | get disposed(): boolean {
return this._isDisposed;
} | /**
* Tests whether the editor is disposed.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/archive/opensumi-module-libro/src/mana/editor/opensumi-editor.ts#L923-L925 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LibroAINativeService.getOrCreateLibroAINativeForCellView | async getOrCreateLibroAINativeForCellView(id: string, cell: CellView) {
let libroAINativeForCellView = this.libroAINativeForCellViewMap.get(id);
if (libroAINativeForCellView) {
return libroAINativeForCellView;
} else {
libroAINativeForCellView = await this.viewManager.getOrCreateView(
Li... | // libroAINativeChatViewMap: Map<string, LibroAiNativeChatView> = new Map(); | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-ai-native/src/ai-native-service.ts#L32-L44 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | AiCompletionRequest.constructRequestContext | protected constructRequestContext(
context: ICompletionContext,
token: EditorCancellationToken,
): IAICompletionOption {
// const prompt = lineBasedPromptProcessor.processPrefix(context.prefix);
// const suffix = lineBasedPromptProcessor.processSuffix(context.suffix);
const prompt = context.prefix... | // 拼接上下文信息 | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-ai-native/src/ai-inline-completions/inline-completion-request.ts#L26-L43 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | AiCompletionRequest.run | async run() {
const { context, token } = this;
if (this.isCancelFlag || token.isCancellationRequested) {
return [];
}
let completeResult: IIntelligentCompletionsResult | undefined;
const requestBean = await this.constructRequestContext(context, token);
try {
completeResult = await ... | // 向大模型发送请求 | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-ai-native/src/ai-inline-completions/inline-completion-request.ts#L50-L68 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | processPrefix | function processPrefix(prompt: string): string {
// remove all empty lines
prompt = prompt.replace(/^s*[\n]/gm, '');
const arr = prompt.split('\n');
// if the number of lines is greater than n, take the last n lines
if (arr.length > lineBasedCompletionModelConfigs.completionPromptMaxLineSize) {
prompt = a... | // 去除多余的空行,并且限制前文的长度 | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-ai-native/src/ai-inline-completions/utils.ts#L6-L17 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | processSuffix | function processSuffix(suffix: string): string {
suffix = suffix.replace(/^s*[\n]/gm, '');
const arr = suffix.split('\n');
if (arr.length > lineBasedCompletionModelConfigs.completionSuffixMaxLineSize) {
suffix = arr
.slice(-lineBasedCompletionModelConfigs.completionSuffixMaxLineSize)
.join('\n');
... | // 去除多余的空行,并且限制后文的长度 | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-ai-native/src/ai-inline-completions/utils.ts#L20-L29 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LibroAppOpenHandler.canHandle | canHandle(uri: URI, _options?: AppOpenHandlerOptions) {
if (uri.scheme === 'file' && uri.path.ext === '.ipynb' && _options?.isApp) {
return Priority.PRIOR + 2;
}
return Priority.IDLE;
} | // eslint-disable-next-line @typescript-eslint/no-unused-vars | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-app/src/app-open-handler.ts#L24-L29 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeEditorManager.getEditorDefaultConfig | getEditorDefaultConfig(model: IModel) {
return this.findCodeEditorProvider(model)?.defaultConfig;
} | /**
* 获取默认配置
* @param model
* @returns
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-code-editor/src/code-editor-manager.ts#L45-L47 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeEditorManager.getUserEditorConfig | getUserEditorConfig(model: IModel) {
return {
...this.getEditorDefaultConfig(model),
...this.codeEditorSettings.getUserEditorSettings(),
};
} | /**
* 用户配置+默认配置(还有一部分配置在cell中指定)
* @param model
* @returns
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-code-editor/src/code-editor-manager.ts#L54-L59 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | Model.constructor | constructor(options?: IModelOptions) {
// this.sharedModel = models.createStandaloneCell(this.type, options.id) as models.ISharedText;
// this.sharedModel.changed.connect(this._onSharedModelChanged, this);
this.id = options?.id ?? v4();
this.value = options?.value ?? '';
this.mimeType = options?.mi... | /**
* Construct a new Model.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-code-editor/src/code-editor-model.ts#L82-L90 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | Model.sharedModelSwitched | get sharedModelSwitched(): Event<boolean> {
return this._sharedModelSwitched;
} | /**
* A signal emitted when the shared model was switched.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-code-editor/src/code-editor-model.ts#L95-L97 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | Model.isDisposed | get isDisposed(): boolean {
return this._isDisposed;
} | /**
* Whether the model is disposed.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-code-editor/src/code-editor-model.ts#L102-L104 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | Model.dispose | dispose(): void {
if (this._isDisposed) {
return;
}
this._isDisposed = true;
} | /**
* Dispose of the resources used by the model.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-code-editor/src/code-editor-model.ts#L109-L114 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeEditorView.constructor | constructor(
@inject(ViewOption) options: CodeEditorViewOptions,
@inject(CodeEditorInfoManager) codeEditorInfoManager: CodeEditorInfoManager,
) {
super();
this.options = options;
this.codeEditorInfoManager = codeEditorInfoManager;
} | /**
* Construct a new code editor widget.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-code-editor/src/code-editor-view.tsx#L98-L105 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeEditorView.model | get model(): IModel {
return this.editor.model;
} | /**
* Get the model used by the widget.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-code-editor/src/code-editor-view.tsx#L221-L223 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeEditorView.dispose | override dispose(): void {
if (this.isDisposed) {
return;
}
super.dispose();
this.editor.dispose();
} | /**
* Dispose of the resources held by the widget.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-code-editor/src/code-editor-view.tsx#L228-L234 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.