diff --git a/.env.example b/.env.example index 0da9c4954..294c98f72 100644 --- a/.env.example +++ b/.env.example @@ -10,6 +10,7 @@ ANTHROPIC_API_KEY= COHERE_API_KEY= BING_SUBSCRIPTION_KEY= BING_SEARCH_URL= +WOLFRAM_ALPHA_APPID= #For Azure OpenAI AZURE_API_KEY= diff --git a/README.md b/README.md index 2a814a50b..e40e7b4ea 100644 --- a/README.md +++ b/README.md @@ -77,5 +77,3 @@ We appreciate your contributions and aim to make it easy for anyone to create an ## Support We appreciate all the support you can give us, either with contributions, feedback, bug reports or feature requests. Drop a star and share Superagent to the world! - -[![Star History Chart](https://api.star-history.com/svg?repos=homanp/superagent&type=Date)](https://superagent.sh) diff --git a/app/lib/agents/base.py b/app/lib/agents/base.py index 30f543f7b..732afd126 100644 --- a/app/lib/agents/base.py +++ b/app/lib/agents/base.py @@ -15,7 +15,7 @@ agent_template, default_chat_prompt, ) -from app.lib.tools import get_search_tool +from app.lib.tools import get_search_tool, get_wolfram_alpha_tool class AgentBase: @@ -73,7 +73,10 @@ def _get_tool(self) -> Any: if self.tool.type == "SEARCH": tools = get_search_tool() - return tools + if self.tool.type == "WOLFRAM_ALPHA": + tools = get_wolfram_alpha_tool() + + return tools except Exception: return None diff --git a/app/lib/tools.py b/app/lib/tools.py index 27386cf38..1d9a3df18 100644 --- a/app/lib/tools.py +++ b/app/lib/tools.py @@ -3,6 +3,7 @@ from decouple import config from langchain.agents import Tool from langchain.utilities import BingSearchAPIWrapper +from langchain.utilities.wolfram_alpha import WolframAlphaAPIWrapper def get_search_tool() -> List: @@ -19,3 +20,16 @@ def get_search_tool() -> List: ] return tools + + +def get_wolfram_alpha_tool() -> List: + wolfram = WolframAlphaAPIWrapper() + tools = [ + Tool( + name="Wolfram Alpha", + func=wolfram.run, + description="useful for when you need to do computation", + ) + ] + + return tools diff --git a/poetry.lock b/poetry.lock index 7f379ed69..0a9a096f2 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1049,6 +1049,22 @@ files = [ {file = "itsdangerous-2.1.2.tar.gz", hash = "sha256:5dbbc68b317e5e42f327f9021763545dc3fc3bfe22e6deb96aaf1fc38874156a"}, ] +[[package]] +name = "jaraco-context" +version = "4.3.0" +description = "Context managers by jaraco" +category = "main" +optional = false +python-versions = ">=3.7" +files = [ + {file = "jaraco.context-4.3.0-py3-none-any.whl", hash = "sha256:5d9e95ca0faa78943ed66f6bc658dd637430f16125d86988e77844c741ff2f11"}, + {file = "jaraco.context-4.3.0.tar.gz", hash = "sha256:4dad2404540b936a20acedec53355bdaea223acb88fd329fa6de9261c941566e"}, +] + +[package.extras] +docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] +testing = ["flake8 (<5)", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)"] + [[package]] name = "jinja2" version = "3.1.2" @@ -1364,6 +1380,18 @@ files = [ {file = "monotonic-1.6.tar.gz", hash = "sha256:3a55207bcfed53ddd5c5bae174524062935efed17792e9de2ad0205ce9ad63f7"}, ] +[[package]] +name = "more-itertools" +version = "9.1.0" +description = "More routines for operating on iterables, beyond itertools" +category = "main" +optional = false +python-versions = ">=3.7" +files = [ + {file = "more-itertools-9.1.0.tar.gz", hash = "sha256:cabaa341ad0389ea83c17a94566a53ae4c9d07349861ecb14dc6d0345cf9ac5d"}, + {file = "more_itertools-9.1.0-py3-none-any.whl", hash = "sha256:d2bc7f02446e86a68911e58ded76d6561eea00cddfb2a91e7019bbb586c799f3"}, +] + [[package]] name = "msg-parser" version = "1.2.0" @@ -3117,6 +3145,27 @@ files = [ [package.extras] dev = ["black (>=19.3b0)", "pytest (>=4.6.2)"] +[[package]] +name = "wolframalpha" +version = "5.0.0" +description = "Wolfram|Alpha 2.0 API client" +category = "main" +optional = false +python-versions = ">=3.6" +files = [ + {file = "wolframalpha-5.0.0-py3-none-any.whl", hash = "sha256:159f5d8fd31e4a734a34a9f3ae8aec4e9b2ef392607f82069b4a324b6b1831d5"}, + {file = "wolframalpha-5.0.0.tar.gz", hash = "sha256:38bf27654039ec85cc62c199dd319b6a4d6a7badfed7af1cd161f081afdb57c0"}, +] + +[package.dependencies] +"jaraco.context" = "*" +more-itertools = "*" +xmltodict = "*" + +[package.extras] +docs = ["jaraco.packaging (>=8.2)", "rst.linker (>=1.9)", "sphinx"] +testing = ["keyring", "pmxbot", "pytest (>=3.5,!=3.7.3)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=1.2.3)", "pytest-cov", "pytest-enabler", "pytest-flake8", "pytest-mypy"] + [[package]] name = "wrapt" version = "1.14.1" @@ -3203,6 +3252,18 @@ files = [ {file = "XlsxWriter-3.1.0.tar.gz", hash = "sha256:02913b50b74c00f165933d5da3e3a02cab4204cb4932722a1b342c5c71034122"}, ] +[[package]] +name = "xmltodict" +version = "0.13.0" +description = "Makes working with XML feel like you are working with JSON" +category = "main" +optional = false +python-versions = ">=3.4" +files = [ + {file = "xmltodict-0.13.0-py2.py3-none-any.whl", hash = "sha256:aa89e8fd76320154a40d19a0df04a4695fb9dc5ba977cbb68ab3e4eb225e7852"}, + {file = "xmltodict-0.13.0.tar.gz", hash = "sha256:341595a488e3e01a85a9d8911d8912fd922ede5fecc4dce437eb4b6c8d037e56"}, +] + [[package]] name = "yarl" version = "1.9.2" @@ -3310,4 +3371,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "76a209cf169e7e4fcdb2ebe66463b2d39b71d093c47e0e463c90d61e36b8681e" +content-hash = "ae6ecb11ee3c3d05806b342b738dd0e8aec7ee1b3b9f6c757a2b2ce0b95c137d" diff --git a/prisma/migrations/20230608154711_tool_wolfram_alpha/migration.sql b/prisma/migrations/20230608154711_tool_wolfram_alpha/migration.sql new file mode 100644 index 000000000..039838614 --- /dev/null +++ b/prisma/migrations/20230608154711_tool_wolfram_alpha/migration.sql @@ -0,0 +1,2 @@ +-- AlterEnum +ALTER TYPE "ToolType" ADD VALUE 'WOLFRAM_ALPHA'; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index abe92437d..a97535b13 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -29,6 +29,7 @@ enum DocumentType { enum ToolType { BROWSER SEARCH + WOLFRAM_ALPHA } model User { diff --git a/pyproject.toml b/pyproject.toml index ed66b0072..37ed2a75b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,6 +30,7 @@ pinecone-client = "^2.2.1" tiktoken = "^0.4.0" pypdf = "^3.8.1" cohere = "^4.5.1" +wolframalpha = "^5.0.0" [build-system]