diff --git a/agentstack/templates/crewai/tools/perplexity_tool.py b/agentstack/templates/crewai/tools/perplexity_tool.py new file mode 100644 index 0000000..a5a361b --- /dev/null +++ b/agentstack/templates/crewai/tools/perplexity_tool.py @@ -0,0 +1,53 @@ +import os + +import requests +from crewai_tools import tool + +from dotenv import load_dotenv +load_dotenv() + +url = "https://api.perplexity.ai/chat/completions" +api_key = os.getenv("PERPLEXITY_API_KEY") + +@tool +def query_perplexity(query: str): + """ + Use Perplexity to concisely search the internet and answer a query with up-to-date information. + """ + + payload = { + "model": "llama-3.1-sonar-small-128k-online", + "messages": [ + { + "role": "system", + "content": "Be precise and concise." + }, + { + "role": "user", + "content": query + } + ], + # "max_tokens": "Optional", + "temperature": 0.2, + "top_p": 0.9, + "return_citations": True, + "search_domain_filter": ["perplexity.ai"], + "return_images": False, + "return_related_questions": False, + "search_recency_filter": "month", + "top_k": 0, + "stream": False, + "presence_penalty": 0, + "frequency_penalty": 1 + } + headers = { + "Authorization": f"Bearer {api_key}", + "Content-Type": "application/json" + } + + response = requests.request("POST", url, json=payload, headers=headers) + if response.status_code == 200 and response.text: + return response.text + else: + print(f"{response.status_code} - {response.text}") + return "Failed to query perplexity" diff --git a/agentstack/tools/perplexity.json b/agentstack/tools/perplexity.json new file mode 100644 index 0000000..8e75110 --- /dev/null +++ b/agentstack/tools/perplexity.json @@ -0,0 +1,6 @@ +{ + "name": "perplexity", + "package": "", + "env": "PERPLEXITY_API_KEY=pplx-...", + "tools": ["query_perplexity"] +} \ No newline at end of file diff --git a/agentstack/tools/tools.json b/agentstack/tools/tools.json index 15e6bfb..553480b 100644 --- a/agentstack/tools/tools.json +++ b/agentstack/tools/tools.json @@ -42,5 +42,9 @@ "web-retrieval": [{ "name": "exa", "url": "https://exa.ai" + }], + "search": [{ + "name": "perplexity", + "url": "https://perplexity.ai" }] } diff --git a/pyproject.toml b/pyproject.toml index c76d38e..cf628a7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "agentstack" -version = "0.1.8-dev9" +version = "0.1.9" description = "The fastest way to build robust AI agents" authors = [ { name="Braelyn Boynton", email="bboynton97@gmail.com" }