Skip to content

Commit

Permalink
use new credentials system for api key
Browse files Browse the repository at this point in the history
  • Loading branch information
Bentlybro committed Oct 23, 2024
1 parent f1ea47f commit 62b17b8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
15 changes: 10 additions & 5 deletions autogpt_platform/backend/backend/blocks/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import requests

from backend.data.block import Block, BlockCategory, BlockOutput, BlockSchema
from backend.data.model import BlockSecret, SchemaField, SecretField
from backend.data.model import BlockSecret, SchemaField, SecretField, CredentialsField, CredentialsMetaInput
from typing import Literal
from autogpt_libs.supabase_integration_credentials_store import APIKeyCredentials


class GetRequest:
Expand Down Expand Up @@ -168,7 +170,11 @@ def run(self, input_data: Input, **kwargs) -> BlockOutput:
class FactCheckerBlock(Block, GetRequest):
class Input(BlockSchema):
statement: str = SchemaField(description="The statement to check for factuality")
api_key: BlockSecret = SecretField(key="jina_api_key")
credentials: CredentialsMetaInput[Literal['jina'], Literal['api_key']] = CredentialsField(
provider="jina",
supported_credential_types={"api_key"},
description="The Jina AI API key for getting around the API rate limit.",
)

class Output(BlockSchema):
factuality: float = SchemaField(description="The factuality score of the statement")
Expand Down Expand Up @@ -200,14 +206,13 @@ def __init__(self):
},
)

def run(self, input_data: Input, **kwargs) -> BlockOutput:
api_key = input_data.api_key.get_secret_value()
def run(self, input_data: Input, *, credentials: APIKeyCredentials, **kwargs) -> BlockOutput:
encoded_statement = quote(input_data.statement)
url = f"https://g.jina.ai/{encoded_statement}"

headers = {
"Accept": "application/json",
"Authorization": f"Bearer {api_key}"
"Authorization": credentials.bearer()
}

response = self.get_request(url, json=True, headers=headers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import useCredentials from "@/hooks/useCredentials";
import { zodResolver } from "@hookform/resolvers/zod";
import AutoGPTServerAPI from "@/lib/autogpt-server-api";
import { NotionLogoIcon } from "@radix-ui/react-icons";
import { FaGithub, FaGoogle } from "react-icons/fa";
import { FaGithub, FaGoogle, FaKey } from "react-icons/fa";
import { FC, useMemo, useState } from "react";
import { CredentialsMetaInput } from "@/lib/autogpt-server-api/types";
import { IconKey, IconKeyPlus, IconUserPlus } from "@/components/ui/icons";
Expand Down Expand Up @@ -41,6 +41,7 @@ export const providerIcons: Record<string, React.FC<{ className?: string }>> = {
github: FaGithub,
google: FaGoogle,
notion: NotionLogoIcon,
jina: FaKey, // Use a generic icon for now as there is no specific icon for Jina AI
};
// --8<-- [end:ProviderIconsEmbed]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from "react";

// --8<-- [start:CredentialsProviderNames]
const CREDENTIALS_PROVIDER_NAMES = ["github", "google", "notion"] as const;
const CREDENTIALS_PROVIDER_NAMES = ["github", "google", "notion", "jina"] as const;

export type CredentialsProviderName =
(typeof CREDENTIALS_PROVIDER_NAMES)[number];
Expand All @@ -21,6 +21,7 @@ const providerDisplayNames: Record<CredentialsProviderName, string> = {
github: "GitHub",
google: "Google",
notion: "Notion",
jina: "Jina AI",
};
// --8<-- [end:CredentialsProviderNames]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export type CredentialsType = "api_key" | "oauth2";

// --8<-- [start:BlockIOCredentialsSubSchema]
export type BlockIOCredentialsSubSchema = BlockIOSubSchemaMeta & {
credentials_provider: "github" | "google" | "notion";
credentials_provider: "github" | "google" | "notion" | "jina";
credentials_scopes?: string[];
credentials_types: Array<CredentialsType>;
};
Expand Down

0 comments on commit 62b17b8

Please sign in to comment.