repo
stringclasses
454 values
file_path
stringlengths
5
201
extension
stringclasses
1 value
content
stringlengths
8
509k
num_lines
int64
3
16.9k
size_bytes
int64
8
511k
graphrag
packages/graphrag-llm/graphrag_llm/templating/file_template_manager.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """In-memory template manager implementation.""" from pathlib import Path from typing import Any from graphrag_llm.templating.template_manager import TemplateManager class FileTemplateManager(TemplateManager): """Abstract base class f...
77
2,578
graphrag
packages/graphrag-llm/graphrag_llm/templating/template_manager_factory.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Template manager factory implementation.""" from collections.abc import Callable from typing import TYPE_CHECKING from graphrag_common.factory import Factory from graphrag_llm.config.template_engine_config import TemplateEngineConfig fr...
83
2,715
graphrag
packages/graphrag-llm/graphrag_llm/templating/jinja_template_engine.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Jinja template engine.""" from typing import TYPE_CHECKING, Any from jinja2 import StrictUndefined, Template, UndefinedError from graphrag_llm.templating.template_engine import TemplateEngine if TYPE_CHECKING: from graphrag_llm.tem...
56
2,010
graphrag
packages/graphrag-llm/graphrag_llm/tokenizer/tokenizer_factory.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Tokenizer factory.""" from collections.abc import Callable from typing import TYPE_CHECKING from graphrag_common.factory import Factory from graphrag_llm.config.types import TokenizerType from graphrag_llm.tokenizer.tokenizer import Tok...
90
2,605
graphrag
packages/graphrag-llm/graphrag_llm/tokenizer/__init__.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Tokenizer module.""" from graphrag_llm.tokenizer.tokenizer import Tokenizer from graphrag_llm.tokenizer.tokenizer_factory import ( create_tokenizer, register_tokenizer, ) __all__ = [ "Tokenizer", "create_tokenizer", "...
17
343
graphrag
packages/graphrag-llm/graphrag_llm/tokenizer/lite_llm_tokenizer.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """LiteLLM Tokenizer.""" from typing import Any from litellm import decode, encode # type: ignore from graphrag_llm.tokenizer.tokenizer import Tokenizer class LiteLLMTokenizer(Tokenizer): """LiteLLM Tokenizer.""" _model_id: str...
55
1,327
graphrag
packages/graphrag-llm/graphrag_llm/tokenizer/tokenizer.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Tokenizer Abstract Base Class.""" from abc import ABC, abstractmethod from typing import TYPE_CHECKING, Any if TYPE_CHECKING: from graphrag_llm.types import LLMCompletionMessagesParam class Tokenizer(ABC): """Tokenizer Abstract...
112
3,426
graphrag
packages/graphrag-llm/graphrag_llm/tokenizer/tiktoken_tokenizer.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """LiteLLM Tokenizer.""" from typing import Any import tiktoken from graphrag_llm.tokenizer.tokenizer import Tokenizer class TiktokenTokenizer(Tokenizer): """LiteLLM Tokenizer.""" _encoding_name: str def __init__(self, *, e...
56
1,345
graphrag
packages/graphrag-llm/graphrag_llm/retry/exceptions_to_skip.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """List of exception names to skip for retries.""" _default_exceptions_to_skip = [ "BadRequestError", "UnsupportedParamsError", "ContextWindowExceededError", "ContentPolicyViolationError", "ImageFetchError", "InvalidR...
23
579
graphrag
packages/graphrag-llm/graphrag_llm/retry/__init__.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Retry module for graphrag-llm.""" from graphrag_llm.retry.retry import Retry from graphrag_llm.retry.retry_factory import create_retry, register_retry __all__ = [ "Retry", "create_retry", "register_retry", ]
14
303
graphrag
packages/graphrag-llm/graphrag_llm/retry/retry_factory.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Retry factory.""" from collections.abc import Callable from typing import TYPE_CHECKING from graphrag_common.factory import Factory from graphrag_llm.config.types import RetryType from graphrag_llm.retry.retry import Retry if TYPE_CHEC...
87
2,338
graphrag
packages/graphrag-llm/graphrag_llm/retry/immediate_retry.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Native (immediate) retry implementation.""" from collections.abc import Awaitable, Callable from typing import TYPE_CHECKING, Any from graphrag_llm.retry.exceptions_to_skip import _default_exceptions_to_skip from graphrag_llm.retry.retry...
86
2,613
graphrag
packages/graphrag-llm/graphrag_llm/retry/retry.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Retry abstract base class.""" from abc import ABC, abstractmethod from collections.abc import Awaitable, Callable from typing import Any class Retry(ABC): """Retry Abstract Base Class.""" @abstractmethod def __init__(self, ...
33
837
graphrag
packages/graphrag-llm/graphrag_llm/retry/exponential_retry.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Exponential backoff retry implementation.""" import asyncio import random import time from collections.abc import Awaitable, Callable from typing import TYPE_CHECKING, Any from graphrag_llm.retry.exceptions_to_skip import _default_except...
120
3,973
graphrag
packages/graphrag-llm/graphrag_llm/threading/completion_thread.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Completion Thread.""" import threading from queue import Empty, Queue from typing import TYPE_CHECKING if TYPE_CHECKING: from collections.abc import Iterator from graphrag_llm.types import ( LLMCompletionArgs, LL...
92
2,849
graphrag
packages/graphrag-llm/graphrag_llm/threading/__init__.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Threading module.""" from graphrag_llm.threading.completion_thread_runner import completion_thread_runner __all__ = [ "completion_thread_runner", ]
11
235
graphrag
packages/graphrag-llm/graphrag_llm/threading/embedding_thread_runner.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Embedding Thread Runner.""" import asyncio import sys import threading import time from collections.abc import Awaitable, Iterator from contextlib import contextmanager from queue import Empty, Queue from typing import TYPE_CHECKING, Prot...
217
6,584
graphrag
packages/graphrag-llm/graphrag_llm/threading/completion_thread_runner.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Completion Thread Runner.""" import asyncio import sys import threading import time from collections.abc import Awaitable, Iterator from contextlib import contextmanager from queue import Empty, Queue from typing import TYPE_CHECKING, Pro...
244
8,098
graphrag
packages/graphrag-llm/graphrag_llm/threading/embedding_thread.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Embedding Thread.""" import threading from queue import Empty, Queue from typing import TYPE_CHECKING if TYPE_CHECKING: from graphrag_llm.types import ( LLMEmbeddingArgs, LLMEmbeddingFunction, LLMEmbeddingResp...
89
2,704
graphrag
packages/graphrag-llm/graphrag_llm/completion/completion.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Completion Abstract Base Class.""" from abc import ABC, abstractmethod from contextlib import contextmanager from typing import TYPE_CHECKING, Any, Unpack from graphrag_llm.threading.completion_thread_runner import completion_thread_runn...
266
10,278
graphrag
packages/graphrag-llm/graphrag_llm/completion/__init__.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Completion module for graphrag-llm.""" from graphrag_llm.completion.completion import LLMCompletion from graphrag_llm.completion.completion_factory import ( create_completion, register_completion, ) __all__ = [ "LLMCompletion...
17
377
graphrag
packages/graphrag-llm/graphrag_llm/completion/lite_llm_completion.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """LLMCompletion based on litellm.""" from collections.abc import AsyncIterator, Iterator from typing import TYPE_CHECKING, Any, Unpack import litellm from azure.identity import DefaultAzureCredential, get_bearer_token_provider from litellm...
304
11,410
graphrag
packages/graphrag-llm/graphrag_llm/completion/completion_factory.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Completion factory.""" from collections.abc import Callable from typing import TYPE_CHECKING, Any from graphrag_common.factory import Factory from graphrag_llm.cache import create_cache_key from graphrag_llm.config.tokenizer_config impo...
151
5,270
graphrag
packages/graphrag-llm/graphrag_llm/completion/mock_llm_completion.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Mock LLMCompletion.""" from typing import TYPE_CHECKING, Any, Unpack import litellm from graphrag_llm.completion.completion import LLMCompletion from graphrag_llm.utils import ( create_completion_response, structure_completion_r...
131
4,445
graphrag
packages/graphrag-llm/graphrag_llm/config/types.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """GraphRAG LLM configuration types.""" from enum import StrEnum class LLMProviderType(StrEnum): """Enum for LLM provider types.""" LiteLLM = "litellm" MockLLM = "mock" class AuthMethod(StrEnum): """Enum for authenticat...
73
1,348
graphrag
packages/graphrag-llm/graphrag_llm/config/metrics_config.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Metrics configuration.""" from pydantic import BaseModel, ConfigDict, Field, model_validator from graphrag_llm.config.types import ( MetricsProcessorType, MetricsStoreType, MetricsWriterType, ) class MetricsConfig(BaseModel...
58
1,828
graphrag
packages/graphrag-llm/graphrag_llm/config/retry_config.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Retry configuration.""" from pydantic import BaseModel, ConfigDict, Field, model_validator from graphrag_llm.config.types import RetryType class RetryConfig(BaseModel): """Configuration for retry behavior.""" model_config = Co...
70
2,493
graphrag
packages/graphrag-llm/graphrag_llm/config/model_config.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Language model configuration.""" import logging from typing import Any from pydantic import BaseModel, ConfigDict, Field, model_validator from graphrag_llm.config.metrics_config import MetricsConfig from graphrag_llm.config.rate_limit_c...
112
3,640
graphrag
packages/graphrag-llm/graphrag_llm/config/__init__.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Config module for graphrag-llm.""" from graphrag_llm.config.metrics_config import MetricsConfig from graphrag_llm.config.model_config import ModelConfig from graphrag_llm.config.rate_limit_config import RateLimitConfig from graphrag_llm.c...
43
1,129
graphrag
packages/graphrag-llm/graphrag_llm/config/template_engine_config.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Template engine configuration.""" from pydantic import BaseModel, ConfigDict, Field, model_validator from graphrag_llm.config.types import ( TemplateEngineType, TemplateManagerType, ) class TemplateEngineConfig(BaseModel): ...
70
2,310
graphrag
packages/graphrag-llm/graphrag_llm/config/rate_limit_config.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """RateLimit configuration.""" from pydantic import BaseModel, ConfigDict, Field, model_validator from graphrag_llm.config.types import RateLimitType class RateLimitConfig(BaseModel): """Configuration for rate limit behavior.""" ...
61
2,372
graphrag
packages/graphrag-llm/graphrag_llm/config/tokenizer_config.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Tokenizer model configuration.""" from pydantic import BaseModel, ConfigDict, Field, model_validator from graphrag_llm.config.types import TokenizerType class TokenizerConfig(BaseModel): """Configuration for a tokenizer.""" mo...
52
1,823
graphrag
packages/graphrag-llm/graphrag_llm/model_cost_registry/__init__.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Model cost registry module.""" from graphrag_llm.model_cost_registry.model_cost_registry import ( ModelCosts, model_cost_registry, ) __all__ = ["ModelCosts", "model_cost_registry"]
12
272
graphrag
packages/graphrag-llm/graphrag_llm/model_cost_registry/model_cost_registry.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Model cost registry module.""" from typing import Any, ClassVar, TypedDict from litellm import model_cost from typing_extensions import Self class ModelCosts(TypedDict): """Model costs.""" input_cost_per_token: float outpu...
66
1,747
graphrag
packages/graphrag-llm/graphrag_llm/metrics/metrics_aggregator.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Metrics aggregator module.""" from collections.abc import Callable from typing import TYPE_CHECKING, Any, ClassVar from typing_extensions import Self if TYPE_CHECKING: from graphrag_llm.types.types import Metrics class MetricsAggr...
143
4,845
graphrag
packages/graphrag-llm/graphrag_llm/metrics/metrics_writer_factory.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Metrics writer factory.""" from collections.abc import Callable from typing import TYPE_CHECKING from graphrag_common.factory import Factory from graphrag_llm.config.types import MetricsWriterType from graphrag_llm.metrics.metrics_writ...
92
2,911
graphrag
packages/graphrag-llm/graphrag_llm/metrics/noop_metrics_store.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Noop metrics store.""" from typing import Any from graphrag_llm.metrics.metrics_store import MetricsStore from graphrag_llm.types import Metrics class NoopMetricsStore(MetricsStore): """Noop store for metrics.""" def __init__(...
42
887
graphrag
packages/graphrag-llm/graphrag_llm/metrics/default_metrics_processor.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Default Metrics Processor.""" from typing import TYPE_CHECKING, Any from graphrag_llm.metrics.metrics_processor import MetricsProcessor from graphrag_llm.model_cost_registry import model_cost_registry from graphrag_llm.types import LLMCo...
131
4,501
graphrag
packages/graphrag-llm/graphrag_llm/metrics/memory_metrics_store.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Default metrics store.""" import atexit import threading from typing import TYPE_CHECKING, Any from graphrag_llm.metrics.metrics_aggregator import metrics_aggregator from graphrag_llm.metrics.metrics_store import MetricsStore if TYPE_CH...
113
3,205
graphrag
packages/graphrag-llm/graphrag_llm/metrics/metrics_store_factory.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Metrics store factory.""" from collections.abc import Callable from typing import TYPE_CHECKING, Any from graphrag_common.factory import Factory from graphrag_llm.config.types import MetricsStoreType from graphrag_llm.metrics.metrics_st...
92
2,791
graphrag
packages/graphrag-llm/graphrag_llm/metrics/__init__.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Metrics module for graphrag-llm.""" from graphrag_llm.metrics.metrics_aggregator import metrics_aggregator from graphrag_llm.metrics.metrics_processor import MetricsProcessor from graphrag_llm.metrics.metrics_processor_factory import ( ...
35
1,023
graphrag
packages/graphrag-llm/graphrag_llm/metrics/metrics_store.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Metrics Store.""" from abc import ABC, abstractmethod from typing import TYPE_CHECKING, Any if TYPE_CHECKING: from graphrag_llm.metrics.metrics_writer import MetricsWriter from graphrag_llm.types import Metrics class MetricsSto...
82
1,982
graphrag
packages/graphrag-llm/graphrag_llm/metrics/metrics_processor.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Metrics processor abstract base class.""" from abc import ABC, abstractmethod from typing import TYPE_CHECKING, Any if TYPE_CHECKING: from collections.abc import AsyncIterator, Iterator from graphrag_llm.config import ModelConfi...
60
1,650
graphrag
packages/graphrag-llm/graphrag_llm/metrics/file_metrics_writer.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """File metrics writer implementation.""" import json from collections.abc import Callable from datetime import datetime, timezone from pathlib import Path from typing import TYPE_CHECKING, Any from graphrag_llm.metrics.metrics_writer impor...
38
1,231
graphrag
packages/graphrag-llm/graphrag_llm/metrics/log_metrics_writer.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Log metrics writer implementation.""" import json import logging from collections.abc import Callable from typing import TYPE_CHECKING, Any from graphrag_llm.metrics.metrics_writer import MetricsWriter if TYPE_CHECKING: from graphra...
40
1,150
graphrag
packages/graphrag-llm/graphrag_llm/metrics/metrics_writer.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Metrics writer abstract base class.""" from abc import ABC, abstractmethod from typing import TYPE_CHECKING, Any if TYPE_CHECKING: from graphrag_llm.types import Metrics class MetricsWriter(ABC): """Abstract base class for metr...
33
819
graphrag
packages/graphrag-llm/graphrag_llm/metrics/metrics_processor_factory.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Metrics processor factory.""" from collections.abc import Callable from typing import TYPE_CHECKING from graphrag_common.factory import Factory from graphrag_llm.config.types import MetricsProcessorType from graphrag_llm.metrics.metrics...
80
2,464
graphrag
packages/graphrag-llm/graphrag_llm/utils/create_completion_response.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Create completion response.""" from graphrag_llm.types import ( LLMChoice, LLMCompletionMessage, LLMCompletionResponse, LLMCompletionUsage, ) def create_completion_response(response: str) -> LLMCompletionResponse: ""...
46
1,102
graphrag
packages/graphrag-llm/graphrag_llm/utils/gather_completion_response.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Gather Completion Response Utility.""" from collections.abc import AsyncIterator, Iterator from typing import TYPE_CHECKING if TYPE_CHECKING: from graphrag_llm.types import ( LLMCompletionChunk, LLMCompletionResponse,...
58
1,648
graphrag
packages/graphrag-llm/graphrag_llm/utils/__init__.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Utils module.""" from graphrag_llm.utils.completion_messages_builder import ( CompletionContentPartBuilder, CompletionMessagesBuilder, ) from graphrag_llm.utils.create_completion_response import ( create_completion_response, )...
41
1,138
graphrag
packages/graphrag-llm/graphrag_llm/utils/completion_messages_builder.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """ChatCompletionMessageParamBuilder class.""" from collections.abc import Iterable from typing import TYPE_CHECKING, Literal from openai.types.chat.chat_completion_assistant_message_param import ( ChatCompletionAssistantMessageParam, )...
329
9,687
graphrag
packages/graphrag-llm/graphrag_llm/utils/create_embedding_response.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Create embedding response utilities.""" from graphrag_llm.types import LLMEmbedding, LLMEmbeddingResponse, LLMEmbeddingUsage def create_embedding_response( embeddings: list[float], batch_size: int = 1 ) -> LLMEmbeddingResponse: ...
40
971
graphrag
packages/graphrag-llm/graphrag_llm/utils/function_tool_manager.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Function tool manager.""" import json from collections.abc import Callable from typing import TYPE_CHECKING, Any, Generic, TypeVar from openai import pydantic_function_tool from pydantic import BaseModel from typing_extensions import Typ...
139
4,123
graphrag
packages/graphrag-llm/graphrag_llm/utils/structure_response.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Structure response as pydantic base model.""" import json from typing import Any, TypeVar from pydantic import BaseModel T = TypeVar("T", bound=BaseModel, covariant=True) def structure_completion_response(response: str, model: type[T]...
30
758
graphrag
packages/graphrag-llm/graphrag_llm/rate_limit/rate_limiter.py
.py
# Copyright (c) 2025 Microsoft Corporation. # Licensed under the MIT License """LiteLLM Rate Limiter.""" from abc import ABC, abstractmethod from collections.abc import Iterator from contextlib import contextmanager from typing import Any class RateLimiter(ABC): """Abstract base class for rate limiters.""" ...
39
917
graphrag
packages/graphrag-llm/graphrag_llm/rate_limit/rate_limit_factory.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Rate limit factory.""" from collections.abc import Callable from typing import TYPE_CHECKING from graphrag_common.factory import Factory from graphrag_llm.config import RateLimitType from graphrag_llm.rate_limit.rate_limiter import Rate...
85
2,469
graphrag
packages/graphrag-llm/graphrag_llm/rate_limit/sliding_window_rate_limiter.py
.py
# Copyright (c) 2025 Microsoft Corporation. # Licensed under the MIT License """LiteLLM Static Rate Limiter.""" import threading import time from collections import deque from collections.abc import Iterator from contextlib import contextmanager from typing import Any from graphrag_llm.rate_limit.rate_limiter import...
144
5,406
graphrag
packages/graphrag-llm/graphrag_llm/rate_limit/__init__.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Rate limit module for graphrag-llm.""" from graphrag_llm.rate_limit.rate_limit_factory import ( create_rate_limiter, register_rate_limiter, ) from graphrag_llm.rate_limit.rate_limiter import RateLimiter __all__ = [ "RateLimit...
17
383
graphrag
packages/graphrag-llm/graphrag_llm/middleware/with_metrics.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Metrics middleware to process metrics using a MetricsProcessor.""" import time from typing import TYPE_CHECKING, Any if TYPE_CHECKING: from graphrag_llm.config import ModelConfig from graphrag_llm.metrics import MetricsProcessor ...
99
3,040
graphrag
packages/graphrag-llm/graphrag_llm/middleware/with_cache.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Cache middleware.""" import asyncio from typing import TYPE_CHECKING, Any, Literal from graphrag_llm.types import LLMCompletionResponse, LLMEmbeddingResponse if TYPE_CHECKING: from graphrag_cache import Cache, CacheKeyCreator f...
155
5,473
graphrag
packages/graphrag-llm/graphrag_llm/middleware/__init__.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Middleware.""" from graphrag_llm.middleware.with_cache import with_cache from graphrag_llm.middleware.with_errors_for_testing import with_errors_for_testing from graphrag_llm.middleware.with_logging import with_logging from graphrag_llm.m...
25
867
graphrag
packages/graphrag-llm/graphrag_llm/middleware/with_errors_for_testing.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Error testing middleware.""" import asyncio import random import time from typing import TYPE_CHECKING, Any import litellm.exceptions as exceptions if TYPE_CHECKING: from graphrag_llm.types import ( AsyncLLMFunction, ...
84
2,604
graphrag
packages/graphrag-llm/graphrag_llm/middleware/with_retries.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Retry middleware.""" from typing import TYPE_CHECKING, Any if TYPE_CHECKING: from graphrag_llm.retry import Retry from graphrag_llm.types import ( AsyncLLMFunction, LLMFunction, ) def with_retries( *, ...
61
1,552
graphrag
packages/graphrag-llm/graphrag_llm/middleware/with_rate_limiting.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Rate limit middleware.""" from typing import TYPE_CHECKING, Any if TYPE_CHECKING: from graphrag_llm.rate_limit import RateLimiter from graphrag_llm.tokenizer import Tokenizer from graphrag_llm.types import ( AsyncLLMF...
80
2,592
graphrag
packages/graphrag-llm/graphrag_llm/middleware/with_logging.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Request count middleware.""" import logging from typing import TYPE_CHECKING, Any if TYPE_CHECKING: from graphrag_llm.types import ( AsyncLLMFunction, LLMFunction, Metrics, ) logger = logging.getLogger(__...
74
2,181
graphrag
packages/graphrag-llm/graphrag_llm/middleware/with_request_count.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Request count middleware.""" from typing import TYPE_CHECKING, Any if TYPE_CHECKING: from graphrag_llm.types import ( AsyncLLMFunction, LLMFunction, Metrics, ) def with_request_count( *, sync_mid...
82
2,537
graphrag
packages/graphrag-llm/graphrag_llm/middleware/with_middleware_pipeline.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Wraps model functions in middleware pipeline.""" from typing import TYPE_CHECKING, Literal from graphrag_llm.middleware.with_cache import with_cache from graphrag_llm.middleware.with_errors_for_testing import with_errors_for_testing from...
155
5,941
graphrag
packages/graphrag-llm/graphrag_llm/types/types.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Types for graphrag-llm.""" from collections.abc import AsyncIterator, Awaitable, Iterator, Sequence from typing import ( Any, Generic, Literal, Protocol, Required, TypeVar, Unpack, runtime_checkable, ) fro...
269
8,122
graphrag
packages/graphrag-llm/graphrag_llm/types/__init__.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Types module for graphrag-llm.""" from graphrag_llm.types.types import ( AsyncLLMCompletionFunction, AsyncLLMEmbeddingFunction, AsyncLLMFunction, LLMChoice, LLMChoiceChunk, LLMChoiceDelta, LLMCompletionArgs, ...
59
1,388
graphrag
packages/graphrag-llm/graphrag_llm/embedding/__init__.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """LLMEmbedding module for graphrag_llm.""" from graphrag_llm.embedding.embedding import LLMEmbedding from graphrag_llm.embedding.embedding_factory import ( create_embedding, register_embedding, ) __all__ = [ "LLMEmbedding", ...
17
369
graphrag
packages/graphrag-llm/graphrag_llm/embedding/embedding_factory.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Embedding factory.""" from collections.abc import Callable from typing import TYPE_CHECKING, Any from graphrag_common.factory import Factory from graphrag_llm.cache import create_cache_key from graphrag_llm.config.tokenizer_config impor...
151
5,198
graphrag
packages/graphrag-llm/graphrag_llm/embedding/lite_llm_embedding.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """LLMEmbedding based on litellm.""" from typing import TYPE_CHECKING, Any, Unpack import litellm from azure.identity import DefaultAzureCredential, get_bearer_token_provider from graphrag_llm.config.types import AuthMethod from graphrag_l...
199
7,338
graphrag
packages/graphrag-llm/graphrag_llm/embedding/embedding.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Completion Abstract Base Class.""" from abc import ABC, abstractmethod from contextlib import contextmanager from typing import TYPE_CHECKING, Any, Unpack from graphrag_llm.threading.embedding_thread_runner import embedding_thread_runner...
192
6,639
graphrag
packages/graphrag-llm/graphrag_llm/embedding/mock_llm_embedding.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """MockLLMEmbedding.""" from typing import TYPE_CHECKING, Any, Unpack import litellm from graphrag_llm.embedding.embedding import LLMEmbedding from graphrag_llm.utils import create_embedding_response if TYPE_CHECKING: from graphrag_ll...
82
2,373
graphrag
packages/graphrag-llm/graphrag_llm/cache/__init__.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Cache module.""" from graphrag_llm.cache.create_cache_key import create_cache_key __all__ = [ "create_cache_key", ]
11
203
graphrag
packages/graphrag-llm/graphrag_llm/cache/create_cache_key.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Create cache key.""" from typing import Any from graphrag_cache import create_cache_key as default_create_cache_key _CACHE_VERSION = 4 """ If there's a breaking change in what we cache, we should increment this version number to invalid...
72
2,013
graphrag
packages/graphrag-input/graphrag_input/input_reader_factory.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """A module containing 'InputReaderFactory' model.""" import logging from collections.abc import Callable from graphrag_common.factory import Factory from graphrag_common.factory.factory import ServiceScope from graphrag_storage.storage imp...
95
3,230
graphrag
packages/graphrag-input/graphrag_input/json.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """A module containing 'JSONFileReader' model.""" import json import logging from graphrag_input.structured_file_reader import StructuredFileReader from graphrag_input.text_document import TextDocument logger = logging.getLogger(__name__) ...
39
1,236
graphrag
packages/graphrag-input/graphrag_input/get_property.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Utility for retrieving properties from nested dictionaries.""" from typing import Any def get_property(data: dict[str, Any], path: str) -> Any: """Retrieve a property from a dictionary using dot notation. Parameters -------...
37
945
graphrag
packages/graphrag-input/graphrag_input/markitdown.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """A module containing 'TextFileReader' model.""" import logging from io import BytesIO from pathlib import Path from markitdown import MarkItDown, StreamInfo from graphrag_input.hashing import gen_sha512_hash from graphrag_input.input_rea...
50
1,506
graphrag
packages/graphrag-input/graphrag_input/parquet.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """A module containing 'ParquetFileReader' model.""" import io import logging import pyarrow.parquet as pq from graphrag_input.structured_file_reader import StructuredFileReader from graphrag_input.text_document import TextDocument logger...
40
1,186
graphrag
packages/graphrag-input/graphrag_input/__init__.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """GraphRAG input document loading package.""" from graphrag_input.get_property import get_property from graphrag_input.input_config import InputConfig from graphrag_input.input_reader import InputReader from graphrag_input.input_reader_fact...
21
590
graphrag
packages/graphrag-input/graphrag_input/input_type.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """A module containing input file type enum.""" from enum import StrEnum class InputType(StrEnum): """The input file type for the pipeline.""" Csv = "csv" """The CSV input type.""" Text = "text" """The text input type....
28
660
graphrag
packages/graphrag-input/graphrag_input/jsonl.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """A module containing 'JSONLinesFileReader' model.""" import json import logging from graphrag_input.structured_file_reader import StructuredFileReader from graphrag_input.text_document import TextDocument logger = logging.getLogger(__nam...
62
1,927
graphrag
packages/graphrag-input/graphrag_input/input_reader.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """A module containing 'InputReader' model.""" from __future__ import annotations import logging import re from abc import ABCMeta, abstractmethod from typing import TYPE_CHECKING if TYPE_CHECKING: from collections.abc import AsyncIter...
88
2,584
graphrag
packages/graphrag-input/graphrag_input/csv.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """A module containing 'CSVFileReader' model.""" import csv import io import logging import sys from graphrag_input.structured_file_reader import StructuredFileReader from graphrag_input.text_document import TextDocument logger = logging.g...
46
1,265
graphrag
packages/graphrag-input/graphrag_input/text.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """A module containing 'TextFileReader' model.""" import logging from pathlib import Path from graphrag_input.hashing import gen_sha512_hash from graphrag_input.input_reader import InputReader from graphrag_input.text_document import TextDo...
44
1,324
graphrag
packages/graphrag-input/graphrag_input/hashing.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Hashing utilities.""" from collections.abc import Iterable from hashlib import sha512 from typing import Any def gen_sha512_hash(item: dict[str, Any], hashcode: Iterable[str]) -> str: """Generate a SHA512 hash. Parameters -...
28
713
graphrag
packages/graphrag-input/graphrag_input/text_document.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """TextDocument dataclass.""" import logging from dataclasses import dataclass from typing import Any from graphrag_input.get_property import get_property logger = logging.getLogger(__name__) @dataclass class TextDocument: """The Tex...
60
1,976
graphrag
packages/graphrag-input/graphrag_input/structured_file_reader.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """A module containing 'StructuredFileReader' model.""" import logging from typing import Any from graphrag_input.get_property import get_property from graphrag_input.hashing import gen_sha512_hash from graphrag_input.input_reader import In...
66
2,161
graphrag
packages/graphrag-input/graphrag_input/input_config.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Parameterization settings for the default configuration.""" from pydantic import BaseModel, ConfigDict, Field from graphrag_input.input_type import InputType class InputConfig(BaseModel): """The default configuration section for In...
41
1,147
graphrag
packages/graphrag-storage/graphrag_storage/storage_factory.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Storage factory implementation.""" from collections.abc import Callable from graphrag_common.factory import Factory, ServiceScope from graphrag_storage.storage import Storage from graphrag_storage.storage_config import StorageConfig fr...
79
2,486
graphrag
packages/graphrag-storage/graphrag_storage/memory_storage.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """In-memory storage implementation.""" import re from collections.abc import Iterator from typing import TYPE_CHECKING, Any from graphrag_storage.file_storage import FileStorage if TYPE_CHECKING: from graphrag_storage.storage import S...
103
2,757
graphrag
packages/graphrag-storage/graphrag_storage/file_storage.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """File-based Storage implementation of Storage.""" import logging import os import re import shutil from collections.abc import Iterator from datetime import datetime, timezone from pathlib import Path from typing import Any, cast import a...
155
5,037
graphrag
packages/graphrag-storage/graphrag_storage/storage.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Abstract base class for storage.""" import re from abc import ABC, abstractmethod from collections.abc import Iterator from datetime import datetime from typing import Any class Storage(ABC): """Provide a storage interface.""" ...
142
3,476
graphrag
packages/graphrag-storage/graphrag_storage/azure_cosmos_storage.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Azure CosmosDB key-value Storage implementation. This module provides a simple key-value store on top of Cosmos DB for non-tabular data: pipeline state (context.json, stats.json), GraphML snapshots, and LLM cache entries. Tabular data (D...
325
11,935
graphrag
packages/graphrag-storage/graphrag_storage/storage_type.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Builtin storage implementation types.""" from enum import StrEnum class StorageType(StrEnum): """Enum for storage types.""" File = "file" Memory = "memory" AzureBlob = "blob" AzureCosmos = "cosmosdb"
17
306
graphrag
packages/graphrag-storage/graphrag_storage/__init__.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """The GraphRAG Storage package.""" from graphrag_storage.storage import Storage from graphrag_storage.storage_config import StorageConfig from graphrag_storage.storage_factory import ( create_storage, register_storage, ) from graphr...
23
550
graphrag
packages/graphrag-storage/graphrag_storage/azure_blob_storage.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Azure Blob Storage implementation of Storage.""" import logging import re from collections.abc import Iterator from pathlib import Path from typing import Any from azure.identity import DefaultAzureCredential from azure.storage.blob impo...
279
10,037
graphrag
packages/graphrag-storage/graphrag_storage/storage_config.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Storage configuration model.""" from pydantic import BaseModel, ConfigDict, Field from graphrag_storage.storage_type import StorageType class StorageConfig(BaseModel): """The default configuration section for storage.""" model...
49
1,427