repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | from typing import Optional, Union |
| #2 | |
| #3 | import google.generativeai as genai |
| #4 | from chromadb import EmbeddingFunction, Embeddings |
| #5 | |
| #6 | from embedchain.config.embedder.google import GoogleAIEmbedderConfig |
| #7 | from embedchain.embedder.base import BaseEmbedder |
| #8 | from embedchain.models import VectorDimensions |
| #9 | |
| #10 | |
| #11 | class GoogleAIEmbeddingFunction(EmbeddingFunction): |
| #12 | def __init__(self, config: Optional[GoogleAIEmbedderConfig] = None) -> None: |
| #13 | super().__init__() |
| #14 | self.config = config or GoogleAIEmbedderConfig() |
| #15 | |
| #16 | def __call__(self, input: Union[list[str], str]) -> Embeddings: |
| #17 | model = self.config.model |
| #18 | title = self.config.title |
| #19 | task_type = self.config.task_type |
| #20 | if isinstance(input, str): |
| #21 | input_ = [input] |
| #22 | else: |
| #23 | input_ = input |
| #24 | data = genai.embed_content(model=model, content=input_, task_type=task_type, title=title) |
| #25 | embeddings = data["embedding"] |
| #26 | if isinstance(input_, str): |
| #27 | embeddings = [embeddings] |
| #28 | return embeddings |
| #29 | |
| #30 | |
| #31 | class GoogleAIEmbedder(BaseEmbedder): |
| #32 | def __init__(self, config: Optional[GoogleAIEmbedderConfig] = None): |
| #33 | super().__init__(config) |
| #34 | embedding_fn = GoogleAIEmbeddingFunction(config=config) |
| #35 | self.set_embedding_fn(embedding_fn=embedding_fn) |
| #36 | |
| #37 | vector_dimension = self.config.vector_dimension or VectorDimensions.GOOGLE_AI.value |
| #38 | self.set_vector_dimension(vector_dimension=vector_dimension) |
| #39 |