Skip to content

Commit

Permalink
shared jina provider
Browse files Browse the repository at this point in the history
  • Loading branch information
aarushik93 committed Oct 23, 2024
1 parent 8de2177 commit 035fb19
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
8 changes: 2 additions & 6 deletions autogpt_platform/backend/backend/blocks/chunking/jina.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import requests

from backend.blocks.jina._auth import JinaCredentialsField, JinaCredentialsInput
from backend.data.block import Block, BlockCategory, BlockOutput, BlockSchema
from backend.data.model import BlockSecret, SchemaField, SecretField, CredentialsMetaInput, CredentialsField

Expand All @@ -10,12 +11,7 @@ class JinaChunkingBlock(Block):
class Input(BlockSchema):
texts: list = SchemaField(description="List of texts to chunk")

credentials: CredentialsMetaInput[Literal['jina'], Literal['api_key']] = CredentialsField(
provider="jina",
supported_credential_types={"api_key"}, # noqa
description="The Jina integration can be used with "
"any API key with sufficient permissions for the blocks it is used on.",
)
credentials: JinaCredentialsInput = JinaCredentialsField()
max_chunk_length: int = SchemaField(
description="Maximum length of each chunk", default=1000
)
Expand Down
8 changes: 2 additions & 6 deletions autogpt_platform/backend/backend/blocks/embeddings/jina.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@
import requests

from autogpt_libs.supabase_integration_credentials_store import Credentials
from backend.blocks.jina._auth import JinaCredentialsField, JinaCredentialsInput
from backend.data.block import Block, BlockCategory, BlockOutput, BlockSchema
from backend.data.model import BlockSecret, SchemaField, SecretField, CredentialsMetaInput, CredentialsField


class JinaEmbeddingBlock(Block):
class Input(BlockSchema):
texts: list = SchemaField(description="List of texts to embed")
credentials: CredentialsMetaInput[Literal['jina'], Literal['api_key']] = CredentialsField(
provider="jina",
supported_credential_types={"api_key"}, # noqa
description="The Jina integration can be used with "
"any API key with sufficient permissions for the blocks it is used on.",
)
credentials: JinaCredentialsInput = JinaCredentialsField()
model: str = SchemaField(
description="Jina embedding model to use",
default="jina-embeddings-v2-base-en",
Expand Down
42 changes: 42 additions & 0 deletions autogpt_platform/backend/backend/blocks/jina/_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from typing import Literal

from autogpt_libs.supabase_integration_credentials_store.types import (
APIKeyCredentials,
)
from pydantic import SecretStr

from backend.data.model import CredentialsField, CredentialsMetaInput


JinaCredentials = APIKeyCredentials
JinaCredentialsInput = CredentialsMetaInput[
Literal["jina"],
Literal["api_key"],
]


def JinaCredentialsField() -> JinaCredentialsInput:
"""
Creates a Jina credentials input on a block.
"""
return CredentialsField(
provider="jina",
supported_credential_types={"api_key"} , # noqa
description="The Jina integration can be used with an API Key."
)


TEST_CREDENTIALS = APIKeyCredentials(
id="01234567-89ab-cdef-0123-456789abcdef",
provider="jina",
api_key=SecretStr("mock-jina-api-key"),
title="Mock Jina API key",
expires_at=None,
)
TEST_CREDENTIALS_INPUT = {
"provider": TEST_CREDENTIALS.provider,
"id": TEST_CREDENTIALS.id,
"type": TEST_CREDENTIALS.type,
"title": TEST_CREDENTIALS.type,
}

0 comments on commit 035fb19

Please sign in to comment.