forked from balisujohn/localwriter
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy path__init__.py
More file actions
93 lines (81 loc) · 3.02 KB
/
Copy path__init__.py
File metadata and controls
93 lines (81 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# WriterAgent - AI Writing Assistant for LibreOffice
# Copyright (c) 2026 KeithCu
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Shared HTTP client helpers.
Heavy LLM / embeddings symbols are lazy (PEP 562). LibrePy imports
``plugin.framework.client.requests`` for the weekly update check; loading this
package must not import ``llm_client`` (not in the core OXT).
"""
from __future__ import annotations
import importlib
from typing import TYPE_CHECKING, Any
from .errors import (
format_error_for_display,
is_audio_unsupported_error,
)
from .provider_detection import (
get_provider_from_endpoint,
is_local_host,
is_openrouter_endpoint,
)
from .requests import sync_request
if TYPE_CHECKING:
from plugin.scripting.client import run_analysis as run_trusted_analysis
from .embedding_client import EmbeddingBatch, embed_texts, get_embedding_model
from .embeddings_service import delete_paragraphs, index_paragraphs, knn_search
from .llm_client import (
LlmClient,
OPENROUTER_CHAT_EXTRA_BLOCKLIST,
merge_openrouter_chat_extra,
strip_leaked_chat_template_control_tokens,
)
from .stream_normalizer import iterate_sse
__all__ = [
"EmbeddingBatch",
"run_trusted_analysis",
"embed_texts",
"get_embedding_model",
"delete_paragraphs",
"index_paragraphs",
"knn_search",
"LlmClient",
"OPENROUTER_CHAT_EXTRA_BLOCKLIST",
"format_error_for_display",
"get_provider_from_endpoint",
"is_audio_unsupported_error",
"is_local_host",
"is_openrouter_endpoint",
"iterate_sse",
"merge_openrouter_chat_extra",
"strip_leaked_chat_template_control_tokens",
"sync_request",
]
# name -> (module, attr). Relative names load against this package.
_LAZY_ATTRS: dict[str, tuple[str, str]] = {
"EmbeddingBatch": (".embedding_client", "EmbeddingBatch"),
"embed_texts": (".embedding_client", "embed_texts"),
"get_embedding_model": (".embedding_client", "get_embedding_model"),
"delete_paragraphs": (".embeddings_service", "delete_paragraphs"),
"index_paragraphs": (".embeddings_service", "index_paragraphs"),
"knn_search": (".embeddings_service", "knn_search"),
"LlmClient": (".llm_client", "LlmClient"),
"OPENROUTER_CHAT_EXTRA_BLOCKLIST": (".llm_client", "OPENROUTER_CHAT_EXTRA_BLOCKLIST"),
"merge_openrouter_chat_extra": (".llm_client", "merge_openrouter_chat_extra"),
"strip_leaked_chat_template_control_tokens": (
".llm_client",
"strip_leaked_chat_template_control_tokens",
),
"iterate_sse": (".stream_normalizer", "iterate_sse"),
"run_trusted_analysis": ("plugin.scripting.client", "run_analysis"),
}
def __getattr__(name: str) -> Any:
spec = _LAZY_ATTRS.get(name)
if spec is None:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
module_name, attr = spec
value = getattr(importlib.import_module(module_name, __name__), attr)
globals()[name] = value
return value
def __dir__() -> list[str]:
return sorted(set(__all__) | set(globals()))