toprompt 0.2.0__tar.gz → 0.2.2__tar.gz

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.
Files changed (28) hide show
  1. {toprompt-0.2.0 → toprompt-0.2.2}/PKG-INFO +1 -1
  2. {toprompt-0.2.0 → toprompt-0.2.2}/src/toprompt/__init__.py +19 -19
  3. {toprompt-0.2.0 → toprompt-0.2.2}/src/toprompt/cli_types.py +165 -165
  4. {toprompt-0.2.0 → toprompt-0.2.2}/src/toprompt/dataclass_types.py +30 -30
  5. {toprompt-0.2.0 → toprompt-0.2.2}/src/toprompt/fastapi_types.py +75 -75
  6. {toprompt-0.2.0 → toprompt-0.2.2}/src/toprompt/llmling_types.py +29 -29
  7. {toprompt-0.2.0 → toprompt-0.2.2}/src/toprompt/sqlite_types.py +241 -241
  8. {toprompt-0.2.0 → toprompt-0.2.2}/src/toprompt/sqlmodel_types.py +59 -59
  9. {toprompt-0.2.0 → toprompt-0.2.2}/src/toprompt/to_prompt.py +233 -227
  10. {toprompt-0.2.0 → toprompt-0.2.2}/tests/test_toprompt.py +102 -102
  11. {toprompt-0.2.0 → toprompt-0.2.2}/.copier-answers.yml +0 -0
  12. {toprompt-0.2.0 → toprompt-0.2.2}/.github/FUNDING.yml +0 -0
  13. {toprompt-0.2.0 → toprompt-0.2.2}/.github/copilot-instructions.md +0 -0
  14. {toprompt-0.2.0 → toprompt-0.2.2}/.github/dependabot.yml +0 -0
  15. {toprompt-0.2.0 → toprompt-0.2.2}/.github/workflows/build.yml +0 -0
  16. {toprompt-0.2.0 → toprompt-0.2.2}/.github/workflows/documentation.yml +0 -0
  17. {toprompt-0.2.0 → toprompt-0.2.2}/.gitignore +0 -0
  18. {toprompt-0.2.0 → toprompt-0.2.2}/.pre-commit-config.yaml +0 -0
  19. {toprompt-0.2.0 → toprompt-0.2.2}/LICENSE +0 -0
  20. {toprompt-0.2.0 → toprompt-0.2.2}/README.md +0 -0
  21. {toprompt-0.2.0 → toprompt-0.2.2}/docs/.empty +0 -0
  22. {toprompt-0.2.0 → toprompt-0.2.2}/duties.py +0 -0
  23. {toprompt-0.2.0 → toprompt-0.2.2}/mkdocs.yml +0 -0
  24. {toprompt-0.2.0 → toprompt-0.2.2}/overrides/_dummy.txt +0 -0
  25. {toprompt-0.2.0 → toprompt-0.2.2}/pyproject.toml +0 -0
  26. {toprompt-0.2.0 → toprompt-0.2.2}/src/toprompt/py.typed +0 -0
  27. {toprompt-0.2.0 → toprompt-0.2.2}/tests/__init__.py +0 -0
  28. {toprompt-0.2.0 → toprompt-0.2.2}/tests/conftest.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: toprompt
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Convert python objects to LLM-friendly descriptions
5
5
  Project-URL: Documentation, https://phil65.github.io/toprompt/
6
6
  Project-URL: Source, https://github.com/phil65/toprompt
@@ -1,19 +1,19 @@
1
- from toprompt.to_prompt import (
2
- Template,
3
- to_prompt,
4
- AnyPromptType,
5
- render_prompt,
6
- PromptConvertible,
7
- PromptTypeConvertible,
8
- )
9
-
10
- __version__ = "0.2.0"
11
-
12
- __all__ = [
13
- "AnyPromptType",
14
- "PromptConvertible",
15
- "PromptTypeConvertible",
16
- "Template",
17
- "render_prompt",
18
- "to_prompt",
19
- ]
1
+ from toprompt.to_prompt import (
2
+ Template,
3
+ to_prompt,
4
+ AnyPromptType,
5
+ render_prompt,
6
+ PromptConvertible,
7
+ PromptTypeConvertible,
8
+ )
9
+
10
+ __version__ = "0.2.2"
11
+
12
+ __all__ = [
13
+ "AnyPromptType",
14
+ "PromptConvertible",
15
+ "PromptTypeConvertible",
16
+ "Template",
17
+ "render_prompt",
18
+ "to_prompt",
19
+ ]
@@ -1,165 +1,165 @@
1
- from __future__ import annotations
2
-
3
- import importlib.util
4
- from typing import TYPE_CHECKING, Any, Protocol, runtime_checkable
5
-
6
-
7
- if TYPE_CHECKING:
8
- from clinspector.models.commandinfo import CommandInfo
9
-
10
-
11
- @runtime_checkable
12
- class ClickCommandLike(Protocol):
13
- """Protocol for Click-like command objects."""
14
-
15
- name: str # Click commands always have a name
16
- commands: dict[str, Any] # Groups have subcommands
17
- params: list[Any] # Click commands have params
18
- help: str | None # Click commands can have help text
19
-
20
-
21
- @runtime_checkable
22
- class TyperCommandLike(Protocol):
23
- """Protocol for Typer-like command objects."""
24
-
25
- info: Any # Typer instances have an info attribute
26
- registered_callback: Any # And a registered_callback
27
- registered_commands: dict[str, Any] # Commands are stored here
28
-
29
-
30
- def is_click_command(obj: Any) -> bool:
31
- """Check if object looks like a Click command/group.
32
-
33
- Tries to detect Click commands by their distinctive attributes,
34
- without requiring Click to be installed.
35
- """
36
- return isinstance(obj, ClickCommandLike) and obj.__class__.__module__.startswith(
37
- "click"
38
- )
39
-
40
-
41
- def is_typer_command(obj: Any) -> bool:
42
- """Check if object looks like a Typer app.
43
-
44
- Tries to detect Typer apps by their distinctive attributes,
45
- without requiring Typer to be installed.
46
- """
47
- return isinstance(obj, TyperCommandLike) and obj.__class__.__module__.startswith(
48
- "typer"
49
- )
50
-
51
-
52
- def is_cli_object(obj: Any) -> bool:
53
- """Check if object is a supported CLI framework object.
54
-
55
- Safely checks for installed CLI frameworks before doing type checks.
56
- Prevents import errors if a framework is not installed.
57
-
58
- Args:
59
- obj: Object to check
60
- """
61
- # ArgumentParser is from stdlib, so we can always check it
62
- if importlib.util.find_spec("argparse"):
63
- import argparse
64
-
65
- if isinstance(obj, argparse.ArgumentParser):
66
- return True
67
-
68
- # Check Click
69
- if importlib.util.find_spec("click"):
70
- import click
71
-
72
- if isinstance(obj, click.Group):
73
- return True
74
-
75
- # Check Typer
76
- if importlib.util.find_spec("typer"):
77
- import typer
78
-
79
- if isinstance(obj, typer.Typer):
80
- return True
81
-
82
- # Check Cleo
83
- if importlib.util.find_spec("cleo"):
84
- from cleo.application import Application # type: ignore
85
-
86
- if isinstance(obj, Application):
87
- return True
88
-
89
- # Check Cappa
90
- if importlib.util.find_spec("cappa"):
91
- from cappa import Command as CappaCommand # type: ignore
92
-
93
- if isinstance(obj, CappaCommand):
94
- return True
95
-
96
- return False
97
-
98
-
99
- def format_cli_command(
100
- info: CommandInfo,
101
- *,
102
- indent_level: int = 0,
103
- ) -> str:
104
- """Format a CommandInfo object into a prompt-friendly string recursively.
105
-
106
- Args:
107
- info: The CommandInfo object to format
108
- indent_level: Current indentation level for nested commands
109
- """
110
- indent = " " * indent_level
111
- lines = [f"{indent}Command: {info.name}"]
112
-
113
- if info.description:
114
- lines.extend(["", f"{indent}Description: {info.description}"])
115
-
116
- if info.usage:
117
- lines.extend(["", f"{indent}Usage: {info.usage}"])
118
-
119
- if info.params:
120
- lines.extend(["", f"{indent}Parameters:"])
121
- for param in info.params:
122
- # Format parameter line
123
- parts = []
124
-
125
- # Add options/name
126
- if param.opts:
127
- parts.append(f"{', '.join(param.opts)}")
128
- else:
129
- parts.append(param.name)
130
-
131
- # Add type info
132
- if param.type:
133
- parts.append(f"({param.type})")
134
-
135
- # Add help text
136
- if param.help:
137
- parts.append(f"- {param.help}")
138
-
139
- # Add constraints
140
- constraints = []
141
- if param.required:
142
- constraints.append("required")
143
- if param.multiple:
144
- constraints.append("multiple values allowed")
145
- if param.is_flag:
146
- constraints.append("flag")
147
- if param.default is not None:
148
- constraints.append(f"default: {param.default}")
149
-
150
- if constraints:
151
- parts.append(f"[{', '.join(constraints)}]")
152
-
153
- lines.append(f"{indent} {' '.join(parts)}")
154
-
155
- if info.subcommands:
156
- lines.extend(["", f"{indent}Subcommands:"])
157
- for subcmd in info.subcommands.values():
158
- # Recursively format each subcommand with increased indentation
159
- subcommand_text = format_cli_command(
160
- subcmd,
161
- indent_level=indent_level + 1,
162
- )
163
- lines.extend(["", subcommand_text])
164
-
165
- return "\n".join(lines)
1
+ from __future__ import annotations
2
+
3
+ import importlib.util
4
+ from typing import TYPE_CHECKING, Any, Protocol, runtime_checkable
5
+
6
+
7
+ if TYPE_CHECKING:
8
+ from clinspector.models.commandinfo import CommandInfo
9
+
10
+
11
+ @runtime_checkable
12
+ class ClickCommandLike(Protocol):
13
+ """Protocol for Click-like command objects."""
14
+
15
+ name: str # Click commands always have a name
16
+ commands: dict[str, Any] # Groups have subcommands
17
+ params: list[Any] # Click commands have params
18
+ help: str | None # Click commands can have help text
19
+
20
+
21
+ @runtime_checkable
22
+ class TyperCommandLike(Protocol):
23
+ """Protocol for Typer-like command objects."""
24
+
25
+ info: Any # Typer instances have an info attribute
26
+ registered_callback: Any # And a registered_callback
27
+ registered_commands: dict[str, Any] # Commands are stored here
28
+
29
+
30
+ def is_click_command(obj: Any) -> bool:
31
+ """Check if object looks like a Click command/group.
32
+
33
+ Tries to detect Click commands by their distinctive attributes,
34
+ without requiring Click to be installed.
35
+ """
36
+ return isinstance(obj, ClickCommandLike) and obj.__class__.__module__.startswith(
37
+ "click"
38
+ )
39
+
40
+
41
+ def is_typer_command(obj: Any) -> bool:
42
+ """Check if object looks like a Typer app.
43
+
44
+ Tries to detect Typer apps by their distinctive attributes,
45
+ without requiring Typer to be installed.
46
+ """
47
+ return isinstance(obj, TyperCommandLike) and obj.__class__.__module__.startswith(
48
+ "typer"
49
+ )
50
+
51
+
52
+ def is_cli_object(obj: Any) -> bool:
53
+ """Check if object is a supported CLI framework object.
54
+
55
+ Safely checks for installed CLI frameworks before doing type checks.
56
+ Prevents import errors if a framework is not installed.
57
+
58
+ Args:
59
+ obj: Object to check
60
+ """
61
+ # ArgumentParser is from stdlib, so we can always check it
62
+ if importlib.util.find_spec("argparse"):
63
+ import argparse
64
+
65
+ if isinstance(obj, argparse.ArgumentParser):
66
+ return True
67
+
68
+ # Check Click
69
+ if importlib.util.find_spec("click"):
70
+ import click
71
+
72
+ if isinstance(obj, click.Group):
73
+ return True
74
+
75
+ # Check Typer
76
+ if importlib.util.find_spec("typer"):
77
+ import typer
78
+
79
+ if isinstance(obj, typer.Typer):
80
+ return True
81
+
82
+ # Check Cleo
83
+ if importlib.util.find_spec("cleo"):
84
+ from cleo.application import Application # type: ignore
85
+
86
+ if isinstance(obj, Application):
87
+ return True
88
+
89
+ # Check Cappa
90
+ if importlib.util.find_spec("cappa"):
91
+ from cappa import Command as CappaCommand # type: ignore
92
+
93
+ if isinstance(obj, CappaCommand):
94
+ return True
95
+
96
+ return False
97
+
98
+
99
+ def format_cli_command(
100
+ info: CommandInfo,
101
+ *,
102
+ indent_level: int = 0,
103
+ ) -> str:
104
+ """Format a CommandInfo object into a prompt-friendly string recursively.
105
+
106
+ Args:
107
+ info: The CommandInfo object to format
108
+ indent_level: Current indentation level for nested commands
109
+ """
110
+ indent = " " * indent_level
111
+ lines = [f"{indent}Command: {info.name}"]
112
+
113
+ if info.description:
114
+ lines.extend(["", f"{indent}Description: {info.description}"])
115
+
116
+ if info.usage:
117
+ lines.extend(["", f"{indent}Usage: {info.usage}"])
118
+
119
+ if info.params:
120
+ lines.extend(["", f"{indent}Parameters:"])
121
+ for param in info.params:
122
+ # Format parameter line
123
+ parts = []
124
+
125
+ # Add options/name
126
+ if param.opts:
127
+ parts.append(f"{', '.join(param.opts)}")
128
+ else:
129
+ parts.append(param.name)
130
+
131
+ # Add type info
132
+ if param.type:
133
+ parts.append(f"({param.type})")
134
+
135
+ # Add help text
136
+ if param.help:
137
+ parts.append(f"- {param.help}")
138
+
139
+ # Add constraints
140
+ constraints = []
141
+ if param.required:
142
+ constraints.append("required")
143
+ if param.multiple:
144
+ constraints.append("multiple values allowed")
145
+ if param.is_flag:
146
+ constraints.append("flag")
147
+ if param.default is not None:
148
+ constraints.append(f"default: {param.default}")
149
+
150
+ if constraints:
151
+ parts.append(f"[{', '.join(constraints)}]")
152
+
153
+ lines.append(f"{indent} {' '.join(parts)}")
154
+
155
+ if info.subcommands:
156
+ lines.extend(["", f"{indent}Subcommands:"])
157
+ for subcmd in info.subcommands.values():
158
+ # Recursively format each subcommand with increased indentation
159
+ subcommand_text = format_cli_command(
160
+ subcmd,
161
+ indent_level=indent_level + 1,
162
+ )
163
+ lines.extend(["", subcommand_text])
164
+
165
+ return "\n".join(lines)
@@ -1,30 +1,30 @@
1
- from __future__ import annotations
2
-
3
- from typing import Any, TypeVar
4
-
5
- from fieldz import fields
6
-
7
-
8
- T = TypeVar("T")
9
-
10
-
11
- def format_dataclass_like(obj: Any) -> str:
12
- """Format object instance showing structure and current values."""
13
- try:
14
- obj_fields = fields(obj)
15
- except TypeError:
16
- return f"Unable to inspect fields of {type(obj)}"
17
-
18
- lines = [f"{type(obj).__name__}:\n{type(obj).__doc__}\n"]
19
-
20
- for field in obj_fields:
21
- if field.name.startswith("_"):
22
- continue
23
- value = getattr(obj, field.name)
24
- if field.description:
25
- lines.append(f"- {field.name} = {value!r} ({field.description})")
26
- else:
27
- type_name = field.type if field.type else "any"
28
- lines.append(f"- {field.name} = {value!r} ({type_name})")
29
-
30
- return "\n".join(lines)
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, TypeVar
4
+
5
+ from fieldz import fields
6
+
7
+
8
+ T = TypeVar("T")
9
+
10
+
11
+ def format_dataclass_like(obj: Any) -> str:
12
+ """Format object instance showing structure and current values."""
13
+ try:
14
+ obj_fields = fields(obj)
15
+ except TypeError:
16
+ return f"Unable to inspect fields of {type(obj)}"
17
+
18
+ lines = [f"{type(obj).__name__}:\n{type(obj).__doc__}\n"]
19
+
20
+ for field in obj_fields:
21
+ if field.name.startswith("_"):
22
+ continue
23
+ value = getattr(obj, field.name)
24
+ if field.description:
25
+ lines.append(f"- {field.name} = {value!r} ({field.description})")
26
+ else:
27
+ type_name = field.type if field.type else "any"
28
+ lines.append(f"- {field.name} = {value!r} ({type_name})")
29
+
30
+ return "\n".join(lines)
@@ -1,75 +1,75 @@
1
- from __future__ import annotations
2
-
3
- from typing import Any, Protocol, runtime_checkable
4
-
5
-
6
- @runtime_checkable
7
- class FastApiAppLike(Protocol):
8
- """Protocol for in-memory database-like objects."""
9
-
10
- def openapi(self, *args, **kwargs) -> Any: ...
11
-
12
-
13
- def format_fastapi_app(app: Any) -> str:
14
- """Generate human-readable documentation from FastAPI application."""
15
- schema = app.openapi()
16
- lines = ["FastAPI Application Schema:"]
17
-
18
- # Info section
19
- if info := schema.get("info", {}):
20
- if title := info.get("title"):
21
- lines.append(f"\nTitle: {title}")
22
- if description := info.get("description"):
23
- lines.append(f"Description: {description}")
24
- if version := info.get("version"):
25
- lines.append(f"Version: {version}")
26
-
27
- # Endpoints
28
- lines.append("\nEndpoints:")
29
- paths = schema.get("paths", {})
30
- for path, methods in paths.items():
31
- lines.append(f"\n{path}")
32
- for method, details in methods.items():
33
- method_upper = method.upper()
34
- desc = details.get("description", "No description")
35
- lines.append(f" {method_upper}: {desc}")
36
-
37
- # Parameters
38
- if params := details.get("parameters"):
39
- lines.append(" Parameters:")
40
- for param in params:
41
- req = "*" if param.get("required") else ""
42
- param_type = param.get("schema", {}).get("type", "any")
43
- lines.append(
44
- f" - {param['name']}{req}: {param_type} "
45
- f"({param.get('description', 'No description')})"
46
- )
47
-
48
- # Request body
49
- if (body := details.get("requestBody")) and (
50
- ref := (
51
- body.get("content", {})
52
- .get("application/json", {})
53
- .get("schema", {})
54
- .get("$ref")
55
- )
56
- ):
57
- schema_name = ref.split("/")[-1]
58
- lines.append(f" Request Body: {schema_name}")
59
-
60
- # Responses
61
- if responses := details.get("responses"):
62
- lines.append(" Responses:")
63
- for status, response in responses.items():
64
- desc = response.get("description", "No description")
65
- lines.append(f" {status}: {desc}")
66
- if ref := (
67
- response.get("content", {})
68
- .get("application/json", {})
69
- .get("schema", {})
70
- .get("$ref")
71
- ):
72
- schema_name = ref.split("/")[-1]
73
- lines.append(f" Schema: {schema_name}")
74
-
75
- return "\n".join(lines)
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Protocol, runtime_checkable
4
+
5
+
6
+ @runtime_checkable
7
+ class FastApiAppLike(Protocol):
8
+ """Protocol for in-memory database-like objects."""
9
+
10
+ def openapi(self, *args, **kwargs) -> Any: ...
11
+
12
+
13
+ def format_fastapi_app(app: Any) -> str:
14
+ """Generate human-readable documentation from FastAPI application."""
15
+ schema = app.openapi()
16
+ lines = ["FastAPI Application Schema:"]
17
+
18
+ # Info section
19
+ if info := schema.get("info", {}):
20
+ if title := info.get("title"):
21
+ lines.append(f"\nTitle: {title}")
22
+ if description := info.get("description"):
23
+ lines.append(f"Description: {description}")
24
+ if version := info.get("version"):
25
+ lines.append(f"Version: {version}")
26
+
27
+ # Endpoints
28
+ lines.append("\nEndpoints:")
29
+ paths = schema.get("paths", {})
30
+ for path, methods in paths.items():
31
+ lines.append(f"\n{path}")
32
+ for method, details in methods.items():
33
+ method_upper = method.upper()
34
+ desc = details.get("description", "No description")
35
+ lines.append(f" {method_upper}: {desc}")
36
+
37
+ # Parameters
38
+ if params := details.get("parameters"):
39
+ lines.append(" Parameters:")
40
+ for param in params:
41
+ req = "*" if param.get("required") else ""
42
+ param_type = param.get("schema", {}).get("type", "any")
43
+ lines.append(
44
+ f" - {param['name']}{req}: {param_type} "
45
+ f"({param.get('description', 'No description')})"
46
+ )
47
+
48
+ # Request body
49
+ if (body := details.get("requestBody")) and (
50
+ ref := (
51
+ body.get("content", {})
52
+ .get("application/json", {})
53
+ .get("schema", {})
54
+ .get("$ref")
55
+ )
56
+ ):
57
+ schema_name = ref.split("/")[-1]
58
+ lines.append(f" Request Body: {schema_name}")
59
+
60
+ # Responses
61
+ if responses := details.get("responses"):
62
+ lines.append(" Responses:")
63
+ for status, response in responses.items():
64
+ desc = response.get("description", "No description")
65
+ lines.append(f" {status}: {desc}")
66
+ if ref := (
67
+ response.get("content", {})
68
+ .get("application/json", {})
69
+ .get("schema", {})
70
+ .get("$ref")
71
+ ):
72
+ schema_name = ref.split("/")[-1]
73
+ lines.append(f" Schema: {schema_name}")
74
+
75
+ return "\n".join(lines)
@@ -1,29 +1,29 @@
1
- from __future__ import annotations
2
-
3
- from typing import TYPE_CHECKING, Any, Protocol, runtime_checkable
4
-
5
-
6
- if TYPE_CHECKING:
7
- from collections.abc import Sequence
8
-
9
-
10
- class PromptMessage(Protocol):
11
- """Protocol for prompt messages."""
12
-
13
- def get_text_content(self) -> str: ...
14
-
15
-
16
- @runtime_checkable
17
- class BasePromptProtocol(Protocol):
18
- """Protocol for base prompt interface."""
19
-
20
- messages: Sequence[PromptMessage]
21
-
22
- def get_messages(self) -> Sequence[PromptMessage]: ...
23
-
24
- def validate_arguments(self, provided: dict[str, Any]) -> None: ...
25
-
26
- async def format(
27
- self,
28
- arguments: dict[str, Any] | None = None,
29
- ) -> Sequence[PromptMessage]: ...
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, Any, Protocol, runtime_checkable
4
+
5
+
6
+ if TYPE_CHECKING:
7
+ from collections.abc import Sequence
8
+
9
+
10
+ class PromptMessage(Protocol):
11
+ """Protocol for prompt messages."""
12
+
13
+ def get_text_content(self) -> str: ...
14
+
15
+
16
+ @runtime_checkable
17
+ class BasePromptProtocol(Protocol):
18
+ """Protocol for base prompt interface."""
19
+
20
+ messages: Sequence[PromptMessage]
21
+
22
+ def get_messages(self) -> Sequence[PromptMessage]: ...
23
+
24
+ def validate_arguments(self, provided: dict[str, Any]) -> None: ...
25
+
26
+ async def format(
27
+ self,
28
+ arguments: dict[str, Any] | None = None,
29
+ ) -> Sequence[PromptMessage]: ...