Skip to content

feat(platform/backend): auto discover credentials in all block modules #10028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
20 changes: 20 additions & 0 deletions autogpt_platform/backend/backend/blocks/apollo/_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,33 @@

from backend.data.model import APIKeyCredentials, CredentialsField, CredentialsMetaInput
from backend.integrations.providers import ProviderName
from backend.util.settings import Settings

ApolloCredentials = APIKeyCredentials
ApolloCredentialsInput = CredentialsMetaInput[
Literal[ProviderName.APOLLO],
Literal["api_key"],
]

DEFAULT_CREDENTIAL_ID = "544c62b5-1d0f-4156-8fb4-9525f11656eb"
ENV_VAR = "apollo_api_key"
DEFAULT_TITLE = "Use Credits for Apollo"


def default_credentials() -> APIKeyCredentials | None:
settings = Settings()
key = getattr(settings.secrets, ENV_VAR, "")
if not key:
return None
return APIKeyCredentials(
id=DEFAULT_CREDENTIAL_ID,
provider=ProviderName.APOLLO.value,
api_key=SecretStr(key),
title=DEFAULT_TITLE,
expires_at=None,
)


TEST_CREDENTIALS = APIKeyCredentials(
id="01234567-89ab-cdef-0123-456789abcdef",
provider="apollo",
Expand Down
Empty file.
20 changes: 20 additions & 0 deletions autogpt_platform/backend/backend/blocks/exa/_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,33 @@

from backend.data.model import APIKeyCredentials, CredentialsField, CredentialsMetaInput
from backend.integrations.providers import ProviderName
from backend.util.settings import Settings

ExaCredentials = APIKeyCredentials
ExaCredentialsInput = CredentialsMetaInput[
Literal[ProviderName.EXA],
Literal["api_key"],
]

DEFAULT_CREDENTIAL_ID = "96153e04-9c6c-4486-895f-5bb683b1ecec"
ENV_VAR = "exa_api_key"
DEFAULT_TITLE = "Use Credits for Exa search"


def default_credentials() -> APIKeyCredentials | None:
settings = Settings()
key = getattr(settings.secrets, ENV_VAR, "")
if not key:
return None
return APIKeyCredentials(
id=DEFAULT_CREDENTIAL_ID,
provider=ProviderName.EXA.value,
api_key=SecretStr(key),
title=DEFAULT_TITLE,
expires_at=None,
)


TEST_CREDENTIALS = APIKeyCredentials(
id="01234567-89ab-cdef-0123-456789abcdef",
provider="exa",
Expand Down
Empty file.
20 changes: 20 additions & 0 deletions autogpt_platform/backend/backend/blocks/fal/_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,33 @@

from backend.data.model import APIKeyCredentials, CredentialsField, CredentialsMetaInput
from backend.integrations.providers import ProviderName
from backend.util.settings import Settings

FalCredentials = APIKeyCredentials
FalCredentialsInput = CredentialsMetaInput[
Literal[ProviderName.FAL],
Literal["api_key"],
]

DEFAULT_CREDENTIAL_ID = "6c0f5bd0-9008-4638-9d79-4b40b631803e"
ENV_VAR = "fal_api_key"
DEFAULT_TITLE = "Use Credits for FAL"


def default_credentials() -> APIKeyCredentials | None:
settings = Settings()
key = getattr(settings.secrets, ENV_VAR, "")
if not key:
return None
return APIKeyCredentials(
id=DEFAULT_CREDENTIAL_ID,
provider=ProviderName.FAL.value,
api_key=SecretStr(key),
title=DEFAULT_TITLE,
expires_at=None,
)


TEST_CREDENTIALS = APIKeyCredentials(
id="01234567-89ab-cdef-0123-456789abcdef",
provider="fal",
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
19 changes: 19 additions & 0 deletions autogpt_platform/backend/backend/blocks/jina/_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,32 @@

from backend.data.model import APIKeyCredentials, CredentialsField, CredentialsMetaInput
from backend.integrations.providers import ProviderName
from backend.util.settings import Settings

JinaCredentials = APIKeyCredentials
JinaCredentialsInput = CredentialsMetaInput[
Literal[ProviderName.JINA],
Literal["api_key"],
]

DEFAULT_CREDENTIAL_ID = "7f26de70-ba0d-494e-ba76-238e65e7b45f"
ENV_VAR = "jina_api_key"
DEFAULT_TITLE = "Use Credits for Jina"


def default_credentials() -> APIKeyCredentials | None:
settings = Settings()
key = getattr(settings.secrets, ENV_VAR, "")
if not key:
return None
return APIKeyCredentials(
id=DEFAULT_CREDENTIAL_ID,
provider=ProviderName.JINA.value,
api_key=SecretStr(key),
title=DEFAULT_TITLE,
expires_at=None,
)


def JinaCredentialsField() -> JinaCredentialsInput:
"""
Expand Down
Empty file.
Empty file.
20 changes: 20 additions & 0 deletions autogpt_platform/backend/backend/blocks/nvidia/_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,33 @@

from backend.data.model import APIKeyCredentials, CredentialsField, CredentialsMetaInput
from backend.integrations.providers import ProviderName
from backend.util.settings import Settings

NvidiaCredentials = APIKeyCredentials
NvidiaCredentialsInput = CredentialsMetaInput[
Literal[ProviderName.NVIDIA],
Literal["api_key"],
]

DEFAULT_CREDENTIAL_ID = "96b83908-2789-4dec-9968-18f0ece4ceb3"
ENV_VAR = "nvidia_api_key"
DEFAULT_TITLE = "Use Credits for Nvidia"


def default_credentials() -> APIKeyCredentials | None:
settings = Settings()
key = getattr(settings.secrets, ENV_VAR, "")
if not key:
return None
return APIKeyCredentials(
id=DEFAULT_CREDENTIAL_ID,
provider=ProviderName.NVIDIA.value,
api_key=SecretStr(key),
title=DEFAULT_TITLE,
expires_at=None,
)


TEST_CREDENTIALS = APIKeyCredentials(
id="01234567-89ab-cdef-0123-456789abcdef",
provider="nvidia",
Expand Down
Empty file.
20 changes: 20 additions & 0 deletions autogpt_platform/backend/backend/blocks/smartlead/_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,33 @@

from backend.data.model import APIKeyCredentials, CredentialsField, CredentialsMetaInput
from backend.integrations.providers import ProviderName
from backend.util.settings import Settings

SmartLeadCredentials = APIKeyCredentials
SmartLeadCredentialsInput = CredentialsMetaInput[
Literal[ProviderName.SMARTLEAD],
Literal["api_key"],
]

DEFAULT_CREDENTIAL_ID = "3bcdbda3-84a3-46af-8fdb-bfd2472298b8"
ENV_VAR = "smartlead_api_key"
DEFAULT_TITLE = "Use Credits for SmartLead"


def default_credentials() -> APIKeyCredentials | None:
settings = Settings()
key = getattr(settings.secrets, ENV_VAR, "")
if not key:
return None
return APIKeyCredentials(
id=DEFAULT_CREDENTIAL_ID,
provider=ProviderName.SMARTLEAD.value,
api_key=SecretStr(key),
title=DEFAULT_TITLE,
expires_at=None,
)


TEST_CREDENTIALS = APIKeyCredentials(
id="01234567-89ab-cdef-0123-456789abcdef",
provider="smartlead",
Expand Down
Empty file.
Empty file.
Empty file.
20 changes: 20 additions & 0 deletions autogpt_platform/backend/backend/blocks/zerobounce/_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,33 @@

from backend.data.model import APIKeyCredentials, CredentialsField, CredentialsMetaInput
from backend.integrations.providers import ProviderName
from backend.util.settings import Settings

ZeroBounceCredentials = APIKeyCredentials
ZeroBounceCredentialsInput = CredentialsMetaInput[
Literal[ProviderName.ZEROBOUNCE],
Literal["api_key"],
]

DEFAULT_CREDENTIAL_ID = "63a6e279-2dc2-448e-bf57-85776f7176dc"
ENV_VAR = "zerobounce_api_key"
DEFAULT_TITLE = "Use Credits for ZeroBounce"


def default_credentials() -> APIKeyCredentials | None:
settings = Settings()
key = getattr(settings.secrets, ENV_VAR, "")
if not key:
return None
return APIKeyCredentials(
id=DEFAULT_CREDENTIAL_ID,
provider=ProviderName.ZEROBOUNCE.value,
api_key=SecretStr(key),
title=DEFAULT_TITLE,
expires_at=None,
)


TEST_CREDENTIALS = APIKeyCredentials(
id="01234567-89ab-cdef-0123-456789abcdef",
provider="zerobounce",
Expand Down
66 changes: 49 additions & 17 deletions autogpt_platform/backend/backend/data/block_cost_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Type

from pydantic import SecretStr

from backend.blocks.ai_music_generator import AIMusicGeneratorBlock
from backend.blocks.ai_shortform_video_block import AIShortformVideoCreatorBlock
from backend.blocks.ideogram import IdeogramModelBlock
Expand All @@ -20,19 +22,49 @@
from backend.blocks.text_to_speech_block import UnrealTextToSpeechBlock
from backend.data.block import Block
from backend.data.cost import BlockCost, BlockCostType
from backend.integrations.credentials_store import (
anthropic_credentials,
did_credentials,
groq_credentials,
ideogram_credentials,
jina_credentials,
llama_api_credentials,
open_router_credentials,
openai_credentials,
replicate_credentials,
revid_credentials,
unreal_credentials,
from backend.data.model import APIKeyCredentials
from backend.integrations.credentials_store import discover_default_credentials

_DEFAULTS = {c.provider: c for c in discover_default_credentials()}


def _fallback(provider: str) -> APIKeyCredentials:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not have a fallback here

return APIKeyCredentials(
id="", provider=provider, api_key=SecretStr(""), title="", expires_at=None
)


anthropic_credentials: APIKeyCredentials = _DEFAULTS.get("anthropic") or _fallback(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn’t do what we want. We should do this similar to getting avail blocks

"anthropic"
)
did_credentials: APIKeyCredentials = _DEFAULTS.get("d_id") or _fallback("d_id")
groq_credentials: APIKeyCredentials = _DEFAULTS.get("groq") or _fallback("groq")
ideogram_credentials: APIKeyCredentials = _DEFAULTS.get("ideogram") or _fallback(
"ideogram"
)
jina_credentials: APIKeyCredentials = _DEFAULTS.get("jina") or _fallback("jina")
llama_api_credentials: APIKeyCredentials = _DEFAULTS.get("llama_api") or _fallback(
"llama_api"
)
open_router_credentials: APIKeyCredentials = _DEFAULTS.get("open_router") or _fallback(
"open_router"
)
openai_credentials: APIKeyCredentials = _DEFAULTS.get("openai") or _fallback("openai")
replicate_credentials: APIKeyCredentials = _DEFAULTS.get("replicate") or _fallback(
"replicate"
)
revid_credentials: APIKeyCredentials = _DEFAULTS.get("revid") or _fallback("revid")
unreal_credentials: APIKeyCredentials = _DEFAULTS.get("unreal") or _fallback("unreal")

for name in list(locals().keys()):
if name.endswith("_credentials") and locals()[name] is None:
locals()[name] = APIKeyCredentials(
id="",
provider=name.removesuffix("_credentials"),
api_key=SecretStr(""),
title="",
expires_at=None,
)

# =============== Configure the cost for each LLM Model call =============== #

Expand Down Expand Up @@ -111,7 +143,7 @@
cost_amount=cost,
)
for model, cost in MODEL_COST.items()
if MODEL_METADATA[model].provider == "anthropic"
if MODEL_METADATA[model].provider == "anthropic" and anthropic_credentials
]
# OpenAI Models
+ [
Expand All @@ -128,7 +160,7 @@
cost_amount=cost,
)
for model, cost in MODEL_COST.items()
if MODEL_METADATA[model].provider == "openai"
if MODEL_METADATA[model].provider == "openai" and openai_credentials
]
# Groq Models
+ [
Expand All @@ -141,7 +173,7 @@
cost_amount=cost,
)
for model, cost in MODEL_COST.items()
if MODEL_METADATA[model].provider == "groq"
if MODEL_METADATA[model].provider == "groq" and groq_credentials
]
# Open Router Models
+ [
Expand All @@ -158,7 +190,7 @@
cost_amount=cost,
)
for model, cost in MODEL_COST.items()
if MODEL_METADATA[model].provider == "open_router"
if MODEL_METADATA[model].provider == "open_router" and open_router_credentials
]
# Llama API Models
+ [
Expand All @@ -175,7 +207,7 @@
cost_amount=cost,
)
for model, cost in MODEL_COST.items()
if MODEL_METADATA[model].provider == "llama_api"
if MODEL_METADATA[model].provider == "llama_api" and llama_api_credentials
]
)

Expand Down
Loading