forked from TransformerOptimus/SuperAGI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding llm thinking & webscraper tool
- Loading branch information
TransformerOptimus
committed
May 27, 2023
1 parent
bf2a0e6
commit 07661a0
Showing
5 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from typing import Type | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
from superagi.llms.base_llm import BaseLlm | ||
from superagi.tools.base_tool import BaseTool | ||
|
||
|
||
class LlmTaskSchema(BaseModel): | ||
task_description: str = Field( | ||
..., | ||
description="Text describing the task for which the LLM should generate a response.", | ||
) | ||
|
||
class LlmThinkingTool(BaseTool): | ||
llm: BaseLlm = None | ||
name = "LlmThinkingTool" | ||
description = ( | ||
"A tool that interacts with any given LLM " | ||
"to generate text given a certain task description." | ||
) | ||
args_schema: Type[LlmTaskSchema] = LlmTaskSchema | ||
|
||
class Config: | ||
arbitrary_types_allowed = True | ||
|
||
def _execute(self, task_description: str = "") -> str: | ||
try: | ||
messages = [{"role": "system", "content": task_description}] | ||
result = self.llm.chat_completion(messages) | ||
return result["content"] | ||
except Exception as e: | ||
print(e) | ||
return f"Error generating text: {e}" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from typing import Type | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
from superagi.helper.webpage_extractor import WebpageExtractor | ||
from superagi.tools.base_tool import BaseTool | ||
|
||
|
||
class WebScraperSchema(BaseModel): | ||
website_url: str = Field( | ||
..., | ||
description="website url", | ||
) | ||
|
||
|
||
class WebScraperTool(BaseTool): | ||
name = "WebScraperTool" | ||
description = ( | ||
"Used to scrape website urls and extract text content" | ||
) | ||
args_schema: Type[WebScraperSchema] = WebScraperSchema | ||
|
||
def _execute(self, website_url: str) -> tuple: | ||
content = WebpageExtractor().extract_with_bs4(website_url) | ||
return content[:1000] |