Patch both api and web sides
This commit is contained in:
@@ -146,12 +146,27 @@ def delete_knowledge_base(kb_id: str, db: Session = Depends(get_db)):
|
||||
@router.post("/bases/{kb_id}/documents")
|
||||
def upload_document(
|
||||
kb_id: str,
|
||||
data: KnowledgeDocumentCreate,
|
||||
data: Optional[KnowledgeDocumentCreate] = None,
|
||||
name: Optional[str] = Query(default=None),
|
||||
size: Optional[str] = Query(default=None),
|
||||
file_type: Optional[str] = Query(default=None),
|
||||
storage_url: Optional[str] = Query(default=None),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
kb = db.query(KnowledgeBase).filter(KnowledgeBase.id == kb_id).first()
|
||||
if not kb:
|
||||
raise HTTPException(status_code=404, detail="Knowledge base not found")
|
||||
|
||||
if data is None:
|
||||
if not name or not size:
|
||||
raise HTTPException(status_code=422, detail="name and size are required")
|
||||
data = KnowledgeDocumentCreate(
|
||||
name=name,
|
||||
size=size,
|
||||
fileType=file_type or "txt",
|
||||
storageUrl=storage_url,
|
||||
)
|
||||
|
||||
doc = KnowledgeDocument(
|
||||
id=str(uuid.uuid4())[:8],
|
||||
kb_id=kb_id,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import List
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
@@ -11,7 +10,7 @@ from ..schemas import WorkflowCreate, WorkflowUpdate, WorkflowOut
|
||||
router = APIRouter(prefix="/workflows", tags=["Workflows"])
|
||||
|
||||
|
||||
@router.get("", response_model=List[WorkflowOut])
|
||||
@router.get("")
|
||||
def list_workflows(
|
||||
page: int = 1,
|
||||
limit: int = 50,
|
||||
@@ -62,8 +61,12 @@ def update_workflow(id: str, data: WorkflowUpdate, db: Session = Depends(get_db)
|
||||
raise HTTPException(status_code=404, detail="Workflow not found")
|
||||
|
||||
update_data = data.model_dump(exclude_unset=True)
|
||||
field_map = {
|
||||
"nodeCount": "node_count",
|
||||
"globalPrompt": "global_prompt",
|
||||
}
|
||||
for field, value in update_data.items():
|
||||
setattr(workflow, field, value)
|
||||
setattr(workflow, field_map.get(field, field), value)
|
||||
|
||||
workflow.updated_at = datetime.utcnow().isoformat()
|
||||
db.commit()
|
||||
|
||||
@@ -16,6 +16,6 @@ View your app in AI Studio: https://ai.studio/apps/drive/1Cg9WH_2bOQEHVVj-lSN5l2
|
||||
1. Install dependencies:
|
||||
`npm install`
|
||||
2. Set the `GEMINI_API_KEY` in [.env.local](.env.local) to your Gemini API key
|
||||
3. Optional: set `VITE_API_BASE_URL` (for backend API, default `http://localhost:8000/api`)
|
||||
3. Optional: set `VITE_API_BASE_URL` (for backend API, default `http://127.0.0.1:8100/api`)
|
||||
4. Run the app:
|
||||
`npm run dev`
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const DEFAULT_API_BASE_URL = 'http://localhost:8000/api';
|
||||
const DEFAULT_API_BASE_URL = 'http://127.0.0.1:8100/api';
|
||||
|
||||
const trimTrailingSlash = (value: string): string => value.replace(/\/+$/, '');
|
||||
|
||||
|
||||
@@ -173,13 +173,15 @@ export const deleteAssistant = async (id: string): Promise<void> => {
|
||||
};
|
||||
|
||||
export const fetchVoices = async (): Promise<Voice[]> => {
|
||||
const response = await apiRequest<AnyRecord[]>('/voices');
|
||||
return response.map((item) => mapVoice(item));
|
||||
const response = await apiRequest<{ list?: AnyRecord[] } | AnyRecord[]>('/voices');
|
||||
const list = Array.isArray(response) ? response : (response.list || []);
|
||||
return list.map((item) => mapVoice(item));
|
||||
};
|
||||
|
||||
export const fetchWorkflows = async (): Promise<Workflow[]> => {
|
||||
const response = await apiRequest<AnyRecord[]>('/workflows');
|
||||
return response.map((item) => mapWorkflow(item));
|
||||
const response = await apiRequest<{ list?: AnyRecord[] } | AnyRecord[]>('/workflows');
|
||||
const list = Array.isArray(response) ? response : (response.list || []);
|
||||
return list.map((item) => mapWorkflow(item));
|
||||
};
|
||||
|
||||
export const fetchWorkflowById = async (id: string): Promise<Workflow> => {
|
||||
@@ -238,12 +240,12 @@ export const deleteKnowledgeBase = async (kbId: string): Promise<void> => {
|
||||
};
|
||||
|
||||
export const uploadKnowledgeDocument = async (kbId: string, file: File): Promise<void> => {
|
||||
const params = new URLSearchParams({
|
||||
const payload = {
|
||||
name: file.name,
|
||||
size: `${(file.size / 1024).toFixed(1)} KB`,
|
||||
file_type: file.type || 'txt',
|
||||
});
|
||||
await apiRequest(`/knowledge/bases/${kbId}/documents?${params.toString()}`, { method: 'POST' });
|
||||
fileType: file.type || 'txt',
|
||||
};
|
||||
await apiRequest(`/knowledge/bases/${kbId}/documents`, { method: 'POST', body: payload });
|
||||
};
|
||||
|
||||
export const deleteKnowledgeDocument = async (kbId: string, docId: string): Promise<void> => {
|
||||
|
||||
Reference in New Issue
Block a user