Skip to content

Commit

Permalink
Merge pull request #46 from AgentOps-AI/perplexity-tool
Browse files Browse the repository at this point in the history
perplexity tool
  • Loading branch information
bboynton97 authored Nov 13, 2024
2 parents fccd435 + 1592dcc commit b0f1cda
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
53 changes: 53 additions & 0 deletions agentstack/templates/crewai/tools/perplexity_tool.py
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 6 additions & 0 deletions agentstack/tools/perplexity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "perplexity",
"package": "",
"env": "PERPLEXITY_API_KEY=pplx-...",
"tools": ["query_perplexity"]
}
4 changes: 4 additions & 0 deletions agentstack/tools/tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@
"web-retrieval": [{
"name": "exa",
"url": "https://exa.ai"
}],
"search": [{
"name": "perplexity",
"url": "https://perplexity.ai"
}]
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]" }
Expand Down

0 comments on commit b0f1cda

Please sign in to comment.