Skip to content

Commit

Permalink
exception is kb is not there
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayush0054 committed Feb 6, 2025
1 parent 1c7b33f commit e923255
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 82 deletions.
83 changes: 42 additions & 41 deletions libs/agno/agno/playground/async_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ async def create_agent_run(
if agent is None:
raise HTTPException(status_code=404, detail="Agent not found")

if files:
if agent.knowledge is None:
raise HTTPException(status_code=404, detail="KnowledgeBase not found")

if session_id is not None:
logger.debug(f"Continuing session: {session_id}")
else:
Expand All @@ -161,44 +157,49 @@ async def create_agent_run(
except Exception as e:
logger.error(f"Error processing image {file.filename}: {e}")
continue
elif file.content_type == "application/pdf":
from agno.document.reader.pdf_reader import PDFReader

contents = await file.read()
pdf_file = BytesIO(contents)
pdf_file.name = file.filename
file_content = PDFReader().read(pdf_file)
if agent.knowledge is not None:
agent.knowledge.load_documents(file_content)
elif file.content_type == "text/csv":
from agno.document.reader.csv_reader import CSVReader

contents = await file.read()
csv_file = BytesIO(contents)
csv_file.name = file.filename
file_content = CSVReader().read(csv_file)
if agent.knowledge is not None:
agent.knowledge.load_documents(file_content)
elif file.content_type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
from agno.document.reader.docx_reader import DocxReader

contents = await file.read()
docx_file = BytesIO(contents)
docx_file.name = file.filename
file_content = DocxReader().read(docx_file)
if agent.knowledge is not None:
agent.knowledge.load_documents(file_content)
elif file.content_type == "text/plain":
from agno.document.reader.text_reader import TextReader

contents = await file.read()
text_file = BytesIO(contents)
text_file.name = file.filename
file_content = TextReader().read(text_file)
if agent.knowledge is not None:
agent.knowledge.load_documents(file_content)
else:
raise HTTPException(status_code=400, detail="Unsupported file type")
# Check for knowledge base before processing documents
if agent.knowledge is None:
raise HTTPException(status_code=404, detail="KnowledgeBase not found")

if file.content_type == "application/pdf":
from agno.document.reader.pdf_reader import PDFReader

contents = await file.read()
pdf_file = BytesIO(contents)
pdf_file.name = file.filename
file_content = PDFReader().read(pdf_file)
if agent.knowledge is not None:
agent.knowledge.load_documents(file_content)
elif file.content_type == "text/csv":
from agno.document.reader.csv_reader import CSVReader

contents = await file.read()
csv_file = BytesIO(contents)
csv_file.name = file.filename
file_content = CSVReader().read(csv_file)
if agent.knowledge is not None:
agent.knowledge.load_documents(file_content)
elif file.content_type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
from agno.document.reader.docx_reader import DocxReader

contents = await file.read()
docx_file = BytesIO(contents)
docx_file.name = file.filename
file_content = DocxReader().read(docx_file)
if agent.knowledge is not None:
agent.knowledge.load_documents(file_content)
elif file.content_type == "text/plain":
from agno.document.reader.text_reader import TextReader

contents = await file.read()
text_file = BytesIO(contents)
text_file.name = file.filename
file_content = TextReader().read(text_file)
if agent.knowledge is not None:
agent.knowledge.load_documents(file_content)
else:
raise HTTPException(status_code=400, detail="Unsupported file type")

if stream:
return StreamingResponse(
Expand Down
83 changes: 42 additions & 41 deletions libs/agno/agno/playground/sync_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ def create_agent_run(
if agent is None:
raise HTTPException(status_code=404, detail="Agent not found")

if files:
if agent.knowledge is None:
raise HTTPException(status_code=404, detail="KnowledgeBase not found")

if session_id is not None:
logger.debug(f"Continuing session: {session_id}")
else:
Expand Down Expand Up @@ -145,44 +141,49 @@ def create_agent_run(
except Exception as e:
logger.error(f"Error processing image {file.filename}: {e}")
continue
elif file.content_type == "application/pdf":
from agno.document.reader.pdf_reader import PDFReader

contents = file.file.read()
pdf_file = BytesIO(contents)
pdf_file.name = file.filename
file_content = PDFReader().read(pdf_file)
if agent.knowledge is not None:
agent.knowledge.load_documents(file_content)
elif file.content_type == "text/csv":
from agno.document.reader.csv_reader import CSVReader

contents = file.file.read()
csv_file = BytesIO(contents)
csv_file.name = file.filename
file_content = CSVReader().read(csv_file)
if agent.knowledge is not None:
agent.knowledge.load_documents(file_content)
elif file.content_type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
from agno.document.reader.docx_reader import DocxReader

contents = file.file.read()
docx_file = BytesIO(contents)
docx_file.name = file.filename
file_content = DocxReader().read(docx_file)
if agent.knowledge is not None:
agent.knowledge.load_documents(file_content)
elif file.content_type == "text/plain":
from agno.document.reader.text_reader import TextReader

contents = file.file.read()
text_file = BytesIO(contents)
text_file.name = file.filename
file_content = TextReader().read(text_file)
if agent.knowledge is not None:
agent.knowledge.load_documents(file_content)
else:
raise HTTPException(status_code=400, detail="Unsupported file type")
# Check for knowledge base before processing documents
if agent.knowledge is None:
raise HTTPException(status_code=404, detail="KnowledgeBase not found")

if file.content_type == "application/pdf":
from agno.document.reader.pdf_reader import PDFReader

contents = file.file.read()
pdf_file = BytesIO(contents)
pdf_file.name = file.filename
file_content = PDFReader().read(pdf_file)
if agent.knowledge is not None:
agent.knowledge.load_documents(file_content)
elif file.content_type == "text/csv":
from agno.document.reader.csv_reader import CSVReader

contents = file.file.read()
csv_file = BytesIO(contents)
csv_file.name = file.filename
file_content = CSVReader().read(csv_file)
if agent.knowledge is not None:
agent.knowledge.load_documents(file_content)
elif file.content_type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
from agno.document.reader.docx_reader import DocxReader

contents = file.file.read()
docx_file = BytesIO(contents)
docx_file.name = file.filename
file_content = DocxReader().read(docx_file)
if agent.knowledge is not None:
agent.knowledge.load_documents(file_content)
elif file.content_type == "text/plain":
from agno.document.reader.text_reader import TextReader

contents = file.file.read()
text_file = BytesIO(contents)
text_file.name = file.filename
file_content = TextReader().read(text_file)
if agent.knowledge is not None:
agent.knowledge.load_documents(file_content)
else:
raise HTTPException(status_code=400, detail="Unsupported file type")

if stream:
return StreamingResponse(
Expand Down

0 comments on commit e923255

Please sign in to comment.