mirror of
https://github.com/hexastack/hexabot
synced 2025-01-22 10:35:37 +00:00
fix: adjust nlu prediction
This commit is contained in:
parent
88168795c0
commit
bc17c3d284
86
Makefile
86
Makefile
@ -1,64 +1,60 @@
|
|||||||
COMPOSE_FILES := -f ./docker/docker-compose.yml
|
# Makefile
|
||||||
|
FOLDER := ./docker
|
||||||
|
|
||||||
# Function to add service files
|
# The services that can be toggled
|
||||||
define add_service
|
SERVICES := nginx nlu smtp4dev
|
||||||
ifeq ($(PROD), true)
|
|
||||||
COMPOSE_FILES += -f ./docker/docker-compose.$(1).yml
|
# Function to dynamically add Docker Compose files based on enabled services
|
||||||
ifneq ($(wildcard ./docker/docker-compose.$(1).prod.yml),)
|
define compose_files
|
||||||
COMPOSE_FILES += -f ./docker/docker-compose.$(1).prod.yml
|
$(foreach service,$(SERVICES),$(if $($(shell echo $(service) | tr a-z A-Z)), -f $(FOLDER)/docker-compose.$(service).yml))
|
||||||
endif
|
|
||||||
else ifeq ($(DEV_MODE), true)
|
|
||||||
COMPOSE_FILES += -f ./docker/docker-compose.$(1).yml
|
|
||||||
ifneq ($(wildcard ./docker/docker-compose.$(1).dev.yml),)
|
|
||||||
COMPOSE_FILES += -f ./docker/docker-compose.$(1).dev.yml
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
# Function to dynamically add Docker Compose dev files based on enabled services and file existence
|
||||||
|
define compose_dev_files
|
||||||
|
$(foreach service,$(SERVICES), \
|
||||||
|
$(if $($(shell echo $(service) | tr a-z A-Z)), \
|
||||||
|
$(if $(shell [ -f $(FOLDER)/docker-compose.$(service).dev.yml ] && echo yes), -f $(FOLDER)/docker-compose.$(service).dev.yml)))
|
||||||
|
endef
|
||||||
|
|
||||||
# Function to set up COMPOSE_FILES
|
# Function to dynamically add Docker Compose dev files based on enabled services and file existence
|
||||||
define compose_files
|
define compose_prod_files
|
||||||
ifeq ($(1), true)
|
$(foreach service,$(SERVICES), \
|
||||||
ifneq ($(wildcard ./docker/docker-compose.dev.yml),)
|
$(if $($(shell echo $(service) | tr a-z A-Z)), \
|
||||||
COMPOSE_FILES += -f ./docker/docker-compose.dev.yml
|
$(if $(shell [ -f $(FOLDER)/docker-compose.$(service).prod.yml ] && echo yes), -f $(FOLDER)/docker-compose.$(service).dev.yml)))
|
||||||
endif
|
|
||||||
endif
|
|
||||||
ifneq ($(NGINX),)
|
|
||||||
$(eval $(call add_service,nginx))
|
|
||||||
endif
|
|
||||||
ifneq ($(NLU),)
|
|
||||||
$(eval $(call add_service,nlu))
|
|
||||||
endif
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# Ensure .env file exists and matches .env.example
|
# Ensure .env file exists and matches .env.example
|
||||||
check-env:
|
check-env:
|
||||||
@if [ ! -f "./docker/.env" ]; then \
|
@if [ ! -f "$(FOLDER)/.env" ]; then \
|
||||||
echo "Error: .env file does not exist. Creating one now from .env.example ..."; \
|
echo "Error: .env file does not exist. Creating one now from .env.example ..."; \
|
||||||
cp ./docker/.env.example ./docker/.env; \
|
cp $(FOLDER)/.env.example $(FOLDER)/.env; \
|
||||||
fi
|
fi
|
||||||
@echo "Checking .env file for missing variables..."
|
@echo "Checking .env file for missing variables..."
|
||||||
@awk -F '=' 'NR==FNR {a[$$1]; next} !($$1 in a) {print "Missing env var: " $$1}' ./docker/.env ./docker/.env.example
|
@awk -F '=' 'NR==FNR {a[$$1]; next} !($$1 in a) {print "Missing env var: " $$1}' $(FOLDER)/.env $(FOLDER)/.env.example
|
||||||
|
|
||||||
init:
|
init:
|
||||||
cp ./docker/.env.example ./docker/.env
|
cp $(FOLDER)/.env.example $(FOLDER)/.env
|
||||||
|
|
||||||
dev: check-env
|
|
||||||
$(eval $(call compose_files,true))
|
|
||||||
docker compose $(COMPOSE_FILES) up -d
|
|
||||||
|
|
||||||
|
# Start command: runs docker-compose with the main file and any additional service files
|
||||||
start: check-env
|
start: check-env
|
||||||
$(eval $(call compose_files,false))
|
@docker compose -f $(FOLDER)/docker-compose.yml $(call compose_files) up -d
|
||||||
docker compose $(COMPOSE_FILES) up -d
|
|
||||||
|
|
||||||
stop: check-env
|
# Dev command: runs docker-compose with the main file, dev file, and any additional service dev files (if they exist)
|
||||||
$(eval $(call compose_files,true))
|
dev: check-env
|
||||||
docker compose $(COMPOSE_FILES) down
|
@docker compose -f $(FOLDER)/docker-compose.yml -f $(FOLDER)/docker-compose.dev.yml $(call compose_files) $(call compose_dev_files) up -d
|
||||||
|
|
||||||
destroy: check-env
|
# Start command: runs docker-compose with the main file and any additional service files
|
||||||
$(eval $(call compose_files,true))
|
start-prod: check-env
|
||||||
docker compose $(COMPOSE_FILES) down -v
|
@docker compose -f $(FOLDER)/docker-compose.yml -f $(FOLDER)/docker-compose.prod.yml $(call compose_files) $(call compose_prod_files) up -d
|
||||||
|
|
||||||
|
# Stop command: stops the running containers
|
||||||
|
stop:
|
||||||
|
@docker compose -f $(FOLDER)/docker-compose.yml -f $(FOLDER)/docker-compose.dev.yml $(call compose_files) $(call compose_dev_files) $(call compose_prod_files) down
|
||||||
|
|
||||||
|
# Destroy command: stops the running containers and removes the volumes
|
||||||
|
destroy:
|
||||||
|
@docker compose -f $(FOLDER)/docker-compose.yml -f $(FOLDER)/docker-compose.dev.yml $(call compose_files) $(call compose_dev_files) $(call compose_prod_files) down -v
|
||||||
|
|
||||||
|
# Migrate command:
|
||||||
migrate-up:
|
migrate-up:
|
||||||
$(eval $(call compose_files,false))
|
@docker compose -f $(FOLDER)/docker-compose.yml -f $(FOLDER)/docker-compose.dev.yml $(call compose_files) $(call compose_dev_files) up --no-deps -d database-init
|
||||||
docker-compose $(COMPOSE_FILES) up --no-deps -d database-init
|
|
||||||
|
@ -5,5 +5,6 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: ../nlu
|
context: ../nlu
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
|
pull_policy: build
|
||||||
ports:
|
ports:
|
||||||
- ${NLP_PORT}:5000
|
- ${NLP_PORT}:5000
|
||||||
|
@ -1,5 +1 @@
|
|||||||
version: "3.8"
|
version: "3.8"
|
||||||
|
|
||||||
widget:
|
|
||||||
build:
|
|
||||||
target: production
|
|
||||||
|
10
nlu/main.py
10
nlu/main.py
@ -94,10 +94,16 @@ def parse(input: ParseInput, is_authenticated: Annotated[str, Depends(authentica
|
|||||||
input.q) # type: ignore
|
input.q) # type: ignore
|
||||||
slot_prediction = app.slot_fillers[language].get_prediction(
|
slot_prediction = app.slot_fillers[language].get_prediction(
|
||||||
input.q) # type: ignore
|
input.q) # type: ignore
|
||||||
slot_prediction.get("entities").append(language_prediction)
|
|
||||||
|
if slot_prediction.get("entities"):
|
||||||
|
entities = slot_prediction.get("entities")
|
||||||
|
else:
|
||||||
|
entities = []
|
||||||
|
|
||||||
|
entities.append(language_prediction)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"text": input.q,
|
"text": input.q,
|
||||||
"intent": intent_prediction.get("intent"),
|
"intent": intent_prediction.get("intent"),
|
||||||
"entities": slot_prediction.get("entities"),
|
"entities": entities,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user