sample_id stringlengths 21 196 | text stringlengths 105 936k | metadata dict | category stringclasses 6
values |
|---|---|---|---|
microsoft/graphrag:packages/graphrag/graphrag/cache/cache_key_creator.py | # Copyright (c) 2025 Microsoft Corporation.
# Licensed under the MIT License
"""Cache key creation for Graphrag."""
from typing import Any
from graphrag_llm.cache import create_cache_key
_CACHE_VERSION = 4
"""
If there's a breaking change in what we cache, we should increment this version number to invalidate exist... | {
"repo_id": "microsoft/graphrag",
"file_path": "packages/graphrag/graphrag/cache/cache_key_creator.py",
"license": "MIT License",
"lines": 33,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
microsoft/graphrag:packages/graphrag/graphrag/cli/query.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""CLI implementation of the query subcommand."""
import asyncio
import sys
from pathlib import Path
from typing import TYPE_CHECKING, Any
from graphrag_storage import create_storage
from graphrag_storage.tables.table_provider_factory impor... | {
"repo_id": "microsoft/graphrag",
"file_path": "packages/graphrag/graphrag/cli/query.py",
"license": "MIT License",
"lines": 339,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
microsoft/graphrag:packages/graphrag/graphrag/config/embeddings.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""A module containing embeddings values."""
entity_description_embedding = "entity_description"
community_full_content_embedding = "community_full_content"
text_unit_text_embedding = "text_unit_text"
all_embeddings: set[str] = {
entity... | {
"repo_id": "microsoft/graphrag",
"file_path": "packages/graphrag/graphrag/config/embeddings.py",
"license": "MIT License",
"lines": 16,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
microsoft/graphrag:packages/graphrag/graphrag/config/enums.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""A module containing config enums."""
from __future__ import annotations
from enum import Enum
class ReportingType(str, Enum):
"""The reporting configuration type for the pipeline."""
file = "file"
"""The file reporting con... | {
"repo_id": "microsoft/graphrag",
"file_path": "packages/graphrag/graphrag/config/enums.py",
"license": "MIT License",
"lines": 52,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
microsoft/graphrag:packages/graphrag/graphrag/config/load_config.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Default method for loading config."""
from pathlib import Path
from typing import Any
from graphrag_common.config import load_config as lc
from graphrag.config.models.graph_rag_config import GraphRagConfig
def load_config(
root_di... | {
"repo_id": "microsoft/graphrag",
"file_path": "packages/graphrag/graphrag/config/load_config.py",
"license": "MIT License",
"lines": 38,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
microsoft/graphrag:packages/graphrag/graphrag/config/models/embed_text_config.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Parameterization settings for the default configuration."""
from pydantic import BaseModel, Field
from graphrag.config.defaults import graphrag_config_defaults
class EmbedTextConfig(BaseModel):
"""Configuration section for text emb... | {
"repo_id": "microsoft/graphrag",
"file_path": "packages/graphrag/graphrag/config/models/embed_text_config.py",
"license": "MIT License",
"lines": 27,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
microsoft/graphrag:packages/graphrag/graphrag/config/models/graph_rag_config.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Parameterization settings for the default configuration."""
from dataclasses import asdict
from pathlib import Path
from devtools import pformat
from graphrag_cache import CacheConfig
from graphrag_chunking.chunking_config import Chunkin... | {
"repo_id": "microsoft/graphrag",
"file_path": "packages/graphrag/graphrag/config/models/graph_rag_config.py",
"license": "MIT License",
"lines": 281,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
microsoft/graphrag:packages/graphrag/graphrag/index/operations/embed_text/embed_text.py | # Copyright (C) 2026 Microsoft
# Licensed under the MIT License
"""Streaming text embedding operation."""
import logging
from typing import TYPE_CHECKING, Any
import numpy as np
from graphrag_llm.tokenizer import Tokenizer
from graphrag_storage.tables.table import Table
from graphrag_vectors import VectorStore, Vect... | {
"repo_id": "microsoft/graphrag",
"file_path": "packages/graphrag/graphrag/index/operations/embed_text/embed_text.py",
"license": "MIT License",
"lines": 130,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
microsoft/graphrag:packages/graphrag/graphrag/index/operations/extract_covariates/claim_extractor.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""A module containing 'ClaimExtractorResult' and 'ClaimExtractor' models."""
import logging
import traceback
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any
from graphrag_llm.utils import (
CompletionMessagesBui... | {
"repo_id": "microsoft/graphrag",
"file_path": "packages/graphrag/graphrag/index/operations/extract_covariates/claim_extractor.py",
"license": "MIT License",
"lines": 164,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
microsoft/graphrag:packages/graphrag/graphrag/index/operations/extract_graph/graph_extractor.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Graph extraction helpers that return tabular data."""
import logging
import re
import traceback
from typing import TYPE_CHECKING, Any
import pandas as pd
from graphrag_llm.utils import (
CompletionMessagesBuilder,
)
from graphrag.in... | {
"repo_id": "microsoft/graphrag",
"file_path": "packages/graphrag/graphrag/index/operations/extract_graph/graph_extractor.py",
"license": "MIT License",
"lines": 156,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
microsoft/graphrag:packages/graphrag/graphrag/index/operations/summarize_descriptions/typing.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""A module containing 'SummarizedDescriptionResult' model."""
from dataclasses import dataclass
from typing import Any, NamedTuple
@dataclass
class SummarizedDescriptionResult:
"""Entity summarization result class definition."""
... | {
"repo_id": "microsoft/graphrag",
"file_path": "packages/graphrag/graphrag/index/operations/summarize_descriptions/typing.py",
"license": "MIT License",
"lines": 13,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
microsoft/graphrag:packages/graphrag/graphrag/index/text_splitting/text_splitting.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""A module containing 'TokenTextSplitter' class and 'split_single_text_on_tokens' function."""
import logging
from abc import ABC
from collections.abc import Callable
from typing import cast
import pandas as pd
from graphrag_llm.tokenizer ... | {
"repo_id": "microsoft/graphrag",
"file_path": "packages/graphrag/graphrag/index/text_splitting/text_splitting.py",
"license": "MIT License",
"lines": 84,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
microsoft/graphrag:packages/graphrag/graphrag/index/validate_config.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""A module containing validate_config_names definition."""
import asyncio
import logging
import sys
from graphrag_llm.completion import create_completion
from graphrag_llm.embedding import create_embedding
from graphrag.config.models.grap... | {
"repo_id": "microsoft/graphrag",
"file_path": "packages/graphrag/graphrag/index/validate_config.py",
"license": "MIT License",
"lines": 34,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
microsoft/graphrag:packages/graphrag/graphrag/index/workflows/create_base_text_units.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""A module containing run_workflow method definition."""
import logging
from typing import Any
from graphrag_chunking.chunker import Chunker
from graphrag_chunking.chunker_factory import create_chunker
from graphrag_chunking.transformers i... | {
"repo_id": "microsoft/graphrag",
"file_path": "packages/graphrag/graphrag/index/workflows/create_base_text_units.py",
"license": "MIT License",
"lines": 135,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
microsoft/graphrag:packages/graphrag/graphrag/logger/factory.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Factory functions for creating a logger."""
from __future__ import annotations
import logging
from pathlib import Path
from graphrag_common.factory import Factory
from graphrag.config.enums import ReportingType
LOG_FORMAT = "%(asctime... | {
"repo_id": "microsoft/graphrag",
"file_path": "packages/graphrag/graphrag/logger/factory.py",
"license": "MIT License",
"lines": 43,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
microsoft/graphrag:packages/graphrag/graphrag/prompts/index/extract_graph.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""A file containing prompts definition."""
GRAPH_EXTRACTION_PROMPT = """
-Goal-
Given a text document that is potentially relevant to this activity and a list of entity types, identify all entities of those types from the text and all relat... | {
"repo_id": "microsoft/graphrag",
"file_path": "packages/graphrag/graphrag/prompts/index/extract_graph.py",
"license": "MIT License",
"lines": 113,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
microsoft/graphrag:packages/graphrag/graphrag/utils/api.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""API functions for the GraphRAG module."""
from pathlib import Path
from graphrag_vectors import (
VectorStore,
VectorStoreConfig,
create_vector_store,
)
def get_embedding_store(
config: VectorStoreConfig,
embedding_... | {
"repo_id": "microsoft/graphrag",
"file_path": "packages/graphrag/graphrag/utils/api.py",
"license": "MIT License",
"lines": 59,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
microsoft/graphrag:scripts/copy_build_assets.py | # Copyright (c) 2025 Microsoft Corporation.
# Licensed under the MIT License
"""Copy root build assets to package directories."""
import shutil
from pathlib import Path
def copy_build_assets():
"""Copy root build assets to package build directories so files are included in pypi distributions."""
root_dir = ... | {
"repo_id": "microsoft/graphrag",
"file_path": "scripts/copy_build_assets.py",
"license": "MIT License",
"lines": 18,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
microsoft/graphrag:scripts/update_workspace_dependency_versions.py | # Copyright (c) 2025 Microsoft Corporation.
# Licensed under the MIT License
"""Update workspace dependency versions."""
import os
import re
import subprocess # noqa: S404
from pathlib import Path
def _get_version() -> str:
command = ["uv", "run", "semversioner", "current-version"]
completion = subprocess.... | {
"repo_id": "microsoft/graphrag",
"file_path": "scripts/update_workspace_dependency_versions.py",
"license": "MIT License",
"lines": 44,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
microsoft/graphrag:tests/integration/language_model/test_retries.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Test LiteLLM Retries."""
import time
from typing import Any
import httpx
import litellm.exceptions as exceptions
import pytest
from graphrag_llm.config import RetryConfig, RetryType
from graphrag_llm.retry import create_retry
@pytest.m... | {
"repo_id": "microsoft/graphrag",
"file_path": "tests/integration/language_model/test_retries.py",
"license": "MIT License",
"lines": 222,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/graphrag:tests/unit/chunking/test_chunker.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
from typing import Any
from unittest.mock import Mock, patch
from graphrag.tokenizer.get_tokenizer import get_tokenizer
from graphrag_chunking.bootstrap_nltk import bootstrap
from graphrag_chunking.chunk_strategy_type import ChunkerType
from... | {
"repo_id": "microsoft/graphrag",
"file_path": "tests/unit/chunking/test_chunker.py",
"license": "MIT License",
"lines": 155,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/graphrag:tests/unit/chunking/test_prepend_metadata.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
from graphrag_chunking.transformers import add_metadata
def test_add_metadata_one_row():
"""Test prepending metadata to chunks"""
chunks = ["This is a test.", "Another sentence."]
metadata = {"message": "hello"}
transformer ... | {
"repo_id": "microsoft/graphrag",
"file_path": "tests/unit/chunking/test_prepend_metadata.py",
"license": "MIT License",
"lines": 35,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/graphrag:tests/unit/config/test_metrics_config.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Test metrics configuration loading."""
import pytest
from graphrag_llm.config import (
MetricsConfig,
MetricsWriterType,
)
def test_file_metrics_writer_validation() -> None:
"""Test that missing required parameters raise val... | {
"repo_id": "microsoft/graphrag",
"file_path": "tests/unit/config/test_metrics_config.py",
"license": "MIT License",
"lines": 23,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/graphrag:tests/unit/config/test_model_config.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Test model configuration loading."""
import pytest
from graphrag_llm.config import AuthMethod, LLMProviderType, ModelConfig
from pydantic import ValidationError
def test_litellm_provider_validation() -> None:
"""Test that missing re... | {
"repo_id": "microsoft/graphrag",
"file_path": "tests/unit/config/test_model_config.py",
"license": "MIT License",
"lines": 98,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/graphrag:tests/unit/config/test_rate_limit_config.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Test rate limit configuration loading."""
import pytest
from graphrag_llm.config import RateLimitConfig, RateLimitType
def test_sliding_window_validation() -> None:
"""Test that missing required parameters raise validation errors.""... | {
"repo_id": "microsoft/graphrag",
"file_path": "tests/unit/config/test_rate_limit_config.py",
"license": "MIT License",
"lines": 57,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/graphrag:tests/unit/config/test_retry_config.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Test retry configuration loading."""
import pytest
from graphrag_llm.config import RetryConfig, RetryType
def test_exponential_backoff_validation() -> None:
"""Test that missing required parameters raise validation errors."""
w... | {
"repo_id": "microsoft/graphrag",
"file_path": "tests/unit/config/test_retry_config.py",
"license": "MIT License",
"lines": 55,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/graphrag:tests/unit/config/test_template_engine_config.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Test metrics configuration loading."""
import pytest
from graphrag_llm.config import (
TemplateEngineConfig,
TemplateEngineType,
TemplateManagerType,
)
def test_template_engine_config_validation() -> None:
"""Test that m... | {
"repo_id": "microsoft/graphrag",
"file_path": "tests/unit/config/test_template_engine_config.py",
"license": "MIT License",
"lines": 37,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/graphrag:tests/unit/config/test_tokenizer_config.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Test tokenizer configuration loading."""
import pytest
from graphrag_llm.config import TokenizerConfig, TokenizerType
def test_litellm_tokenizer_validation() -> None:
"""Test that missing required parameters raise validation errors.... | {
"repo_id": "microsoft/graphrag",
"file_path": "tests/unit/config/test_tokenizer_config.py",
"license": "MIT License",
"lines": 32,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/graphrag:tests/unit/graphrag_factory/test_factory.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Unit tests for graphrag_factory package."""
from abc import ABC, abstractmethod
from graphrag_common.factory import Factory
class TestABC(ABC):
"""Test abstract base class."""
@abstractmethod
def get_value(self) -> str:
... | {
"repo_id": "microsoft/graphrag",
"file_path": "tests/unit/graphrag_factory/test_factory.py",
"license": "MIT License",
"lines": 46,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/graphrag:tests/unit/hasher/test_hasher.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Test hasher"""
from graphrag_common.hasher import hash_data
def test_hash_data() -> None:
"""Test hash data function."""
# Test different types of data
class TestClass: # noqa: B903
"""Test hasher class."""
... | {
"repo_id": "microsoft/graphrag",
"file_path": "tests/unit/hasher/test_hasher.py",
"license": "MIT License",
"lines": 90,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/graphrag:tests/unit/indexing/input/test_jsonl_loader.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
from graphrag_input import InputConfig, InputType, create_input_reader
from graphrag_storage import StorageConfig, create_storage
async def test_jsonl_loader_one_file_multiple_objects():
config = InputConfig(
type=InputType.Json... | {
"repo_id": "microsoft/graphrag",
"file_path": "tests/unit/indexing/input/test_jsonl_loader.py",
"license": "MIT License",
"lines": 37,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/graphrag:tests/unit/indexing/input/test_markitdown_loader.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
from graphrag_input import InputConfig, InputType, create_input_reader
from graphrag_storage import StorageConfig, create_storage
# these tests just confirm we can load files with MarkItDown,
# and use html specifically because it requires ... | {
"repo_id": "microsoft/graphrag",
"file_path": "tests/unit/indexing/input/test_markitdown_loader.py",
"license": "MIT License",
"lines": 23,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/graphrag:tests/unit/indexing/input/test_text_document.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
import pytest
from graphrag_input import get_property
def test_get_property_single_level():
data = {"foo": "bar"}
assert get_property(data, "foo") == "bar"
def test_get_property_two_levels():
data = {"foo": {"bar": "baz"}}
... | {
"repo_id": "microsoft/graphrag",
"file_path": "tests/unit/indexing/input/test_text_document.py",
"license": "MIT License",
"lines": 49,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/graphrag:tests/unit/indexing/input/test_text_loader.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
from graphrag_input import InputConfig, InputType, create_input_reader
from graphrag_storage import StorageConfig, create_storage
async def test_text_loader_one_file():
config = InputConfig(
type=InputType.Text,
file_pat... | {
"repo_id": "microsoft/graphrag",
"file_path": "tests/unit/indexing/input/test_text_loader.py",
"license": "MIT License",
"lines": 31,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/graphrag:tests/unit/load_config/config.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Config models for load_config unit tests."""
from pydantic import BaseModel, ConfigDict, Field
class TestNestedModel(BaseModel):
"""Test nested model."""
model_config = ConfigDict(extra="forbid")
nested_str: str = Field(de... | {
"repo_id": "microsoft/graphrag",
"file_path": "tests/unit/load_config/config.py",
"license": "MIT License",
"lines": 17,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/graphrag:tests/unit/load_config/test_load_config.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Unit tests for graphrag-config.load_config."""
import os
from pathlib import Path
import pytest
from graphrag_common.config import ConfigParsingError, load_config
from pydantic import ValidationError
from .config import TestConfigModel
... | {
"repo_id": "microsoft/graphrag",
"file_path": "tests/unit/load_config/test_load_config.py",
"license": "MIT License",
"lines": 129,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/graphrag:tests/unit/query/context_builder/dynamic_community_selection.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""Tests for dynamic community selection with type handling."""
from unittest.mock import MagicMock
from graphrag.data_model.community import Community
from graphrag.data_model.community_report import CommunityReport
from graphrag.query.con... | {
"repo_id": "microsoft/graphrag",
"file_path": "tests/unit/query/context_builder/dynamic_community_selection.py",
"license": "MIT License",
"lines": 183,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/graphrag:tests/unit/utils/test_encoding.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
from graphrag.tokenizer.get_tokenizer import get_tokenizer
def test_encode_basic():
tokenizer = get_tokenizer()
result = tokenizer.encode("abc def")
assert result == [26682, 1056], (
f"Encoding failed to return expected... | {
"repo_id": "microsoft/graphrag",
"file_path": "tests/unit/utils/test_encoding.py",
"license": "MIT License",
"lines": 13,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/graphrag:tests/integration/cache/test_factory.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""CacheFactory Tests.
These tests will test the CacheFactory() class and the creation of each cache type that is natively supported.
"""
import sys
import pytest
from graphrag_cache import Cache, CacheConfig, CacheType, create_cache, regis... | {
"repo_id": "microsoft/graphrag",
"file_path": "tests/integration/cache/test_factory.py",
"license": "MIT License",
"lines": 127,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/graphrag:tests/integration/logging/test_factory.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""LoggerFactory Tests.
These tests will test the LoggerFactory class and the creation of each reporting type that is natively supported.
"""
import logging
import pytest
from graphrag.config.enums import ReportingType
from graphrag.logger.... | {
"repo_id": "microsoft/graphrag",
"file_path": "tests/integration/logging/test_factory.py",
"license": "MIT License",
"lines": 46,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/graphrag:tests/integration/vector_stores/test_factory.py | # Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
"""VectorStoreFactory Tests.
These tests will test the VectorStoreFactory class and the creation of each vector store type that is natively supported.
"""
import pytest
from graphrag_vectors import (
VectorStore,
VectorStoreFactory,
... | {
"repo_id": "microsoft/graphrag",
"file_path": "tests/integration/vector_stores/test_factory.py",
"license": "MIT License",
"lines": 130,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/markitdown:packages/markitdown/tests/test_pdf_masterformat.py | #!/usr/bin/env python3 -m pytest
"""Tests for MasterFormat-style partial numbering in PDF conversion."""
import os
import re
import pytest
from markitdown import MarkItDown
from markitdown.converters._pdf_converter import PARTIAL_NUMBERING_PATTERN
TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), "test_files"... | {
"repo_id": "microsoft/markitdown",
"file_path": "packages/markitdown/tests/test_pdf_masterformat.py",
"license": "MIT License",
"lines": 137,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/markitdown:packages/markitdown/tests/test_docintel_html.py | import io
from markitdown.converters._doc_intel_converter import (
DocumentIntelligenceConverter,
DocumentIntelligenceFileType,
)
from markitdown._stream_info import StreamInfo
def _make_converter(file_types):
conv = DocumentIntelligenceConverter.__new__(DocumentIntelligenceConverter)
conv._file_types... | {
"repo_id": "microsoft/markitdown",
"file_path": "packages/markitdown/tests/test_docintel_html.py",
"license": "MIT License",
"lines": 20,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/qlib:tests/backtest/test_soft_topk_strategy.py | import pandas as pd
import pytest
from qlib.contrib.strategy.cost_control import SoftTopkStrategy
class MockPosition:
def __init__(self, weights):
self.weights = weights
def get_stock_weight_dict(self, only_stock=True):
return self.weights
def test_soft_topk_logic():
# Initial: A=0.8, B... | {
"repo_id": "microsoft/qlib",
"file_path": "tests/backtest/test_soft_topk_strategy.py",
"license": "MIT License",
"lines": 43,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/qlib:tests/backtest/test_soft_topk_strategy_cold_start.py | import pandas as pd
import pytest
from qlib.contrib.strategy.cost_control import SoftTopkStrategy
class MockPosition:
def __init__(self, weights):
self.weights = weights
def get_stock_weight_dict(self, only_stock=True):
return self.weights
def create_test_strategy(topk, risk_degree, impact... | {
"repo_id": "microsoft/qlib",
"file_path": "tests/backtest/test_soft_topk_strategy_cold_start.py",
"license": "MIT License",
"lines": 28,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
microsoft/qlib:qlib/utils/pickle_utils.py | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""
Secure pickle utilities to prevent arbitrary code execution through deserialization.
This module provides a secure alternative to pickle.load() and pickle.loads()
that restricts deserialization to a whitelist of safe classes.
"""
import io
i... | {
"repo_id": "microsoft/qlib",
"file_path": "qlib/utils/pickle_utils.py",
"license": "MIT License",
"lines": 133,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
microsoft/unilm:Diff-Transformer/Diff-Transformer-V2/multihead_flashdiffv2.py | import torch
from torch import nn
from typing import Optional, Tuple
from ..kernel.rotary import apply_rotary_emb
from flash_attn import flash_attn_func
@torch.compile
def diff_func(attn1: torch.Tensor, attn2: torch.Tensor, lambda_val: torch.Tensor) -> torch.Tensor:
return attn1 - torch.sigmoid(lambda_val).unsque... | {
"repo_id": "microsoft/unilm",
"file_path": "Diff-Transformer/Diff-Transformer-V2/multihead_flashdiffv2.py",
"license": "MIT License",
"lines": 63,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
microsoft/unilm:ReSA/llm/arch/context_manager.py | import torch
import torch.nn.functional as F
import triton
import triton.language as tl
@triton.autotune(
configs=[
triton.Config({"BLOCK_N": BLOCK_N}, num_warps=num_warps, num_stages=1)
for num_warps in [1, 2, 4, 8]
for BLOCK_N in [32, 64]
],
key=['local_block_num', 'head_di... | {
"repo_id": "microsoft/unilm",
"file_path": "ReSA/llm/arch/context_manager.py",
"license": "MIT License",
"lines": 135,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
microsoft/unilm:ReSA/llm/arch/model.py | import random
import torch
from torch import nn
from torch.nn import functional as F
from einops import rearrange, repeat
from typing import Optional, Tuple, List
from dataclasses import dataclass
from apex.normalization.fused_layer_norm import fused_rms_norm_affine
from kernel.flash_sparse_decoding import flash_block_... | {
"repo_id": "microsoft/unilm",
"file_path": "ReSA/llm/arch/model.py",
"license": "MIT License",
"lines": 198,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
microsoft/unilm:ReSA/llm/config.py | import argparse
def parse_eval_args():
parser = argparse.ArgumentParser(description="evaluation arguments")
parser.add_argument(f"--limit", type=int, default=None)
parser.add_argument(f"--batch_size", type=int, default=32)
parser.add_argument(f"--tasks", type=str, default=None)
parser.add_argument(... | {
"repo_id": "microsoft/unilm",
"file_path": "ReSA/llm/config.py",
"license": "MIT License",
"lines": 23,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
microsoft/unilm:ReSA/llm/data/tokenizer.py | import os
from typing import List
from transformers import LlamaTokenizerFast
os.environ["TOKENIZERS_PARALLELISM"] = "true"
class Tokenizer:
def __init__(self, tokenizer_path: str):
self.tok = LlamaTokenizerFast.from_pretrained(tokenizer_path)
@property
def n_words(self) -> int:
return se... | {
"repo_id": "microsoft/unilm",
"file_path": "ReSA/llm/data/tokenizer.py",
"license": "MIT License",
"lines": 37,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
microsoft/unilm:ReSA/llm/eval.py | import time
import torch
import torch.nn as nn
from torch.distributed import init_process_group, destroy_process_group
from typing import Optional
import datetime
import lm_eval
from lm_eval.models.huggingface import HFLM as eval_wrapper
from lm_eval.tasks import get_task_dict, TaskManager
from lm_eval.evaluator import... | {
"repo_id": "microsoft/unilm",
"file_path": "ReSA/llm/eval.py",
"license": "MIT License",
"lines": 297,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
microsoft/unilm:ReSA/llm/kernel/flash_attention_with_kv_cache.py | import math
import torch
import triton
import triton.language as tl
def is_hip():
return triton.runtime.driver.active.get_current_target().backend == "hip"
def num_splits_heuristic(total_mblocks, num_SMs, num_n_blocks, num_m_blocks, size_one_kv_head,
is_causal_or_local, max_splits):
... | {
"repo_id": "microsoft/unilm",
"file_path": "ReSA/llm/kernel/flash_attention_with_kv_cache.py",
"license": "MIT License",
"lines": 299,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
microsoft/unilm:ReSA/llm/kernel/rotary.py | # Copyright (c) 2023, Tri Dao.
from typing import Optional, Union
import torch
import triton
import triton.language as tl
from typing import Optional, Union
from einops import rearrange, repeat
def rotate_half(x, interleaved=False):
if not interleaved:
x1, x2 = x.chunk(2, dim=-1)
return torch.... | {
"repo_id": "microsoft/unilm",
"file_path": "ReSA/llm/kernel/rotary.py",
"license": "MIT License",
"lines": 330,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
microsoft/unilm:ReSA/llm/kernel/tilelang_attention_with_kv_cache.py | # Copyright (c) Tile-AI Corporation.
# Licensed under the MIT License.
import torch
import torch.nn.functional as F
import tilelang
from tilelang.autotuner import *
import tilelang.language as T
import argparse
import time
import math
def num_splits_heuristic(total_mblocks, num_SMs, num_n_blocks, num_m_blocks, size_o... | {
"repo_id": "microsoft/unilm",
"file_path": "ReSA/llm/kernel/tilelang_attention_with_kv_cache.py",
"license": "MIT License",
"lines": 324,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
microsoft/unilm:ReSA/llm/kernel/tilelang_sparse_decoding.py | # Copyright (c) Tile-AI Corporation.
# Licensed under the MIT License.
import torch
import torch.nn.functional as F
import tilelang
from tilelang.autotuner import *
import tilelang.language as T
from einops import rearrange, einsum
import argparse
import time
import math
def num_splits_heuristic(total_mblocks, num_SM... | {
"repo_id": "microsoft/unilm",
"file_path": "ReSA/llm/kernel/tilelang_sparse_decoding.py",
"license": "MIT License",
"lines": 459,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | license |
microsoft/unilm:ReSA/scripts/math_eval_result_length.py | import argparse
from transformers import LlamaTokenizerFast
import os
os.environ["TOKENIZERS_PARALLELISM"] = "true"
from math_utils import evaluate, load_jsonl
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--data_names", default="gsm8k", type=str)
parser.add_argument("--result_... | {
"repo_id": "microsoft/unilm",
"file_path": "ReSA/scripts/math_eval_result_length.py",
"license": "MIT License",
"lines": 75,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
microsoft/unilm:ReSA/scripts/math_utils.py | import re
import os
import io
import json
import copy
import regex
import pickle
import datetime
import traceback
import numpy as np
from tqdm import tqdm
from math import isclose
from pathlib import Path
from contextlib import redirect_stdout
from concurrent.futures import TimeoutError
from functools import partial
im... | {
"repo_id": "microsoft/unilm",
"file_path": "ReSA/scripts/math_utils.py",
"license": "MIT License",
"lines": 1385,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
mingrammer/diagrams:diagrams/cli.py | import argparse
import sys
def run() -> int:
"""
Run diagrams code files in a diagrams environment.
Args:
paths: A list of paths to Python files containing diagrams code.
Returns:
The exit code.
"""
parser = argparse.ArgumentParser(
description="Run diagrams code files... | {
"repo_id": "mingrammer/diagrams",
"file_path": "diagrams/cli.py",
"license": "MIT License",
"lines": 29,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
mitmproxy/mitmproxy:mitmproxy/contentviews/_view_zip.py | import io
import zipfile
from mitmproxy.contentviews._api import Contentview
from mitmproxy.contentviews._api import Metadata
from mitmproxy.contentviews._utils import yaml_dumps
class ZipContentview(Contentview):
name = "ZIP Archive"
syntax_highlight = "yaml"
def prettify(self, data: bytes, metadata: M... | {
"repo_id": "mitmproxy/mitmproxy",
"file_path": "mitmproxy/contentviews/_view_zip.py",
"license": "MIT License",
"lines": 15,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
mitmproxy/mitmproxy:test/mitmproxy/contentviews/test__view_zip.py | import io
import zipfile
from mitmproxy import http
from mitmproxy.contentviews import Metadata
from mitmproxy.contentviews._view_zip import zip
def meta(content_type: str) -> Metadata:
return Metadata(
content_type=content_type.split(";")[0],
http_message=http.Request.make(
"POST", "... | {
"repo_id": "mitmproxy/mitmproxy",
"file_path": "test/mitmproxy/contentviews/test__view_zip.py",
"license": "MIT License",
"lines": 46,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
mitmproxy/mitmproxy:examples/addons/dns-simple.py | """
Spoof DNS responses.
In this example, we fiddle with IPv6 (AAAA) records:
- For example.com, `::1` is returned.
(domain is hosted on localhost)
- For example.org, an NXDOMAIN error is returned.
(domain does not exist)
- For all other domains, return a non-error response without any records.
(domain exi... | {
"repo_id": "mitmproxy/mitmproxy",
"file_path": "examples/addons/dns-simple.py",
"license": "MIT License",
"lines": 33,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
mitmproxy/mitmproxy:mitmproxy/utils/htpasswd.py | """
A standalone, minimal htpasswd parser.
This implementation currently supports bcrypt and SHA1 passwords. SHA1 is insecure.
"""
from __future__ import annotations
import base64
import hashlib
from pathlib import Path
import bcrypt
class HtpasswdFile:
def __init__(self, content: str):
"""
Cr... | {
"repo_id": "mitmproxy/mitmproxy",
"file_path": "mitmproxy/utils/htpasswd.py",
"license": "MIT License",
"lines": 65,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
mitmproxy/mitmproxy:test/mitmproxy/utils/test_htpasswd.py | from pathlib import Path
import pytest
from mitmproxy.utils import htpasswd
def test_sha1():
ht = htpasswd.HtpasswdFile(
"user1:{SHA}8FePHnF0saQcTqjG4X96ijuIySo=\n"
"user2:{SHA}i+UhJqb95FCnFio2UdWJu1HpV50=\n"
"user3:{SHA}3ipNV1GrBtxPmHFC21fCbVCSXIo=:extra\n"
)
assert ht.check_pas... | {
"repo_id": "mitmproxy/mitmproxy",
"file_path": "test/mitmproxy/utils/test_htpasswd.py",
"license": "MIT License",
"lines": 45,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
mitmproxy/mitmproxy:examples/contrib/portfile.py | import json
import pathlib
from typing import Optional
from mitmproxy import ctx
class PortFile:
def load(self, loader):
loader.add_option(
name="datadir",
typespec=Optional[str],
default=None,
help="Creates `portfile` mapping proxies (by mode spec) to the ... | {
"repo_id": "mitmproxy/mitmproxy",
"file_path": "examples/contrib/portfile.py",
"license": "MIT License",
"lines": 32,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
mlc-ai/mlc-llm:python/mlc_llm/loader/standard_loader.py | """Standard HuggingFace loader mapping helpers."""
from __future__ import annotations
import functools
from typing import Callable, Iterable, Optional, Sequence, Type
import numpy as np
from tvm.relax.frontend import nn # type: ignore[import]
from mlc_llm.loader import ExternMapping
from mlc_llm.quantization impor... | {
"repo_id": "mlc-ai/mlc-llm",
"file_path": "python/mlc_llm/loader/standard_loader.py",
"license": "Apache License 2.0",
"lines": 129,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
mlc-ai/mlc-llm:python/mlc_llm/quantization/model_quantization.py | """Quantization factory utilities for model quantization."""
from typing import Any, Callable, Dict, Optional, Tuple, Type
from tvm.relax.frontend import nn
from mlc_llm.loader import QuantizeMapping
from .awq_quantization import AWQQuantize
from .block_scale_quantization import BlockScaleQuantize
from .ft_quantiza... | {
"repo_id": "mlc-ai/mlc-llm",
"file_path": "python/mlc_llm/quantization/model_quantization.py",
"license": "Apache License 2.0",
"lines": 138,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
mlc-ai/mlc-llm:python/mlc_llm/bench/evaluation/mmlu.py | """Eval MMLU with MLCEngine."""
import argparse
import asyncio
import csv
import json
import string
from datetime import datetime
from pathlib import Path
from typing import Any, Dict, List, Optional
import numpy as np
import tqdm
from mlc_llm import AsyncMLCEngine
SUBJECTS = [
"abstract_algebra",
"anatomy"... | {
"repo_id": "mlc-ai/mlc-llm",
"file_path": "python/mlc_llm/bench/evaluation/mmlu.py",
"license": "Apache License 2.0",
"lines": 218,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
mlc-ai/mlc-llm:python/mlc_llm/bench/evaluation/gsm8k.py | """Eval GSM8K with MLCEngine."""
import argparse
import asyncio
import json
import random
import re
from datetime import datetime
from pathlib import Path
from typing import List, Literal, Optional
import tqdm
from mlc_llm import AsyncMLCEngine
DEVICES = ["cuda", "rocm", "metal", "vulkan"]
ANSWER_TRIGGER = "The ans... | {
"repo_id": "mlc-ai/mlc-llm",
"file_path": "python/mlc_llm/bench/evaluation/gsm8k.py",
"license": "Apache License 2.0",
"lines": 267,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
mlc-ai/mlc-llm:tests/python/support/test_cli_convert_weight.py | # pylint: disable=missing-docstring
import json
import tempfile
from pathlib import Path
import pytest
from mlc_llm.cli import convert_weight as convert_weight_cli
pytestmark = [pytest.mark.unittest]
def test_convert_weight_cli_passes_lora_adapter(monkeypatch):
with tempfile.TemporaryDirectory() as tmp_dir:
... | {
"repo_id": "mlc-ai/mlc-llm",
"file_path": "tests/python/support/test_cli_convert_weight.py",
"license": "Apache License 2.0",
"lines": 55,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
mlc-ai/mlc-llm:tests/python/support/test_convert_weight_lora_merge.py | # pylint: disable=missing-docstring,protected-access
import contextlib
import json
import tempfile
from pathlib import Path
import pytest
from mlc_llm.interface import convert_weight as convert_weight_interface
pytestmark = [pytest.mark.unittest]
def test_resolve_base_model_dir():
with tempfile.TemporaryDirect... | {
"repo_id": "mlc-ai/mlc-llm",
"file_path": "tests/python/support/test_convert_weight_lora_merge.py",
"license": "Apache License 2.0",
"lines": 88,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
mlc-ai/mlc-llm:python/mlc_llm/serve/embedding_engine.py | """Asynchronous embedding inference engine for encoder and decoder models."""
import asyncio
import concurrent.futures
import json
import os
from typing import List, Literal, Optional, Tuple, Union
import numpy as np
import tvm
from tvm import relax
from tvm.runtime import Device, ShapeTuple
from mlc_llm.serve impor... | {
"repo_id": "mlc-ai/mlc-llm",
"file_path": "python/mlc_llm/serve/embedding_engine.py",
"license": "Apache License 2.0",
"lines": 408,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
mlc-ai/mlc-llm:tests/python/serve/server/test_embedding_server.py | """Embedding server endpoint tests in MLC LLM.
Tests the /v1/embeddings endpoint via HTTP using the OpenAI client,
following the same patterns as test_server.py.
Reuses MLC LLM test infrastructure:
- Pytest markers (endpoint)
- expect_error() response validation pattern from test_server.py
- OpenAI client usage... | {
"repo_id": "mlc-ai/mlc-llm",
"file_path": "tests/python/serve/server/test_embedding_server.py",
"license": "Apache License 2.0",
"lines": 286,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
mlc-ai/mlc-llm:tests/python/serve/test_embedding_engine.py | """Embedding engine tests in MLC LLM.
Tests AsyncEmbeddingEngine for both direct (sync) and async embedding inference.
Reuses MLC LLM test infrastructure: markers, require_test_model pattern,
and conventions from test_serve_engine.py.
Run with real model (requires GPU + compiled embedding model):
MLC_SERVE_EMBEDDIN... | {
"repo_id": "mlc-ai/mlc-llm",
"file_path": "tests/python/serve/test_embedding_engine.py",
"license": "Apache License 2.0",
"lines": 254,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
mlc-ai/mlc-llm:tests/python/model/test_gemma3.py | # pylint: disable=invalid-name,missing-docstring
"""Unit tests for Gemma3 model architecture."""
import pytest
from mlc_llm.model import MODEL_PRESETS, MODELS
def test_gemma3_model_registered():
"""Verify Gemma3 model is in the registry."""
assert "gemma3" in MODELS, "gemma3 should be registered in MODELS"
... | {
"repo_id": "mlc-ai/mlc-llm",
"file_path": "tests/python/model/test_gemma3.py",
"license": "Apache License 2.0",
"lines": 55,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
mlc-ai/mlc-llm:python/mlc_llm/conversation_template/ministral3_reasoning.py | """Ministral3 reasoning templates"""
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
from .registry import ConvTemplateRegistry
# Ministral-3-XB-Reasoning-2512
ConvTemplateRegistry.register_conv_template(
Conversation(
name="ministral3_reasoning",
system_templ... | {
"repo_id": "mlc-ai/mlc-llm",
"file_path": "python/mlc_llm/conversation_template/ministral3_reasoning.py",
"license": "Apache License 2.0",
"lines": 35,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
mlc-ai/mlc-llm:python/mlc_llm/conversation_template/ministral3.py | """Ministral3 templates"""
from mlc_llm.protocol.conversation_protocol import Conversation, MessagePlaceholders
from .registry import ConvTemplateRegistry
# Ministral3
ConvTemplateRegistry.register_conv_template(
Conversation(
name="ministral3",
system_template=(
f"[SYSTEM_PROMPT]{Mes... | {
"repo_id": "mlc-ai/mlc-llm",
"file_path": "python/mlc_llm/conversation_template/ministral3.py",
"license": "Apache License 2.0",
"lines": 66,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
mlc-ai/mlc-llm:python/mlc_llm/model/ministral3/ministral3_loader.py | """
This file specifies how MLC's Ministral3 parameter maps from other formats, for example HuggingFace
PyTorch, HuggingFace safetensors.
"""
import functools
from typing import Callable, List, Optional, Tuple
import numpy as np
from mlc_llm.loader import ExternMapping, QuantizeMapping
from mlc_llm.quantization impo... | {
"repo_id": "mlc-ai/mlc-llm",
"file_path": "python/mlc_llm/model/ministral3/ministral3_loader.py",
"license": "Apache License 2.0",
"lines": 234,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
mlc-ai/mlc-llm:python/mlc_llm/model/ministral3/ministral3_model.py | """
Implementation for Ministral 3 architecture.
"""
import dataclasses
import math
from functools import partial
from typing import Any, Dict, Optional, Tuple
from tvm import te, tir
from tvm.relax.frontend import nn
from tvm.relax.frontend.nn import Tensor, op
from mlc_llm import op as op_ext
from mlc_llm.nn impor... | {
"repo_id": "mlc-ai/mlc-llm",
"file_path": "python/mlc_llm/model/ministral3/ministral3_model.py",
"license": "Apache License 2.0",
"lines": 479,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
mlc-ai/mlc-llm:python/mlc_llm/model/llama4/llama4_loader.py | """
This file specifies how MLC's Llama parameter maps from other formats, for example HuggingFace
PyTorch, HuggingFace safetensors.
"""
import functools
import numpy as np
from mlc_llm.loader import ExternMapping
from mlc_llm.quantization import Quantization
from .llama4_model import Llama4Config, Llama4ForCausalL... | {
"repo_id": "mlc-ai/mlc-llm",
"file_path": "python/mlc_llm/model/llama4/llama4_loader.py",
"license": "Apache License 2.0",
"lines": 103,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
mlc-ai/mlc-llm:python/mlc_llm/model/llama4/llama4_model.py | """
Implementation for Llama4 architecture.
"""
import dataclasses
from typing import Any, Dict, Optional
import tvm
from tvm import te, tir
from tvm.relax.frontend import nn
from tvm.relax.frontend.nn import Tensor, op
from tvm.relax.frontend.nn.llm import position_embedding
from mlc_llm import op as op_ext
from ml... | {
"repo_id": "mlc-ai/mlc-llm",
"file_path": "python/mlc_llm/model/llama4/llama4_model.py",
"license": "Apache License 2.0",
"lines": 713,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
mlflow/mlflow:mlflow/utils/uv_utils.py | """
Utilities for uv package manager integration.
This module provides functions for detecting uv projects and exporting dependencies
via ``uv export`` for automatic dependency inference during model logging.
"""
import logging
import re
import shutil
import subprocess
from pathlib import Path
from typing import Name... | {
"repo_id": "mlflow/mlflow",
"file_path": "mlflow/utils/uv_utils.py",
"license": "Apache License 2.0",
"lines": 355,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
mlflow/mlflow:tests/pyfunc/test_uv_model_logging.py | """
Integration tests for uv package manager support in model logging and loading.
Tests the end-to-end workflow:
1. uv project detection during log_model()
2. Artifact generation (uv.lock, pyproject.toml, .python-version, requirements.txt)
3. Model loading with uv artifacts
These tests use REAL uv calls (not mocked)... | {
"repo_id": "mlflow/mlflow",
"file_path": "tests/pyfunc/test_uv_model_logging.py",
"license": "Apache License 2.0",
"lines": 318,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
mlflow/mlflow:tests/utils/test_uv_utils.py | import subprocess
from unittest import mock
import pytest
from packaging.version import Version
from mlflow.environment_variables import MLFLOW_UV_AUTO_DETECT
from mlflow.utils.environment import infer_pip_requirements
from mlflow.utils.uv_utils import (
_PYPROJECT_FILE,
_UV_LOCK_FILE,
copy_uv_project_fil... | {
"repo_id": "mlflow/mlflow",
"file_path": "tests/utils/test_uv_utils.py",
"license": "Apache License 2.0",
"lines": 521,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
mlflow/mlflow:tests/store/tracking/test_sqlalchemy_store_issues.py | import pytest
from mlflow.exceptions import MlflowException
def test_create_issue_required_fields_only(store):
exp_id = store.create_experiment("test")
issue = store.create_issue(
experiment_id=exp_id,
name="High latency",
description="API calls are taking too long",
status="... | {
"repo_id": "mlflow/mlflow",
"file_path": "tests/store/tracking/test_sqlalchemy_store_issues.py",
"license": "Apache License 2.0",
"lines": 164,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
mlflow/mlflow:mlflow/server/gateway_budget.py | """Budget tracking and enforcement for the MLflow Gateway.
This module provides budget-related functions for recording costs, refreshing policies,
firing exceeded-budget webhooks, and creating on_complete callbacks for budget recording.
"""
import logging
from fastapi import HTTPException
import mlflow
from mlflow.... | {
"repo_id": "mlflow/mlflow",
"file_path": "mlflow/server/gateway_budget.py",
"license": "Apache License 2.0",
"lines": 149,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
mlflow/mlflow:tests/gateway/test_gateway_budget.py | from unittest.mock import MagicMock, patch
import fastapi
import pytest
import mlflow
import mlflow.gateway.budget_tracker as _bt_module
from mlflow.entities import SpanType
from mlflow.entities.gateway_budget_policy import (
BudgetAction,
BudgetDurationUnit,
BudgetTargetScope,
BudgetUnit,
Gateway... | {
"repo_id": "mlflow/mlflow",
"file_path": "tests/gateway/test_gateway_budget.py",
"license": "Apache License 2.0",
"lines": 333,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
mlflow/mlflow:mlflow/gateway/budget_tracker/in_memory.py | """In-memory budget tracker implementation."""
from __future__ import annotations
import threading
from dataclasses import dataclass, field
from datetime import datetime, timezone
from mlflow.entities.gateway_budget_policy import BudgetAction, GatewayBudgetPolicy
from mlflow.gateway.budget_tracker import (
Budge... | {
"repo_id": "mlflow/mlflow",
"file_path": "mlflow/gateway/budget_tracker/in_memory.py",
"license": "Apache License 2.0",
"lines": 131,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
mlflow/mlflow:tests/gateway/test_budget_tracker.py | from datetime import datetime, timedelta, timezone
from unittest.mock import patch
import pytest
from mlflow.entities.gateway_budget_policy import (
BudgetAction,
BudgetDurationUnit,
BudgetTargetScope,
BudgetUnit,
GatewayBudgetPolicy,
)
from mlflow.gateway.budget_tracker import (
BudgetTracker... | {
"repo_id": "mlflow/mlflow",
"file_path": "tests/gateway/test_budget_tracker.py",
"license": "Apache License 2.0",
"lines": 318,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
mlflow/mlflow:mlflow/entities/issue.py | from __future__ import annotations
from dataclasses import dataclass
from typing import Any
from mlflow.entities._mlflow_object import _MlflowObject
from mlflow.protos.issues_pb2 import Issue as ProtoIssue
@dataclass
class Issue(_MlflowObject):
"""
An Issue represents a quality or operational problem discov... | {
"repo_id": "mlflow/mlflow",
"file_path": "mlflow/entities/issue.py",
"license": "Apache License 2.0",
"lines": 98,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
mlflow/mlflow:tests/entities/test_issue.py | from mlflow.entities.issue import Issue
from mlflow.protos.issues_pb2 import Issue as ProtoIssue
def test_issue_creation_required_fields():
issue = Issue(
issue_id="iss-123",
experiment_id="exp-123",
name="High latency",
description="API calls are taking too long",
status="... | {
"repo_id": "mlflow/mlflow",
"file_path": "tests/entities/test_issue.py",
"license": "Apache License 2.0",
"lines": 295,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
mlflow/mlflow:dev/clint/src/clint/rules/prefer_os_environ.py | import ast
from typing import Literal
from typing_extensions import Self
from clint.resolver import Resolver
from clint.rules.base import Rule
# See https://github.com/astral-sh/ruff/issues/3608
class PreferOsEnviron(Rule):
def __init__(self, func: Literal["getenv", "putenv"]) -> None:
self.func = func
... | {
"repo_id": "mlflow/mlflow",
"file_path": "dev/clint/src/clint/rules/prefer_os_environ.py",
"license": "Apache License 2.0",
"lines": 19,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
mlflow/mlflow:dev/clint/tests/rules/test_prefer_os_environ.py | from pathlib import Path
import pytest
from clint.config import Config
from clint.linter import lint_file
from clint.rules.prefer_os_environ import PreferOsEnviron
@pytest.mark.parametrize(
"code",
[
pytest.param('import os\n\nval = os.getenv("FOO")', id="os.getenv"),
pytest.param('import os\... | {
"repo_id": "mlflow/mlflow",
"file_path": "dev/clint/tests/rules/test_prefer_os_environ.py",
"license": "Apache License 2.0",
"lines": 32,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
mlflow/mlflow:tests/tracing/utils/test_otlp_auth.py | import base64
from collections.abc import Generator
from contextlib import contextmanager
from unittest.mock import patch
from mlflow.tracing.utils.otlp import MLFLOW_EXPERIMENT_ID_HEADER, build_otlp_headers
from mlflow.utils.credentials import MlflowCreds
@contextmanager
def mock_creds(username: str | None = None, ... | {
"repo_id": "mlflow/mlflow",
"file_path": "tests/tracing/utils/test_otlp_auth.py",
"license": "Apache License 2.0",
"lines": 40,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
mlflow/mlflow:tests/transformers/version.py | import transformers
from packaging.version import Version
transformers_version = Version(transformers.__version__)
IS_NEW_FEATURE_EXTRACTION_API = transformers_version >= Version("4.27.0")
IS_TRANSFORMERS_V5_OR_LATER = transformers_version.major >= 5
| {
"repo_id": "mlflow/mlflow",
"file_path": "tests/transformers/version.py",
"license": "Apache License 2.0",
"lines": 5,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
mlflow/mlflow:dev/clint/src/clint/rules/prefer_next.py | import ast
from clint.rules.base import Rule
class PreferNext(Rule):
def _message(self) -> str:
return (
"Use `next(x for x in items if condition)` instead of "
"`[x for x in items if condition][0]` for finding the first matching element."
)
@staticmethod
def chec... | {
"repo_id": "mlflow/mlflow",
"file_path": "dev/clint/src/clint/rules/prefer_next.py",
"license": "Apache License 2.0",
"lines": 30,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
mlflow/mlflow:dev/clint/tests/rules/test_prefer_next.py | from pathlib import Path
import pytest
from clint.config import Config
from clint.linter import lint_file
from clint.rules import PreferNext
@pytest.mark.parametrize(
"code",
[
pytest.param("[x for x in items if f(x)][0]", id="basic_pattern"),
],
)
def test_flag(index_path: Path, code: str) -> No... | {
"repo_id": "mlflow/mlflow",
"file_path": "dev/clint/tests/rules/test_prefer_next.py",
"license": "Apache License 2.0",
"lines": 32,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
mlflow/mlflow:mlflow/tracing/otel/translation/langfuse.py | """
Translation utilities for Langfuse observation attributes.
Maps ``langfuse.observation.*`` attributes to MLflow span semantics so that
spans forwarded from Langfuse via the generic OTEL processor are stored with
correct span types, inputs, and outputs.
"""
from mlflow.entities.span import SpanType
from mlflow.tra... | {
"repo_id": "mlflow/mlflow",
"file_path": "mlflow/tracing/otel/translation/langfuse.py",
"license": "Apache License 2.0",
"lines": 23,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_simple |
mlflow/mlflow:tests/otel/test_otel_autolog.py | import asyncio
import pytest
langfuse = pytest.importorskip("langfuse", reason="langfuse is not installed")
from langfuse import observe
from langfuse._client.resource_manager import LangfuseResourceManager
from opentelemetry import trace as otel_trace_api
from opentelemetry.sdk.trace import TracerProvider as SdkTrac... | {
"repo_id": "mlflow/mlflow",
"file_path": "tests/otel/test_otel_autolog.py",
"license": "Apache License 2.0",
"lines": 203,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | test |
mlflow/mlflow:mlflow/entities/gateway_budget_policy.py | from __future__ import annotations
from dataclasses import dataclass
from enum import Enum
from mlflow.entities._mlflow_object import _MlflowObject
from mlflow.protos.service_pb2 import BudgetAction as ProtoBudgetAction
from mlflow.protos.service_pb2 import BudgetDurationUnit as ProtoBudgetDurationUnit
from mlflow.pr... | {
"repo_id": "mlflow/mlflow",
"file_path": "mlflow/entities/gateway_budget_policy.py",
"license": "Apache License 2.0",
"lines": 131,
"canary_id": -1,
"canary_value": "",
"pii_type": "",
"provider": "",
"regex_pattern": "",
"repetition": -1,
"template": ""
} | function_complex |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.