Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kcze committed Nov 11, 2024
1 parent 1cb3cec commit c2a9ef7
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,55 +29,48 @@
api_key=SecretStr(settings.secrets.revid_api_key),
title="Use Credits for Revid",
expires_at=None,
hidden=True,
)
ideogram_credentials = APIKeyCredentials(
id="760f84fc-b270-42de-91f6-08efe1b512d0",
provider="ideogram",
api_key=SecretStr(settings.secrets.ideogram_api_key),
title="Use Credits for Ideogram",
expires_at=None,
hidden=True,
)
replicate_credentials = APIKeyCredentials(
id="6b9fc200-4726-4973-86c9-cd526f5ce5db",
provider="replicate",
api_key=SecretStr(settings.secrets.replicate_api_key),
title="Use Credits for Replicate",
expires_at=None,
hidden=True,
)
openai_credentials = APIKeyCredentials(
id="53c25cb8-e3ee-465c-a4d1-e75a4c899c2a",
provider="openai",
api_key=SecretStr(settings.secrets.openai_api_key),
title="Use Credits for OpenAI",
expires_at=None,
hidden=True,
)
anthropic_credentials = APIKeyCredentials(
id="24e5d942-d9e3-4798-8151-90143ee55629",
provider="anthropic",
api_key=SecretStr(settings.secrets.anthropic_api_key),
title="Use Credits for Anthropic",
expires_at=None,
hidden=True,
)
groq_credentials = APIKeyCredentials(
id="4ec22295-8f97-4dd1-b42b-2c6957a02545",
provider="groq",
api_key=SecretStr(settings.secrets.groq_api_key),
title="Use Credits for Groq",
expires_at=None,
hidden=True,
)
did_credentials = APIKeyCredentials(
id="7f7b0654-c36b-4565-8fa7-9a52575dfae2",
provider="d_id",
api_key=SecretStr(settings.secrets.did_api_key),
title="Use Credits for D-ID",
expires_at=None,
hidden=True,
)

DEFAULT_CREDENTIALS = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class _BaseCredentials(BaseModel):
id: str = Field(default_factory=lambda: str(uuid4()))
provider: str
title: Optional[str]
hidden: Optional[bool] = False

@field_serializer("*")
def dump_secret_strings(value: Any, _info):
Expand Down
3 changes: 2 additions & 1 deletion autogpt_platform/backend/backend/blocks/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
# "ollama": BlockSecret(value=""),
# }

AICredentials = CredentialsMetaInput[list[str], Literal["api_key"]]
LLMProviderName = Literal["anthropic", "groq", "openai", "ollama"]
AICredentials = CredentialsMetaInput[LLMProviderName, Literal["api_key"]]

TEST_CREDENTIALS = APIKeyCredentials(
id="ed55ac19-356e-4243-a6cb-bc599e9b716f",
Expand Down
16 changes: 3 additions & 13 deletions autogpt_platform/backend/backend/data/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def SchemaField(
)


CP = TypeVar("CP", bound=str | list[str])
CP = TypeVar("CP", bound=str)
CT = TypeVar("CT", bound=CredentialsType)


Expand All @@ -152,7 +152,7 @@ class CredentialsMetaInput(BaseModel, Generic[CP, CT]):


def CredentialsField(
provider: CP,
provider: CP | list[CP],
supported_credential_types: set[CT],
required_scopes: set[str] = set(),
*,
Expand All @@ -166,14 +166,11 @@ def CredentialsField(
`CredentialsField` must and can only be used on fields named `credentials`.
This is enforced by the `BlockSchema` base class.
"""
# Convert provider list to enum for schema
provider_list = [provider] if isinstance(provider, str) else provider

json_extra = {
k: v
for k, v in {
"credentials_provider": (
provider if isinstance(provider, str) else list(provider)
[provider] if isinstance(provider, str) else provider
),
"credentials_scopes": list(required_scopes) or None, # omit if empty
"credentials_types": list(supported_credential_types),
Expand All @@ -183,13 +180,6 @@ def CredentialsField(
if v is not None
}

# Force provider to always be a string
# Otherwise input provider will fail jsonschema validation
# if multiple providers are provided
json_extra.update(
{"properties": {"provider": {"type": "string", "enum": provider_list}}}
)

return Field(
title=title,
description=description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class CredentialsMetaResponse(BaseModel):
title: str | None
scopes: list[str] | None
username: str | None
hidden: bool | None


@router.post("/{provider}/callback")
Expand Down Expand Up @@ -112,7 +111,6 @@ def callback(
title=credentials.title,
scopes=credentials.scopes,
username=credentials.username,
hidden=credentials.hidden,
)


Expand All @@ -129,7 +127,6 @@ def list_credentials(
title=cred.title,
scopes=cred.scopes if isinstance(cred, OAuth2Credentials) else None,
username=cred.username if isinstance(cred, OAuth2Credentials) else None,
hidden=cred.hidden,
)
for cred in credentials
]
Expand Down
19 changes: 17 additions & 2 deletions autogpt_platform/frontend/src/app/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useSupabase } from "@/components/SupabaseProvider";
import { Button } from "@/components/ui/button";
import useUser from "@/hooks/useUser";
import { useRouter } from "next/navigation";
import { useCallback, useContext } from "react";
import { useCallback, useContext, useMemo } from "react";
import { FaSpinner } from "react-icons/fa";
import { Separator } from "@/components/ui/separator";
import { useToast } from "@/components/ui/use-toast";
Expand Down Expand Up @@ -60,6 +60,21 @@ export default function PrivatePage() {
[providers, toast],
);

//TODO: remove when the way system credentials are handled is updated
// This contains ids for built-in "Use Credits for X" credentials
const hiddenCredentials = useMemo(
() => [
"fdb7f412-f519-48d1-9b5f-d2f73d0e01fe", // Revid
"760f84fc-b270-42de-91f6-08efe1b512d0", // Ideogram
"6b9fc200-4726-4973-86c9-cd526f5ce5db", // Replicate
"53c25cb8-e3ee-465c-a4d1-e75a4c899c2a", // OpenAI
"24e5d942-d9e3-4798-8151-90143ee55629", // Anthropic
"4ec22295-8f97-4dd1-b42b-2c6957a02545", // Groq
"7f7b0654-c36b-4565-8fa7-9a52575dfae2", // D-ID
],
[],
);

if (isLoading || !providers) {
return (
<div className="flex h-[80vh] items-center justify-center">
Expand All @@ -75,7 +90,7 @@ export default function PrivatePage() {

const allCredentials = Object.values(providers).flatMap((provider) =>
[...provider.savedOAuthCredentials, ...provider.savedApiKeys]
.filter((cred) => !cred.hidden)
.filter((cred) => !hiddenCredentials.includes(cred.id))
.map((credentials) => ({
...credentials,
provider: provider.provider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export type OAuthPopupResultMessage = { message_type: "oauth_popup_result" } & (
export const CredentialsInput: FC<{
className?: string;
selectedCredentials?: CredentialsMetaInput;
onSelectCredentials: (newValue: CredentialsMetaInput | undefined) => void;
onSelectCredentials: (newValue?: CredentialsMetaInput) => void;
}> = ({ className, selectedCredentials, onSelectCredentials }) => {
const api = useMemo(() => new AutoGPTServerAPI(), []);
const credentials = useCredentials();
Expand Down Expand Up @@ -255,30 +255,22 @@ export const CredentialsInput: FC<{
)}
</>
);
// Only one saved credential
} else if (
savedApiKeys.length === 0 &&
savedOAuthCredentials.length === 1 &&
selectedCredentials === undefined
) {
if (selectedCredentials === undefined) {
onSelectCredentials({
id: savedOAuthCredentials[0].id,
type: "oauth2",
provider,
title: savedOAuthCredentials[0].title,
});
}
return null;
} else if (savedApiKeys.length === 1 && savedOAuthCredentials.length === 0) {
if (selectedCredentials === undefined) {
onSelectCredentials({
id: savedApiKeys[0].id,
type: "api_key",
provider,
title: savedApiKeys[0].title,
});
}
}

const singleCredential =
savedApiKeys.length === 1 && savedOAuthCredentials.length === 0
? savedApiKeys[0]
: savedOAuthCredentials.length === 1 && savedApiKeys.length === 0
? savedOAuthCredentials[0]
: null;

if (singleCredential && !selectedCredentials) {
onSelectCredentials({
id: singleCredential.id,
type: singleCredential.type,
provider,
title: singleCredential.title,
});
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ export type CredentialsMetaResponse = {
title?: string;
scopes?: Array<string>;
username?: string;
hidden?: boolean;
};

/* Mirror of backend/server/integrations/router.py:CredentialsDeletionResponse */
Expand All @@ -263,7 +262,7 @@ export type CredentialsMetaInput = {
id: string;
type: CredentialsType;
title?: string;
provider: string | string[];
provider: string;
};

/* Mirror of autogpt_libs/supabase_integration_credentials_store/types.py:_BaseCredentials */
Expand All @@ -272,7 +271,6 @@ type BaseCredentials = {
type: CredentialsType;
title?: string;
provider: string;
hidden?: boolean;
};

/* Mirror of autogpt_libs/supabase_integration_credentials_store/types.py:OAuth2Credentials */
Expand Down

0 comments on commit c2a9ef7

Please sign in to comment.