59 lines
1.9 KiB
Python
59 lines
1.9 KiB
Python
from __future__ import annotations
|
|
|
|
import hashlib
|
|
from collections.abc import Sequence
|
|
from typing import Any
|
|
|
|
|
|
class FakeLLM:
|
|
chat_model = "fake-chat-model"
|
|
embedding_model = "fake-embedding-model"
|
|
|
|
def complete_json(self, system: str, user: str) -> dict[str, Any]:
|
|
if "community" in system.casefold():
|
|
return {
|
|
"title": "Atlas product community",
|
|
"summary": "Acme created Atlas, a graph retrieval product.",
|
|
}
|
|
return {
|
|
"entities": [
|
|
{
|
|
"canonical_name": "Acme",
|
|
"entity_type": "Organization",
|
|
"description": "Acme is a technology organization.",
|
|
"aliases": ["Acme Corp"],
|
|
},
|
|
{
|
|
"canonical_name": "Atlas",
|
|
"entity_type": "Product",
|
|
"description": "Atlas is a graph retrieval product.",
|
|
"aliases": [],
|
|
},
|
|
],
|
|
"relationships": [
|
|
{
|
|
"source": "Acme",
|
|
"target": "Atlas",
|
|
"relationship_type": "CREATED",
|
|
"description": "Acme created Atlas.",
|
|
}
|
|
],
|
|
}
|
|
|
|
def complete_text(self, system: str, user: str) -> str:
|
|
return "Acme created Atlas. [S1]"
|
|
|
|
def embed(self, texts: Sequence[str]) -> list[list[float]]:
|
|
vectors: list[list[float]] = []
|
|
for text in texts:
|
|
normalized = text.casefold()
|
|
digest = hashlib.sha256(normalized.encode("utf-8")).digest()
|
|
vectors.append(
|
|
[
|
|
float("atlas" in normalized),
|
|
float("acme" in normalized),
|
|
digest[0] / 255,
|
|
]
|
|
)
|
|
return vectors
|