Skip to content

Commit

Permalink
Override _to_args_and_kwargs method to avoid TypeError to run Tool wi…
Browse files Browse the repository at this point in the history
…thout any arguments
  • Loading branch information
DEENUU1 committed Jan 23, 2024
1 parent ce6c084 commit bf88d50
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions app/ai/tools/news.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
from typing import Optional

from langchain.callbacks.manager import (
AsyncCallbackManagerForToolRun,
CallbackManagerForToolRun,
)
from typing import Union, Dict, Tuple
from langchain_core.tools import BaseTool
from newsapi import NewsApiClient
from config.settings import settings
Expand Down Expand Up @@ -31,13 +26,12 @@ class NewsTool(BaseTool):
name = "news_tool"
description = "Useful for when you need to answer questions about current news"

def _run(
self, run_manager: Optional[CallbackManagerForToolRun] = None
) -> str:
def _to_args_and_kwargs(self, tool_input: Union[str, Dict]) -> Tuple[Tuple, Dict]:
return (), {}

def _run(self) -> str:
return get_top_headlines_formatted()

async def _arun(
self, run_manager: Optional[AsyncCallbackManagerForToolRun] = None
) -> str:
async def _arun(self) -> str:
"""Use the tool asynchronously."""
raise NotImplementedError("custom_search does not support async")

0 comments on commit bf88d50

Please sign in to comment.