mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
feat(Builder): Adds node to get summary from wikipedia (#7384)
* adds node to get summary from wikipedia * update name * Fix naming again
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from autogpt_server.blocks import sample, reddit, text, ai
|
||||
from autogpt_server.blocks.wikipedia import GetWikipediaSummary
|
||||
from autogpt_server.data.block import Block
|
||||
|
||||
AVAILABLE_BLOCKS = {
|
||||
@@ -6,4 +7,4 @@ AVAILABLE_BLOCKS = {
|
||||
for block in [v() for v in Block.__subclasses__()]
|
||||
}
|
||||
|
||||
__all__ = ["ai", "sample", "reddit", "text", "AVAILABLE_BLOCKS"]
|
||||
__all__ = ["ai", "sample", "reddit", "text", "AVAILABLE_BLOCKS", "GetWikipediaSummary"]
|
||||
|
||||
33
rnd/autogpt_server/autogpt_server/blocks/wikipedia.py
Normal file
33
rnd/autogpt_server/autogpt_server/blocks/wikipedia.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import requests
|
||||
from autogpt_server.data.block import Block, BlockSchema, BlockOutput
|
||||
|
||||
class GetWikipediaSummary(Block):
|
||||
class Input(BlockSchema):
|
||||
topic: str
|
||||
|
||||
class Output(BlockSchema):
|
||||
summary: str
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
id="h5e7f8g9-1b2c-3d4e-5f6g-7h8i9j0k1l2m",
|
||||
input_schema=GetWikipediaSummary.Input,
|
||||
output_schema=GetWikipediaSummary.Output,
|
||||
test_input={"topic": "Artificial Intelligence"},
|
||||
test_output={"summary": "Artificial intelligence (AI) is intelligence demonstrated by machines, in contrast to the natural intelligence displayed by humans and animals."},
|
||||
)
|
||||
|
||||
def run(self, input_data: Input) -> BlockOutput:
|
||||
try:
|
||||
response = requests.get(f"https://en.wikipedia.org/api/rest_v1/page/summary/{input_data.topic}")
|
||||
response.raise_for_status()
|
||||
summary_data = response.json()
|
||||
|
||||
yield "summary", summary_data['extract']
|
||||
|
||||
except requests.exceptions.HTTPError as http_err:
|
||||
raise ValueError(f"HTTP error occurred: {http_err}")
|
||||
except requests.RequestException as e:
|
||||
raise ValueError(f"Request to Wikipedia API failed: {e}")
|
||||
except KeyError as e:
|
||||
raise ValueError(f"Error processing Wikipedia data: {e}")
|
||||
Reference in New Issue
Block a user