mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-06-22 08:38:13 +02:00
feat: add full document mode in knowledge base
This commit is contained in:
parent
c085398933
commit
87c8c5e2c8
26 changed files with 1144 additions and 351 deletions
|
|
@ -124,6 +124,7 @@ async def process_document(
|
|||
mime_type="application/octet-stream", # Will be detected by background task
|
||||
custom_metadata={"s3_key": request.s3_key},
|
||||
document_uuid=request.document_uuid, # Use UUID from upload
|
||||
retrieval_mode=request.retrieval_mode,
|
||||
)
|
||||
|
||||
# Enqueue background task for processing
|
||||
|
|
@ -133,6 +134,7 @@ async def process_document(
|
|||
request.s3_key,
|
||||
user.selected_organization_id,
|
||||
128, # max_tokens (default)
|
||||
request.retrieval_mode,
|
||||
)
|
||||
|
||||
logger.info(
|
||||
|
|
@ -150,6 +152,7 @@ async def process_document(
|
|||
processing_status="pending",
|
||||
processing_error=None,
|
||||
total_chunks=0,
|
||||
retrieval_mode=request.retrieval_mode,
|
||||
custom_metadata={"s3_key": request.s3_key},
|
||||
docling_metadata={},
|
||||
source_url=None,
|
||||
|
|
@ -209,6 +212,7 @@ async def list_documents(
|
|||
processing_status=doc.processing_status,
|
||||
processing_error=doc.processing_error,
|
||||
total_chunks=doc.total_chunks,
|
||||
retrieval_mode=doc.retrieval_mode,
|
||||
custom_metadata=doc.custom_metadata,
|
||||
docling_metadata=doc.docling_metadata,
|
||||
source_url=doc.source_url,
|
||||
|
|
@ -267,6 +271,7 @@ async def get_document(
|
|||
processing_status=document.processing_status,
|
||||
processing_error=document.processing_error,
|
||||
total_chunks=document.total_chunks,
|
||||
retrieval_mode=document.retrieval_mode,
|
||||
custom_metadata=document.custom_metadata,
|
||||
docling_metadata=document.docling_metadata,
|
||||
source_url=document.source_url,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import json
|
||||
import re
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from typing import List, Literal, Optional
|
||||
|
|
@ -6,13 +7,13 @@ from typing import List, Literal, Optional
|
|||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from httpx import HTTPStatusError
|
||||
from loguru import logger
|
||||
from pydantic import BaseModel, ValidationError
|
||||
from pydantic import BaseModel, Field, ValidationError
|
||||
|
||||
from api.constants import DEPLOYMENT_MODE
|
||||
from api.db import db_client
|
||||
from api.db.models import UserModel
|
||||
from api.db.workflow_template_client import WorkflowTemplateClient
|
||||
from api.enums import CallType
|
||||
from api.enums import CallType, StorageBackend
|
||||
from api.schemas.workflow import WorkflowRunResponseSchema
|
||||
from api.services.auth.depends import get_user
|
||||
from api.services.configuration.check_validity import UserConfigurationValidator
|
||||
|
|
@ -22,6 +23,7 @@ from api.services.configuration.masking import (
|
|||
)
|
||||
from api.services.configuration.resolve import resolve_effective_config
|
||||
from api.services.mps_service_key_client import mps_service_key_client
|
||||
from api.services.storage import storage_fs
|
||||
from api.services.workflow.dto import ReactFlowDTO
|
||||
from api.services.workflow.duplicate import duplicate_workflow
|
||||
from api.services.workflow.errors import ItemKind, WorkflowError
|
||||
|
|
@ -1030,3 +1032,60 @@ async def duplicate_workflow_template(
|
|||
"call_disposition_codes": workflow.call_disposition_codes,
|
||||
"workflow_configurations": workflow.workflow_configurations,
|
||||
}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Ambient Noise Upload
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class AmbientNoiseUploadRequest(BaseModel):
|
||||
workflow_id: int
|
||||
filename: str
|
||||
mime_type: str = "audio/wav"
|
||||
file_size: int = Field(..., gt=0, le=10_485_760, description="Max 10MB")
|
||||
|
||||
|
||||
class AmbientNoiseUploadResponse(BaseModel):
|
||||
upload_url: str
|
||||
storage_key: str
|
||||
storage_backend: str
|
||||
|
||||
|
||||
@router.post(
|
||||
"/ambient-noise/upload-url",
|
||||
response_model=AmbientNoiseUploadResponse,
|
||||
summary="Get a presigned URL to upload a custom ambient noise audio file",
|
||||
)
|
||||
async def get_ambient_noise_upload_url(
|
||||
request: AmbientNoiseUploadRequest,
|
||||
user=Depends(get_user),
|
||||
):
|
||||
"""Generate a presigned PUT URL for uploading a custom ambient noise file."""
|
||||
# Verify user owns this workflow
|
||||
workflow = await db_client.get_workflow(
|
||||
request.workflow_id, organization_id=user.selected_organization_id
|
||||
)
|
||||
if not workflow:
|
||||
raise HTTPException(status_code=404, detail="Workflow not found")
|
||||
|
||||
sanitized = re.sub(r"[^a-zA-Z0-9._-]", "_", request.filename)
|
||||
storage_key = (
|
||||
f"ambient-noise/{user.selected_organization_id}"
|
||||
f"/{request.workflow_id}/{uuid.uuid4()}_{sanitized}"
|
||||
)
|
||||
|
||||
upload_url = await storage_fs.aget_presigned_put_url(
|
||||
file_path=storage_key,
|
||||
expiration=1800,
|
||||
content_type=request.mime_type,
|
||||
max_size=request.file_size,
|
||||
)
|
||||
if not upload_url:
|
||||
raise HTTPException(status_code=500, detail="Failed to generate upload URL")
|
||||
|
||||
return AmbientNoiseUploadResponse(
|
||||
upload_url=upload_url,
|
||||
storage_key=storage_key,
|
||||
storage_backend=StorageBackend.get_current_backend().value,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue