graphiti/graphiti_core/embedder/chutes.py
facronactz a7f2c92bb4 feat: Add support for Chutes API integration
- Introduced CHUTES_API_TOKEN in .env.example files for configuration.
- Updated README.md in quickstart example to include Chutes API setup.
- Created quickstart_chutes.py example for demonstrating Chutes integration.
- Added ChutesEmbedder and ChutesClient classes for embedding and LLM functionalities.
- Updated LLM and embedder provider configurations to support Chutes.
- Enhanced factories to include Chutes client and embedder.
- Modified schema.py to define Chutes provider configuration.
- Updated mcp_server configuration files to integrate Chutes API.
- Added necessary dependencies in pyproject.toml for Chutes support.
2025-11-15 16:12:09 +07:00

65 lines
2.1 KiB
Python

"""
Copyright 2024, Zep Software, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import os
from collections.abc import Iterable
from openai import AsyncOpenAI
from openai.types import EmbeddingModel
from .client import EmbedderClient, EmbedderConfig
DEFAULT_EMBEDDING_MODEL = "qwen-3-8b"
class ChutesEmbedderConfig(EmbedderConfig):
embedding_model: EmbeddingModel | str = DEFAULT_EMBEDDING_MODEL
api_key: str | None = os.environ.get("CHUTES_API_TOKEN")
base_url: str | None = "https://chutes-qwen-qwen3-embedding-8b.chutes.ai/v1"
class ChutesEmbedder(EmbedderClient):
"""
Chutes Embedder Client
"""
def __init__(
self,
config: ChutesEmbedderConfig | None = None,
client: AsyncOpenAI | None = None,
):
if config is None:
config = ChutesEmbedderConfig()
self.config = config
if client is not None:
self.client = client
else:
self.client = AsyncOpenAI(api_key=config.api_key, base_url=config.base_url)
async def create(
self, input_data: str | list[str] | Iterable[int] | Iterable[Iterable[int]]
) -> list[float]:
result = await self.client.embeddings.create(
input=input_data, model=None
)
return result.data[0].embedding[: self.config.embedding_dim]
async def create_batch(self, input_data_list: list[str]) -> list[list[float]]:
result = await self.client.embeddings.create(
input=input_data_list, model=None
)
return [embedding.embedding[: self.config.embedding_dim] for embedding in result.data]