From 55df820748cc14d75218876afbfcb08dc3e5f950 Mon Sep 17 00:00:00 2001 From: Ismail Pelaseyed Date: Wed, 24 Apr 2024 15:38:02 +0200 Subject: [PATCH 1/5] Add support for SEC API as a tool --- .../app/api/workflow_configs/saml_schema.py | 1 + libs/superagent/app/models/tools.py | 4 ++++ libs/superagent/app/tools/__init__.py | 3 +++ libs/superagent/app/tools/sec.py | 19 +++++++++++++++++++ libs/superagent/prisma/schema.prisma | 1 + libs/ui/config/site.ts | 16 ++++++++++++++++ 6 files changed, 44 insertions(+) create mode 100644 libs/superagent/app/tools/sec.py diff --git a/libs/superagent/app/api/workflow_configs/saml_schema.py b/libs/superagent/app/api/workflow_configs/saml_schema.py index 01253e758..b4866dc02 100644 --- a/libs/superagent/app/api/workflow_configs/saml_schema.py +++ b/libs/superagent/app/api/workflow_configs/saml_schema.py @@ -82,6 +82,7 @@ class ToolModel(BaseModel): metaphor: Optional[Tool] function: Optional[Tool] research: Optional[Tool] + sec_api: Optional[Tool] # ~~~~~~Assistants as tools~~~~~~ superagent: Optional["SuperagentAgentTool"] openai_assistant: Optional["OpenAIAgentTool"] diff --git a/libs/superagent/app/models/tools.py b/libs/superagent/app/models/tools.py index bc6d365f6..4cc9e38a3 100644 --- a/libs/superagent/app/models/tools.py +++ b/libs/superagent/app/models/tools.py @@ -108,3 +108,7 @@ class AdvancedScraperInput(BaseModel): class GoogleSearchInput(BaseModel): query: str + + +class SECInput(BaseModel): + ticker: str diff --git a/libs/superagent/app/tools/__init__.py b/libs/superagent/app/tools/__init__.py index 049549501..92d25eb05 100644 --- a/libs/superagent/app/tools/__init__.py +++ b/libs/superagent/app/tools/__init__.py @@ -28,6 +28,7 @@ TTS1Input, WolframInput, ZapierInput, + SECInput, ) from app.tools.advanced_scraper import AdvancedScraper from app.tools.agent import Agent @@ -53,6 +54,7 @@ from app.tools.tts_1 import TTS1 from app.tools.wolfram_alpha import WolframAlpha from app.tools.zapier import ZapierNLA +from app.tools.sec import SEC logger = logging.getLogger(__name__) @@ -89,6 +91,7 @@ "SCRAPER": {"class": Scraper, "schema": ScraperInput}, "ADVANCED_SCRAPER": {"class": AdvancedScraper, "schema": AdvancedScraperInput}, "GOOGLE_SEARCH": {"class": GoogleSearch, "schema": GoogleSearchInput}, + "SEC": {"class": SEC, "schema": SECInput}, } OSS_TOOL_TYPE_MAPPING = {"BROWSER": Browser, "BING_SEARCH": BingSearch} diff --git a/libs/superagent/app/tools/sec.py b/libs/superagent/app/tools/sec.py new file mode 100644 index 000000000..ff7db7165 --- /dev/null +++ b/libs/superagent/app/tools/sec.py @@ -0,0 +1,19 @@ +import aiohttp + +from langchain_community.tools import BaseTool + + +class SEC(BaseTool): + name = "SEC" + description = "useful for searching SEC filings for a company" + return_direct = False + + async def _arun(self, ticker: str) -> str: + form = self.metadata.get("form") + indentity = self.metadata.get("identity") + url = "https://super-sec.replit.app/search" + data = {"form": form, "identity": indentity, "ticker": ticker} + + async with aiohttp.ClientSession() as session: + async with session.post(url, json=data) as response: + return await response.text() diff --git a/libs/superagent/prisma/schema.prisma b/libs/superagent/prisma/schema.prisma index c3125752d..d10bb6620 100644 --- a/libs/superagent/prisma/schema.prisma +++ b/libs/superagent/prisma/schema.prisma @@ -67,6 +67,7 @@ enum ToolType { SCRAPER ADVANCED_SCRAPER GOOGLE_SEARCH + SEC } enum DatasourceType { diff --git a/libs/ui/config/site.ts b/libs/ui/config/site.ts index f65099579..64fa1e01c 100644 --- a/libs/ui/config/site.ts +++ b/libs/ui/config/site.ts @@ -446,6 +446,22 @@ export const siteConfig = { }, ], }, + { + value: "SEC", + title: "SEC API", + metadata: [ + { + key: "identity", + type: "input", + label: "Identity string", + }, + { + key: "form", + type: "input", + label: "10-K, 10-Q, 8-K etc", + }, + ], + }, ], llmForm: [ { From 46bceb28ef03364fb1f08654a38d489eaa57e644 Mon Sep 17 00:00:00 2001 From: Ismail Pelaseyed Date: Wed, 24 Apr 2024 16:25:25 +0200 Subject: [PATCH 2/5] Minor tweaks --- libs/superagent/app/api/workflow_configs/saml_schema.py | 2 +- libs/superagent/app/tools/sec.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/superagent/app/api/workflow_configs/saml_schema.py b/libs/superagent/app/api/workflow_configs/saml_schema.py index b4866dc02..2d7761881 100644 --- a/libs/superagent/app/api/workflow_configs/saml_schema.py +++ b/libs/superagent/app/api/workflow_configs/saml_schema.py @@ -82,7 +82,7 @@ class ToolModel(BaseModel): metaphor: Optional[Tool] function: Optional[Tool] research: Optional[Tool] - sec_api: Optional[Tool] + sec: Optional[Tool] # ~~~~~~Assistants as tools~~~~~~ superagent: Optional["SuperagentAgentTool"] openai_assistant: Optional["OpenAIAgentTool"] diff --git a/libs/superagent/app/tools/sec.py b/libs/superagent/app/tools/sec.py index ff7db7165..3cfd5330f 100644 --- a/libs/superagent/app/tools/sec.py +++ b/libs/superagent/app/tools/sec.py @@ -10,9 +10,9 @@ class SEC(BaseTool): async def _arun(self, ticker: str) -> str: form = self.metadata.get("form") - indentity = self.metadata.get("identity") + identity = self.metadata.get("identity") url = "https://super-sec.replit.app/search" - data = {"form": form, "identity": indentity, "ticker": ticker} + data = {"form": form, "identity": identity, "ticker": ticker} async with aiohttp.ClientSession() as session: async with session.post(url, json=data) as response: From 40df732671eb868021c5063506b803173eb3f877 Mon Sep 17 00:00:00 2001 From: Ismail Pelaseyed Date: Wed, 24 Apr 2024 16:27:16 +0200 Subject: [PATCH 3/5] Add field description to ticker model --- libs/superagent/app/models/tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/superagent/app/models/tools.py b/libs/superagent/app/models/tools.py index 4cc9e38a3..af0ce6185 100644 --- a/libs/superagent/app/models/tools.py +++ b/libs/superagent/app/models/tools.py @@ -1,6 +1,6 @@ from typing import Optional -from pydantic import BaseModel +from pydantic import BaseModel, Field class AlgoliaInput(BaseModel): @@ -111,4 +111,4 @@ class GoogleSearchInput(BaseModel): class SECInput(BaseModel): - ticker: str + ticker: str = Field(..., description="The stock ticker symbol for the company") From edfc02b4c9050a3f340c2c69a119705ef72ced01 Mon Sep 17 00:00:00 2001 From: Ismail Pelaseyed Date: Wed, 24 Apr 2024 16:36:48 +0200 Subject: [PATCH 4/5] Add migrations --- .../prisma/migrations/20240424143511_add_sec_api/migration.sql | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 libs/superagent/prisma/migrations/20240424143511_add_sec_api/migration.sql diff --git a/libs/superagent/prisma/migrations/20240424143511_add_sec_api/migration.sql b/libs/superagent/prisma/migrations/20240424143511_add_sec_api/migration.sql new file mode 100644 index 000000000..cff891724 --- /dev/null +++ b/libs/superagent/prisma/migrations/20240424143511_add_sec_api/migration.sql @@ -0,0 +1,2 @@ +-- AlterEnum +ALTER TYPE "ToolType" ADD VALUE 'SEC'; From b79af5b01828c0d8fe2e16b44da160bfb740a24a Mon Sep 17 00:00:00 2001 From: Ismail Pelaseyed Date: Wed, 24 Apr 2024 19:58:47 +0200 Subject: [PATCH 5/5] Add _run method to SEC tool --- libs/superagent/app/tools/sec.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/superagent/app/tools/sec.py b/libs/superagent/app/tools/sec.py index 3cfd5330f..114696611 100644 --- a/libs/superagent/app/tools/sec.py +++ b/libs/superagent/app/tools/sec.py @@ -8,6 +8,9 @@ class SEC(BaseTool): description = "useful for searching SEC filings for a company" return_direct = False + def _run(self, ticker: str) -> str: + pass + async def _arun(self, ticker: str) -> str: form = self.metadata.get("form") identity = self.metadata.get("identity")