pyllym 1.16.0__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 (178) hide show
  1. pyllym-1.16.0/.claude/hooks/block-dangerous-commands.sh +83 -0
  2. pyllym-1.16.0/.claude/settings.json +84 -0
  3. pyllym-1.16.0/.claude/skills/add-provider/SKILL.md +62 -0
  4. pyllym-1.16.0/.claude/skills/bdd-build/SKILL.md +77 -0
  5. pyllym-1.16.0/.claude/skills/dev-checks/SKILL.md +47 -0
  6. pyllym-1.16.0/.claude/skills/pyllym-structured-prompting/SKILL.md +240 -0
  7. pyllym-1.16.0/.env.example +58 -0
  8. pyllym-1.16.0/.github/dependabot.yml +47 -0
  9. pyllym-1.16.0/.github/workflows/publish.yml +64 -0
  10. pyllym-1.16.0/.gitignore +30 -0
  11. pyllym-1.16.0/CHANGELOG.md +239 -0
  12. pyllym-1.16.0/CLAUDE.md +148 -0
  13. pyllym-1.16.0/LICENSE +22 -0
  14. pyllym-1.16.0/PKG-INFO +776 -0
  15. pyllym-1.16.0/README.md +713 -0
  16. pyllym-1.16.0/examples/.gitignore +2 -0
  17. pyllym-1.16.0/examples/README.md +62 -0
  18. pyllym-1.16.0/examples/_bootstrap.py +31 -0
  19. pyllym-1.16.0/examples/analysis_tools.toml +92 -0
  20. pyllym-1.16.0/examples/chat.py +23 -0
  21. pyllym-1.16.0/examples/moderation.py +225 -0
  22. pyllym-1.16.0/examples/stats.py +377 -0
  23. pyllym-1.16.0/examples/stream.py +23 -0
  24. pyllym-1.16.0/examples/structured.py +36 -0
  25. pyllym-1.16.0/examples/tools.py +35 -0
  26. pyllym-1.16.0/new-branch.sh +60 -0
  27. pyllym-1.16.0/pyproject.toml +106 -0
  28. pyllym-1.16.0/reactullm-pyllum.contract.json +174 -0
  29. pyllym-1.16.0/reactullm-pyllum.runtime.json +100 -0
  30. pyllym-1.16.0/src/pyllym/__init__.py +310 -0
  31. pyllym-1.16.0/src/pyllym/agent.py +74 -0
  32. pyllym-1.16.0/src/pyllym/aliases.json +642 -0
  33. pyllym-1.16.0/src/pyllym/aliases.py +35 -0
  34. pyllym-1.16.0/src/pyllym/attachment.py +221 -0
  35. pyllym-1.16.0/src/pyllym/bdd/__init__.py +59 -0
  36. pyllym-1.16.0/src/pyllym/bdd/__main__.py +69 -0
  37. pyllym-1.16.0/src/pyllym/bdd/brief.py +120 -0
  38. pyllym-1.16.0/src/pyllym/bdd/builder.py +173 -0
  39. pyllym-1.16.0/src/pyllym/bdd/checks.py +61 -0
  40. pyllym-1.16.0/src/pyllym/bdd/planner.py +140 -0
  41. pyllym-1.16.0/src/pyllym/bdd/renderer.py +106 -0
  42. pyllym-1.16.0/src/pyllym/bdd/safety.py +141 -0
  43. pyllym-1.16.0/src/pyllym/bdd/schema.py +87 -0
  44. pyllym-1.16.0/src/pyllym/bdd/sequence.py +147 -0
  45. pyllym-1.16.0/src/pyllym/bdd/toml_spec.py +367 -0
  46. pyllym-1.16.0/src/pyllym/celery/__init__.py +36 -0
  47. pyllym-1.16.0/src/pyllym/celery/tasks.py +218 -0
  48. pyllym-1.16.0/src/pyllym/chat.py +497 -0
  49. pyllym-1.16.0/src/pyllym/chunk.py +9 -0
  50. pyllym-1.16.0/src/pyllym/citation.py +44 -0
  51. pyllym-1.16.0/src/pyllym/configuration.py +126 -0
  52. pyllym-1.16.0/src/pyllym/connection.py +490 -0
  53. pyllym-1.16.0/src/pyllym/content.py +77 -0
  54. pyllym-1.16.0/src/pyllym/context.py +60 -0
  55. pyllym-1.16.0/src/pyllym/cost.py +269 -0
  56. pyllym-1.16.0/src/pyllym/decision.py +244 -0
  57. pyllym-1.16.0/src/pyllym/embedding.py +37 -0
  58. pyllym-1.16.0/src/pyllym/errors.py +183 -0
  59. pyllym-1.16.0/src/pyllym/image.py +92 -0
  60. pyllym-1.16.0/src/pyllym/layout_parsing.py +84 -0
  61. pyllym-1.16.0/src/pyllym/mcp.py +351 -0
  62. pyllym-1.16.0/src/pyllym/message.py +184 -0
  63. pyllym-1.16.0/src/pyllym/mime_type.py +136 -0
  64. pyllym-1.16.0/src/pyllym/model/__init__.py +11 -0
  65. pyllym-1.16.0/src/pyllym/model/info.py +183 -0
  66. pyllym-1.16.0/src/pyllym/model/modalities.py +17 -0
  67. pyllym-1.16.0/src/pyllym/model/pricing.py +54 -0
  68. pyllym-1.16.0/src/pyllym/model/pricing_category.py +52 -0
  69. pyllym-1.16.0/src/pyllym/model/pricing_tier.py +44 -0
  70. pyllym-1.16.0/src/pyllym/models.json +65836 -0
  71. pyllym-1.16.0/src/pyllym/models.py +291 -0
  72. pyllym-1.16.0/src/pyllym/models_schema.json +169 -0
  73. pyllym-1.16.0/src/pyllym/moderation.py +55 -0
  74. pyllym-1.16.0/src/pyllym/persistence/__init__.py +27 -0
  75. pyllym-1.16.0/src/pyllym/persistence/models.py +173 -0
  76. pyllym-1.16.0/src/pyllym/protocol.py +289 -0
  77. pyllym-1.16.0/src/pyllym/protocols/__init__.py +1 -0
  78. pyllym-1.16.0/src/pyllym/protocols/anthropic.py +537 -0
  79. pyllym-1.16.0/src/pyllym/protocols/chat_completions.py +687 -0
  80. pyllym-1.16.0/src/pyllym/protocols/converse.py +619 -0
  81. pyllym-1.16.0/src/pyllym/protocols/fal.py +123 -0
  82. pyllym-1.16.0/src/pyllym/protocols/gemini.py +939 -0
  83. pyllym-1.16.0/src/pyllym/protocols/nli_classify.py +138 -0
  84. pyllym-1.16.0/src/pyllym/protocols/systemone.py +82 -0
  85. pyllym-1.16.0/src/pyllym/protocols/zhipu_layout.py +79 -0
  86. pyllym-1.16.0/src/pyllym/provider.py +355 -0
  87. pyllym-1.16.0/src/pyllym/providers/__init__.py +1 -0
  88. pyllym-1.16.0/src/pyllym/providers/anthropic.py +39 -0
  89. pyllym-1.16.0/src/pyllym/providers/azure.py +33 -0
  90. pyllym-1.16.0/src/pyllym/providers/bedrock.py +227 -0
  91. pyllym-1.16.0/src/pyllym/providers/capabilities.py +37 -0
  92. pyllym-1.16.0/src/pyllym/providers/cerebras.py +10 -0
  93. pyllym-1.16.0/src/pyllym/providers/databricks.py +14 -0
  94. pyllym-1.16.0/src/pyllym/providers/deepseek.py +10 -0
  95. pyllym-1.16.0/src/pyllym/providers/doubao.py +14 -0
  96. pyllym-1.16.0/src/pyllym/providers/ernie.py +13 -0
  97. pyllym-1.16.0/src/pyllym/providers/fal.py +40 -0
  98. pyllym-1.16.0/src/pyllym/providers/gemini.py +154 -0
  99. pyllym-1.16.0/src/pyllym/providers/gpustack.py +33 -0
  100. pyllym-1.16.0/src/pyllym/providers/huggingface.py +10 -0
  101. pyllym-1.16.0/src/pyllym/providers/minimax.py +15 -0
  102. pyllym-1.16.0/src/pyllym/providers/mistral.py +9 -0
  103. pyllym-1.16.0/src/pyllym/providers/moonshot.py +15 -0
  104. pyllym-1.16.0/src/pyllym/providers/nvidia.py +10 -0
  105. pyllym-1.16.0/src/pyllym/providers/ollama.py +33 -0
  106. pyllym-1.16.0/src/pyllym/providers/openai.py +57 -0
  107. pyllym-1.16.0/src/pyllym/providers/openai_compatible.py +61 -0
  108. pyllym-1.16.0/src/pyllym/providers/openrouter.py +9 -0
  109. pyllym-1.16.0/src/pyllym/providers/perplexity.py +25 -0
  110. pyllym-1.16.0/src/pyllym/providers/qwen.py +15 -0
  111. pyllym-1.16.0/src/pyllym/providers/typesafe.py +24 -0
  112. pyllym-1.16.0/src/pyllym/providers/vertexai.py +106 -0
  113. pyllym-1.16.0/src/pyllym/providers/vllm.py +45 -0
  114. pyllym-1.16.0/src/pyllym/providers/xai.py +10 -0
  115. pyllym-1.16.0/src/pyllym/providers/zhipu.py +19 -0
  116. pyllym-1.16.0/src/pyllym/py.typed +0 -0
  117. pyllym-1.16.0/src/pyllym/reactllm_bridge.py +165 -0
  118. pyllym-1.16.0/src/pyllym/reactullm_bridge.py +228 -0
  119. pyllym-1.16.0/src/pyllym/reactullm_handoff.py +352 -0
  120. pyllym-1.16.0/src/pyllym/reactullm_runtime.py +405 -0
  121. pyllym-1.16.0/src/pyllym/search_results.py +45 -0
  122. pyllym-1.16.0/src/pyllym/speech.py +73 -0
  123. pyllym-1.16.0/src/pyllym/stream_accumulator.py +249 -0
  124. pyllym-1.16.0/src/pyllym/streaming.py +169 -0
  125. pyllym-1.16.0/src/pyllym/tdg/__init__.py +66 -0
  126. pyllym-1.16.0/src/pyllym/tdg/__main__.py +86 -0
  127. pyllym-1.16.0/src/pyllym/tdg/brief.py +120 -0
  128. pyllym-1.16.0/src/pyllym/tdg/builder.py +288 -0
  129. pyllym-1.16.0/src/pyllym/tdg/checks.py +61 -0
  130. pyllym-1.16.0/src/pyllym/tdg/deps.py +251 -0
  131. pyllym-1.16.0/src/pyllym/tdg/planner.py +140 -0
  132. pyllym-1.16.0/src/pyllym/tdg/renderer.py +106 -0
  133. pyllym-1.16.0/src/pyllym/tdg/runs.py +142 -0
  134. pyllym-1.16.0/src/pyllym/tdg/safety.py +141 -0
  135. pyllym-1.16.0/src/pyllym/tdg/schema.py +87 -0
  136. pyllym-1.16.0/src/pyllym/tdg/sequence.py +147 -0
  137. pyllym-1.16.0/src/pyllym/tdg/toml_spec.py +367 -0
  138. pyllym-1.16.0/src/pyllym/thinking.py +42 -0
  139. pyllym-1.16.0/src/pyllym/tokens.py +53 -0
  140. pyllym-1.16.0/src/pyllym/tool.py +197 -0
  141. pyllym-1.16.0/src/pyllym/tool_call.py +23 -0
  142. pyllym-1.16.0/src/pyllym/toolset.py +343 -0
  143. pyllym-1.16.0/src/pyllym/transcription.py +44 -0
  144. pyllym-1.16.0/src/pyllym/uploaded_file.py +59 -0
  145. pyllym-1.16.0/src/pyllym/utils.py +124 -0
  146. pyllym-1.16.0/src/pyllym/video.py +94 -0
  147. pyllym-1.16.0/tests/__init__.py +0 -0
  148. pyllym-1.16.0/tests/conftest.py +104 -0
  149. pyllym-1.16.0/tests/factories.py +165 -0
  150. pyllym-1.16.0/tests/seed_fixtures.py +69 -0
  151. pyllym-1.16.0/tests/test_bdd.py +551 -0
  152. pyllym-1.16.0/tests/test_bedrock.py +42 -0
  153. pyllym-1.16.0/tests/test_behaviors.py +164 -0
  154. pyllym-1.16.0/tests/test_capabilities.py +58 -0
  155. pyllym-1.16.0/tests/test_celery.py +107 -0
  156. pyllym-1.16.0/tests/test_chat.py +193 -0
  157. pyllym-1.16.0/tests/test_connection_errors.py +82 -0
  158. pyllym-1.16.0/tests/test_core.py +67 -0
  159. pyllym-1.16.0/tests/test_decisions.py +288 -0
  160. pyllym-1.16.0/tests/test_errors.py +44 -0
  161. pyllym-1.16.0/tests/test_fal.py +66 -0
  162. pyllym-1.16.0/tests/test_gemini_extra.py +85 -0
  163. pyllym-1.16.0/tests/test_mcp.py +328 -0
  164. pyllym-1.16.0/tests/test_ollama.py +114 -0
  165. pyllym-1.16.0/tests/test_persistence.py +52 -0
  166. pyllym-1.16.0/tests/test_provider_matrix.py +136 -0
  167. pyllym-1.16.0/tests/test_reactullm_bridge.py +215 -0
  168. pyllym-1.16.0/tests/test_reactullm_handoff.py +199 -0
  169. pyllym-1.16.0/tests/test_reactullm_runtime.py +358 -0
  170. pyllym-1.16.0/tests/test_retry.py +217 -0
  171. pyllym-1.16.0/tests/test_review_fixes.py +204 -0
  172. pyllym-1.16.0/tests/test_seeder.py +20 -0
  173. pyllym-1.16.0/tests/test_tdg_deps.py +166 -0
  174. pyllym-1.16.0/tests/test_tdg_runs.py +104 -0
  175. pyllym-1.16.0/tests/test_toolset.py +175 -0
  176. pyllym-1.16.0/tests/test_value_objects.py +51 -0
  177. pyllym-1.16.0/tests/test_zhipu_layout.py +137 -0
  178. pyllym-1.16.0/uv.lock +2603 -0
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # PreToolUse hook: hard-block dangerous shell commands.
4
+ #
5
+ # Claude Code invokes this before every Bash tool call and pipes the tool
6
+ # input as JSON on stdin, e.g. {"tool_name":"Bash","tool_input":{"command":"..."}}.
7
+ #
8
+ # Exit 0 -> allow the command.
9
+ # Exit 2 -> block the command; stderr is shown to Claude as the reason.
10
+ # JSON on stdout -> structured decision (we use exit codes for simplicity).
11
+ #
12
+ # This is defense-in-depth, NOT a sandbox. A determined pattern can evade a
13
+ # static denylist. The real boundary is human review + running untrusted code
14
+ # only where secrets/network are unreachable (see CLAUDE.md security model).
15
+
16
+ set -euo pipefail
17
+
18
+ input="$(cat)"
19
+
20
+ # Pull the command string out of the JSON without needing jq.
21
+ command="$(printf '%s' "$input" | python3 -c '
22
+ import json, sys
23
+ try:
24
+ data = json.load(sys.stdin)
25
+ except Exception:
26
+ print("")
27
+ sys.exit(0)
28
+ print(data.get("tool_input", {}).get("command", ""))
29
+ ' 2>/dev/null || printf '')"
30
+
31
+ # Nothing to inspect -> allow.
32
+ [ -z "$command" ] && exit 0
33
+
34
+ block() {
35
+ echo "BLOCKED by block-dangerous-commands hook: $1" >&2
36
+ echo "Command: $command" >&2
37
+ exit 2
38
+ }
39
+
40
+ # --- Dangerous patterns (POSIX ERE, case-insensitive) -------------------------
41
+ # Each entry: "regex::human reason". Bash `[[ =~ ]]` uses POSIX ERE, which has
42
+ # NO \b word boundary and NO \d — use (^|[^alnum]) style guards and explicit
43
+ # whitespace via [[:space:]]. Keep patterns conservative to avoid false
44
+ # positives on legitimate project commands.
45
+ #
46
+ # Patterns match the whole command string, quoted text included, so a bare
47
+ # (^|[^[:alnum:]])word([^[:alnum:]]|$) guard also fires on the word inside a
48
+ # commit message, an echo, or a grep needle. For verbs that are only dangerous
49
+ # as the command itself, anchor to command position — start of string or after
50
+ # a separator (; & | && ||) — rather than to word boundaries.
51
+ patterns=(
52
+ 'rm[[:space:]]+(-[[:alnum:]]*[rf][[:alnum:]]*[[:space:]]+)+(/|~|\$HOME|\*|\.($|[[:space:]]))::recursive/forced rm of root, home, or wildcard'
53
+ ':[[:space:]]*\([[:space:]]*\)[[:space:]]*\{[[:space:]]*:[[:space:]]*\|[[:space:]]*:[[:space:]]*&::fork bomb'
54
+ '(^|[;&|]|&&|\|\|)[[:space:]]*(sudo[[:space:]]+)?(/sbin/|/usr/sbin/)?mkfs(\.[[:alnum:]]+)?([[:space:]]|;|&|\||$)::filesystem format (mkfs)'
55
+ '(^|[^[:alnum:]])dd[[:space:]][^|]*of=/dev/::dd writing to a raw device'
56
+ '>[[:space:]]*/dev/(sd|nvme|disk|hd)::redirect into a raw disk device'
57
+ '(^|[;&|]|&&|\|\|)[[:space:]]*(sudo[[:space:]]+)?(/usr/bin/)?shred([[:space:]]|;|&|\||$)::secure-erase (shred)'
58
+ '(^|[;&|]|&&|\|\|)[[:space:]]*(sudo[[:space:]]+)?(systemctl[[:space:]]+)?(/sbin/|/usr/sbin/)?(shutdown|reboot|halt|poweroff)([[:space:]]|;|&|\||$)::power state change'
59
+ 'chmod[[:space:]]+-R[[:space:]]+0*777[[:space:]]+/::recursive world-writable on root'
60
+ 'chown[[:space:]]+-R[[:space:]].*[[:space:]]+/[[:space:]]*$::recursive chown of root'
61
+ 'git[[:space:]]+push[[:space:]].*--force::git push --force (use --force-with-lease)'
62
+ 'git[[:space:]]+push[[:space:]].*(^|[[:space:]])-f($|[[:space:]])::git push -f (use --force-with-lease)'
63
+ 'git[[:space:]]+reset[[:space:]]+--hard.*origin/::hard reset onto a remote ref (discards local work)'
64
+ 'git[[:space:]]+clean[[:space:]]+-[[:alpha:]]*f[[:alpha:]]*d::git clean -fd (deletes untracked files)'
65
+ 'curl[[:space:]].*\|[[:space:]]*(sudo[[:space:]]+)?(bash|sh|zsh)([^[:alnum:]]|$)::piping remote script straight into a shell'
66
+ 'wget[[:space:]].*\|[[:space:]]*(sudo[[:space:]]+)?(bash|sh|zsh)([^[:alnum:]]|$)::piping remote script straight into a shell'
67
+ 'eval[[:space:]].*\$\(curl::eval of remote content'
68
+ 'sudo[[:space:]]+rm([^[:alnum:]]|$)::sudo rm'
69
+ '(pip|pip3|python[0-9.]*[[:space:]]+-m[[:space:]]+pip)[[:space:]]+.*--break-system-packages::pip --break-system-packages'
70
+ '/dev/(tcp|udp)/::raw network socket via /dev/tcp'
71
+ 'history[[:space:]]+-c([^[:alnum:]]|$)::clearing shell history'
72
+ )
73
+
74
+ shopt -s nocasematch
75
+ for entry in "${patterns[@]}"; do
76
+ regex="${entry%%::*}"
77
+ reason="${entry##*::}"
78
+ if [[ "$command" =~ $regex ]]; then
79
+ block "$reason"
80
+ fi
81
+ done
82
+
83
+ exit 0
@@ -0,0 +1,84 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/claude-code-settings.json",
3
+ "permissions": {
4
+ "deny": [
5
+ "Bash(rm -rf /*)",
6
+ "Bash(rm -rf ~*)",
7
+ "Bash(rm -rf .*)",
8
+ "Bash(sudo rm*)",
9
+ "Bash(mkfs*)",
10
+ "Bash(dd*of=/dev/*)",
11
+ "Bash(shutdown*)",
12
+ "Bash(reboot*)",
13
+ "Bash(halt*)",
14
+ "Bash(poweroff*)",
15
+ "Bash(shred*)",
16
+ "Bash(git push*--force*)",
17
+ "Bash(git push*-f*)",
18
+ "Bash(git reset --hard*origin/*)",
19
+ "Bash(git clean -*f*d*)",
20
+ "Bash(chmod -R 777 /*)",
21
+ "Bash(curl*|*sh*)",
22
+ "Bash(curl*|*bash*)",
23
+ "Bash(wget*|*sh*)",
24
+ "Bash(wget*|*bash*)",
25
+ "Bash(history -c*)",
26
+ "Read(./.env)",
27
+ "Read(./.env.*)",
28
+ "Read(./**/*secret*)",
29
+ "Read(./llm_ignore/**)"
30
+ ],
31
+ "ask": [
32
+ "Bash(rm:*)",
33
+ "Bash(rmdir:*)",
34
+ "Bash(mv:*)",
35
+ "Bash(truncate:*)",
36
+ "Bash(:>*)",
37
+ "Bash(find:* -delete)",
38
+ "Bash(find:* -exec rm *)",
39
+ "Bash(xargs rm:*)",
40
+ "Bash(chmod -R:*)",
41
+ "Bash(chown -R:*)",
42
+ "Bash(git rm:*)",
43
+ "Bash(git reset --hard:*)",
44
+ "Bash(git clean:*)",
45
+ "Bash(git checkout -- :*)",
46
+ "Bash(git restore:*)",
47
+ "Bash(git branch -D:*)",
48
+ "Bash(git branch -d:*)",
49
+ "Bash(git stash drop:*)",
50
+ "Bash(git stash clear:*)",
51
+ "Bash(cargo clean:*)"
52
+ ],
53
+ "allow": [
54
+ "Bash(.venv/bin/ruff check*)",
55
+ "Bash(.venv/bin/ruff format*)",
56
+ "Bash(.venv/bin/mypy*)",
57
+ "Bash(.venv/bin/pytest*)",
58
+ "Bash(.venv/bin/python*)",
59
+ "Bash(pytest*)",
60
+ "Bash(ruff check*)",
61
+ "Bash(ruff format*)",
62
+ "Bash(mypy src*)",
63
+ "Bash(git status*)",
64
+ "Bash(git diff*)",
65
+ "Bash(git log*)",
66
+ "Bash(git fetch*)",
67
+ "Bash(git add*)",
68
+ "Bash(git branch*)"
69
+ ]
70
+ },
71
+ "hooks": {
72
+ "PreToolUse": [
73
+ {
74
+ "matcher": "Bash",
75
+ "hooks": [
76
+ {
77
+ "type": "command",
78
+ "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/block-dangerous-commands.sh"
79
+ }
80
+ ]
81
+ }
82
+ ]
83
+ }
84
+ }
@@ -0,0 +1,62 @@
1
+ ---
2
+ name: add-provider
3
+ description: Add a new OpenAI-compatible AI provider to pyllym — create the provider class under src/pyllym/providers/ and register it in the package façade. Use when the user wants to "add a provider", "support <vendor>'s API", or wire up a new OpenAI-compatible endpoint.
4
+ ---
5
+
6
+ # add-provider
7
+
8
+ Add a provider following pyllym's **Provider (where/who) → Protocol (wire format)
9
+ → Connection (aiohttp)** architecture. For any endpoint that speaks the
10
+ OpenAI chat-completions wire format this is a ~10-line file plus one line of
11
+ registration. Non-compatible vendors (Anthropic, Gemini, Bedrock Converse, fal)
12
+ implement their own protocol instead — that is a larger task; flag it rather
13
+ than forcing `OpenAICompatible`.
14
+
15
+ ## Steps for an OpenAI-compatible provider
16
+
17
+ 1. **Create `src/pyllym/providers/<slug>.py`.** Subclass `OpenAICompatible`.
18
+ Use an existing minimal provider such as `providers/deepseek.py` as the
19
+ template:
20
+
21
+ ```python
22
+ """<Vendor> API integration."""
23
+
24
+ from __future__ import annotations
25
+
26
+ from .openai_compatible import OpenAICompatible
27
+
28
+
29
+ class <Vendor>(OpenAICompatible):
30
+ default_api_base = "https://api.<vendor>.com/v1"
31
+ assume_models = True # skip a models-exist preflight when the vendor
32
+ # has no /models listing
33
+ ```
34
+
35
+ - `default_api_base` — the chat-completions base URL.
36
+ - `assume_models` — set `True` when the vendor doesn't expose a model list.
37
+ - Only override headers / config options if the vendor needs a non-standard
38
+ auth header; otherwise `OpenAICompatible` handles `Authorization: Bearer`.
39
+
40
+ 2. **Register it** in `src/pyllym/__init__.py`, inside
41
+ `_register_builtin_providers()`, by appending a `(slug, ClassName)` tuple to
42
+ the `registrations` list (keep it grouped with its peers). Registration is
43
+ defensive — a module that fails to import is silently skipped.
44
+
45
+ 3. **Config / env fallback.** Provider options fall back to the uppercase env
46
+ var of the same name (e.g. `<vendor>_api_key` → `<VENDOR>_API_KEY`); values
47
+ set via `pyllym.configure()` win. No extra wiring needed for the standard
48
+ API-key case.
49
+
50
+ 4. **Verify** with the `dev-checks` skill (ruff, mypy, pytest). Confirm the
51
+ provider is discoverable:
52
+
53
+ ```bash
54
+ .venv/bin/python -c "import pyllym; print('<slug>' in [p.slug for p in pyllym.list_providers()])"
55
+ ```
56
+
57
+ ## Conventions
58
+
59
+ - `from __future__ import annotations` at the top; PEP 604 unions; builtin
60
+ generics.
61
+ - Don't hand-edit `models.json` — it's generated. Prefer `pyllym.models.refresh()`.
62
+ - Keep provider modules thin: they declare *where/who*, not wire format.
@@ -0,0 +1,77 @@
1
+ ---
2
+ name: bdd-build
3
+ description: >-
4
+ Drive the BDD→TDD workflow with pyllym.bdd: generate a red pytest suite plus
5
+ a build brief from a TOML spec, then implement code until the suite is green
6
+ without editing the generated tests. Use when the user asks to "build from a
7
+ spec", mentions a .toml spec, a BRIEF_*.md or *.plan.json file, wants to
8
+ scaffold tests from a TOML spec, or asks to implement against a generated
9
+ bdd_pending suite.
10
+ ---
11
+
12
+ # BDD build workflow
13
+
14
+ Two phases with a mandatory human review gate between them.
15
+
16
+ ## Phase 1 — generate the specification
17
+
18
+ 1. Run the builder from a TOML spec (request mode needs a configured provider
19
+ key; plan mode does not):
20
+
21
+ ```bash
22
+ python -m pyllym.bdd <spec-path> --out tests/generated --model <model-id>
23
+ ```
24
+
25
+ `<spec-path>` is a `.toml` spec file or a directory of them. Mode is
26
+ auto-detected from the presence of `[[cases]]` (override with `--toml-mode
27
+ plan|request`):
28
+
29
+ - **plan mode** — the spec carries hand-written `[[cases]]`; the plan is
30
+ built deterministically with **no LLM** (no model/key needed).
31
+ - **request mode** — a loose spec (`[[rules]]`/`[[edge_cases]]`, no cases);
32
+ the planner model fills the plan. Pass `--api-hint "<module path /
33
+ existing signatures>"` when the target module already exists — the
34
+ planner must honor it exactly.
35
+
36
+ A spec may absorb mermaid `sequenceDiagram` blocks via `[[sequences]]`
37
+ tables as binding collaboration contracts. Encourage the user to provide
38
+ them — they make generation materially more airtight: every diagram message
39
+ gets an id (`M1`, ...), test cases must claim coverage of each id (as must
40
+ every rule/edge id), and the build fails mechanically on any gap
41
+ (`PlanValidationError`). If it fails, inspect the written
42
+ `<slug>.plan.json`, then either re-run or relax with `strict=False` via the
43
+ Python API and review the warnings in the brief.
44
+
45
+ Every executable string in the plan (a case's `given`/`when`/`then`, fixture
46
+ bodies) is also screened by an AST safety gate before rendering — imports,
47
+ dangerous builtins/names, dunder reflection, or non-Python raise
48
+ `PlanSafetyError` and write nothing runnable. This is a hard fail in both
49
+ modes and is not relaxed by `strict=False`; it is defense-in-depth, not a
50
+ sandbox, so still review generated tests before running them anywhere with
51
+ secrets or network access.
52
+
53
+ 2. For each spec this writes `test_<slug>.py` (red suite),
54
+ `<slug>.plan.json` (the plan), and `BRIEF_<slug>.md` (the building
55
+ instruction with rule/edge and message→tests traceability tables), plus a
56
+ `conftest.py` registering the `bdd_pending` marker.
57
+
58
+ 3. **Stop here.** Present the plan and generated tests to the user for
59
+ review. Do not start implementing in the same pass: once the suite is
60
+ treated as the spec, a misread scenario is locked in. Point out anything
61
+ in the plan that looks like invented behavior (cases marked
62
+ `edge_case: true` deserve extra scrutiny).
63
+
64
+ ## Phase 2 — implement to green
65
+
66
+ Only after the user approves the tests (or asks you to implement against an
67
+ existing brief):
68
+
69
+ 1. Read `BRIEF_<slug>.md`. Implement exactly the API surface it lists —
70
+ module path and signatures verbatim; keep everything else private.
71
+ 2. The generated tests are **read-only**. If a test looks wrong or
72
+ unsatisfiable, stop and flag it to the user — never adapt a test to the
73
+ implementation. Regeneration from the .toml spec is the only sanctioned
74
+ way tests change.
75
+ 3. Iterate: `pytest tests/generated/test_<slug>.py` until green.
76
+ 4. Definition of done is in the brief: the suite passes with zero edits to
77
+ the test file. Run the repo's full lint/type gate afterwards.
@@ -0,0 +1,47 @@
1
+ ---
2
+ name: dev-checks
3
+ description: Run the pyllym quality gate — ruff lint, ruff format check, mypy type-check, and pytest. Use when the user asks to "run checks", "lint", "typecheck", "run the tests", "is it green?", verify a change is ready to commit, or before opening a PR.
4
+ ---
5
+
6
+ # dev-checks
7
+
8
+ Run the full local quality gate for the **pyllym** package and report results.
9
+ Prefer the project virtualenv (`.venv/bin/*`, created by `uv sync` from `uv.lock`) so the
10
+ pinned tool versions are used.
11
+
12
+ ## The gate
13
+
14
+ Run these in order. Stop and report on the first failure unless the user asked
15
+ for the whole sweep regardless.
16
+
17
+ ```bash
18
+ # 1. Lint
19
+ .venv/bin/ruff check src tests
20
+
21
+ # 2. Format (check only — do not auto-format unless asked)
22
+ .venv/bin/ruff format --check src tests
23
+
24
+ # 3. Types
25
+ .venv/bin/mypy src
26
+
27
+ # 4. Tests
28
+ .venv/bin/pytest
29
+ ```
30
+
31
+ If `.venv/bin/*` is missing, fall back to bare `ruff` / `mypy` / `pytest`, and
32
+ tell the user the venv wasn't found (they may need `uv sync`).
33
+
34
+ ## Conventions to respect
35
+
36
+ - `ruff` config lives in `pyproject.toml` (`line-length = 100`, `target-version = py313`).
37
+ - Do **not** run `ruff format` (mutating) as part of a check — only `--check`.
38
+ Offer to apply formatting as a separate, explicit step.
39
+ - `mypy` runs against `src` only, not `tests`.
40
+ - Generated BDD suites carry the `bdd_pending` marker and may be expected to
41
+ fail (red) during a build — mention this if pytest reports `bdd_pending`
42
+ failures so they aren't mistaken for regressions.
43
+
44
+ ## Reporting
45
+
46
+ Summarize pass/fail per stage. On failure, show the offending output and point
47
+ at the file:line. Don't claim green unless every stage actually passed.
@@ -0,0 +1,240 @@
1
+ ---
2
+ name: pyllym-structured-prompting
3
+ description: >-
4
+ Build structured prompting with the async-first pyllym library (Python 3.14):
5
+ structured output via Pydantic schemas, tools/function-calling, system
6
+ instructions, reasoning/thinking controls, streaming, and multimodal input —
7
+ plus how to register new models and add new providers. Use when writing or
8
+ reviewing code that calls pyllym (pyllym.create_chat / embed / paint /
9
+ animate), when
10
+ designing a JSON-schema/Pydantic response contract, when a model id isn't
11
+ found, or when wiring up a new AI provider.
12
+ ---
13
+
14
+ # pyllym: structured prompting & new models
15
+
16
+ `pyllym` is one async-first Python framework for every major AI provider. This
17
+ skill covers the two things people most often need: **structured prompting**
18
+ (reliable, typed outputs and tool use) and **extending the model/provider set**.
19
+
20
+ Target runtime: **Python 3.14** (3.13+). Everything I/O is `async`.
21
+
22
+ ## Setup
23
+
24
+ ```python
25
+ import pyllym
26
+
27
+ pyllym.configure(lambda c: setattr(c, "openai_api_key", "sk-..."))
28
+ # multiple keys:
29
+ pyllym.configure(lambda c: (
30
+ setattr(c, "anthropic_api_key", "sk-ant-..."),
31
+ setattr(c, "gemini_api_key", "..."),
32
+ ))
33
+ ```
34
+
35
+ Per-call overrides use a `Context` (isolated config copy):
36
+
37
+ ```python
38
+ ctx = pyllym.context(lambda c: setattr(c, "request_timeout", 30))
39
+ chat = ctx.create_chat(model="claude-sonnet-4-6")
40
+ ```
41
+
42
+ ## Structured output (typed responses)
43
+
44
+ Prefer a **Pydantic model** — pass the *class* (not an instance) to
45
+ `with_schema`. The provider is asked for JSON matching the schema, and
46
+ `message.content` comes back as a parsed `dict`; validate it into your model.
47
+
48
+ ```python
49
+ from pydantic import BaseModel
50
+ import pyllym
51
+
52
+ class Recipe(BaseModel):
53
+ title: str
54
+ ingredients: list[str]
55
+ minutes: int
56
+
57
+ chat = pyllym.create_chat(model="gpt-5.4").with_schema(Recipe)
58
+ msg = await chat.ask("Give me a quick pancake recipe")
59
+ recipe = Recipe.model_validate(msg.content) # msg.content is a dict
60
+ ```
61
+
62
+ - `with_schema` also accepts a raw JSON-Schema `dict` or any object exposing
63
+ `to_json_schema()`.
64
+ - Schemas are sent as strict `json_schema` where the provider supports it. If a
65
+ model can't guarantee JSON, `msg.content` may stay a string — guard with
66
+ `isinstance(msg.content, dict)`.
67
+ - Keep schemas flat and name fields descriptively; add field descriptions via
68
+ Pydantic `Field(description=...)` — they reach the model.
69
+
70
+ ## Tools (function calling)
71
+
72
+ Subclass `Tool`; the parameter schema is **inferred from `execute`'s
73
+ keyword-only signature** (or declare it explicitly). `execute` may be sync or
74
+ async. `chat.ask` runs the full agentic loop (model → tool → model → answer).
75
+
76
+ ```python
77
+ from pyllym import Tool
78
+
79
+ class Weather(Tool):
80
+ description = "Look up the current weather for a city"
81
+
82
+ async def execute(self, *, city: str, units: str = "celsius") -> str:
83
+ return f"18°{units[0].upper()} and clear in {city}"
84
+
85
+ chat = pyllym.create_chat(model="gpt-5.4").with_tools(Weather)
86
+ answer = await chat.ask("What's the weather in Oslo?")
87
+ ```
88
+
89
+ - Force/limit tool use: `with_tools(Weather, choice="required", calls="one")`
90
+ (`choice` ∈ `auto|none|required|<tool-name>`; `calls` ∈ `many|one`).
91
+ - Run independent tool calls concurrently: `with_tools(A, B, concurrency=True)`
92
+ (uses `asyncio.gather`).
93
+ - Explicit params instead of signature inference — set a raw JSON-schema class
94
+ attribute, or declare `Parameter`s via the `param` classmethod:
95
+ ```python
96
+ class Search(Tool):
97
+ description = "Search the KB"
98
+ _params_schema = { # raw JSON schema wins
99
+ "type": "object",
100
+ "properties": {"query": {"type": "string"}},
101
+ "required": ["query"],
102
+ }
103
+ def execute(self, *, query: str): ...
104
+
105
+ class Lookup(Tool):
106
+ description = "Look up a record"
107
+ Lookup.param("record_id", type="string", description="the id", required=True)
108
+ ```
109
+ - Return `pyllym.SearchResults(title=..., url=..., text=...)` from a tool to give
110
+ citation-capable providers citable results.
111
+
112
+ ## System instructions, reasoning, params
113
+
114
+ ```python
115
+ chat = (
116
+ pyllym.create_chat(model="claude-sonnet-4-6")
117
+ .with_instructions("You are a terse assistant. Answer in one sentence.")
118
+ .with_thinking(effort="high") # or budget=2048
119
+ .with_temperature(0.2)
120
+ .with_citations()
121
+ .with_params(top_p=0.9) # provider-passthrough
122
+ )
123
+ ```
124
+
125
+ Compose a reusable configuration as an `Agent`:
126
+
127
+ ```python
128
+ from pyllym import Agent
129
+
130
+ class Analyst(Agent):
131
+ chat_model = "gpt-5.4"
132
+ instructions = "You are a rigorous financial analyst."
133
+ tools = [Weather]
134
+ temperature = 0.1
135
+
136
+ chat = Analyst.create_chat()
137
+ ```
138
+
139
+ ## Streaming & multimodal
140
+
141
+ ```python
142
+ async for chunk in chat.stream("Write a haiku about async"):
143
+ print(chunk.content or "", end="", flush=True)
144
+
145
+ await chat.ask("What's in this image?", with_="diagram.png") # url, path, bytes, or file
146
+ ```
147
+
148
+ ## Other capabilities
149
+
150
+ ```python
151
+ emb = await pyllym.embed("hello") # Embedding(vectors=...)
152
+ img = await pyllym.paint("a red panda", provider="fal", model="fal-ai/flux/dev")
153
+ vid = await pyllym.animate("a timelapse sunrise", model="fal-ai/ltx-video-13b-distilled")
154
+ audio = await pyllym.speak("hello", model="gpt-4o-mini-tts")
155
+ text = await pyllym.transcribe("meeting.wav")
156
+ flags = await pyllym.moderate("some text")
157
+ ```
158
+
159
+ ## Including new models
160
+
161
+ The bundled registry (`models.json`) powers `pyllym.models.find(...)`. Three ways
162
+ to use a model that isn't in it yet:
163
+
164
+ 1. **assume-exists** — pass the id + provider and skip the registry:
165
+ ```python
166
+ await pyllym.create_chat(model="deepseek-r2", provider="deepseek",
167
+ assume_model_exists=True).ask("hi")
168
+ ```
169
+ Providers whose catalogs live off-registry set `assumes_models_exist=True`,
170
+ so `assume_model_exists` isn't even needed (e.g. `qwen`, `zhipu`, `moonshot`,
171
+ `nvidia`, `fal`).
172
+ 2. **refresh the registry** from providers + models.dev, then persist:
173
+ ```python
174
+ await pyllym.models.refresh()
175
+ pyllym.models.save_to_json()
176
+ ```
177
+ 3. Inspect what's available: `pyllym.models.find("gpt-5.4")`,
178
+ `pyllym.models.chat_models()`, `[m.id for m in pyllym.models.all() if m.provider == "gemini"]`.
179
+
180
+ Never hand-edit `models.json`; it's generated data.
181
+
182
+ ## Adding a new provider
183
+
184
+ An OpenAI-compatible provider is ~30 lines. Create
185
+ `src/pyllym/providers/<slug>.py`:
186
+
187
+ ```python
188
+ from __future__ import annotations
189
+
190
+ from ..protocols.chat_completions import ChatCompletions
191
+ from ..provider import Provider
192
+
193
+
194
+ class Acme(Provider):
195
+ protocols = {"chat_completions": ChatCompletions}
196
+ default_protocol_name = "chat_completions"
197
+
198
+ @property
199
+ def api_base(self) -> str:
200
+ return self.config.acme_api_base or "https://api.acme.ai/v1"
201
+
202
+ @property
203
+ def headers(self) -> dict[str, str]:
204
+ return {"Authorization": f"Bearer {self.config.acme_api_key}"}
205
+
206
+ @classmethod
207
+ def assumes_models_exist(cls) -> bool: # catalog not in models.json
208
+ return True
209
+
210
+ @classmethod
211
+ def configuration_options(cls) -> list[str]:
212
+ return ["acme_api_key", "acme_api_base"]
213
+
214
+ @classmethod
215
+ def configuration_requirements_list(cls) -> list[str]:
216
+ return ["acme_api_key"]
217
+ ```
218
+
219
+ Then register it in `src/pyllym/__init__.py` (add `("acme", "Acme")` to the
220
+ `registrations` list). Local providers override `is_local`; providers needing a
221
+ different wire format implement their own protocol under `protocols/` (see
222
+ `anthropic.py`, `gemini.py`, `converse.py`, `fal.py`) instead of reusing
223
+ `ChatCompletions`.
224
+
225
+ Add a test with a seeded factory response (`tests/factories.py`) and mount it
226
+ with `respx` — see `tests/test_provider_matrix.py`.
227
+
228
+ ## Gotchas
229
+
230
+ - Everything I/O is `async`; `await` `ask`/`embed`/`paint`/`animate`, and
231
+ `async for` over `stream`.
232
+ - The message-building kwarg is `with_=` (trailing underscore — `with` is a
233
+ Python keyword).
234
+ - `msg.content` is a `dict` only when `with_schema` was set and the model
235
+ returned valid JSON; otherwise it's a `str`.
236
+ - Predicates read as `message.is_tool_call()`, `is_tool_result()`,
237
+ `is_stopped()`.
238
+ - Token usage: `msg.input_tokens` / `msg.output_tokens`; cost via `chat.cost` /
239
+ `msg.cost()`.
240
+ ```
@@ -0,0 +1,58 @@
1
+ # pyllym provider credentials — copy to .env and fill in what you use.
2
+ # (pyllym does not auto-load .env; read it yourself, e.g. with python-dotenv,
3
+ # then pass values via pyllym.configure.)
4
+
5
+ # OpenAI
6
+ OPENAI_API_KEY=
7
+ OPENAI_ORGANIZATION_ID=
8
+ OPENAI_PROJECT_ID=
9
+
10
+ # Anthropic
11
+ ANTHROPIC_API_KEY=
12
+
13
+ # Google Gemini
14
+ GEMINI_API_KEY=
15
+
16
+ # DeepSeek / Mistral / xAI / Perplexity / OpenRouter
17
+ DEEPSEEK_API_KEY=
18
+ MISTRAL_API_KEY=
19
+ XAI_API_KEY=
20
+ PERPLEXITY_API_KEY=
21
+ OPENROUTER_API_KEY=
22
+
23
+ # Local
24
+ OLLAMA_API_BASE=http://localhost:11434/v1
25
+ GPUSTACK_API_BASE=
26
+
27
+ # Azure OpenAI
28
+ AZURE_API_BASE=
29
+ AZURE_API_KEY=
30
+
31
+ # AWS Bedrock
32
+ BEDROCK_API_KEY=
33
+ BEDROCK_SECRET_KEY=
34
+ BEDROCK_REGION=us-east-1
35
+ BEDROCK_SESSION_TOKEN=
36
+
37
+ # Vertex AI
38
+ VERTEXAI_PROJECT_ID=
39
+ VERTEXAI_LOCATION=us-central1
40
+ VERTEXAI_ACCESS_TOKEN=
41
+
42
+ # NVIDIA NIM / Cerebras / Hugging Face / Databricks (OpenAI-compatible)
43
+ NVIDIA_API_KEY=
44
+ CEREBRAS_API_KEY=
45
+ HUGGINGFACE_API_KEY=
46
+ DATABRICKS_API_BASE=
47
+ DATABRICKS_API_KEY=
48
+
49
+ # Qwen (DashScope) / Zhipu GLM / Moonshot Kimi / Doubao / ERNIE / MiniMax
50
+ QWEN_API_KEY=
51
+ ZHIPU_API_KEY=
52
+ MOONSHOT_API_KEY=
53
+ DOUBAO_API_KEY=
54
+ ERNIE_API_KEY=
55
+ MINIMAX_API_KEY=
56
+
57
+ # fal.ai (image + video generation)
58
+ FAL_API_KEY=