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(blocks): Add Wolfram Alpha LLM API Block (#10486)
Swiftybb71492c8f93
diff --git a/autogpt_platform/backend/backend/blocks/wolfram/__init__.py b/autogpt_platform/backend/backend/blocks/wolfram/__init__.pynew file mode 100644index 0000000000..e69de29bb2diff --git a/autogpt_platform/backend/backend/blocks/wolfram/_api.py b/autogpt_platform/backend/backend/blocks/wolfram/_api.pynew file mode 100644index 0000000000..8c76542b1f--- /dev/null+++ b/autogpt_platform/backend/backend/blocks/wolfram/_api.py@@ -0,0 +1,14 @@+from backend.sdk import APIKeyCredentials, Requests+++async def llm_api_call(credentials: APIKeyCredentials, question: str) -> str:+ params = {"appid": credentials.api_key.get_secret_value(), "input": question}+ response = await Requests().get(+ "https://www.wolframalpha.com/api/v1/llm-api", params=params+ )+ if not response.ok:+ raise ValueError(f"API request failed: {response.status} {response.text()}")++ answer = response.text() if response.text() else ""++ return answerdiff --git a/autogpt_platform/backend/backend/blocks/wolfram/llm_api.py b/autogpt_platform/backend/backend/blocks/wolfram/llm_api.pynew file mode 100644index 0000000000..5586e0d8ef--- /dev/null+++ b/autogpt_platform/backend/backend/blocks/wolfram/llm_api.py@@ -0,0 +1,50 @@+from backend.sdk import (+ APIKeyCredentials,+ Block,+ BlockCategory,+ BlockCostType,+ BlockOutput,+ BlockSchema,+ CredentialsMetaInput,+ ProviderBuilder,+ SchemaField,+)++from ._api import llm_api_call++wolfram = (+ ProviderBuilder("wolfram")+ .with_api_key("WOLFRAM_APP_ID", "Wolfram Alpha App ID")+ .with_base_cost(1, BlockCostType.RUN)+ .build()+)+++class AskWolframBlock(Block):+ """+ Ask Wolfram Alpha a question.+ """++ class Input(BlockSchema):+ credentials: CredentialsMetaInput = wolfram.credentials_field(+ description="Wolfram Alpha API credentials"+ )+ question: str = SchemaField(description="The question to ask")++ class Output(BlockSchema):+ answer: str = SchemaField(description="The answer to the question")++ def __init__(self):+ super().__init__(+ id="b7710ce4-68ef-4e82-9a2f-f0b874ef9c7d",+ description="Ask Wolfram Alpha a question",+ categories={BlockCategory.SEARCH},+ input_schema=self.Input,+ output_schema=self.Output,+ )++ async def run(+ self, input_data: Input, *, credentials: APIKeyCredentials, **kwargs+ ) -> BlockOutput:+ answer = await llm_api_call(credentials, input_data.question)+ yield "answer", answer