mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
fix(server): various linting errors (#7498)
This commit is contained in:
@@ -8,7 +8,7 @@ from autogpt_server.data.model import BlockSecret, SchemaField, SecretField
|
||||
|
||||
class CreateMediumPostBlock(Block):
|
||||
class Input(BlockSchema):
|
||||
author_id: str = SecretField(
|
||||
author_id: BlockSecret = SecretField(
|
||||
key="medium_author_id",
|
||||
description="""The Medium AuthorID of the user. You can get this by calling the /me endpoint of the Medium API.\n\ncurl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" https://api.medium.com/v1/me" the response will contain the authorId field.""",
|
||||
placeholder="Enter the author's Medium AuthorID",
|
||||
@@ -29,7 +29,7 @@ class CreateMediumPostBlock(Block):
|
||||
description="List of tags for your Medium post (up to 5)",
|
||||
placeholder="['technology', 'AI', 'blogging']",
|
||||
)
|
||||
canonical_url: str = SchemaField(
|
||||
canonical_url: str | None = SchemaField(
|
||||
default=None,
|
||||
description="The original home of this content, if it was originally published elsewhere",
|
||||
placeholder="https://yourblog.com/original-post",
|
||||
|
||||
@@ -6,6 +6,7 @@ import requests
|
||||
from autogpt_server.data.block import Block, BlockOutput, BlockSchema
|
||||
from autogpt_server.data.model import BlockSecret, SecretField
|
||||
|
||||
|
||||
class GetRequest:
|
||||
@classmethod
|
||||
def get_request(cls, url: str, json=False) -> Any:
|
||||
@@ -141,16 +142,22 @@ class GetOpenWeatherMapWeather(Block, GetRequest):
|
||||
id="f7a8b2c3-6d4e-5f8b-9e7f-6d4e5f8b9e7f",
|
||||
input_schema=GetOpenWeatherMapWeather.Input,
|
||||
output_schema=GetOpenWeatherMapWeather.Output,
|
||||
test_input={"location": "New York", "api_key": "YOUR_API_KEY", "use_celsius": True},
|
||||
test_input={
|
||||
"location": "New York",
|
||||
"api_key": "YOUR_API_KEY",
|
||||
"use_celsius": True,
|
||||
},
|
||||
test_output=[
|
||||
("temperature", "21.66"),
|
||||
("humidity", "32"),
|
||||
("condition", "overcast clouds")
|
||||
("condition", "overcast clouds"),
|
||||
],
|
||||
test_mock={"get_request": lambda url, json: {
|
||||
"main": {"temp": 21.66, "humidity": 32},
|
||||
"weather": [{"description": "overcast clouds"}]
|
||||
}},
|
||||
test_mock={
|
||||
"get_request": lambda url, json: {
|
||||
"main": {"temp": 21.66, "humidity": 32},
|
||||
"weather": [{"description": "overcast clouds"}],
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
def run(self, input_data: Input) -> BlockOutput:
|
||||
@@ -161,19 +168,19 @@ class GetOpenWeatherMapWeather(Block, GetRequest):
|
||||
url = f"http://api.openweathermap.org/data/2.5/weather?q={quote(location)}&appid={api_key}&units={units}"
|
||||
weather_data = self.get_request(url, json=True)
|
||||
|
||||
if 'main' in weather_data and 'weather' in weather_data:
|
||||
yield "temperature", str(weather_data['main']['temp'])
|
||||
yield "humidity", str(weather_data['main']['humidity'])
|
||||
yield "condition", weather_data['weather'][0]['description']
|
||||
if "main" in weather_data and "weather" in weather_data:
|
||||
yield "temperature", str(weather_data["main"]["temp"])
|
||||
yield "humidity", str(weather_data["main"]["humidity"])
|
||||
yield "condition", weather_data["weather"][0]["description"]
|
||||
else:
|
||||
yield "error", f"Expected keys not found in response: {weather_data}"
|
||||
|
||||
except requests.exceptions.HTTPError as http_err:
|
||||
if http_err.response.status_code == 403:
|
||||
yield "error", f"Request to weather API failed: 403 Forbidden. Check your API key and permissions."
|
||||
yield "error", "Request to weather API failed: 403 Forbidden. Check your API key and permissions."
|
||||
else:
|
||||
yield "error", f"HTTP error occurred: {http_err}"
|
||||
except requests.RequestException as e:
|
||||
yield "error", f"Request to weather API failed: {e}"
|
||||
except KeyError as e:
|
||||
yield "error", f"Error processing weather data: {e}"
|
||||
yield "error", f"Error processing weather data: {e}"
|
||||
|
||||
@@ -103,7 +103,7 @@ def SchemaField(
|
||||
json_extra: dict[str, Any] = {}
|
||||
if placeholder:
|
||||
json_extra["placeholder"] = placeholder
|
||||
if secret:
|
||||
if secret:
|
||||
json_extra["secret"] = True
|
||||
|
||||
return Field(
|
||||
|
||||
@@ -80,7 +80,9 @@ class Secrets(UpdateTrackingModel["Secrets"], BaseSettings):
|
||||
reddit_username: str = Field(default="", description="Reddit username")
|
||||
reddit_password: str = Field(default="", description="Reddit password")
|
||||
|
||||
openweathermap_api_key: str = Field(default="", description="OpenWeatherMap API key")
|
||||
openweathermap_api_key: str = Field(
|
||||
default="", description="OpenWeatherMap API key"
|
||||
)
|
||||
|
||||
medium_api_key: str = Field(default="", description="Medium API key")
|
||||
medium_author_id: str = Field(default="", description="Medium author ID")
|
||||
|
||||
Reference in New Issue
Block a user