Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new options to documents and user service #156

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions b2b/api_gateway/proxy/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ resource "aws_api_gateway_integration" "rag" {

resource "aws_lambda_permission" "rag" {
count = var.enable_rag_endpoint ? 1 : 0
statement_id = "AllowPOSTExecutionFromAPIGateway"
statement_id = "AllowPOSTExecutionFromAPIGatewayFor${var.tenant}"
action = "lambda:InvokeFunction"
function_name = var.rag_integration_config.function_name
principal = "apigateway.amazonaws.com"
Expand Down Expand Up @@ -417,7 +417,7 @@ resource "aws_api_gateway_integration" "rag_options" {

resource "aws_lambda_permission" "rag_options" {
count = var.enable_rag_endpoint ? 1 : 0
statement_id = "AllowOPTIONSExecutionFromAPIGateway"
statement_id = "AllowOPTIONSExecutionFromAPIGatewayFor${var.tenant}"
action = "lambda:InvokeFunction"
function_name = var.rag_integration_config.function_name
principal = "apigateway.amazonaws.com"
Expand Down
51 changes: 31 additions & 20 deletions b2b/service/documents/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ data "aws_partition" "current" {}
data "aws_caller_identity" "current" {}

locals {
sagemaker_enabled = length(var.sagemaker_endpoint) > 0
create_task_role = local.sagemaker_enabled ? true : false
account_id = data.aws_caller_identity.current.account_id
partition = data.aws_partition.current.partition
region = data.aws_region.current.name
sagemaker_enabled = length(var.sagemaker_endpoint) > 0
create_task_role = local.sagemaker_enabled ? true : false
use_openai_endpoint = length(var.openai_endpoint) > 0 ? true : false
account_id = data.aws_caller_identity.current.account_id
partition = data.aws_partition.current.partition
region = data.aws_region.current.name
}

resource "null_resource" "validate" {
Expand All @@ -20,6 +21,10 @@ resource "null_resource" "validate" {
condition = !local.sagemaker_enabled || (try(var.sagemaker_endpoint.name, null) != null && try(var.sagemaker_endpoint.model_embedding_size, null) != null)
error_message = "In combination with sagemaker, the model embedding size need to be specified."
}
postcondition {
condition = !(local.sagemaker_enabled && local.use_openai_endpoint)
error_message = "Can not define sagemaker and openai_endpoints together, just use one of both."
}
}
}

Expand Down Expand Up @@ -157,25 +162,31 @@ module "service" {
task_execution_role_arn = module.task_role.arn
task_role_arn = local.create_task_role ? aws_iam_role.task_role[0].arn : null
environment = merge({
XAYN_WEB_API__NET__BIND_TO = "0.0.0.0:${var.container_port}"
XAYN_WEB_API__STORAGE__ELASTIC__URL = var.elasticsearch_url
XAYN_WEB_API__STORAGE__ELASTIC__INDEX_NAME = var.elasticsearch_index
XAYN_WEB_API__STORAGE__ELASTIC__USER = var.elasticsearch_username
XAYN_WEB_API__STORAGE__POSTGRES__BASE_URL = "${var.postgres_url}/${var.tenant}"
XAYN_WEB_API__STORAGE__POSTGRES__USER = var.postgres_username
XAYN_WEB_API__STORAGE__POSTGRES__APPLICATION_NAME = var.tenant
XAYN_WEB_API__NET__KEEP_ALIVE = var.keep_alive
XAYN_WEB_API__NET__CLIENT_REQUEST_TIMEOUT = var.request_timeout
XAYN_WEB_API__LOGGING__LEVEL = var.logging_level
XAYN_WEB_API__INGESTION__MAX_SNIPPET_SIZE = var.max_snippet_size
XAYN_WEB_API__INGESTION__MAX_PROPERTIES_SIZE = var.max_properties_size
XAYN_WEB_API__INGESTION__MAX_PROPERTIES_STRING_SIZE = var.max_properties_string_size
XAYN_WEB_API__INGESTION__MAX_DOCUMENT_BATCH_SIZE = var.max_document_batch_size
XAYN_WEB_API__TENANTS__ENABLE_DEV = var.enable_dev_options
XAYN_WEB_API__NET__BIND_TO = "0.0.0.0:${var.container_port}"
XAYN_WEB_API__STORAGE__ELASTIC__URL = var.elasticsearch_url
XAYN_WEB_API__STORAGE__ELASTIC__INDEX_NAME = var.elasticsearch_index
XAYN_WEB_API__STORAGE__ELASTIC__USER = var.elasticsearch_username
XAYN_WEB_API__STORAGE__POSTGRES__BASE_URL = "${var.postgres_url}/${var.tenant}"
XAYN_WEB_API__STORAGE__POSTGRES__USER = var.postgres_username
XAYN_WEB_API__STORAGE__POSTGRES__APPLICATION_NAME = var.tenant
XAYN_WEB_API__NET__KEEP_ALIVE = var.keep_alive
XAYN_WEB_API__NET__CLIENT_REQUEST_TIMEOUT = var.request_timeout
XAYN_WEB_API__LOGGING__LEVEL = var.logging_level
XAYN_WEB_API__INGESTION__MAX_SNIPPET_SIZE = var.max_snippet_size
XAYN_WEB_API__INGESTION__MAX_PROPERTIES_SIZE = var.max_properties_size
XAYN_WEB_API__INGESTION__MAX_PROPERTIES_STRING_SIZE = var.max_properties_string_size
XAYN_WEB_API__INGESTION__SNIPPET_EXTRACTOR__LANGUAGE = var.snippet_language
XAYN_WEB_API__INGESTION__MAX_DOCUMENT_BATCH_SIZE = var.max_document_batch_size
XAYN_WEB_API__TENANTS__ENABLE_DEV = var.enable_dev_options
}, local.sagemaker_enabled ? {
XAYN_WEB_API__EMBEDDING__TYPE = "sagemaker",
XAYN_WEB_API__EMBEDDING__ENDPOINT = var.sagemaker_endpoint.name,
XAYN_WEB_API__EMBEDDING__EMBEDDING_SIZE = var.sagemaker_endpoint.model_embedding_size
} : local.use_openai_endpoint ? {
XAYN_WEB_API__EMBEDDING__TYPE = "open_ai",
XAYN_WEB_API__EMBEDDING__URL = "${var.openai_endpoint.url}&user=${var.tenant}",
XAYN_WEB_API__EMBEDDING__API_KEY = var.openai_endpoint.api_key,
XAYN_WEB_API__EMBEDDING__EMBEDDING_SIZE = var.openai_endpoint.model_embedding_size
} : {
XAYN_WEB_API__EMBEDDING__TYPE = "pipeline",
XAYN_WEB_API__EMBEDDING__TOKEN_SIZE = var.token_size
Expand Down
24 changes: 23 additions & 1 deletion b2b/service/documents/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ variable "max_snippet_size" {
default = 2048
}

variable "snippet_language" {
description = "The language used for the snippet. This is useful i.e. for the splitter."
type = string
default = "english"
validation {
condition = contains(["german", "english", "czech", "danish", "dutch", "estonian", "finnish", "frensh", "greek", "italian", "malayalam", "norwegian", "polish", "portuguese", "russian", "slovene", "spanish", "swedish", "turkish"], var.snippet_language)
error_message = "Allowed values for input_parameter are: ${join(", ", ["german", "english", "czech", "danish", "dutch", "estonian", "finnish", "frensh", "greek", "italian", "malayalam", "norwegian", "polish", "portuguese", "russian", "slovene", "spanish", "swedish", "turkish"])}."
}
}

variable "max_properties_size" {
description = "The max size for properties"
type = number
Expand Down Expand Up @@ -221,7 +231,7 @@ variable "enable_dev_options" {
}

variable "sagemaker_endpoint" {
description = "The name of the sagemaker endpoint config."
description = "The sagemaker endpoint config. Can not work with openai. "
type = any
default = {}
# example
Expand All @@ -233,6 +243,18 @@ variable "sagemaker_endpoint" {
# }
}

variable "openai_endpoint" {
description = "The openai endpoint config, can not work with sagemaker."
type = any
default = {}
# example
# {
# url = i.e. "https://openai.azure.com/openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-07-01-preview"
# api_key = your very secret key
# model_embedding_size = 384
# }
}

variable "health_check_grace_period_seconds" {
description = "Seconds to ignore failing load balancer health checks on newly instantiated tasks to prevent premature shutdown"
type = number
Expand Down
18 changes: 14 additions & 4 deletions b2b/service/users/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ data "aws_partition" "current" {}
data "aws_caller_identity" "current" {}

locals {
create_task_role = length(var.sagemaker_endpoint) > 0 ? true : false
account_id = data.aws_caller_identity.current.account_id
partition = data.aws_partition.current.partition
region = data.aws_region.current.name
create_task_role = length(var.sagemaker_endpoint) > 0 ? true : false
use_openai_endpoint = length(var.openai_endpoint) > 0 ? true : false
account_id = data.aws_caller_identity.current.account_id
partition = data.aws_partition.current.partition
region = data.aws_region.current.name
}

resource "null_resource" "validate" {
Expand All @@ -19,6 +20,10 @@ resource "null_resource" "validate" {
condition = (local.create_task_role && try(var.sagemaker_endpoint.name, null) != null && try(var.sagemaker_endpoint.model_embedding_size, null) != null) || !local.create_task_role
error_message = "In combination with sagemaker, the model embedding size need to be specified."
}
postcondition {
condition = !(local.create_task_role && local.use_openai_endpoint)
error_message = "Can not define sagemaker and openai_endpoints together, just use one of both."
}
}
}

Expand Down Expand Up @@ -176,6 +181,11 @@ module "service" {
XAYN_WEB_API__EMBEDDING__TYPE = "sagemaker",
XAYN_WEB_API__EMBEDDING__ENDPOINT = var.sagemaker_endpoint.name,
XAYN_WEB_API__EMBEDDING__EMBEDDING_SIZE = var.sagemaker_endpoint.model_embedding_size
} : local.use_openai_endpoint ? {
XAYN_WEB_API__EMBEDDING__TYPE = "open_ai",
XAYN_WEB_API__EMBEDDING__URL = "${var.openai_endpoint.url}&user=${var.tenant}",
XAYN_WEB_API__EMBEDDING__API_KEY = var.openai_endpoint.api_key,
XAYN_WEB_API__EMBEDDING__EMBEDDING_SIZE = var.openai_endpoint.model_embedding_size
} : {
XAYN_WEB_API__EMBEDDING__TYPE = "pipeline",
XAYN_WEB_API__EMBEDDING__TOKEN_SIZE = var.token_size
Expand Down
14 changes: 13 additions & 1 deletion b2b/service/users/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ variable "enable_dev_options" {
}

variable "sagemaker_endpoint" {
description = "The name of the sagemaker endpoint config."
description = "The sagemaker endpoint config. Can not work with openai. "
type = any
default = {}
# example
Expand All @@ -221,6 +221,18 @@ variable "sagemaker_endpoint" {
# }
}

variable "openai_endpoint" {
description = "The openai endpoint config, can not work with sagemaker."
type = any
default = {}
# example
# {
# url = i.e. "https://openai.azure.com/openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-07-01-preview"
# api_key = your very secret key
# model_embedding_size = 384
# }
}

variable "health_check_grace_period_seconds" {
description = "Seconds to ignore failing load balancer health checks on newly instantiated tasks to prevent premature shutdown"
type = number
Expand Down
Loading