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 | import logging |
| #2 | from typing import Optional |
| #3 | |
| #4 | try: |
| #5 | from ollama import Client |
| #6 | except ImportError: |
| #7 | raise ImportError("Ollama Embedder requires extra dependencies. Install with `pip install ollama`") from None |
| #8 | |
| #9 | from langchain_community.embeddings import OllamaEmbeddings |
| #10 | |
| #11 | from embedchain.config import OllamaEmbedderConfig |
| #12 | from embedchain.embedder.base import BaseEmbedder |
| #13 | from embedchain.models import VectorDimensions |
| #14 | |
| #15 | logger = logging.getLogger(__name__) |
| #16 | |
| #17 | |
| #18 | class OllamaEmbedder(BaseEmbedder): |
| #19 | def __init__(self, config: Optional[OllamaEmbedderConfig] = None): |
| #20 | super().__init__(config=config) |
| #21 | |
| #22 | client = Client(host=config.base_url) |
| #23 | local_models = client.list()["models"] |
| #24 | if not any(model.get("name") == self.config.model for model in local_models): |
| #25 | logger.info(f"Pulling {self.config.model} from Ollama!") |
| #26 | client.pull(self.config.model) |
| #27 | embeddings = OllamaEmbeddings(model=self.config.model, base_url=config.base_url) |
| #28 | embedding_fn = BaseEmbedder._langchain_default_concept(embeddings) |
| #29 | self.set_embedding_fn(embedding_fn=embedding_fn) |
| #30 | |
| #31 | vector_dimension = self.config.vector_dimension or VectorDimensions.OLLAMA.value |
| #32 | self.set_vector_dimension(vector_dimension=vector_dimension) |
| #33 |