feat: add cloudflare workers ai embeddings (#3697)
This commit is contained in:
parent
e38af369e5
commit
5307f0683f
6 changed files with 108 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ from .aiml import AIMLEmbeddingsComponent
|
||||||
from .amazon_bedrock import AmazonBedrockEmbeddingsComponent
|
from .amazon_bedrock import AmazonBedrockEmbeddingsComponent
|
||||||
from .astra_vectorize import AstraVectorizeComponent
|
from .astra_vectorize import AstraVectorizeComponent
|
||||||
from .azure_openai import AzureOpenAIEmbeddingsComponent
|
from .azure_openai import AzureOpenAIEmbeddingsComponent
|
||||||
|
from .cloudflare import CloudflareWorkersAIEmbeddingsComponent
|
||||||
from .cohere import CohereEmbeddingsComponent
|
from .cohere import CohereEmbeddingsComponent
|
||||||
from .google_generative_ai import GoogleGenerativeAIEmbeddingsComponent
|
from .google_generative_ai import GoogleGenerativeAIEmbeddingsComponent
|
||||||
from .huggingface_inference_api import HuggingFaceInferenceAPIEmbeddingsComponent
|
from .huggingface_inference_api import HuggingFaceInferenceAPIEmbeddingsComponent
|
||||||
|
|
@ -19,6 +20,7 @@ __all__ = [
|
||||||
"AmazonBedrockEmbeddingsComponent",
|
"AmazonBedrockEmbeddingsComponent",
|
||||||
"AstraVectorizeComponent",
|
"AstraVectorizeComponent",
|
||||||
"AzureOpenAIEmbeddingsComponent",
|
"AzureOpenAIEmbeddingsComponent",
|
||||||
|
"CloudflareWorkersAIEmbeddingsComponent",
|
||||||
"CohereEmbeddingsComponent",
|
"CohereEmbeddingsComponent",
|
||||||
"EmbeddingSimilarityComponent",
|
"EmbeddingSimilarityComponent",
|
||||||
"GoogleGenerativeAIEmbeddingsComponent",
|
"GoogleGenerativeAIEmbeddingsComponent",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
from langchain_community.embeddings.cloudflare_workersai import CloudflareWorkersAIEmbeddings
|
||||||
|
|
||||||
|
from langflow.base.models.model import LCModelComponent
|
||||||
|
from langflow.field_typing import Embeddings
|
||||||
|
from langflow.io import BoolInput, DictInput, IntInput, MessageTextInput, Output, SecretStrInput
|
||||||
|
|
||||||
|
|
||||||
|
class CloudflareWorkersAIEmbeddingsComponent(LCModelComponent):
|
||||||
|
display_name: str = "Cloudflare Workers AI Embeddings"
|
||||||
|
description: str = "Generate embeddings using Cloudflare Workers AI models."
|
||||||
|
documentation: str = "https://python.langchain.com/docs/integrations/text_embedding/cloudflare_workersai/"
|
||||||
|
icon = "Cloudflare"
|
||||||
|
name = "CloudflareWorkersAIEmbeddings"
|
||||||
|
|
||||||
|
inputs = [
|
||||||
|
MessageTextInput(
|
||||||
|
name="account_id",
|
||||||
|
display_name="Cloudflare account ID",
|
||||||
|
info="Find your account ID https://developers.cloudflare.com/fundamentals/setup/find-account-and-zone-ids/#find-account-id-workers-and-pages",
|
||||||
|
required=True,
|
||||||
|
),
|
||||||
|
SecretStrInput(
|
||||||
|
name="api_token",
|
||||||
|
display_name="Cloudflare API token",
|
||||||
|
info="Create an API token https://developers.cloudflare.com/fundamentals/api/get-started/create-token/",
|
||||||
|
required=True,
|
||||||
|
),
|
||||||
|
MessageTextInput(
|
||||||
|
name="model_name",
|
||||||
|
display_name="Model Name",
|
||||||
|
info="List of supported models https://developers.cloudflare.com/workers-ai/models/#text-embeddings",
|
||||||
|
required=True,
|
||||||
|
value="@cf/baai/bge-base-en-v1.5"
|
||||||
|
),
|
||||||
|
BoolInput(
|
||||||
|
name="strip_new_lines",
|
||||||
|
display_name="Strip New Lines",
|
||||||
|
advanced=True,
|
||||||
|
value=True,
|
||||||
|
),
|
||||||
|
IntInput(
|
||||||
|
name="batch_size",
|
||||||
|
display_name="Batch Size",
|
||||||
|
advanced=True,
|
||||||
|
value=50,
|
||||||
|
),
|
||||||
|
MessageTextInput(
|
||||||
|
name="api_base_url",
|
||||||
|
display_name="Cloudflare API base URL",
|
||||||
|
advanced=True,
|
||||||
|
value="https://api.cloudflare.com/client/v4/accounts",
|
||||||
|
),
|
||||||
|
DictInput(
|
||||||
|
name="headers",
|
||||||
|
display_name="Headers",
|
||||||
|
info="Additional request headers",
|
||||||
|
is_list=True,
|
||||||
|
advanced=True,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
outputs = [
|
||||||
|
Output(display_name="Embeddings", name="embeddings", method="build_embeddings"),
|
||||||
|
]
|
||||||
|
|
||||||
|
def build_embeddings(self) -> Embeddings:
|
||||||
|
try:
|
||||||
|
embeddings = CloudflareWorkersAIEmbeddings(
|
||||||
|
account_id=self.account_id,
|
||||||
|
api_base_url=self.api_base_url,
|
||||||
|
api_token=self.api_token,
|
||||||
|
batch_size=self.batch_size,
|
||||||
|
headers=self.headers,
|
||||||
|
model_name=self.model_name,
|
||||||
|
strip_new_lines=self.strip_new_lines,
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
raise ValueError(f"Could not connect to CloudflareWorkersAIEmbeddings API: {str(e)}") from e
|
||||||
|
|
||||||
|
return embeddings
|
||||||
14
src/frontend/src/icons/Cloudflare/Cloudflare.jsx
Normal file
14
src/frontend/src/icons/Cloudflare/Cloudflare.jsx
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
const SvgCloudflareIcon = (props) => (
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 209.51 94.74" {...props}>
|
||||||
|
<path
|
||||||
|
fill="#f4801f"
|
||||||
|
d="M143.05,93.42l1.07-3.71c1.27-4.41.8-8.48-1.34-11.48-2-2.76-5.26-4.38-9.25-4.57L58,72.7a1.47,1.47,0,0,1-1.35-2,2,2,0,0,1,1.75-1.34l76.26-1c9-.41,18.84-7.75,22.27-16.71l4.34-11.36a2.68,2.68,0,0,0,.18-1,3.31,3.31,0,0,0-.06-.54,49.67,49.67,0,0,0-95.49-5.14,22.35,22.35,0,0,0-35,23.42A31.73,31.73,0,0,0,.34,93.45a1.47,1.47,0,0,0,1.45,1.27l139.49,0h0A1.83,1.83,0,0,0,143.05,93.42Z"
|
||||||
|
/>
|
||||||
|
<path
|
||||||
|
fill="#f9ab41"
|
||||||
|
d="M168.22,41.15q-1,0-2.1.06a.88.88,0,0,0-.32.07,1.17,1.17,0,0,0-.76.8l-3,10.26c-1.28,4.41-.81,8.48,1.34,11.48a11.65,11.65,0,0,0,9.24,4.57l16.11,1a1.44,1.44,0,0,1,1.14.62,1.5,1.5,0,0,1,.17,1.37,2,2,0,0,1-1.75,1.34l-16.73,1c-9.09.42-18.88,7.75-22.31,16.7l-1.21,3.16a.9.9,0,0,0,.79,1.22h57.63A1.55,1.55,0,0,0,208,93.63a41.34,41.34,0,0,0-39.76-52.48Z"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default SvgCloudflareIcon;
|
||||||
1
src/frontend/src/icons/Cloudflare/cloudflare.svg
Normal file
1
src/frontend/src/icons/Cloudflare/cloudflare.svg
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 209.51 94.74"><defs><style>.cls-1{fill:#f4801f;}.cls-2{fill:#f9ab41;}</style></defs><path class="cls-1" d="M143.05,93.42l1.07-3.71c1.27-4.41.8-8.48-1.34-11.48-2-2.76-5.26-4.38-9.25-4.57L58,72.7a1.47,1.47,0,0,1-1.35-2,2,2,0,0,1,1.75-1.34l76.26-1c9-.41,18.84-7.75,22.27-16.71l4.34-11.36a2.68,2.68,0,0,0,.18-1,3.31,3.31,0,0,0-.06-.54,49.67,49.67,0,0,0-95.49-5.14,22.35,22.35,0,0,0-35,23.42A31.73,31.73,0,0,0,.34,93.45a1.47,1.47,0,0,0,1.45,1.27l139.49,0h0A1.83,1.83,0,0,0,143.05,93.42Z"/><path class="cls-2" d="M168.22,41.15q-1,0-2.1.06a.88.88,0,0,0-.32.07,1.17,1.17,0,0,0-.76.8l-3,10.26c-1.28,4.41-.81,8.48,1.34,11.48a11.65,11.65,0,0,0,9.24,4.57l16.11,1a1.44,1.44,0,0,1,1.14.62,1.5,1.5,0,0,1,.17,1.37,2,2,0,0,1-1.75,1.34l-16.73,1c-9.09.42-18.88,7.75-22.31,16.7l-1.21,3.16a.9.9,0,0,0,.79,1.22h57.63A1.55,1.55,0,0,0,208,93.63a41.34,41.34,0,0,0-39.76-52.48Z"/></svg>
|
||||||
|
After Width: | Height: | Size: 946 B |
9
src/frontend/src/icons/Cloudflare/index.tsx
Normal file
9
src/frontend/src/icons/Cloudflare/index.tsx
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
import React, { forwardRef } from "react";
|
||||||
|
import SvgCloudflareIcon from "./Cloudflare";
|
||||||
|
|
||||||
|
export const CloudflareIcon = forwardRef<
|
||||||
|
SVGSVGElement,
|
||||||
|
React.PropsWithChildren<{}>
|
||||||
|
>((props, ref) => {
|
||||||
|
return <SvgCloudflareIcon ref={ref} {...props} />;
|
||||||
|
});
|
||||||
|
|
@ -241,6 +241,7 @@ import { BotMessageSquareIcon } from "../icons/BotMessageSquare";
|
||||||
import { CassandraIcon } from "../icons/Cassandra";
|
import { CassandraIcon } from "../icons/Cassandra";
|
||||||
import { ChromaIcon } from "../icons/ChromaIcon";
|
import { ChromaIcon } from "../icons/ChromaIcon";
|
||||||
import { ClickhouseIcon } from "../icons/Clickhouse";
|
import { ClickhouseIcon } from "../icons/Clickhouse";
|
||||||
|
import { CloudflareIcon } from "../icons/Cloudflare";
|
||||||
import { CohereIcon } from "../icons/Cohere";
|
import { CohereIcon } from "../icons/Cohere";
|
||||||
import { ComposioIcon } from "../icons/Composio";
|
import { ComposioIcon } from "../icons/Composio";
|
||||||
import { ConfluenceIcon } from "../icons/Confluence";
|
import { ConfluenceIcon } from "../icons/Confluence";
|
||||||
|
|
@ -601,6 +602,7 @@ export const nodeIconsLucide: iconsType = {
|
||||||
Chroma: ChromaIcon,
|
Chroma: ChromaIcon,
|
||||||
Couchbase: CouchbaseIcon,
|
Couchbase: CouchbaseIcon,
|
||||||
Clickhouse: ClickhouseIcon,
|
Clickhouse: ClickhouseIcon,
|
||||||
|
Cloudflare: CloudflareIcon,
|
||||||
AirbyteJSONLoader: AirbyteIcon,
|
AirbyteJSONLoader: AirbyteIcon,
|
||||||
AmazonBedrockEmbeddings: AWSIcon,
|
AmazonBedrockEmbeddings: AWSIcon,
|
||||||
Amazon: AWSIcon,
|
Amazon: AWSIcon,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue