Spaces:
Build error
Build error
Youngger9765 Claude Happy commited on
Commit ·
b830e05
1
Parent(s): 3b3c9f5
fix: Python 3.9 compatibility for HuggingFace Spaces
Browse files- Replace Python 3.10+ union syntax (str | None) with Optional[str]
- Replace list[T] with List[T] from typing module
- HuggingFace Spaces uses Python 3.9 which doesn't support PEP 604 syntax
- Fixes TypeError: unsupported operand type(s) for |
- Note: Ignoring ruff UP035/UP006 as we need Python 3.9 compatibility
Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
- backend/api/agents.py +8 -6
- backend/api/chat.py +4 -2
- backend/api/search.py +3 -1
- backend/api/stats.py +4 -2
backend/api/agents.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
"""API endpoints for agent management"""
|
| 2 |
|
|
|
|
|
|
|
| 3 |
from fastapi import APIRouter, Depends, HTTPException
|
| 4 |
from pydantic import BaseModel
|
| 5 |
from sqlalchemy import select
|
|
@@ -14,22 +16,22 @@ router = APIRouter(prefix="/api/agents", tags=["agents"])
|
|
| 14 |
class AgentCreate(BaseModel):
|
| 15 |
slug: str
|
| 16 |
name: str
|
| 17 |
-
description: str
|
| 18 |
status: str = "draft"
|
| 19 |
|
| 20 |
|
| 21 |
class AgentVersionCreate(BaseModel):
|
| 22 |
config_json: dict
|
| 23 |
-
created_by: str
|
| 24 |
|
| 25 |
|
| 26 |
class AgentResponse(BaseModel):
|
| 27 |
id: int
|
| 28 |
slug: str
|
| 29 |
name: str
|
| 30 |
-
description: str
|
| 31 |
status: str
|
| 32 |
-
active_version_id: int
|
| 33 |
|
| 34 |
|
| 35 |
class AgentVersionResponse(BaseModel):
|
|
@@ -40,7 +42,7 @@ class AgentVersionResponse(BaseModel):
|
|
| 40 |
config_json: dict
|
| 41 |
|
| 42 |
|
| 43 |
-
@router.get("/", response_model=
|
| 44 |
async def list_agents(db: AsyncSession = Depends(get_db)):
|
| 45 |
"""List all agents"""
|
| 46 |
|
|
@@ -120,7 +122,7 @@ async def get_agent(agent_id: int, db: AsyncSession = Depends(get_db)):
|
|
| 120 |
raise HTTPException(status_code=500, detail=f"Failed to get agent: {str(e)}") from e
|
| 121 |
|
| 122 |
|
| 123 |
-
@router.get("/{agent_id}/versions", response_model=
|
| 124 |
async def list_agent_versions(agent_id: int, db: AsyncSession = Depends(get_db)):
|
| 125 |
"""List all versions for an agent"""
|
| 126 |
|
|
|
|
| 1 |
"""API endpoints for agent management"""
|
| 2 |
|
| 3 |
+
from typing import List, Optional
|
| 4 |
+
|
| 5 |
from fastapi import APIRouter, Depends, HTTPException
|
| 6 |
from pydantic import BaseModel
|
| 7 |
from sqlalchemy import select
|
|
|
|
| 16 |
class AgentCreate(BaseModel):
|
| 17 |
slug: str
|
| 18 |
name: str
|
| 19 |
+
description: Optional[str] = None
|
| 20 |
status: str = "draft"
|
| 21 |
|
| 22 |
|
| 23 |
class AgentVersionCreate(BaseModel):
|
| 24 |
config_json: dict
|
| 25 |
+
created_by: Optional[str] = None
|
| 26 |
|
| 27 |
|
| 28 |
class AgentResponse(BaseModel):
|
| 29 |
id: int
|
| 30 |
slug: str
|
| 31 |
name: str
|
| 32 |
+
description: Optional[str]
|
| 33 |
status: str
|
| 34 |
+
active_version_id: Optional[int]
|
| 35 |
|
| 36 |
|
| 37 |
class AgentVersionResponse(BaseModel):
|
|
|
|
| 42 |
config_json: dict
|
| 43 |
|
| 44 |
|
| 45 |
+
@router.get("/", response_model=List[AgentResponse])
|
| 46 |
async def list_agents(db: AsyncSession = Depends(get_db)):
|
| 47 |
"""List all agents"""
|
| 48 |
|
|
|
|
| 122 |
raise HTTPException(status_code=500, detail=f"Failed to get agent: {str(e)}") from e
|
| 123 |
|
| 124 |
|
| 125 |
+
@router.get("/{agent_id}/versions", response_model=List[AgentVersionResponse])
|
| 126 |
async def list_agent_versions(agent_id: int, db: AsyncSession = Depends(get_db)):
|
| 127 |
"""List all versions for an agent"""
|
| 128 |
|
backend/api/chat.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
"""API endpoints for RAG-powered chat"""
|
| 2 |
|
|
|
|
|
|
|
| 3 |
from fastapi import APIRouter, Depends, HTTPException
|
| 4 |
from pydantic import BaseModel
|
| 5 |
from sqlalchemy import Float, Integer, String, bindparam, text
|
|
@@ -15,7 +17,7 @@ class ChatRequest(BaseModel):
|
|
| 15 |
question: str
|
| 16 |
top_k: int = 7 # Increased for better coverage with 59 chunks
|
| 17 |
similarity_threshold: float = 0.55 # Balanced threshold for quality results
|
| 18 |
-
system_prompt: str
|
| 19 |
temperature: float = 0.6 # Lowered for more accurate responses
|
| 20 |
|
| 21 |
|
|
@@ -30,7 +32,7 @@ class Citation(BaseModel):
|
|
| 30 |
class ChatResponse(BaseModel):
|
| 31 |
question: str
|
| 32 |
answer: str
|
| 33 |
-
citations:
|
| 34 |
total_citations: int
|
| 35 |
|
| 36 |
|
|
|
|
| 1 |
"""API endpoints for RAG-powered chat"""
|
| 2 |
|
| 3 |
+
from typing import List, Optional
|
| 4 |
+
|
| 5 |
from fastapi import APIRouter, Depends, HTTPException
|
| 6 |
from pydantic import BaseModel
|
| 7 |
from sqlalchemy import Float, Integer, String, bindparam, text
|
|
|
|
| 17 |
question: str
|
| 18 |
top_k: int = 7 # Increased for better coverage with 59 chunks
|
| 19 |
similarity_threshold: float = 0.55 # Balanced threshold for quality results
|
| 20 |
+
system_prompt: Optional[str] = None
|
| 21 |
temperature: float = 0.6 # Lowered for more accurate responses
|
| 22 |
|
| 23 |
|
|
|
|
| 32 |
class ChatResponse(BaseModel):
|
| 33 |
question: str
|
| 34 |
answer: str
|
| 35 |
+
citations: List[Citation]
|
| 36 |
total_citations: int
|
| 37 |
|
| 38 |
|
backend/api/search.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
"""API endpoints for vector similarity search"""
|
| 2 |
|
|
|
|
|
|
|
| 3 |
from fastapi import APIRouter, Depends, HTTPException
|
| 4 |
from pydantic import BaseModel
|
| 5 |
from sqlalchemy import Float, Integer, String, bindparam, text
|
|
@@ -28,7 +30,7 @@ class SearchResult(BaseModel):
|
|
| 28 |
|
| 29 |
class SearchResponse(BaseModel):
|
| 30 |
query: str
|
| 31 |
-
results:
|
| 32 |
total_results: int
|
| 33 |
|
| 34 |
|
|
|
|
| 1 |
"""API endpoints for vector similarity search"""
|
| 2 |
|
| 3 |
+
from typing import List
|
| 4 |
+
|
| 5 |
from fastapi import APIRouter, Depends, HTTPException
|
| 6 |
from pydantic import BaseModel
|
| 7 |
from sqlalchemy import Float, Integer, String, bindparam, text
|
|
|
|
| 30 |
|
| 31 |
class SearchResponse(BaseModel):
|
| 32 |
query: str
|
| 33 |
+
results: List[SearchResult]
|
| 34 |
total_results: int
|
| 35 |
|
| 36 |
|
backend/api/stats.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
"""API endpoints for database statistics"""
|
| 2 |
|
|
|
|
|
|
|
| 3 |
from fastapi import APIRouter, Depends
|
| 4 |
from pydantic import BaseModel
|
| 5 |
from sqlalchemy import text
|
|
@@ -25,7 +27,7 @@ class DatabaseStats(BaseModel):
|
|
| 25 |
total_chunks: int
|
| 26 |
total_embeddings: int
|
| 27 |
total_bytes: int
|
| 28 |
-
documents:
|
| 29 |
|
| 30 |
|
| 31 |
@router.get("/", response_model=DatabaseStats)
|
|
@@ -92,7 +94,7 @@ class ChunkDetail(BaseModel):
|
|
| 92 |
document_title: str
|
| 93 |
|
| 94 |
|
| 95 |
-
@router.get("/chunks/{doc_id}", response_model=
|
| 96 |
async def get_document_chunks(doc_id: int, db: AsyncSession = Depends(get_db)):
|
| 97 |
"""
|
| 98 |
Get all chunks for a specific document
|
|
|
|
| 1 |
"""API endpoints for database statistics"""
|
| 2 |
|
| 3 |
+
from typing import List
|
| 4 |
+
|
| 5 |
from fastapi import APIRouter, Depends
|
| 6 |
from pydantic import BaseModel
|
| 7 |
from sqlalchemy import text
|
|
|
|
| 27 |
total_chunks: int
|
| 28 |
total_embeddings: int
|
| 29 |
total_bytes: int
|
| 30 |
+
documents: List[DocumentStats]
|
| 31 |
|
| 32 |
|
| 33 |
@router.get("/", response_model=DatabaseStats)
|
|
|
|
| 94 |
document_title: str
|
| 95 |
|
| 96 |
|
| 97 |
+
@router.get("/chunks/{doc_id}", response_model=List[ChunkDetail])
|
| 98 |
async def get_document_chunks(doc_id: int, db: AsyncSession = Depends(get_db)):
|
| 99 |
"""
|
| 100 |
Get all chunks for a specific document
|