Skip to content

Commit

Permalink
chore: upadte asknews example and api key setting (#1182)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wendong-Fan authored Nov 15, 2024
1 parent 5d62942 commit 92289e8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 29 deletions.
17 changes: 3 additions & 14 deletions camel/toolkits/ask_news_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,12 @@ def __init__(self):
r"""Initialize the AskNewsToolkit with API clients.The API keys and
credentials are retrieved from environment variables.
"""
from asknews_sdk import AskNewsSDK # type: ignore[import]
from asknews_sdk import AskNewsSDK

client_id = os.environ.get("ASKNEWS_CLIENT_ID")
client_secret = os.environ.get("ASKNEWS_CLIENT_SECRET")

if client_id and client_secret:
self.asknews_client = AskNewsSDK(client_id, client_secret)
else:
self.asknews_client = None
self.asknews_client = AskNewsSDK(client_id, client_secret)

def get_news(
self,
Expand Down Expand Up @@ -182,7 +179,6 @@ def get_stories(
for story in response.stories
]
}

return stories_data

except Exception as e:
Expand Down Expand Up @@ -368,10 +364,7 @@ def __init__(self):
client_id = os.environ.get("ASKNEWS_CLIENT_ID")
client_secret = os.environ.get("ASKNEWS_CLIENT_SECRET")

if client_id and client_secret:
self.asknews_client = AsyncAskNewsSDK(client_id, client_secret)
else:
self.asknews_client = None
self.asknews_client = AsyncAskNewsSDK(client_id, client_secret)

async def get_news(
self,
Expand Down Expand Up @@ -647,7 +640,3 @@ def get_tools(self) -> List[FunctionTool]:
FunctionTool(self.search_reddit),
FunctionTool(self.query_finance),
]


ASKNEWS_FUNCS: List[FunctionTool] = AskNewsToolkit().get_tools()
ASYNC_ASKNEWS_FUNCS: List[FunctionTool] = AsyncAskNewsToolkit().get_tools()
31 changes: 16 additions & 15 deletions examples/toolkits/ask_news_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,27 @@

ask_news = AskNewsToolkit()

news_output = ask_news.get_news(query="camel-ai")
news_output = ask_news.get_news(query="President of United States")
print(news_output[:1000])

"""
===============================================================================
<doc>
[1]:
Title: Robot Creates Painting of Alan Turing for $130,000 to $195,000 Auction
Summary: A robot named 'Ai-Da' created a painting of Alan Turing, a British
mathematician and father of modern computer science, using artificial
intelligence technology. The painting is part of an online auction that will
take place from October 31 to November 7, and is estimated to be worth between
$130,000 and $195,000. Ai-Da is a highly advanced robot that has arms and a
face that resembles a human, complete with brown hair. The robot was created
in 2019 by a team led by Aidan Meller, an art dealer and founder of Ai-Da
Robot Studio, in collaboration with experts in artificial intelligence from
the universities of Oxford and Birmingham. Ai-Da uses AI to create paintings
or sculptures, and has cameras in its eyes and electronic arms. According to
Ai-Da, 'Through my works on Alan Turing, I celebrate his achievements and
contributions to the development of computing and artificial intelligence.' T
Title: Can Elon Musk Become President of the United States?
Summary: Elon Musk, the American billionaire, has been appointed to lead the
Department of Government Efficiency in Donald Trump's upcoming administration,
sparking speculation about his potential presidential ambitions. However,
according to the US Constitution, the President must be a natural-born citizen
of the United States. As Musk was born in South Africa and became a Canadian
citizen through his mother, he does not meet this requirement. While he
acquired US citizenship in 2002, this does not make him a natural-born
citizen. Additionally, the Constitution requires the President to be at least
35 years old and a resident of the United States for at least 14 years. Musk
can, however, hold other government positions, as the requirement of being a
natural-born citizen only applies to the President and Vice President. Many
non-US-born citizens have held prominent government positions in the past,
including Henry
===============================================================================
"""

Expand All @@ -50,5 +51,5 @@
reddit_output = ask_news.search_reddit(keywords=["camel-ai", "multi-agent"])
print(reddit_output)

finance_output = ask_news.finance_query(asset="bitcoin")
finance_output = ask_news.query_finance(asset="bitcoin")
print(finance_output)

0 comments on commit 92289e8

Please sign in to comment.