Files
microsoft--graphrag/tests/integration/language_model/test_factory.py
T
wehub-resource-sync 6b7e6b44f1
gh-pages / build (push) Waiting to run
Python Publish (pypi) / Upload release to PyPI (push) Waiting to run
Spellcheck / spellcheck (push) Waiting to run
Python Build and Type Check / python-ci (ubuntu-latest, 3.11) (push) Has been cancelled
Python Build and Type Check / python-ci (ubuntu-latest, 3.13) (push) Has been cancelled
Python Build and Type Check / python-ci (windows-latest, 3.11) (push) Has been cancelled
Python Build and Type Check / python-ci (windows-latest, 3.13) (push) Has been cancelled
Python Integration Tests / python-ci (ubuntu-latest, 3.13) (push) Has been cancelled
Python Integration Tests / python-ci (windows-latest, 3.13) (push) Has been cancelled
Python Notebook Tests / python-ci (ubuntu-latest, 3.13) (push) Has been cancelled
Python Notebook Tests / python-ci (windows-latest, 3.13) (push) Has been cancelled
Python Smoke Tests / python-ci (ubuntu-latest, 3.13) (push) Has been cancelled
Python Smoke Tests / python-ci (windows-latest, 3.13) (push) Has been cancelled
Python Unit Tests / python-ci (ubuntu-latest, 3.13) (push) Has been cancelled
Python Unit Tests / python-ci (windows-latest, 3.13) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:37:31 +08:00

102 lines
2.7 KiB
Python

# Copyright (c) 2025 Microsoft Corporation.
# Licensed under the MIT License
"""LLMFactory Tests.
These tests will test the LLMFactory class and the creation of custom and provided LLMs.
"""
from typing import TYPE_CHECKING, Any, Unpack
from graphrag_llm.completion import (
LLMCompletion,
create_completion,
register_completion,
)
from graphrag_llm.config import ModelConfig
from graphrag_llm.embedding import LLMEmbedding, create_embedding, register_embedding
if TYPE_CHECKING:
from collections.abc import AsyncIterator, Iterator
from graphrag_llm.metrics import MetricsStore
from graphrag_llm.tokenizer import Tokenizer
from graphrag_llm.types import (
LLMCompletionArgs,
LLMCompletionChunk,
LLMCompletionResponse,
LLMEmbeddingArgs,
LLMEmbeddingResponse,
ResponseFormat,
)
def test_create_custom_chat_model():
class CustomChatModel(LLMCompletion):
config: Any
def __init__(self, **kwargs):
pass
def completion(
self,
/,
**kwargs: Unpack["LLMCompletionArgs[ResponseFormat]"],
) -> "LLMCompletionResponse[ResponseFormat] | Iterator[LLMCompletionChunk]": ...
async def completion_async(
self,
/,
**kwargs: Unpack["LLMCompletionArgs[ResponseFormat]"],
) -> (
"LLMCompletionResponse[ResponseFormat] | AsyncIterator[LLMCompletionChunk]"
): ...
@property
def metrics_store(self) -> "MetricsStore": ...
@property
def tokenizer(self) -> "Tokenizer": ...
register_completion("custom_chat", CustomChatModel)
model = create_completion(
ModelConfig(
type="custom_chat",
model_provider="custom_provider",
model="custom_chat_model",
)
)
assert isinstance(model, CustomChatModel)
def test_create_custom_embedding_llm():
class CustomEmbeddingModel(LLMEmbedding):
def __init__(self, **kwargs): ...
def embedding(
self, /, **kwargs: Unpack["LLMEmbeddingArgs"]
) -> "LLMEmbeddingResponse": ...
async def embedding_async(
self, /, **kwargs: Unpack["LLMEmbeddingArgs"]
) -> "LLMEmbeddingResponse": ...
@property
def metrics_store(self) -> "MetricsStore": ...
@property
def tokenizer(self) -> "Tokenizer": ...
register_embedding("custom_embedding", CustomEmbeddingModel)
model = create_embedding(
ModelConfig(
type="custom_embedding",
model_provider="custom_provider",
model="custom_embedding_model",
)
)
assert isinstance(model, CustomEmbeddingModel)