AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
feat(Builder): Adds node to get summary from wikipedia (#7384)
Bently2ecce276539f
diff --git a/rnd/autogpt_server/autogpt_server/blocks/__init__.py b/rnd/autogpt_server/autogpt_server/blocks/__init__.pyindex b7631b954f..7a0f255ca0 100644--- a/rnd/autogpt_server/autogpt_server/blocks/__init__.py+++ b/rnd/autogpt_server/autogpt_server/blocks/__init__.py@@ -1,4 +1,5 @@from autogpt_server.blocks import sample, reddit, text, ai+from autogpt_server.blocks.wikipedia import GetWikipediaSummaryfrom autogpt_server.data.block import BlockAVAILABLE_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"]diff --git a/rnd/autogpt_server/autogpt_server/blocks/wikipedia.py b/rnd/autogpt_server/autogpt_server/blocks/wikipedia.pynew file mode 100644index 0000000000..5d1ac7ce2a--- /dev/null+++ b/rnd/autogpt_server/autogpt_server/blocks/wikipedia.py@@ -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}")\ No newline at end of file