Skip to content

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 DataForSEO keyword research blocks (#10711)

Swifty7c908c10b850
diff --git a/autogpt_platform/backend/backend/blocks/dataforseo/__init__.py b/autogpt_platform/backend/backend/blocks/dataforseo/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/autogpt_platform/backend/backend/blocks/dataforseo/_api.py b/autogpt_platform/backend/backend/blocks/dataforseo/_api.py
new file mode 100644
index 0000000000..025b322e48
--- /dev/null
+++ b/autogpt_platform/backend/backend/blocks/dataforseo/_api.py
@@ -0,0 +1,178 @@
+"""
+DataForSEO API client with async support using the SDK patterns.
+"""
+
+import base64
+from typing import Any, Dict, List, Optional
+
+from backend.sdk import Requests, UserPasswordCredentials
+
+
+class DataForSeoClient:
+ """Client for the DataForSEO API using async requests."""
+
+ API_URL = "https://api.dataforseo.com"
+
+ def __init__(self, credentials: UserPasswordCredentials):
+ self.credentials = credentials
+ self.requests = Requests(
+ trusted_origins=["https://api.dataforseo.com"],
+ raise_for_status=False,
+ )
+
+ def _get_headers(self) -> Dict[str, str]:
+ """Generate the authorization header using Basic Auth."""
+ username = self.credentials.username.get_secret_value()
+ password = self.credentials.password.get_secret_value()
+ credentials_str = f"{username}:{password}"
+ encoded = base64.b64encode(credentials_str.encode("ascii")).decode("ascii")
+ return {
+ "Authorization": f"Basic {encoded}",
+ "Content-Type": "application/json",
+ }
+
+ async def keyword_suggestions(
+ self,
+ keyword: str,
+ location_code: Optional[int] = None,
+ language_code: Optional[str] = None,
+ include_seed_keyword: bool = True,
+ include_serp_info: bool = False,
+ include_clickstream_data: bool = False,
+ limit: int = 100,
+ ) -> List[Dict[str, Any]]:
+ """
+ Get keyword suggestions from DataForSEO Labs.
+
+ Args:
+ keyword: Seed keyword
+ location_code: Location code for targeting
+ language_code: Language code (e.g., "en")
+ include_seed_keyword: Include seed keyword in results
+ include_serp_info: Include SERP data
+ include_clickstream_data: Include clickstream metrics
+ limit: Maximum number of results (up to 3000)
+
+ Returns:
+ API response with keyword suggestions
+ """
+ endpoint = f"{self.API_URL}/v3/dataforseo_labs/google/keyword_suggestions/live"
+
+ # Build payload only with non-None values to avoid sending null fields
+ task_data: dict[str, Any] = {
+ "keyword": keyword,
+ }
+
+ if location_code is not None:
+ task_data["location_code"] = location_code
+ if language_code is not None:
+ task_data["language_code"] = language_code
+ if include_seed_keyword is not None:
+ task_data["include_seed_keyword"] = include_seed_keyword
+ if include_serp_info is not None:
+ task_data["include_serp_info"] = include_serp_info
+ if include_clickstream_data is not None:
+ task_data["include_clickstream_data"] = include_clickstream_data
+ if limit is not None:
+ task_data["limit"] = limit
+
+ payload = [task_data]
+
+ response = await self.requests.post(
+ endpoint,
+ headers=self._get_headers(),
+ json=payload,
+ )
+
+ data = response.json()
+
+ # Check for API errors
+ if response.status != 200:
+ error_message = data.get("status_message", "Unknown error")
+ raise Exception(
+ f"DataForSEO API error ({response.status}): {error_message}"
+ )
+
+ # Extract the results from the response
+ if data.get("tasks") and len(data["tasks"]) > 0:
+ task = data["tasks"][0]
+ if task.get("status_code") == 20000: # Success code
+ return task.get("result", [])
+ else:
+ error_msg = task.get("status_message", "Task failed")
+ raise Exception(f"DataForSEO task error: {error_msg}")
+
+ return []
+
+ async def related_keywords(
+ self,
+ keyword: str,
+ location_code: Optional[int] = None,
+ language_code: Optional[str] = None,
+ include_seed_keyword: bool = True,
+ include_serp_info: bool = False,
+ include_clickstream_data: bool = False,
+ limit: int = 100,
+ ) -> List[Dict[str, Any]]:
+ """
+ Get related keywords from DataForSEO Labs.
+
+ Args:
+ keyword: Seed keyword
+ location_code: Location code for targeting
+ language_code: Language code (e.g., "en")
+ include_seed_keyword: Include seed keyword in results
+ include_serp_info: Include SERP data
+ include_clickstream_data: Include clickstream metrics
+ limit: Maximum number of results (up to 3000)
+
+ Returns:
+ API response with related keywords
+ """
+ endpoint = f"{self.API_URL}/v3/dataforseo_labs/google/related_keywords/live"
+
+ # Build payload only with non-None values to avoid sending null fields
+ task_data: dict[str, Any] = {
+ "keyword": keyword,
+ }
+
+ if location_code is not None:
+ task_data["location_code"] = location_code
+ if language_code is not None:
+ task_data["language_code"] = language_code
+ if include_seed_keyword is not None:
+ task_data["include_seed_keyword"] = include_seed_keyword
+ if include_serp_info is not None:
+ task_data["include_serp_info"] = include_serp_info
+ if include_clickstream_data is not None:
+ task_data["include_clickstream_data"] = include_clickstream_data
+ if limit is not None:
+ task_data["limit"] = limit
+
+ payload = [task_data]
+
+ response = await self.requests.post(
+ endpoint,
+ headers=self._get_headers(),
+ json=payload,
+ )
+
+ data = response.json()
+
+ # Check for API errors
+ if response.status != 200:
+ error_message = data.get("status_message", "Unknown error")
+ raise Exception(
+ f"DataForSEO API error ({response.status}): {error_message}"
+ )
+
+ # Extract the results from the response
+ if data.get("tasks") and len(data["tasks"]) > 0:
+ task = data["tasks"][0]
+ if task.get("status_code") == 20000: # Success code
+ return task.get("result", [])
+ else:
+ error_msg = task.get("status_message", "Task failed")
+ raise Exception(f"DataForSEO task error: {error_msg}")
+
+ return []
diff --git a/autogpt_platform/backend/backend/blocks/dataforseo/_config.py b/autogpt_platform/backend/backend/blocks/dataforseo/_config.py
new file mode 100644
index 0000000000..10b2b91130
--- /dev/null
+++ b/autogpt_platform/backend/backend/blocks/dataforseo/_config.py
@@ -0,0 +1,17 @@
+"""
+Configuration for all DataForSEO blocks using the new SDK pattern.
+"""
+
+from backend.sdk import BlockCostType, ProviderBuilder
+
+# Build the DataForSEO provider with username/password authentication
+dataforseo = (
+ ProviderBuilder("dataforseo")
+ .with_user_password(
+ username_env_var="DATAFORSEO_USERNAME",
+ password_env_var="DATAFORSEO_PASSWORD",
+ title="DataForSEO Credentials",
+ )
+ .with_base_cost(1, BlockCostType.RUN)
+ .build()
+)
diff --git a/autogpt_platform/backend/backend/blocks/dataforseo/keyword_suggestions.py b/autogpt_platform/backend/backend/blocks/dataforseo/keyword_suggestions.py
new file mode 100644
index 0000000000..ac36215bc7
--- /dev/null
+++ b/autogpt_platform/backend/backend/blocks/dataforseo/keyword_suggestions.py
@@ -0,0 +1,273 @@
+"""
+DataForSEO Google Keyword Suggestions block.
+"""
+
+from typing import Any, Dict, List, Optional
+
+from backend.sdk import (
+ Block,
+ BlockCategory,
+ BlockOutput,
+ BlockSchema,
+ CredentialsMetaInput,
+ SchemaField,
+ UserPasswordCredentials,
+)
+
+from ._api import DataForSeoClient
+from ._config import dataforseo
+
+
+class KeywordSuggestion(BlockSchema):
+ """Schema for a keyword suggestion result."""
+
+ keyword: str = SchemaField(description="The keyword suggestion")
+ search_volume: Optional[int] = SchemaField(
+ description="Monthly search volume", default=None
+ )
+ competition: Optional[float] = SchemaField(
+ description="Competition level (0-1)", default=None
+ )
+ cpc: Optional[float] = SchemaField(
+ description="Cost per click in USD", default=None
+ )
+ keyword_difficulty: Optional[int] = SchemaField(
+ description="Keyword difficulty score", default=None
+ )
+ serp_info: Optional[Dict[str, Any]] = SchemaField(
+ description="data from SERP for each keyword", default=None
+ )
+ clickstream_data: Optional[Dict[str, Any]] = SchemaField(
+ description="Clickstream data metrics", default=None
+ )
+
+
+class DataForSeoKeywordSuggestionsBlock(Block):
+ """Block for getting keyword suggestions from DataForSEO Labs."""
+
+ class Input(BlockSchema):
+ credentials: CredentialsMetaInput = dataforseo.credentials_field(
+ description="DataForSEO credentials (username and password)"
+ )
+ keyword: str = SchemaField(description="Seed keyword to get suggestions for")
+ location_code: Optional[int] = SchemaField(
+ description="Location code for targeting (e.g., 2840 for USA)",
+ default=2840, # USA
+ )
+ language_code: Optional[str] = SchemaField(
+ description="Language code (e.g., 'en' for English)",
+ default="en",
+ )
+ include_seed_keyword: bool = SchemaField(
+ description="Include the seed keyword in results",
+ default=True,
+ )
+ include_serp_info: bool = SchemaField(
+ description="Include SERP information",
+ default=False,
+ )
+ include_clickstream_data: bool = SchemaField(
+ description="Include clickstream metrics",
+ default=False,
+ )
+ limit: int = SchemaField(
+ description="Maximum number of results (up to 3000)",
+ default=100,
+ ge=1,
+ le=3000,
+ )
+
+ class Output(BlockSchema):
+ suggestions: List[KeywordSuggestion] = SchemaField(
+ description="List of keyword suggestions with metrics"
+ )
+ suggestion: KeywordSuggestion = SchemaField(
+ description="A single keyword suggestion with metrics"
+ )
+ total_count: int = SchemaField(
+ description="Total number of suggestions returned"
+ )
+ seed_keyword: str = SchemaField(
+ description="The seed keyword used for the query"
+ )
+
+ def __init__(self):
+ super().__init__(
+ id="73c3e7c4-2b3f-4e9f-9e3e-8f7a5c3e2d45",
+ description="Get keyword suggestions from DataForSEO Labs Google API",
+ categories={BlockCategory.SEARCH, BlockCategory.DATA},
+ input_schema=self.Input,
+ output_schema=self.Output,
+ test_input={
+ "credentials": dataforseo.get_test_credentials().model_dump(),
+ "keyword": "digital marketing",
+ "location_code": 2840,
+ "language_code": "en",
+ "limit": 1,
+ },
+ test_credentials=dataforseo.get_test_credentials(),
+ test_output=[
+ (
+ "suggestion",
+ lambda x: hasattr(x, "keyword")
+ and x.keyword == "digital marketing strategy",
+ ),
+ ("suggestions", lambda x: isinstance(x, list) and len(x) == 1),
+ ("total_count", 1),
+ ("seed_keyword", "digital marketing"),
+ ],
+ test_mock={
+ "_fetch_keyword_suggestions": lambda *args, **kwargs: [
+ {
+ "items": [
+ {
+ "keyword": "digital marketing strategy",
+ "keyword_info": {
+ "search_volume": 10000,
+ "competition": 0.5,
+ "cpc": 2.5,
+ },
+ "keyword_properties": {
+ "keyword_difficulty": 50,
+ },
+ }
+ ]
+ }
+ ]
+ },
+ )
+
+ async def _fetch_keyword_suggestions(
+ self,
+ client: DataForSeoClient,
+ input_data: Input,
+ ) -> Any:
+ """Private method to fetch keyword suggestions - can be mocked for testing."""
+ return await client.keyword_suggestions(
+ keyword=input_data.keyword,
+ location_code=input_data.location_code,
+ language_code=input_data.language_code,
+ include_seed_keyword=input_data.include_seed_keyword,
+ include_serp_info=input_data.include_serp_info,
+ include_clickstream_data=input_data.include_clickstream_data,
+ limit=input_data.limit,
+ )
+
+ async def run(
+ self,
+ input_data: Input,
+ *,
+ credentials: UserPasswordCredentials,
+ **kwargs,
+ ) -> BlockOutput:
+ """Execute the keyword suggestions query."""
+ client = DataForSeoClient(credentials)
+
+ results = await self._fetch_keyword_suggestions(client, input_data)
+
+ # Process and format the results
+ suggestions = []
+ if results and len(results) > 0:
+ # results is a list, get the first element
+ first_result = results[0] if isinstance(results, list) else results
+ items = (
+ first_result.get("items", []) if isinstance(first_result, dict) else []
+ )
+ for item in items:
+ # Create the KeywordSuggestion object
+ suggestion = KeywordSuggestion(
+ keyword=item.get("keyword", ""),
+ search_volume=item.get("keyword_info", {}).get("search_volume"),
+ competition=item.get("keyword_info", {}).get("competition"),
+ cpc=item.get("keyword_info", {}).get("cpc"),
+ keyword_difficulty=item.get("keyword_properties", {}).get(
+ "keyword_difficulty"
+ ),
+ serp_info=(
+ item.get("serp_info") if input_data.include_serp_info else None
+ ),
+ clickstream_data=(
+ item.get("clickstream_keyword_info")
+ if input_data.include_clickstream_data
+ else None
+ ),
+ )
+ yield "suggestion", suggestion
+ suggestions.append(suggestion)
+
+ yield "suggestions", suggestions
+ yield "total_count", len(suggestions)
+ yield "seed_keyword", input_data.keyword
+
+
+class KeywordSuggestionExtractorBlock(Block):
+ """Extracts individual fields from a KeywordSuggestion object."""
+
+ class Input(BlockSchema):
+ suggestion: KeywordSuggestion = SchemaField(
+ description="The keyword suggestion object to extract fields from"
+ )
+
+ class Output(BlockSchema):
+ keyword: str = SchemaField(description="The keyword suggestion")
+ search_volume: Optional[int] = SchemaField(
+ description="Monthly search volume", default=None
+ )
+ competition: Optional[float] = SchemaField(
+ description="Competition level (0-1)", default=None
+ )
+ cpc: Optional[float] = SchemaField(
+ description="Cost per click in USD", default=None
+ )
+ keyword_difficulty: Optional[int] = SchemaField(
+ description="Keyword difficulty score", default=None
+ )
+ serp_info: Optional[Dict[str, Any]] = SchemaField(
+ description="data from SERP for each keyword", default=None
+ )
+ clickstream_data: Optional[Dict[str, Any]] = SchemaField(
+ description="Clickstream data metrics", default=None
+ )
+
+ def __init__(self):
+ super().__init__(
+ id="4193cb94-677c-48b0-9eec-6ac72fffd0f2",
+ description="Extract individual fields from a KeywordSuggestion object",
+ categories={BlockCategory.DATA},
+ input_schema=self.Input,
+ output_schema=self.Output,
+ test_input={
+ "suggestion": KeywordSuggestion(
+ keyword="test keyword",
+ search_volume=1000,
+ competition=0.5,
+ cpc=2.5,
+ keyword_difficulty=60,
+ ).model_dump()
+ },
+ test_output=[
+ ("keyword", "test keyword"),
+ ("search_volume", 1000),
+ ("competition", 0.5),
+ ("cpc", 2.5),
+ ("keyword_difficulty", 60),
+ ("serp_info", None),
+ ("clickstream_data", None),
+ ],
+ )
+
+ async def run(
+ self,
+ input_data: Input,
+ **kwargs,
+ ) -> BlockOutput:
+ """Extract fields from the KeywordSuggestion object."""
+ suggestion = input_data.suggestion
+
+ yield "keyword", suggestion.keyword
+ yield "search_volume", suggestion.search_volume
+ yield "competition", suggestion.competition
+ yield "cpc", suggestion.cpc
+ yield "keyword_difficulty", suggestion.keyword_difficulty
+ yield "serp_info", suggestion.serp_info
+ yield "clickstream_data", suggestion.clickstream_data
diff --git a/autogpt_platform/backend/backend/blocks/dataforseo/related_keywords.py b/autogpt_platform/backend/backend/blocks/dataforseo/related_keywords.py
new file mode 100644
index 0000000000..ae0ecf93e3
--- /dev/null
+++ b/autogpt_platform/backend/backend/blocks/dataforseo/related_keywords.py
@@ -0,0 +1,283 @@
+"""
+DataForSEO Google Related Keywords block.
+"""
+
+from typing import Any, Dict, List, Optional
+
+from backend.sdk import (
+ Block,
+ BlockCategory,
+ BlockOutput,
+ BlockSchema,
+ CredentialsMetaInput,
+ SchemaField,
+ UserPasswordCredentials,
+)
+
+from ._api import DataForSeoClient
+from ._config import dataforseo
+
+
+class RelatedKeyword(BlockSchema):
+ """Schema for a related keyword result."""
+
+ keyword: str = SchemaField(description="The related keyword")
+ search_volume: Optional[int] = SchemaField(
+ description="Monthly search volume", default=None
+ )
+ competition: Optional[float] = SchemaField(
+ description="Competition level (0-1)", default=None
+ )
+ cpc: Optional[float] = SchemaField(
+ description="Cost per click in USD", default=None
+ )
+ keyword_difficulty: Optional[int] = SchemaField(
+ description="Keyword difficulty score", default=None
+ )
+ serp_info: Optional[Dict[str, Any]] = SchemaField(
+ description="SERP data for the keyword", default=None
+ )
+ clickstream_data: Optional[Dict[str, Any]] = SchemaField(
+ description="Clickstream data metrics", default=None
+ )
+
+
+class DataForSeoRelatedKeywordsBlock(Block):
+ """Block for getting related keywords from DataForSEO Labs."""
+
+ class Input(BlockSchema):
+ credentials: CredentialsMetaInput = dataforseo.credentials_field(
+ description="DataForSEO credentials (username and password)"
+ )
+ keyword: str = SchemaField(
+ description="Seed keyword to find related keywords for"
+ )
+ location_code: Optional[int] = SchemaField(
+ description="Location code for targeting (e.g., 2840 for USA)",
+ default=2840, # USA
+ )
+ language_code: Optional[str] = SchemaField(
+ description="Language code (e.g., 'en' for English)",
+ default="en",
+ )
+ include_seed_keyword: bool = SchemaField(
+ description="Include the seed keyword in results",
+ default=True,
+ )
+ include_serp_info: bool = SchemaField(
+ description="Include SERP information",
+ default=False,
+ )
+ include_clickstream_data: bool = SchemaField(
+ description="Include clickstream metrics",
+ default=False,
+ )
+ limit: int = SchemaField(
+ description="Maximum number of results (up to 3000)",
+ default=100,
+ ge=1,
+ le=3000,
+ )
+
+ class Output(BlockSchema):
+ related_keywords: List[RelatedKeyword] = SchemaField(
+ description="List of related keywords with metrics"
+ )
+ related_keyword: RelatedKeyword = SchemaField(
+ description="A related keyword with metrics"
+ )
+ total_count: int = SchemaField(
+ description="Total number of related keywords returned"
+ )
+ seed_keyword: str = SchemaField(
+ description="The seed keyword used for the query"
+ )
+
+ def __init__(self):
+ super().__init__(
+ id="8f2e4d6a-1b3c-4a5e-9d7f-2c8e6a4b3f1d",
+ description="Get related keywords from DataForSEO Labs Google API",
+ categories={BlockCategory.SEARCH, BlockCategory.DATA},
+ input_schema=self.Input,
+ output_schema=self.Output,
+ test_input={
+ "credentials": dataforseo.get_test_credentials().model_dump(),
+ "keyword": "content marketing",
+ "location_code": 2840,
+ "language_code": "en",
+ "limit": 1,
+ },
+ test_credentials=dataforseo.get_test_credentials(),
+ test_output=[
+ (
+ "related_keyword",
+ lambda x: hasattr(x, "keyword") and x.keyword == "content strategy",
+ ),
+ ("related_keywords", lambda x: isinstance(x, list) and len(x) == 1),
+ ("total_count", 1),
+ ("seed_keyword", "content marketing"),
+ ],
+ test_mock={
+ "_fetch_related_keywords": lambda *args, **kwargs: [
+ {
+ "items": [
+ {
+ "keyword_data": {
+ "keyword": "content strategy",
+ "keyword_info": {
+ "search_volume": 8000,
+ "competition": 0.4,
+ "cpc": 3.0,
+ },
+ "keyword_properties": {
+ "keyword_difficulty": 45,
+ },
+ }
+ }
+ ]
+ }
+ ]
+ },
+ )
+
+ async def _fetch_related_keywords(
+ self,
+ client: DataForSeoClient,
+ input_data: Input,
+ ) -> Any:
+ """Private method to fetch related keywords - can be mocked for testing."""
+ return await client.related_keywords(
+ keyword=input_data.keyword,
+ location_code=input_data.location_code,
+ language_code=input_data.language_code,
+ include_seed_keyword=input_data.include_seed_keyword,
+ include_serp_info=input_data.include_serp_info,
+ include_clickstream_data=input_data.include_clickstream_data,
+ limit=input_data.limit,
+ )
+
+ async def run(
+ self,
+ input_data: Input,
+ *,
+ credentials: UserPasswordCredentials,
+ **kwargs,
+ ) -> BlockOutput:
+ """Execute the related keywords query."""
+ client = DataForSeoClient(credentials)
+
+ results = await self._fetch_related_keywords(client, input_data)
+
+ # Process and format the results
+ related_keywords = []
+ if results and len(results) > 0:
+ # results is a list, get the first element
+ first_result = results[0] if isinstance(results, list) else results
+ items = (
+ first_result.get("items", []) if isinstance(first_result, dict) else []
+ )
+ for item in items:
+ # Extract keyword_data from the item
+ keyword_data = item.get("keyword_data", {})
+
+ # Create the RelatedKeyword object
+ keyword = RelatedKeyword(
+ keyword=keyword_data.get("keyword", ""),
+ search_volume=keyword_data.get("keyword_info", {}).get(
+ "search_volume"
+ ),
+ competition=keyword_data.get("keyword_info", {}).get("competition"),
+ cpc=keyword_data.get("keyword_info", {}).get("cpc"),
+ keyword_difficulty=keyword_data.get("keyword_properties", {}).get(
+ "keyword_difficulty"
+ ),
+ serp_info=(
+ keyword_data.get("serp_info")
+ if input_data.include_serp_info
+ else None
+ ),
+ clickstream_data=(
+ keyword_data.get("clickstream_keyword_info")
+ if input_data.include_clickstream_data
+ else None
+ ),
+ )
+ yield "related_keyword", keyword
+ related_keywords.append(keyword)
+
+ yield "related_keywords", related_keywords
+ yield "total_count", len(related_keywords)
+ yield "seed_keyword", input_data.keyword
+
+
+class RelatedKeywordExtractorBlock(Block):
+ """Extracts individual fields from a RelatedKeyword object."""
+
+ class Input(BlockSchema):
+ related_keyword: RelatedKeyword = SchemaField(
+ description="The related keyword object to extract fields from"
+ )
+
+ class Output(BlockSchema):
+ keyword: str = SchemaField(description="The related keyword")
+ search_volume: Optional[int] = SchemaField(
+ description="Monthly search volume", default=None
+ )
+ competition: Optional[float] = SchemaField(
+ description="Competition level (0-1)", default=None
+ )
+ cpc: Optional[float] = SchemaField(
+ description="Cost per click in USD", default=None
+ )
+ keyword_difficulty: Optional[int] = SchemaField(
+ description="Keyword difficulty score", default=None
+ )
+ serp_info: Optional[Dict[str, Any]] = SchemaField(
+ description="SERP data for the keyword", default=None
+ )
+ clickstream_data: Optional[Dict[str, Any]] = SchemaField(
+ description="Clickstream data metrics", default=None
+ )
+
+ def __init__(self):
+ super().__init__(
+ id="98342061-09d2-4952-bf77-0761fc8cc9a8",
+ description="Extract individual fields from a RelatedKeyword object",
+ categories={BlockCategory.DATA},
+ input_schema=self.Input,
+ output_schema=self.Output,
+ test_input={
+ "related_keyword": RelatedKeyword(
+ keyword="test related keyword",
+ search_volume=800,
+ competition=0.4,
+ cpc=3.0,
+ keyword_difficulty=55,
+ ).model_dump()
+ },
+ test_output=[
+ ("keyword", "test related keyword"),
+ ("search_volume", 800),
+ ("competition", 0.4),
+ ("cpc", 3.0),
+ ("keyword_difficulty", 55),
+ ("serp_info", None),
+ ("clickstream_data", None),
+ ],
+ )
+
+ async def run(
+ self,
+ input_data: Input,
+ **kwargs,
+ ) -> BlockOutput:
+ """Extract fields from the RelatedKeyword object."""
+ related_keyword = input_data.related_keyword
+
+ yield "keyword", related_keyword.keyword
+ yield "search_volume", related_keyword.search_volume
+ yield "competition", related_keyword.competition
+ yield "cpc", related_keyword.cpc
+ yield "keyword_difficulty", related_keyword.keyword_difficulty
+ yield "serp_info", related_keyword.serp_info
+ yield "clickstream_data", related_keyword.clickstream_data
diff --git a/autogpt_platform/backend/backend/sdk/provider.py b/autogpt_platform/backend/backend/sdk/provider.py
index 8d9b488562..83a24ab021 100644
--- a/autogpt_platform/backend/backend/sdk/provider.py
+++ b/autogpt_platform/backend/backend/sdk/provider.py
@@ -14,6 +14,8 @@ from backend.data.model import (
CredentialsField,
CredentialsMetaInput,
CredentialsType,
+ OAuth2Credentials,
+ UserPasswordCredentials,
)
from backend.integrations.oauth.base import BaseOAuthHandler
from backend.integrations.webhooks._base import BaseWebhooksManager
@@ -104,14 +106,39 @@ class Provider:
)
def get_test_credentials(self) -> Credentials:
- """Get test credentials for the provider."""
- return APIKeyCredentials(
- id=str(self.test_credentials_uuid),
- provider=self.name,
- api_key=SecretStr("mock-api-key"),
- title=f"Mock {self.name.title()} API key",
- expires_at=None,
- )
+ """Get test credentials for the provider based on supported auth types."""
+ test_id = str(self.test_credentials_uuid)
+
+ # Return credentials based on the first supported auth type
+ if "user_password" in self.supported_auth_types:
+ return UserPasswordCredentials(
+ id=test_id,
+ provider=self.name,
+ username=SecretStr(f"mock-{self.name}-username"),
+ password=SecretStr(f"mock-{self.name}-password"),
+ title=f"Mock {self.name.title()} credentials",
+ )
+ elif "oauth2" in self.supported_auth_types:
+ return OAuth2Credentials(
+ id=test_id,
+ provider=self.name,
+ username=f"mock-{self.name}-username",
+ access_token=SecretStr(f"mock-{self.name}-access-token"),
+ access_token_expires_at=None,
+ refresh_token=SecretStr(f"mock-{self.name}-refresh-token"),
+ refresh_token_expires_at=None,
+ scopes=[f"mock-{self.name}-scope"],
+ title=f"Mock {self.name.title()} OAuth credentials",
+ )
+ else:
+ # Default to API key credentials
+ return APIKeyCredentials(
+ id=test_id,
+ provider=self.name,
+ api_key=SecretStr(f"mock-{self.name}-api-key"),
+ title=f"Mock {self.name.title()} API key",
+ expires_at=None,
+ )
def get_api(self, credentials: Credentials) -> Any:
"""Get API client instance for the given credentials."""