llm-function 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- llm_function/.paa.tracking/.paa.config +12 -0
- llm_function/.paa.tracking/.paa.version +1 -0
- llm_function/.paa.tracking/git/dependencies/llm_func_deps/llm_function_config.py +35 -0
- llm_function/.paa.tracking/git/dependencies/llm_func_deps/tool_registry.py +250 -0
- llm_function/.paa.tracking/git/docs_cache/llm_function.md +0 -0
- llm_function/.paa.tracking/git/module/llm_function.py +250 -0
- llm_function/.paa.tracking/git/tracking/release_notes.md +5 -0
- llm_function/.paa.tracking/git_repo/COMMIT_EDITMSG +1 -0
- llm_function/.paa.tracking/git_repo/HEAD +1 -0
- llm_function/.paa.tracking/git_repo/config +8 -0
- llm_function/.paa.tracking/git_repo/description +1 -0
- llm_function/.paa.tracking/git_repo/hooks/applypatch-msg.sample +15 -0
- llm_function/.paa.tracking/git_repo/hooks/commit-msg.sample +24 -0
- llm_function/.paa.tracking/git_repo/hooks/fsmonitor-watchman.sample +174 -0
- llm_function/.paa.tracking/git_repo/hooks/post-update.sample +8 -0
- llm_function/.paa.tracking/git_repo/hooks/pre-applypatch.sample +14 -0
- llm_function/.paa.tracking/git_repo/hooks/pre-commit.sample +49 -0
- llm_function/.paa.tracking/git_repo/hooks/pre-merge-commit.sample +13 -0
- llm_function/.paa.tracking/git_repo/hooks/pre-push.sample +53 -0
- llm_function/.paa.tracking/git_repo/hooks/pre-rebase.sample +169 -0
- llm_function/.paa.tracking/git_repo/hooks/pre-receive.sample +24 -0
- llm_function/.paa.tracking/git_repo/hooks/prepare-commit-msg.sample +42 -0
- llm_function/.paa.tracking/git_repo/hooks/push-to-checkout.sample +78 -0
- llm_function/.paa.tracking/git_repo/hooks/sendemail-validate.sample +77 -0
- llm_function/.paa.tracking/git_repo/hooks/update.sample +128 -0
- llm_function/.paa.tracking/git_repo/index +0 -0
- llm_function/.paa.tracking/git_repo/info/exclude +6 -0
- llm_function/.paa.tracking/git_repo/logs/HEAD +1 -0
- llm_function/.paa.tracking/git_repo/logs/refs/heads/master +1 -0
- llm_function/.paa.tracking/git_repo/objects/13/9201e8ffeb4e42262e90eeaefd5267debb6e1d +1 -0
- llm_function/.paa.tracking/git_repo/objects/23/d10b479e3102724a6eb510225cc24bb2ce9d78 +0 -0
- llm_function/.paa.tracking/git_repo/objects/2d/fa3abff2848ff521ead3abb4364bd2c3ca01a6 +0 -0
- llm_function/.paa.tracking/git_repo/objects/45/6fc88abc846d76e0f82a3ef180425e497f8281 +0 -0
- llm_function/.paa.tracking/git_repo/objects/55/d196aad68e2cc20a2ea496529d9dabeb75bb0e +0 -0
- llm_function/.paa.tracking/git_repo/objects/63/9282ebc80b9db9b677374a7c16bc7472d5e71c +0 -0
- llm_function/.paa.tracking/git_repo/objects/91/f1d4c0830abe4ebb0902dc052f5dfe9e8fade7 +0 -0
- llm_function/.paa.tracking/git_repo/objects/9d/2a8151dd42e6abfffbbbd674b850a7066daa1a +0 -0
- llm_function/.paa.tracking/git_repo/objects/aa/0b3847c3f0683eed107a405b9443ec040c3eec +0 -0
- llm_function/.paa.tracking/git_repo/objects/cf/024b71ae427969a985d86a267adf154f526cd8 +0 -0
- llm_function/.paa.tracking/git_repo/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 +0 -0
- llm_function/.paa.tracking/git_repo/objects/fb/834f2f59b432c0688699b91926899c0e0f2a5d +0 -0
- llm_function/.paa.tracking/git_repo/refs/heads/master +1 -0
- llm_function/.paa.tracking/git_repo/refs/tags/v0.0.1 +1 -0
- llm_function/.paa.tracking/lsts_package_versions.yml +3 -0
- llm_function/.paa.tracking/package_licenses.json +1 -0
- llm_function/.paa.tracking/package_mapping.json +1 -0
- llm_function/.paa.tracking/python_modules/components/llm_func_deps/llm_function_config.py +35 -0
- llm_function/.paa.tracking/python_modules/components/llm_func_deps/tool_registry.py +250 -0
- llm_function/.paa.tracking/python_modules/llm_function.py +250 -0
- llm_function/.paa.tracking/release_notes.md +5 -0
- llm_function/.paa.tracking/version_logs.csv +5 -0
- llm_function/__init__.py +17 -0
- llm_function/artifacts/.paa.tracking/git/dependencies/llm_func_deps/llm_function_config.py +35 -0
- llm_function/artifacts/.paa.tracking/git/dependencies/llm_func_deps/tool_registry.py +250 -0
- llm_function/artifacts/.paa.tracking/git/docs_cache/llm_function.md +0 -0
- llm_function/artifacts/.paa.tracking/git/module/llm_function.py +250 -0
- llm_function/artifacts/.paa.tracking/git/tracking/release_notes.md +5 -0
- llm_function/artifacts/.paa.tracking/git_repo/COMMIT_EDITMSG +1 -0
- llm_function/artifacts/.paa.tracking/git_repo/HEAD +1 -0
- llm_function/artifacts/.paa.tracking/git_repo/config +8 -0
- llm_function/artifacts/.paa.tracking/git_repo/description +1 -0
- llm_function/artifacts/.paa.tracking/git_repo/hooks/applypatch-msg.sample +15 -0
- llm_function/artifacts/.paa.tracking/git_repo/hooks/commit-msg.sample +24 -0
- llm_function/artifacts/.paa.tracking/git_repo/hooks/fsmonitor-watchman.sample +174 -0
- llm_function/artifacts/.paa.tracking/git_repo/hooks/post-update.sample +8 -0
- llm_function/artifacts/.paa.tracking/git_repo/hooks/pre-applypatch.sample +14 -0
- llm_function/artifacts/.paa.tracking/git_repo/hooks/pre-commit.sample +49 -0
- llm_function/artifacts/.paa.tracking/git_repo/hooks/pre-merge-commit.sample +13 -0
- llm_function/artifacts/.paa.tracking/git_repo/hooks/pre-push.sample +53 -0
- llm_function/artifacts/.paa.tracking/git_repo/hooks/pre-rebase.sample +169 -0
- llm_function/artifacts/.paa.tracking/git_repo/hooks/pre-receive.sample +24 -0
- llm_function/artifacts/.paa.tracking/git_repo/hooks/prepare-commit-msg.sample +42 -0
- llm_function/artifacts/.paa.tracking/git_repo/hooks/push-to-checkout.sample +78 -0
- llm_function/artifacts/.paa.tracking/git_repo/hooks/sendemail-validate.sample +77 -0
- llm_function/artifacts/.paa.tracking/git_repo/hooks/update.sample +128 -0
- llm_function/artifacts/.paa.tracking/git_repo/index +0 -0
- llm_function/artifacts/.paa.tracking/git_repo/info/exclude +6 -0
- llm_function/artifacts/.paa.tracking/git_repo/logs/HEAD +1 -0
- llm_function/artifacts/.paa.tracking/git_repo/logs/refs/heads/master +1 -0
- llm_function/artifacts/.paa.tracking/git_repo/objects/13/9201e8ffeb4e42262e90eeaefd5267debb6e1d +1 -0
- llm_function/artifacts/.paa.tracking/git_repo/objects/23/d10b479e3102724a6eb510225cc24bb2ce9d78 +0 -0
- llm_function/artifacts/.paa.tracking/git_repo/objects/2d/fa3abff2848ff521ead3abb4364bd2c3ca01a6 +0 -0
- llm_function/artifacts/.paa.tracking/git_repo/objects/45/6fc88abc846d76e0f82a3ef180425e497f8281 +0 -0
- llm_function/artifacts/.paa.tracking/git_repo/objects/55/d196aad68e2cc20a2ea496529d9dabeb75bb0e +0 -0
- llm_function/artifacts/.paa.tracking/git_repo/objects/63/9282ebc80b9db9b677374a7c16bc7472d5e71c +0 -0
- llm_function/artifacts/.paa.tracking/git_repo/objects/91/f1d4c0830abe4ebb0902dc052f5dfe9e8fade7 +0 -0
- llm_function/artifacts/.paa.tracking/git_repo/objects/9d/2a8151dd42e6abfffbbbd674b850a7066daa1a +0 -0
- llm_function/artifacts/.paa.tracking/git_repo/objects/aa/0b3847c3f0683eed107a405b9443ec040c3eec +0 -0
- llm_function/artifacts/.paa.tracking/git_repo/objects/cf/024b71ae427969a985d86a267adf154f526cd8 +0 -0
- llm_function/artifacts/.paa.tracking/git_repo/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 +0 -0
- llm_function/artifacts/.paa.tracking/git_repo/objects/fb/834f2f59b432c0688699b91926899c0e0f2a5d +0 -0
- llm_function/artifacts/.paa.tracking/git_repo/refs/heads/master +1 -0
- llm_function/artifacts/.paa.tracking/git_repo/refs/tags/v0.0.1 +1 -0
- llm_function/llm_function.py +518 -0
- llm_function/mkdocs/docs/css/extra.css +38 -0
- llm_function/mkdocs/docs/index.md +24 -0
- llm_function/mkdocs/docs/llm_function_tools.md +168 -0
- llm_function/mkdocs/docs/release-notes.md +5 -0
- llm_function/mkdocs/mkdocs.yml +37 -0
- llm_function/mkdocs/site/404.html +370 -0
- llm_function/mkdocs/site/assets/images/favicon.png +0 -0
- llm_function/mkdocs/site/assets/javascripts/bundle.fe8b6f2b.min.js +29 -0
- llm_function/mkdocs/site/assets/javascripts/bundle.fe8b6f2b.min.js.map +7 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.ar.min.js +1 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.da.min.js +18 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.de.min.js +18 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.du.min.js +18 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.el.min.js +1 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.es.min.js +18 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.fi.min.js +18 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.fr.min.js +18 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.he.min.js +1 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.hi.min.js +1 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.hu.min.js +18 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.hy.min.js +1 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.it.min.js +18 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.ja.min.js +1 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.jp.min.js +1 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.kn.min.js +1 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.ko.min.js +1 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.multi.min.js +1 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.nl.min.js +18 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.no.min.js +18 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.pt.min.js +18 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.ro.min.js +18 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.ru.min.js +18 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.sa.min.js +1 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.stemmer.support.min.js +1 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.sv.min.js +18 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.ta.min.js +1 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.te.min.js +1 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.th.min.js +1 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.tr.min.js +18 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.vi.min.js +1 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/min/lunr.zh.min.js +1 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/tinyseg.js +206 -0
- llm_function/mkdocs/site/assets/javascripts/lunr/wordcut.js +6708 -0
- llm_function/mkdocs/site/assets/javascripts/workers/search.b8dbb3d2.min.js +42 -0
- llm_function/mkdocs/site/assets/javascripts/workers/search.b8dbb3d2.min.js.map +7 -0
- llm_function/mkdocs/site/assets/stylesheets/main.3cba04c6.min.css +1 -0
- llm_function/mkdocs/site/assets/stylesheets/main.3cba04c6.min.css.map +1 -0
- llm_function/mkdocs/site/assets/stylesheets/palette.06af60db.min.css +1 -0
- llm_function/mkdocs/site/assets/stylesheets/palette.06af60db.min.css.map +1 -0
- llm_function/mkdocs/site/css/extra.css +38 -0
- llm_function/mkdocs/site/index.html +476 -0
- llm_function/mkdocs/site/llm_function_tools/index.html +622 -0
- llm_function/mkdocs/site/release-notes/index.html +468 -0
- llm_function/mkdocs/site/search/search_index.json +1 -0
- llm_function/mkdocs/site/sitemap.xml +3 -0
- llm_function/mkdocs/site/sitemap.xml.gz +0 -0
- llm_function/setup.py +47 -0
- llm_function-0.0.1.dist-info/METADATA +44 -0
- llm_function-0.0.1.dist-info/RECORD +157 -0
- llm_function-0.0.1.dist-info/WHEEL +5 -0
- llm_function-0.0.1.dist-info/licenses/LICENSE +201 -0
- llm_function-0.0.1.dist-info/licenses/NOTICE +4 -0
- llm_function-0.0.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"""
|
|
2
|
+
`llm_function` helps you build reusable LLM functions with normal Python signatures.
|
|
3
|
+
|
|
4
|
+
You define a function with Pydantic input and output models, describe what it should do
|
|
5
|
+
in the docstring, and provide a set of available tools. At runtime, `llm_function`
|
|
6
|
+
uses [`workflow_auto_assembler`](https://pypi.org/project/workflow-auto-assembler/) to
|
|
7
|
+
assemble and execute a workflow that satisfies that typed function contract.
|
|
8
|
+
|
|
9
|
+
The result is an LLM-backed function that can be reused like any other Python function,
|
|
10
|
+
while still being grounded in explicit tools, schemas, and config.
|
|
11
|
+
|
|
12
|
+
Tool definition and discovery live in
|
|
13
|
+
[`llm_function_tools`](https://pypi.org/project/llm-function-tools/).
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import asyncio
|
|
17
|
+
import attrs
|
|
18
|
+
import attrsx
|
|
19
|
+
import inspect
|
|
20
|
+
import threading
|
|
21
|
+
from functools import wraps
|
|
22
|
+
from typing import Any, Callable, Dict, List, Optional, Type, get_type_hints
|
|
23
|
+
|
|
24
|
+
from pydantic import BaseModel
|
|
25
|
+
from workflow_auto_assembler import WorkflowAutoAssembler
|
|
26
|
+
from .components.llm_func_deps.llm_function_config import LlmFunctionConfig, LlmRuntimeConfig
|
|
27
|
+
from .components.llm_func_deps.tool_registry import InMemoryToolSource, ToolRegistry
|
|
28
|
+
|
|
29
|
+
__package_metadata__ = {
|
|
30
|
+
"author": "Kyrylo Mordan",
|
|
31
|
+
"author_email": "parachute.repo@gmail.com",
|
|
32
|
+
"description": "Llm function is a decorator that uses llm to assemble reusable workflows from available tools to match input and output models.",
|
|
33
|
+
"url" : 'https://kiril-mordan.github.io/adaptive-reusables/llm-function/',
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@attrsx.define
|
|
38
|
+
class LlmFunction:
|
|
39
|
+
available_functions: Optional[List[Any]] = attrs.field(default=None)
|
|
40
|
+
available_callables: Optional[Dict[str, Callable[..., Any]]] = attrs.field(default=None)
|
|
41
|
+
tool_registry: Optional[ToolRegistry] = attrs.field(default=None)
|
|
42
|
+
tool_sources: Optional[List[object]] = attrs.field(default=None)
|
|
43
|
+
config: Optional[LlmFunctionConfig] = attrs.field(default=None)
|
|
44
|
+
llm_handler_params: Optional[dict] = attrs.field(default=None)
|
|
45
|
+
storage_path: Optional[str] = attrs.field(default=None)
|
|
46
|
+
force_replan: bool = attrs.field(default=False)
|
|
47
|
+
max_retry: Optional[int] = attrs.field(default=None)
|
|
48
|
+
reset_loops: Optional[int] = attrs.field(default=None)
|
|
49
|
+
compare_params: Optional[dict] = attrs.field(default=None)
|
|
50
|
+
test_params: Optional[list] = attrs.field(default=None)
|
|
51
|
+
resolved_tools: Optional[Dict[str, Any]] = attrs.field(default=None, init=False)
|
|
52
|
+
|
|
53
|
+
def __attrs_post_init__(self):
|
|
54
|
+
self._apply_config_defaults()
|
|
55
|
+
|
|
56
|
+
if self.llm_handler_params is None:
|
|
57
|
+
raise ValueError("llm_handler_params is required either directly or via config.")
|
|
58
|
+
|
|
59
|
+
self.resolved_tools = self._resolve_available_tools()
|
|
60
|
+
|
|
61
|
+
def _apply_config_defaults(self):
|
|
62
|
+
if self.config is None:
|
|
63
|
+
return
|
|
64
|
+
|
|
65
|
+
if self.llm_handler_params is None:
|
|
66
|
+
self.llm_handler_params = self.config.runtime.llm_handler_params
|
|
67
|
+
if self.storage_path is None:
|
|
68
|
+
self.storage_path = self.config.runtime.storage_path
|
|
69
|
+
if self.force_replan is False:
|
|
70
|
+
self.force_replan = self.config.runtime.force_replan
|
|
71
|
+
if self.max_retry is None:
|
|
72
|
+
self.max_retry = self.config.runtime.max_retry
|
|
73
|
+
if self.reset_loops is None:
|
|
74
|
+
self.reset_loops = self.config.runtime.reset_loops
|
|
75
|
+
if self.compare_params is None:
|
|
76
|
+
self.compare_params = self.config.runtime.compare_params
|
|
77
|
+
if self.test_params is None:
|
|
78
|
+
self.test_params = self.config.runtime.test_params
|
|
79
|
+
if self.tool_registry is None:
|
|
80
|
+
self.tool_registry = self.config.tool_registry
|
|
81
|
+
if self.tool_sources is None and self.config.tool_sources is not None:
|
|
82
|
+
self.tool_sources = list(self.config.tool_sources)
|
|
83
|
+
|
|
84
|
+
def _normalize_task_description(self, func: Callable[..., Any]) -> str:
|
|
85
|
+
task_description = inspect.cleandoc(func.__doc__ or "").strip()
|
|
86
|
+
if not task_description:
|
|
87
|
+
raise ValueError("Decorated function must define a docstring to use as task_description.")
|
|
88
|
+
|
|
89
|
+
return task_description
|
|
90
|
+
|
|
91
|
+
def _extract_io_models(self, func: Callable[..., Any]) -> tuple[Type[BaseModel], Type[BaseModel], str]:
|
|
92
|
+
signature = inspect.signature(func)
|
|
93
|
+
params = list(signature.parameters.values())
|
|
94
|
+
if len(params) != 1:
|
|
95
|
+
raise ValueError("Decorated function must accept exactly one parameter annotated with a BaseModel subclass.")
|
|
96
|
+
|
|
97
|
+
input_param = params[0]
|
|
98
|
+
hints = get_type_hints(func)
|
|
99
|
+
input_model = hints.get(input_param.name)
|
|
100
|
+
output_model = hints.get("return")
|
|
101
|
+
|
|
102
|
+
if not inspect.isclass(input_model) or not issubclass(input_model, BaseModel):
|
|
103
|
+
raise TypeError("Decorated function input annotation must be a Pydantic BaseModel subclass.")
|
|
104
|
+
|
|
105
|
+
if not inspect.isclass(output_model) or not issubclass(output_model, BaseModel):
|
|
106
|
+
raise TypeError("Decorated function return annotation must be a Pydantic BaseModel subclass.")
|
|
107
|
+
|
|
108
|
+
return input_model, output_model, input_param.name
|
|
109
|
+
|
|
110
|
+
def _coerce_run_inputs(self, input_model: Type[BaseModel], run_inputs: Any) -> BaseModel:
|
|
111
|
+
if isinstance(run_inputs, input_model):
|
|
112
|
+
return run_inputs
|
|
113
|
+
|
|
114
|
+
if hasattr(input_model, "model_validate"):
|
|
115
|
+
return input_model.model_validate(run_inputs)
|
|
116
|
+
|
|
117
|
+
return input_model.parse_obj(run_inputs)
|
|
118
|
+
|
|
119
|
+
def _run_coro_blocking(self, coro):
|
|
120
|
+
try:
|
|
121
|
+
asyncio.get_running_loop()
|
|
122
|
+
except RuntimeError:
|
|
123
|
+
return asyncio.run(coro)
|
|
124
|
+
|
|
125
|
+
result: Dict[str, Any] = {}
|
|
126
|
+
error: Dict[str, BaseException] = {}
|
|
127
|
+
|
|
128
|
+
def _thread_main():
|
|
129
|
+
try:
|
|
130
|
+
result["value"] = asyncio.run(coro)
|
|
131
|
+
except BaseException as exc: # pragma: no cover
|
|
132
|
+
error["value"] = exc
|
|
133
|
+
|
|
134
|
+
thread = threading.Thread(target=_thread_main, daemon=True)
|
|
135
|
+
thread.start()
|
|
136
|
+
thread.join()
|
|
137
|
+
|
|
138
|
+
if "value" in error:
|
|
139
|
+
raise error["value"]
|
|
140
|
+
|
|
141
|
+
return result["value"]
|
|
142
|
+
|
|
143
|
+
def _resolve_available_tools(self) -> Dict[str, Any]:
|
|
144
|
+
if self.tool_registry is not None and self.tool_sources is not None:
|
|
145
|
+
raise ValueError("Use either tool_registry or tool_sources, not both.")
|
|
146
|
+
|
|
147
|
+
if self.tool_registry is not None:
|
|
148
|
+
return self.tool_registry.build_available_tools()
|
|
149
|
+
|
|
150
|
+
if self.tool_sources is not None:
|
|
151
|
+
return ToolRegistry(sources=self.tool_sources).build_available_tools()
|
|
152
|
+
|
|
153
|
+
if self.available_functions is None or self.available_callables is None:
|
|
154
|
+
raise ValueError(
|
|
155
|
+
"Provide either available_functions and available_callables, or tool_registry/tool_sources."
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
"available_functions": self.available_functions,
|
|
160
|
+
"available_callables": self.available_callables,
|
|
161
|
+
"resolved_tools": None,
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
def as_decorator(self):
|
|
165
|
+
def decorator(func: Callable[..., Any]):
|
|
166
|
+
signature = inspect.signature(func)
|
|
167
|
+
task_description = self._normalize_task_description(func)
|
|
168
|
+
input_model, output_model, input_name = self._extract_io_models(func)
|
|
169
|
+
|
|
170
|
+
async def _invoke_async(run_inputs: Any):
|
|
171
|
+
wa = WorkflowAutoAssembler(
|
|
172
|
+
available_functions=self.resolved_tools["available_functions"],
|
|
173
|
+
available_callables=self.resolved_tools["available_callables"],
|
|
174
|
+
storage_path=self.storage_path,
|
|
175
|
+
llm_handler_params=self.llm_handler_params,
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
return await wa.actualize_workflow(
|
|
179
|
+
task_description=task_description,
|
|
180
|
+
force_replan=self.force_replan,
|
|
181
|
+
run_inputs=self._coerce_run_inputs(input_model=input_model, run_inputs=run_inputs),
|
|
182
|
+
test_params=self.test_params,
|
|
183
|
+
compare_params=self.compare_params,
|
|
184
|
+
input_model=input_model,
|
|
185
|
+
output_model=output_model,
|
|
186
|
+
max_retry=self.max_retry,
|
|
187
|
+
reset_loops=self.reset_loops,
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
if inspect.iscoroutinefunction(func):
|
|
191
|
+
|
|
192
|
+
@wraps(func)
|
|
193
|
+
async def async_wrapper(*args, **kwargs):
|
|
194
|
+
bound = signature.bind(*args, **kwargs)
|
|
195
|
+
return await _invoke_async(bound.arguments[input_name])
|
|
196
|
+
|
|
197
|
+
async_wrapper.input_model = input_model
|
|
198
|
+
async_wrapper.output_model = output_model
|
|
199
|
+
async_wrapper.task_description = task_description
|
|
200
|
+
async_wrapper.ainvoke = _invoke_async
|
|
201
|
+
async_wrapper.resolved_tools = self.resolved_tools["resolved_tools"]
|
|
202
|
+
return async_wrapper
|
|
203
|
+
|
|
204
|
+
@wraps(func)
|
|
205
|
+
def sync_wrapper(*args, **kwargs):
|
|
206
|
+
bound = signature.bind(*args, **kwargs)
|
|
207
|
+
return self._run_coro_blocking(_invoke_async(bound.arguments[input_name]))
|
|
208
|
+
|
|
209
|
+
sync_wrapper.input_model = input_model
|
|
210
|
+
sync_wrapper.output_model = output_model
|
|
211
|
+
sync_wrapper.task_description = task_description
|
|
212
|
+
sync_wrapper.ainvoke = _invoke_async
|
|
213
|
+
sync_wrapper.resolved_tools = self.resolved_tools["resolved_tools"]
|
|
214
|
+
return sync_wrapper
|
|
215
|
+
|
|
216
|
+
return decorator
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def llm_function(
|
|
220
|
+
*,
|
|
221
|
+
available_functions: Optional[List[Any]] = None,
|
|
222
|
+
available_callables: Optional[Dict[str, Callable[..., Any]]] = None,
|
|
223
|
+
tool_registry: Optional[ToolRegistry] = None,
|
|
224
|
+
tool_sources: Optional[List[object]] = None,
|
|
225
|
+
config: Optional[LlmFunctionConfig] = None,
|
|
226
|
+
llm_handler_params: Optional[dict] = None,
|
|
227
|
+
storage_path: Optional[str] = None,
|
|
228
|
+
force_replan: bool = False,
|
|
229
|
+
max_retry: Optional[int] = None,
|
|
230
|
+
reset_loops: Optional[int] = None,
|
|
231
|
+
compare_params: Optional[dict] = None,
|
|
232
|
+
test_params: Optional[list] = None,
|
|
233
|
+
):
|
|
234
|
+
"""
|
|
235
|
+
Decorate a typed function and route its calls through WorkflowAutoAssembler.
|
|
236
|
+
"""
|
|
237
|
+
return LlmFunction(
|
|
238
|
+
available_functions=available_functions,
|
|
239
|
+
available_callables=available_callables,
|
|
240
|
+
tool_registry=tool_registry,
|
|
241
|
+
tool_sources=tool_sources,
|
|
242
|
+
config=config,
|
|
243
|
+
llm_handler_params=llm_handler_params,
|
|
244
|
+
storage_path=storage_path,
|
|
245
|
+
force_replan=force_replan,
|
|
246
|
+
max_retry=max_retry,
|
|
247
|
+
reset_loops=reset_loops,
|
|
248
|
+
compare_params=compare_params,
|
|
249
|
+
test_params=test_params,
|
|
250
|
+
).as_decorator()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
checkpoint[make-package] version=0.0.1 ts=2026-03-29T15:54:16.335632+00:00
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ref: refs/heads/master
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Unnamed repository; edit this file 'description' to name the repository.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
#
|
|
3
|
+
# An example hook script to check the commit log message taken by
|
|
4
|
+
# applypatch from an e-mail message.
|
|
5
|
+
#
|
|
6
|
+
# The hook should exit with non-zero status after issuing an
|
|
7
|
+
# appropriate message if it wants to stop the commit. The hook is
|
|
8
|
+
# allowed to edit the commit message file.
|
|
9
|
+
#
|
|
10
|
+
# To enable this hook, rename this file to "applypatch-msg".
|
|
11
|
+
|
|
12
|
+
. git-sh-setup
|
|
13
|
+
commitmsg="$(git rev-parse --git-path hooks/commit-msg)"
|
|
14
|
+
test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"}
|
|
15
|
+
:
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
#
|
|
3
|
+
# An example hook script to check the commit log message.
|
|
4
|
+
# Called by "git commit" with one argument, the name of the file
|
|
5
|
+
# that has the commit message. The hook should exit with non-zero
|
|
6
|
+
# status after issuing an appropriate message if it wants to stop the
|
|
7
|
+
# commit. The hook is allowed to edit the commit message file.
|
|
8
|
+
#
|
|
9
|
+
# To enable this hook, rename this file to "commit-msg".
|
|
10
|
+
|
|
11
|
+
# Uncomment the below to add a Signed-off-by line to the message.
|
|
12
|
+
# Doing this in a hook is a bad idea in general, but the prepare-commit-msg
|
|
13
|
+
# hook is more suited to it.
|
|
14
|
+
#
|
|
15
|
+
# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
|
|
16
|
+
# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
|
|
17
|
+
|
|
18
|
+
# This example catches duplicate Signed-off-by lines.
|
|
19
|
+
|
|
20
|
+
test "" = "$(grep '^Signed-off-by: ' "$1" |
|
|
21
|
+
sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
|
|
22
|
+
echo >&2 Duplicate Signed-off-by lines.
|
|
23
|
+
exit 1
|
|
24
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
#!/usr/bin/perl
|
|
2
|
+
|
|
3
|
+
use strict;
|
|
4
|
+
use warnings;
|
|
5
|
+
use IPC::Open2;
|
|
6
|
+
|
|
7
|
+
# An example hook script to integrate Watchman
|
|
8
|
+
# (https://facebook.github.io/watchman/) with git to speed up detecting
|
|
9
|
+
# new and modified files.
|
|
10
|
+
#
|
|
11
|
+
# The hook is passed a version (currently 2) and last update token
|
|
12
|
+
# formatted as a string and outputs to stdout a new update token and
|
|
13
|
+
# all files that have been modified since the update token. Paths must
|
|
14
|
+
# be relative to the root of the working tree and separated by a single NUL.
|
|
15
|
+
#
|
|
16
|
+
# To enable this hook, rename this file to "query-watchman" and set
|
|
17
|
+
# 'git config core.fsmonitor .git/hooks/query-watchman'
|
|
18
|
+
#
|
|
19
|
+
my ($version, $last_update_token) = @ARGV;
|
|
20
|
+
|
|
21
|
+
# Uncomment for debugging
|
|
22
|
+
# print STDERR "$0 $version $last_update_token\n";
|
|
23
|
+
|
|
24
|
+
# Check the hook interface version
|
|
25
|
+
if ($version ne 2) {
|
|
26
|
+
die "Unsupported query-fsmonitor hook version '$version'.\n" .
|
|
27
|
+
"Falling back to scanning...\n";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
my $git_work_tree = get_working_dir();
|
|
31
|
+
|
|
32
|
+
my $retry = 1;
|
|
33
|
+
|
|
34
|
+
my $json_pkg;
|
|
35
|
+
eval {
|
|
36
|
+
require JSON::XS;
|
|
37
|
+
$json_pkg = "JSON::XS";
|
|
38
|
+
1;
|
|
39
|
+
} or do {
|
|
40
|
+
require JSON::PP;
|
|
41
|
+
$json_pkg = "JSON::PP";
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
launch_watchman();
|
|
45
|
+
|
|
46
|
+
sub launch_watchman {
|
|
47
|
+
my $o = watchman_query();
|
|
48
|
+
if (is_work_tree_watched($o)) {
|
|
49
|
+
output_result($o->{clock}, @{$o->{files}});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
sub output_result {
|
|
54
|
+
my ($clockid, @files) = @_;
|
|
55
|
+
|
|
56
|
+
# Uncomment for debugging watchman output
|
|
57
|
+
# open (my $fh, ">", ".git/watchman-output.out");
|
|
58
|
+
# binmode $fh, ":utf8";
|
|
59
|
+
# print $fh "$clockid\n@files\n";
|
|
60
|
+
# close $fh;
|
|
61
|
+
|
|
62
|
+
binmode STDOUT, ":utf8";
|
|
63
|
+
print $clockid;
|
|
64
|
+
print "\0";
|
|
65
|
+
local $, = "\0";
|
|
66
|
+
print @files;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
sub watchman_clock {
|
|
70
|
+
my $response = qx/watchman clock "$git_work_tree"/;
|
|
71
|
+
die "Failed to get clock id on '$git_work_tree'.\n" .
|
|
72
|
+
"Falling back to scanning...\n" if $? != 0;
|
|
73
|
+
|
|
74
|
+
return $json_pkg->new->utf8->decode($response);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
sub watchman_query {
|
|
78
|
+
my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty')
|
|
79
|
+
or die "open2() failed: $!\n" .
|
|
80
|
+
"Falling back to scanning...\n";
|
|
81
|
+
|
|
82
|
+
# In the query expression below we're asking for names of files that
|
|
83
|
+
# changed since $last_update_token but not from the .git folder.
|
|
84
|
+
#
|
|
85
|
+
# To accomplish this, we're using the "since" generator to use the
|
|
86
|
+
# recency index to select candidate nodes and "fields" to limit the
|
|
87
|
+
# output to file names only. Then we're using the "expression" term to
|
|
88
|
+
# further constrain the results.
|
|
89
|
+
my $last_update_line = "";
|
|
90
|
+
if (substr($last_update_token, 0, 1) eq "c") {
|
|
91
|
+
$last_update_token = "\"$last_update_token\"";
|
|
92
|
+
$last_update_line = qq[\n"since": $last_update_token,];
|
|
93
|
+
}
|
|
94
|
+
my $query = <<" END";
|
|
95
|
+
["query", "$git_work_tree", {$last_update_line
|
|
96
|
+
"fields": ["name"],
|
|
97
|
+
"expression": ["not", ["dirname", ".git"]]
|
|
98
|
+
}]
|
|
99
|
+
END
|
|
100
|
+
|
|
101
|
+
# Uncomment for debugging the watchman query
|
|
102
|
+
# open (my $fh, ">", ".git/watchman-query.json");
|
|
103
|
+
# print $fh $query;
|
|
104
|
+
# close $fh;
|
|
105
|
+
|
|
106
|
+
print CHLD_IN $query;
|
|
107
|
+
close CHLD_IN;
|
|
108
|
+
my $response = do {local $/; <CHLD_OUT>};
|
|
109
|
+
|
|
110
|
+
# Uncomment for debugging the watch response
|
|
111
|
+
# open ($fh, ">", ".git/watchman-response.json");
|
|
112
|
+
# print $fh $response;
|
|
113
|
+
# close $fh;
|
|
114
|
+
|
|
115
|
+
die "Watchman: command returned no output.\n" .
|
|
116
|
+
"Falling back to scanning...\n" if $response eq "";
|
|
117
|
+
die "Watchman: command returned invalid output: $response\n" .
|
|
118
|
+
"Falling back to scanning...\n" unless $response =~ /^\{/;
|
|
119
|
+
|
|
120
|
+
return $json_pkg->new->utf8->decode($response);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
sub is_work_tree_watched {
|
|
124
|
+
my ($output) = @_;
|
|
125
|
+
my $error = $output->{error};
|
|
126
|
+
if ($retry > 0 and $error and $error =~ m/unable to resolve root .* directory (.*) is not watched/) {
|
|
127
|
+
$retry--;
|
|
128
|
+
my $response = qx/watchman watch "$git_work_tree"/;
|
|
129
|
+
die "Failed to make watchman watch '$git_work_tree'.\n" .
|
|
130
|
+
"Falling back to scanning...\n" if $? != 0;
|
|
131
|
+
$output = $json_pkg->new->utf8->decode($response);
|
|
132
|
+
$error = $output->{error};
|
|
133
|
+
die "Watchman: $error.\n" .
|
|
134
|
+
"Falling back to scanning...\n" if $error;
|
|
135
|
+
|
|
136
|
+
# Uncomment for debugging watchman output
|
|
137
|
+
# open (my $fh, ">", ".git/watchman-output.out");
|
|
138
|
+
# close $fh;
|
|
139
|
+
|
|
140
|
+
# Watchman will always return all files on the first query so
|
|
141
|
+
# return the fast "everything is dirty" flag to git and do the
|
|
142
|
+
# Watchman query just to get it over with now so we won't pay
|
|
143
|
+
# the cost in git to look up each individual file.
|
|
144
|
+
my $o = watchman_clock();
|
|
145
|
+
$error = $output->{error};
|
|
146
|
+
|
|
147
|
+
die "Watchman: $error.\n" .
|
|
148
|
+
"Falling back to scanning...\n" if $error;
|
|
149
|
+
|
|
150
|
+
output_result($o->{clock}, ("/"));
|
|
151
|
+
$last_update_token = $o->{clock};
|
|
152
|
+
|
|
153
|
+
eval { launch_watchman() };
|
|
154
|
+
return 0;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
die "Watchman: $error.\n" .
|
|
158
|
+
"Falling back to scanning...\n" if $error;
|
|
159
|
+
|
|
160
|
+
return 1;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
sub get_working_dir {
|
|
164
|
+
my $working_dir;
|
|
165
|
+
if ($^O =~ 'msys' || $^O =~ 'cygwin') {
|
|
166
|
+
$working_dir = Win32::GetCwd();
|
|
167
|
+
$working_dir =~ tr/\\/\//;
|
|
168
|
+
} else {
|
|
169
|
+
require Cwd;
|
|
170
|
+
$working_dir = Cwd::cwd();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return $working_dir;
|
|
174
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
#
|
|
3
|
+
# An example hook script to verify what is about to be committed
|
|
4
|
+
# by applypatch from an e-mail message.
|
|
5
|
+
#
|
|
6
|
+
# The hook should exit with non-zero status after issuing an
|
|
7
|
+
# appropriate message if it wants to stop the commit.
|
|
8
|
+
#
|
|
9
|
+
# To enable this hook, rename this file to "pre-applypatch".
|
|
10
|
+
|
|
11
|
+
. git-sh-setup
|
|
12
|
+
precommit="$(git rev-parse --git-path hooks/pre-commit)"
|
|
13
|
+
test -x "$precommit" && exec "$precommit" ${1+"$@"}
|
|
14
|
+
:
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
#
|
|
3
|
+
# An example hook script to verify what is about to be committed.
|
|
4
|
+
# Called by "git commit" with no arguments. The hook should
|
|
5
|
+
# exit with non-zero status after issuing an appropriate message if
|
|
6
|
+
# it wants to stop the commit.
|
|
7
|
+
#
|
|
8
|
+
# To enable this hook, rename this file to "pre-commit".
|
|
9
|
+
|
|
10
|
+
if git rev-parse --verify HEAD >/dev/null 2>&1
|
|
11
|
+
then
|
|
12
|
+
against=HEAD
|
|
13
|
+
else
|
|
14
|
+
# Initial commit: diff against an empty tree object
|
|
15
|
+
against=$(git hash-object -t tree /dev/null)
|
|
16
|
+
fi
|
|
17
|
+
|
|
18
|
+
# If you want to allow non-ASCII filenames set this variable to true.
|
|
19
|
+
allownonascii=$(git config --type=bool hooks.allownonascii)
|
|
20
|
+
|
|
21
|
+
# Redirect output to stderr.
|
|
22
|
+
exec 1>&2
|
|
23
|
+
|
|
24
|
+
# Cross platform projects tend to avoid non-ASCII filenames; prevent
|
|
25
|
+
# them from being added to the repository. We exploit the fact that the
|
|
26
|
+
# printable range starts at the space character and ends with tilde.
|
|
27
|
+
if [ "$allownonascii" != "true" ] &&
|
|
28
|
+
# Note that the use of brackets around a tr range is ok here, (it's
|
|
29
|
+
# even required, for portability to Solaris 10's /usr/bin/tr), since
|
|
30
|
+
# the square bracket bytes happen to fall in the designated range.
|
|
31
|
+
test $(git diff-index --cached --name-only --diff-filter=A -z $against |
|
|
32
|
+
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
|
|
33
|
+
then
|
|
34
|
+
cat <<\EOF
|
|
35
|
+
Error: Attempt to add a non-ASCII file name.
|
|
36
|
+
|
|
37
|
+
This can cause problems if you want to work with people on other platforms.
|
|
38
|
+
|
|
39
|
+
To be portable it is advisable to rename the file.
|
|
40
|
+
|
|
41
|
+
If you know what you are doing you can disable this check using:
|
|
42
|
+
|
|
43
|
+
git config hooks.allownonascii true
|
|
44
|
+
EOF
|
|
45
|
+
exit 1
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
# If there are whitespace errors, print the offending file names and fail.
|
|
49
|
+
exec git diff-index --check --cached $against --
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
#
|
|
3
|
+
# An example hook script to verify what is about to be committed.
|
|
4
|
+
# Called by "git merge" with no arguments. The hook should
|
|
5
|
+
# exit with non-zero status after issuing an appropriate message to
|
|
6
|
+
# stderr if it wants to stop the merge commit.
|
|
7
|
+
#
|
|
8
|
+
# To enable this hook, rename this file to "pre-merge-commit".
|
|
9
|
+
|
|
10
|
+
. git-sh-setup
|
|
11
|
+
test -x "$GIT_DIR/hooks/pre-commit" &&
|
|
12
|
+
exec "$GIT_DIR/hooks/pre-commit"
|
|
13
|
+
:
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
|
|
3
|
+
# An example hook script to verify what is about to be pushed. Called by "git
|
|
4
|
+
# push" after it has checked the remote status, but before anything has been
|
|
5
|
+
# pushed. If this script exits with a non-zero status nothing will be pushed.
|
|
6
|
+
#
|
|
7
|
+
# This hook is called with the following parameters:
|
|
8
|
+
#
|
|
9
|
+
# $1 -- Name of the remote to which the push is being done
|
|
10
|
+
# $2 -- URL to which the push is being done
|
|
11
|
+
#
|
|
12
|
+
# If pushing without using a named remote those arguments will be equal.
|
|
13
|
+
#
|
|
14
|
+
# Information about the commits which are being pushed is supplied as lines to
|
|
15
|
+
# the standard input in the form:
|
|
16
|
+
#
|
|
17
|
+
# <local ref> <local oid> <remote ref> <remote oid>
|
|
18
|
+
#
|
|
19
|
+
# This sample shows how to prevent push of commits where the log message starts
|
|
20
|
+
# with "WIP" (work in progress).
|
|
21
|
+
|
|
22
|
+
remote="$1"
|
|
23
|
+
url="$2"
|
|
24
|
+
|
|
25
|
+
zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
|
|
26
|
+
|
|
27
|
+
while read local_ref local_oid remote_ref remote_oid
|
|
28
|
+
do
|
|
29
|
+
if test "$local_oid" = "$zero"
|
|
30
|
+
then
|
|
31
|
+
# Handle delete
|
|
32
|
+
:
|
|
33
|
+
else
|
|
34
|
+
if test "$remote_oid" = "$zero"
|
|
35
|
+
then
|
|
36
|
+
# New branch, examine all commits
|
|
37
|
+
range="$local_oid"
|
|
38
|
+
else
|
|
39
|
+
# Update to existing branch, examine new commits
|
|
40
|
+
range="$remote_oid..$local_oid"
|
|
41
|
+
fi
|
|
42
|
+
|
|
43
|
+
# Check for WIP commit
|
|
44
|
+
commit=$(git rev-list -n 1 --grep '^WIP' "$range")
|
|
45
|
+
if test -n "$commit"
|
|
46
|
+
then
|
|
47
|
+
echo >&2 "Found WIP commit in $local_ref, not pushing"
|
|
48
|
+
exit 1
|
|
49
|
+
fi
|
|
50
|
+
fi
|
|
51
|
+
done
|
|
52
|
+
|
|
53
|
+
exit 0
|