Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backend: add weather tool #101

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/community/config/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
ConnectorRetriever,
LlamaIndexUploadPDFRetriever,
PubMedRetriever,
WeatherDataLoader,
)


Expand Down Expand Up @@ -64,6 +65,15 @@ class CommunityToolName(StrEnum):
category=Category.Function,
description="Evaluate arithmetic expressions.",
),
CommunityToolName.Weather: ManagedTool(
name=CommunityToolName.Weather,
implementation=WeatherDataLoader,
is_visible=True,
is_available=WeatherDataLoader.is_available(),
error_message="WeatherDataLoader is not available.",
category=Category.DataLoader,
description="Retrieves weather data.",
),
}

# For main.py cli setup script
Expand Down
8 changes: 8 additions & 0 deletions src/community/tests/tools/retrieval/test_weather.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from community.tools.retrieval.weather import WeatherDataLoader


def test_pub_med_retriever():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this test name be changed?

retriever = WeatherDataLoader()()
result = retriever.retrieve_documents("What is the weather in Toronto?")
assert len(result) > 0
assert "text" in result[0]
2 changes: 2 additions & 0 deletions src/community/tools/retrieval/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
from community.tools.retrieval.connector import ConnectorRetriever
from community.tools.retrieval.llama_index import LlamaIndexUploadPDFRetriever
from community.tools.retrieval.pub_med import PubMedRetriever
from community.tools.retrieval.weather import WeatherDataLoader

__all__ = [
"ArxivRetriever",
"ConnectorRetriever",
"LlamaIndexUploadPDFRetriever",
"PubMedRetriever",
"WeatherDataLoader",
]
18 changes: 18 additions & 0 deletions src/community/tools/retrieval/weather.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from typing import Any, Dict, List

from langchain_community.document_loaders.weather import WeatherDataLoader

from community.tools import BaseRetrieval


class WeatherDataLoader(BaseRetrieval):
def __init__(self):
self.client = WeatherDataLoader()

@classmethod
def is_available(cls) -> bool:
return True

def retrieve_documents(self, query: str, **kwargs: Any) -> List[Dict[str, Any]]:
result = self.client.from_params(query).load()
return [{"text": result}]