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 Any, ClassVar, Dict, Optional |
| #2 | |
| #3 | from pydantic import BaseModel, ConfigDict, Field, model_validator |
| #4 | |
| #5 | |
| #6 | class ChromaDbConfig(BaseModel): |
| #7 | try: |
| #8 | from chromadb.api.client import Client |
| #9 | except ImportError: |
| #10 | raise ImportError("The 'chromadb' library is required. Please install it using 'pip install chromadb'.") |
| #11 | Client: ClassVar[type] = Client |
| #12 | |
| #13 | collection_name: str = Field("mem0", description="Default name for the collection/database") |
| #14 | client: Optional[Client] = Field(None, description="Existing ChromaDB client instance") |
| #15 | path: Optional[str] = Field(None, description="Path to the database directory") |
| #16 | host: Optional[str] = Field(None, description="Database connection remote host") |
| #17 | port: Optional[int] = Field(None, description="Database connection remote port") |
| #18 | # ChromaDB Cloud configuration |
| #19 | api_key: Optional[str] = Field(None, description="ChromaDB Cloud API key") |
| #20 | tenant: Optional[str] = Field(None, description="ChromaDB Cloud tenant ID") |
| #21 | |
| #22 | @model_validator(mode="before") |
| #23 | def check_connection_config(cls, values): |
| #24 | host, port, path = values.get("host"), values.get("port"), values.get("path") |
| #25 | api_key, tenant = values.get("api_key"), values.get("tenant") |
| #26 | |
| #27 | # Check if cloud configuration is provided |
| #28 | cloud_config = bool(api_key and tenant) |
| #29 | |
| #30 | # If cloud configuration is provided, remove any default path that might have been added |
| #31 | if cloud_config and path == "/tmp/chroma": |
| #32 | values.pop("path", None) |
| #33 | return values |
| #34 | |
| #35 | # Check if local/server configuration is provided (excluding default tmp path for cloud config) |
| #36 | local_config = bool(path and path != "/tmp/chroma") or bool(host and port) |
| #37 | |
| #38 | if not cloud_config and not local_config: |
| #39 | raise ValueError("Either ChromaDB Cloud configuration (api_key, tenant) or local configuration (path or host/port) must be provided.") |
| #40 | |
| #41 | if cloud_config and local_config: |
| #42 | raise ValueError("Cannot specify both cloud configuration and local configuration. Choose one.") |
| #43 | |
| #44 | return values |
| #45 | |
| #46 | @model_validator(mode="before") |
| #47 | @classmethod |
| #48 | def validate_extra_fields(cls, values: Dict[str, Any]) -> Dict[str, Any]: |
| #49 | allowed_fields = set(cls.model_fields.keys()) |
| #50 | input_fields = set(values.keys()) |
| #51 | extra_fields = input_fields - allowed_fields |
| #52 | if extra_fields: |
| #53 | raise ValueError( |
| #54 | f"Extra fields not allowed: {', '.join(extra_fields)}. Please input only the following fields: {', '.join(allowed_fields)}" |
| #55 | ) |
| #56 | return values |
| #57 | |
| #58 | model_config = ConfigDict(arbitrary_types_allowed=True) |
| #59 |