-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathchat-with-pdf.py
More file actions
49 lines (40 loc) · 1.55 KB
/
chat-with-pdf.py
File metadata and controls
49 lines (40 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
Chat with PDF Example
This example demonstrates how to create an agent that can read and answer questions about PDF documents.
It uses the knowledge parameter to load PDF files and provides interactive Q&A capabilities.
"""
from praisonaiagents import Agent
# Configure vector store for PDF storage
config = {
"vector_store": {
"provider": "chroma",
"config": {
"collection_name": "pdf_chat",
"path": ".praison_pdf_chat",
}
}
}
# Create a PDF chat agent
pdf_agent = Agent(
name="PDF Assistant",
role="PDF document expert",
goal="Help users understand and extract information from PDF documents",
backstory="You are an expert at reading, analyzing, and answering questions about PDF documents. You provide accurate, detailed answers based on the document content.",
instructions="Read the provided PDF document and answer questions about its content. Be specific and cite relevant sections when possible.",
knowledge=["document.pdf"], # Replace with your PDF file path
knowledge=config,
reflection=True,
)
# Example usage
if __name__ == "__main__":
# Single question
response = pdf_agent.start("What are the main topics covered in this document?")
print(response)
# Interactive chat
print("\nPDF Chat Assistant Ready! Type 'quit' to exit.")
while True:
question = input("\nYour question: ")
if question.lower() == 'quit':
break
response = pdf_agent.start(question)
print(f"\nAnswer: {response}")