mirror of
https://github.com/aljazceru/enclava.git
synced 2025-12-17 15:34:36 +01:00
chatbot rag testing
This commit is contained in:
@@ -32,12 +32,28 @@ class ChatbotCreateRequest(BaseModel):
|
|||||||
use_rag: bool = False
|
use_rag: bool = False
|
||||||
rag_collection: Optional[str] = None
|
rag_collection: Optional[str] = None
|
||||||
rag_top_k: int = 5
|
rag_top_k: int = 5
|
||||||
|
rag_score_threshold: float = 0.02 # Lowered from default 0.3 to allow more results
|
||||||
temperature: float = 0.7
|
temperature: float = 0.7
|
||||||
max_tokens: int = 1000
|
max_tokens: int = 1000
|
||||||
memory_length: int = 10
|
memory_length: int = 10
|
||||||
fallback_responses: List[str] = []
|
fallback_responses: List[str] = []
|
||||||
|
|
||||||
|
|
||||||
|
class ChatbotUpdateRequest(BaseModel):
|
||||||
|
name: Optional[str] = None
|
||||||
|
chatbot_type: Optional[str] = None
|
||||||
|
model: Optional[str] = None
|
||||||
|
system_prompt: Optional[str] = None
|
||||||
|
use_rag: Optional[bool] = None
|
||||||
|
rag_collection: Optional[str] = None
|
||||||
|
rag_top_k: Optional[int] = None
|
||||||
|
rag_score_threshold: Optional[float] = None
|
||||||
|
temperature: Optional[float] = None
|
||||||
|
max_tokens: Optional[int] = None
|
||||||
|
memory_length: Optional[int] = None
|
||||||
|
fallback_responses: Optional[List[str]] = None
|
||||||
|
|
||||||
|
|
||||||
class ChatRequest(BaseModel):
|
class ChatRequest(BaseModel):
|
||||||
message: str
|
message: str
|
||||||
conversation_id: Optional[str] = None
|
conversation_id: Optional[str] = None
|
||||||
@@ -190,7 +206,7 @@ async def create_chatbot(
|
|||||||
@router.put("/update/{chatbot_id}")
|
@router.put("/update/{chatbot_id}")
|
||||||
async def update_chatbot(
|
async def update_chatbot(
|
||||||
chatbot_id: str,
|
chatbot_id: str,
|
||||||
request: ChatbotCreateRequest,
|
request: ChatbotUpdateRequest,
|
||||||
current_user: User = Depends(get_current_user),
|
current_user: User = Depends(get_current_user),
|
||||||
db: AsyncSession = Depends(get_db)
|
db: AsyncSession = Depends(get_db)
|
||||||
):
|
):
|
||||||
@@ -214,28 +230,23 @@ async def update_chatbot(
|
|||||||
if not chatbot:
|
if not chatbot:
|
||||||
raise HTTPException(status_code=404, detail="Chatbot not found or access denied")
|
raise HTTPException(status_code=404, detail="Chatbot not found or access denied")
|
||||||
|
|
||||||
# Update chatbot configuration
|
# Get existing config
|
||||||
config = {
|
existing_config = chatbot.config.copy() if chatbot.config else {}
|
||||||
"name": request.name,
|
|
||||||
"chatbot_type": request.chatbot_type,
|
# Update only the fields that are provided in the request
|
||||||
"model": request.model,
|
update_data = request.dict(exclude_unset=True)
|
||||||
"system_prompt": request.system_prompt,
|
|
||||||
"use_rag": request.use_rag,
|
# Merge with existing config, preserving unset values
|
||||||
"rag_collection": request.rag_collection,
|
for key, value in update_data.items():
|
||||||
"rag_top_k": request.rag_top_k,
|
existing_config[key] = value
|
||||||
"temperature": request.temperature,
|
|
||||||
"max_tokens": request.max_tokens,
|
|
||||||
"memory_length": request.memory_length,
|
|
||||||
"fallback_responses": request.fallback_responses
|
|
||||||
}
|
|
||||||
|
|
||||||
# Update the chatbot
|
# Update the chatbot
|
||||||
await db.execute(
|
await db.execute(
|
||||||
update(ChatbotInstance)
|
update(ChatbotInstance)
|
||||||
.where(ChatbotInstance.id == chatbot_id)
|
.where(ChatbotInstance.id == chatbot_id)
|
||||||
.values(
|
.values(
|
||||||
name=request.name,
|
name=existing_config.get("name", chatbot.name),
|
||||||
config=config,
|
config=existing_config,
|
||||||
updated_at=datetime.utcnow()
|
updated_at=datetime.utcnow()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ class ChatbotConfig:
|
|||||||
memory_length: int = 10 # Number of previous messages to remember
|
memory_length: int = 10 # Number of previous messages to remember
|
||||||
use_rag: bool = False
|
use_rag: bool = False
|
||||||
rag_top_k: int = 5
|
rag_top_k: int = 5
|
||||||
|
rag_score_threshold: float = 0.02 # Lowered from default 0.3 to allow more results
|
||||||
fallback_responses: List[str] = None
|
fallback_responses: List[str] = None
|
||||||
|
|
||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
@@ -386,7 +387,8 @@ class ChatbotModule(BaseModule):
|
|||||||
rag_results = await self.rag_module.search_documents(
|
rag_results = await self.rag_module.search_documents(
|
||||||
query=message,
|
query=message,
|
||||||
max_results=config.rag_top_k,
|
max_results=config.rag_top_k,
|
||||||
collection_name=qdrant_collection_name
|
collection_name=qdrant_collection_name,
|
||||||
|
score_threshold=config.rag_score_threshold
|
||||||
)
|
)
|
||||||
|
|
||||||
if rag_results:
|
if rag_results:
|
||||||
|
|||||||
@@ -20,11 +20,13 @@ services:
|
|||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
environment:
|
environment:
|
||||||
- DATABASE_URL=postgresql://enclava_user:enclava_pass@enclava-postgres:5432/enclava_db
|
- DATABASE_URL=postgresql://enclava_user:enclava_pass@enclava-postgres:5432/enclava_db
|
||||||
|
- JWT_SECRET=${JWT_SECRET:-your-jwt-secret-here}
|
||||||
depends_on:
|
depends_on:
|
||||||
- enclava-postgres
|
- enclava-postgres
|
||||||
command: ["/usr/local/bin/migrate.sh"]
|
command: ["/usr/local/bin/migrate.sh"]
|
||||||
volumes:
|
volumes:
|
||||||
- ./backend:/app
|
- ./backend:/app
|
||||||
|
- ./.env:/app/.env
|
||||||
networks:
|
networks:
|
||||||
- enclava-net
|
- enclava-net
|
||||||
restart: "no" # Run once and exit
|
restart: "no" # Run once and exit
|
||||||
@@ -63,7 +65,7 @@ services:
|
|||||||
enclava-frontend:
|
enclava-frontend:
|
||||||
image: node:18-alpine
|
image: node:18-alpine
|
||||||
working_dir: /app
|
working_dir: /app
|
||||||
command: sh -c "npm install && npm run dev"
|
command: sh -c "npm ci --ignore-scripts && npm run dev"
|
||||||
environment:
|
environment:
|
||||||
# Required base URL (derives APP/API/WS URLs)
|
# Required base URL (derives APP/API/WS URLs)
|
||||||
- BASE_URL=${BASE_URL}
|
- BASE_URL=${BASE_URL}
|
||||||
@@ -79,7 +81,7 @@ services:
|
|||||||
- "3002:3000" # Direct frontend access for development
|
- "3002:3000" # Direct frontend access for development
|
||||||
volumes:
|
volumes:
|
||||||
- ./frontend:/app
|
- ./frontend:/app
|
||||||
- /app/node_modules
|
- enclava-frontend-node-modules:/app/node_modules
|
||||||
networks:
|
networks:
|
||||||
- enclava-net
|
- enclava-net
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
@@ -148,6 +150,7 @@ volumes:
|
|||||||
enclava-postgres-data:
|
enclava-postgres-data:
|
||||||
enclava-redis-data:
|
enclava-redis-data:
|
||||||
enclava-qdrant-data:
|
enclava-qdrant-data:
|
||||||
|
enclava-frontend-node-modules:
|
||||||
# enclava-ollama-data:
|
# enclava-ollama-data:
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
|
|||||||
Reference in New Issue
Block a user