You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1018 B
37 lines
1018 B
1 year ago
|
This example demonstrates how to vectorize a PDF of the [Attention Is All You Need](https://arxiv.org/pdf/1706.03762.pdf) paper and setup a Swarms agent with rules and the `KnowledgeBase` tool to use it during conversations.
|
||
|
|
||
|
```python
|
||
|
import io
|
||
|
import requests
|
||
|
from swarms.engines import VectorQueryEngine
|
||
|
from swarms.loaders import PdfLoader
|
||
|
from swarms.structures import Agent
|
||
|
from swarms.tools import KnowledgeBaseClient
|
||
|
from swarms.utils import Chat
|
||
|
|
||
|
namespace = "attention"
|
||
|
|
||
|
response = requests.get("https://arxiv.org/pdf/1706.03762.pdf")
|
||
|
engine = VectorQueryEngine()
|
||
|
|
||
|
engine.vector_store_driver.upsert_text_artifacts(
|
||
|
{
|
||
|
namespace: PdfLoader().load(
|
||
|
io.BytesIO(response.content)
|
||
|
)
|
||
|
}
|
||
|
)
|
||
|
|
||
|
kb_client = KnowledgeBaseClient(
|
||
|
description="Contains information about the Attention Is All You Need paper. "
|
||
|
"Use it to answer any related questions.",
|
||
|
query_engine=engine,
|
||
|
namespace=namespace
|
||
|
)
|
||
|
|
||
|
agent = Agent(
|
||
|
tools=[kb_client]
|
||
|
)
|
||
|
|
||
|
Chat(agent).start()
|
||
|
```
|