from agno.knowledge.pdf_url import PDFUrlKnowledgeBase
from agno.vectordb.lancedb import LanceDb, SearchType
from agno.agent import Agent
from agno.models.groq import Groq
from agno.embedder.huggingface import HuggingfaceCustomEmbedder
from agno.tools.duckduckgo import DuckDuckGoTools
import os
from dotenv import load_dotenv
from agno.tools.yfinance import YFinanceTools
load_dotenv()
os.environ[“HUGGINGFACE_API_KEY”]=os.getenv(“HUGGINGFACE_API_KEY”)
os.environ[“GROQ_API_KEY”]=os.getenv(“GROQ_API_KEY”)
agent = Agent(
model=Groq(id=“qwen-2.5-32b”),
description=“You are a Thai cuisine expert!”,
instructions=[
“Search your knowledge base for Thai recipes.”,
“If the question is better suited for the web, search the web to fill in gaps.”,
“Prefer the information in your knowledge base over the web results.”
],
knowledge=PDFUrlKnowledgeBase(
urls=[“http…ThaiRecipes.pdf”],
vector_db=LanceDb(
uri=“tmp/lancedb”,
table_name=“recipes”,
search_type=SearchType.hybrid,
embedder=HuggingfaceCustomEmbedder(id=‘sentence-transformers/all-MiniLM-L6-v2’),
),
),
tools=[DuckDuckGoTools()],
show_tool_calls=True,
markdown=True
)
Comment out after the knowledge base is loaded
if agent.knowledge is not None:
agent.knowledge.load()
agent.print_response(“How do I make chicken and galangal in coconut milk soup”, stream=True)
getting below error while executing the file - C:\Users\DELL\anaconda3\envs\conversational_intent_tasks\Lib\site-packages\huggingface_hub\utils_deprecation.py:131: FutureWarning: ‘post’ (from ‘huggingface_hub.inference._client’) is deprecated and will be removed from version ‘0.31.0’. Making direct POST requests to the inference server is not supported anymore. Please use task methods instead (e.g. InferenceClient.chat_completion
).
Traceback (most recent call last):
File “C:\Users\DELL\anaconda3\envs\conversational_intent_tasks\Lib\site-packages\huggingface_hub\utils_http.py”, line 409, in hf_raise_for_status
response.raise_for_status()
File “C:\Users\DELL\anaconda3\envs\conversational_intent_tasks\Lib\site-packages\requests\models.py”, line 1024, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://router.huggingface.co/hf-inference/models/sentence-transformers/all-MiniLM-L6-v2
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “C:\Users\DELL\Desktop\AI Agents\agent_memory.py”, line 25, in
vector_db=LanceDb(
^^^^^^^^
File “C:\Users\DELL\anaconda3\envs\conversational_intent_tasks\Lib\site-packages\agno\vectordb\lancedb\lance_db.py”, line 111, in init
self.table = self._init_table()
^^^^^^^^^^^^^^^^^^
File “C:\Users\DELL\anaconda3\envs\conversational_intent_tasks\Lib\site-packages\agno\vectordb\lancedb\lance_db.py”, line 168, in _init_table
schema = self._base_schema()
^^^^^^^^^^^^^^^^^^^
File “C:\Users\DELL\anaconda3\envs\conversational_intent_tasks\Lib\site-packages\agno\vectordb\lancedb\lance_db.py”, line 159, in _base_schema
len(self.embedder.get_embedding(“test”)), # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\DELL\anaconda3\envs\conversational_intent_tasks\Lib\site-packages\agno\embedder\huggingface.py”, line 41, in get_embedding
response = self._response(text=text)
^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\DELL\anaconda3\envs\conversational_intent_tasks\Lib\site-packages\agno\embedder\huggingface.py”, line 38, in _response
return self.client.post(json={“inputs”: text}, model=self.id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\DELL\anaconda3\envs\conversational_intent_tasks\Lib\site-packages\huggingface_hub\utils_deprecation.py”, line 132, in inner_f
return f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^
File “C:\Users\DELL\anaconda3\envs\conversational_intent_tasks\Lib\site-packages\huggingface_hub\inference_client.py”, line 268, in post
return self._inner_post(
^^^^^^^^^^^^^^^^^
File “C:\Users\DELL\anaconda3\envs\conversational_intent_tasks\Lib\site-packages\huggingface_hub\inference_client.py”, line 321, in _inner_post
hf_raise_for_status(response)
File “C:\Users\DELL\anaconda3\envs\conversational_intent_tasks\Lib\site-packages\huggingface_hub\utils_http.py”, line 481, in hf_raise_for_status
raise _format(HfHubHTTPError, str(e), response) from e
huggingface_hub.errors.HfHubHTTPError: 401 Client Error: Unauthorized for url: https://router.huggingface.co/hf-inference/models/sentence-transformers/all-MiniLM-L6-v2 (Request ID: Root=1-67d59da8-7435c80c3762300c06b78ccc;7e9a1d32-ffe7-4803-8dd8-26da5ba8b068)
Invalid username or password.