├── python.bazelrc ├── .bazelversion ├── python ├── .python-version ├── dotpromptz │ ├── src │ │ └── dotpromptz │ │ │ ├── py.typed │ │ │ ├── adapters │ │ │ └── __init__.py │ │ │ ├── __init__.py │ │ │ ├── models.py │ │ │ └── errors.py │ └── tests │ │ └── dotpromptz │ │ └── models_test.py ├── handlebarrz │ ├── src │ │ └── handlebarrz │ │ │ └── py.typed │ ├── README.md │ ├── tests │ │ └── __init__.py │ ├── smoke_tests │ │ ├── execute-test.sh │ │ ├── Dockerfile-fedora │ │ ├── Dockerfile-fedora-arm64 │ │ ├── Dockerfile-redhat │ │ ├── pyproject.toml │ │ ├── Dockerfile-debian │ │ ├── Dockerfile-alpine │ │ ├── Dockerfile-redhat-arm64 │ │ ├── Dockerfile-debian-arm64 │ │ └── handlebarrz_test.py │ ├── dockerfile-alpine │ ├── generate-alpine-wheels.sh │ ├── dockerfile-arm64 │ ├── dockerfile-x86-64 │ ├── Cargo.toml │ ├── generate-arm-wheels.sh │ ├── generate-x86-64-wheels.sh │ └── pyproject.toml ├── tests │ └── smoke │ │ ├── README.md │ │ ├── package_test.py │ │ └── pyproject.toml ├── README.md ├── .gitignore └── tox.ini ├── docs ├── contributing │ └── troubleshooting.md └── assets │ └── google-logo-small.png ├── GEMINI.md ├── js ├── tsconfig.build.json ├── .prettierrc ├── typedoc.json ├── vitest.config.mts ├── tsconfig.json ├── src │ ├── index.ts │ ├── handlebars-cjs.d.ts │ └── util.ts ├── .guides │ └── usage.md └── package.json ├── rs ├── smoke │ ├── README.md │ ├── BUILD.bazel │ ├── src │ │ └── lib.rs │ └── Cargo.toml └── dotprompt │ └── Cargo.toml ├── third_party └── docsite │ ├── public │ ├── icon.png │ └── og-image.jpg │ ├── .vscode │ ├── extensions.json │ ├── settings.json │ └── doc.code-snippets │ ├── README.md │ ├── firebase.json │ ├── tsconfig.json │ ├── .gitignore │ ├── components.json │ ├── src │ ├── content │ │ ├── docs │ │ │ ├── implementors.mdx │ │ │ ├── reference.mdx │ │ │ └── implementations.mdx │ │ └── config.ts │ ├── pages │ │ ├── 404.astro │ │ ├── index.astro │ │ ├── [...slug].astro │ │ └── llms.txt.ts │ ├── env.d.ts │ ├── components │ │ ├── core │ │ │ ├── NavMenu.astro │ │ │ ├── BacktoTop.astro │ │ │ ├── Icons.tsx │ │ │ ├── Footer.astro │ │ │ └── HeadSEO.astro │ │ ├── Card.astro │ │ ├── home │ │ │ └── hero.astro │ │ ├── docs │ │ │ ├── TableofContents.astro │ │ │ ├── BacktoTop.astro │ │ │ ├── Breadcrumbs.astro │ │ │ ├── MainContent.astro │ │ │ └── SideNavMenu.astro │ │ └── ui │ │ │ ├── separator.tsx │ │ │ └── input.tsx │ └── layouts │ │ └── BaseLayout.astro │ ├── .prettierrc.mjs │ ├── BUILD.bazel │ └── astro.config.mjs ├── .release-please-manifest.json ├── Cargo.lock ├── .hooks ├── conventional-commit-msg ├── no-commits-on-branches └── commit-message-format-pre-push ├── .vscode └── settings.json ├── .bazelignore ├── scripts ├── gazelle ├── watch_python_tests ├── format_ts_files ├── format_handlebarrz_files ├── format_rust_files ├── format_go_files ├── build_dists ├── format_build_files ├── format_python_files ├── lint ├── update_deps ├── run_python_checks_with_nox ├── run_tests ├── run_handlebarrz_checks ├── run_bazel_checks ├── run_js_checks ├── publish-java.sh └── run_python_checks_with_tox ├── .github ├── ISSUE_TEMPLATE │ ├── 🎻-dotprompt-fiddle.md │ ├── 📝-documentation.md │ ├── 💡-feature-request.md │ ├── 🐞-bug-report--go-.md │ ├── 🐞-bug-report--js-.md │ └── 🐞-bug-report--python-.md ├── workflows │ ├── labeler.yml │ ├── golangci-lint.yml │ ├── test.yml │ ├── go.yml │ ├── java.yml │ └── deploy.yml ├── scripts │ └── release.sh └── release-please.yml ├── .gitignore ├── rust.bazelrc ├── go.bazelrc ├── go ├── example │ ├── example.prompt │ ├── BUILD.bazel │ └── doc.md ├── BUILD.bazel ├── go.mod └── dotprompt │ ├── example_test.go │ ├── test │ └── BUILD.bazel │ ├── doc.go │ └── helper_test.go ├── .editorconfig ├── java ├── BUILD.bazel └── com │ ├── BUILD.bazel │ └── google │ ├── BUILD.bazel │ └── dotprompt │ ├── BUILD.bazel │ ├── models │ ├── TextPart.java │ ├── DeletePromptOrPartialOptions.java │ ├── DataPart.java │ ├── MediaContent.java │ ├── ListPromptsOptions.java │ ├── ListPartialsOptions.java │ ├── LoadPromptOptions.java │ ├── LoadPartialOptions.java │ ├── Prompt.java │ ├── PromptBundle.java │ ├── MediaPart.java │ ├── PaginatedPrompts.java │ ├── PaginatedPartials.java │ ├── Document.java │ ├── PendingPart.java │ ├── PromptRef.java │ ├── RenderedPrompt.java │ ├── PartialRef.java │ ├── PaginatedResponse.java │ ├── PromptData.java │ ├── PartialData.java │ ├── Message.java │ ├── ToolRequestPart.java │ ├── ToolResponsePart.java │ ├── DataArgument.java │ ├── ToolDefinition.java │ ├── Part.java │ └── Role.java │ ├── resolvers │ └── BUILD.bazel │ ├── smoke │ ├── Smoke.java │ └── BUILD.bazel │ ├── store │ ├── DirStoreOptions.java │ ├── PromptStoreWritable.java │ └── PromptStoreWritableSync.java │ ├── helpers │ └── BUILD.bazel │ └── parser │ └── BUILD.bazel ├── bazel ├── rules_vitest │ ├── BUILD.bazel │ └── defs.bzl └── java │ └── BUILD.bazel ├── pnpm-workspace.yaml ├── .bazelrc ├── kotlin.MODULE.bazel ├── taplo.toml ├── .npmrc ├── package.json ├── spec ├── BUILD.bazel ├── helpers │ ├── media.yaml │ └── json.yaml └── schema.json ├── MODULE.bazel ├── rust.MODULE.bazel ├── BUILD.bazel ├── go.MODULE.bazel ├── COMMIT_MESSAGE_TEMPLATE └── java.MODULE.bazel /python.bazelrc: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.bazelversion: -------------------------------------------------------------------------------- 1 | 8.5.0 2 | -------------------------------------------------------------------------------- /python/.python-version: -------------------------------------------------------------------------------- 1 | 3.12 2 | -------------------------------------------------------------------------------- /docs/contributing/troubleshooting.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /python/dotpromptz/src/dotpromptz/py.typed: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /python/handlebarrz/src/handlebarrz/py.typed: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /GEMINI.md: -------------------------------------------------------------------------------- 1 | docs/contributing/coding_guidelines.md -------------------------------------------------------------------------------- /js/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["./tsconfig.json"], 3 | "include": ["src/**/*.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /js/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "tabWidth": 2, 3 | "useTabs": false, 4 | "embeddedLanguageFormatting": "off" 5 | } 6 | -------------------------------------------------------------------------------- /docs/assets/google-logo-small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/dotprompt/HEAD/docs/assets/google-logo-small.png -------------------------------------------------------------------------------- /rs/smoke/README.md: -------------------------------------------------------------------------------- 1 | # Smoke tests 2 | 3 | This is just a smoke test to ensure the build system and imports work. 4 | -------------------------------------------------------------------------------- /third_party/docsite/public/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/dotprompt/HEAD/third_party/docsite/public/icon.png -------------------------------------------------------------------------------- /third_party/docsite/public/og-image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/dotprompt/HEAD/third_party/docsite/public/og-image.jpg -------------------------------------------------------------------------------- /third_party/docsite/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": ["astro-build.astro-vscode"], 3 | "unwantedRecommendations": [] 4 | } 5 | -------------------------------------------------------------------------------- /third_party/docsite/README.md: -------------------------------------------------------------------------------- 1 | # Dotprompt Documentation 2 | 3 | This folder contains the source code for the Dotprompt community documentation site. -------------------------------------------------------------------------------- /python/tests/smoke/README.md: -------------------------------------------------------------------------------- 1 | # Packaging Smoke Test 2 | 3 | This is a smoke test for the packaging system 4 | to ensure that our imports work as expected. 5 | -------------------------------------------------------------------------------- /python/dotpromptz/src/dotpromptz/adapters/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | """Adapters for dotpromptz.""" 5 | -------------------------------------------------------------------------------- /.release-please-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "js": "1.1.1", 3 | "python/dotpromptz": "0.1.4", 4 | "python/handlebarrz": "0.1.3", 5 | "go": "0.1.0", 6 | "java": "0.1.0" 7 | } 8 | -------------------------------------------------------------------------------- /python/handlebarrz/README.md: -------------------------------------------------------------------------------- 1 | # dotprompt-handlebars 2 | 3 | **DISCLAIMER**: Project only intended to be used for dotprompt package. Support for other use cases is not guaranteed. -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 4 4 | 5 | [[package]] 6 | name = "smoke" 7 | version = "0.1.0" 8 | -------------------------------------------------------------------------------- /.hooks/conventional-commit-msg: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright 2025 Google LLC 4 | # SPDX-License-Identifier: Apache-2.0 5 | 6 | set -euo pipefail 7 | 8 | cat "$1" | convco check --from-stdin 9 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "yaml.schemas": { 3 | "./spec/schema.json": ["spec/**/*.yaml"] 4 | }, 5 | "prettier.configPath": "js/.prettierrc", 6 | "typescript.experimental.useTsgo": true 7 | } 8 | -------------------------------------------------------------------------------- /.bazelignore: -------------------------------------------------------------------------------- 1 | .trunk 2 | bazel-bin 3 | bazel-dotprompt 4 | bazel-out 5 | bazel-testlogs 6 | js/coverage 7 | js/dist 8 | js/node_modules 9 | node_modules 10 | target/ 11 | third_party/docsite/node_modules 12 | -------------------------------------------------------------------------------- /third_party/docsite/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "prettier.documentSelectors": [ 3 | "**/*.astro" 4 | ], 5 | "[astro]": { 6 | "editor.defaultFormatter": "astro-build.astro-vscode" 7 | }, 8 | } -------------------------------------------------------------------------------- /scripts/gazelle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | if ((EUID == 0)); then 6 | echo "Please do not run as root" 7 | exit 8 | fi 9 | 10 | bazel run //:gazelle -- "$@" 11 | 12 | buildifier -r . 13 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/🎻-dotprompt-fiddle.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F3BB Dotprompt Fiddle" 3 | about: Report bugs or request new features for Dotprompt Fiddle. 4 | title: "[Fiddle]" 5 | labels: 'fiddle' 6 | assignees: '' 7 | --- 8 | 9 | 10 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/📝-documentation.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F4DD Documentation" 3 | about: Report inaccuracies or request improvements to docs. 4 | title: "[Docs]" 5 | labels: documentation 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/💡-feature-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F4A1 Feature request" 3 | about: Suggest an idea for the Dotprompt format or its implementations. 4 | title: "[FR]" 5 | labels: feature 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /python/README.md: -------------------------------------------------------------------------------- 1 | # Basic instructions 2 | 3 | ## Setup 4 | 5 | From the top level directory: 6 | 7 | ```bash 8 | scripts/setup 9 | ``` 10 | 11 | ## Run tests 12 | 13 | ```bash 14 | # To run tests. 15 | uv run --directory python pytest . 16 | ``` 17 | -------------------------------------------------------------------------------- /third_party/docsite/firebase.json: -------------------------------------------------------------------------------- 1 | { 2 | "hosting": { 3 | "site": "dotprompt-refdocs-test", 4 | "source": ".", 5 | "ignore": ["firebase.json", "**/.*", "**/node_modules/**"], 6 | "frameworksBackend": { 7 | "region": "us-central1" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .aspect 3 | .cache 4 | .firebaserc 5 | .idea 6 | .user.bazelrc 7 | /js/coverage 8 | /js/dist 9 | /third_party/docsite/src/content/refdocs 10 | bazel-* 11 | go/coverage.out 12 | node_modules 13 | python/.nox 14 | python/.tox 15 | python/handlebarrz/target 16 | site/ 17 | target/ 18 | -------------------------------------------------------------------------------- /third_party/docsite/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "astro/tsconfigs/strict", 3 | "compilerOptions": { 4 | "jsx": "react-jsx", 5 | "jsxImportSource": "react", 6 | "baseUrl": ".", 7 | "paths": { 8 | "@/*": [ 9 | "./src/*" 10 | ], 11 | "config": [ 12 | "./config.ts" 13 | ] 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /js/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "entryPoints": ["src/index.ts"], 3 | "outputs": [ 4 | { 5 | "name": "markdown", 6 | "path": "../third_party/docsite/src/content/refdocs" 7 | } 8 | ], 9 | "plugin": ["typedoc-plugin-markdown"], 10 | 11 | "outputFileStrategy": "modules", 12 | "parametersFormat": "table", 13 | "interfacePropertiesFormat": "table" 14 | } 15 | -------------------------------------------------------------------------------- /.hooks/no-commits-on-branches: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # pre-commit script 3 | 4 | protected_branches="$@" 5 | 6 | branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') 7 | 8 | for protected_branch in $protected_branches; do 9 | if [ "$branch" = "$protected_branch" ]; then 10 | echo "Direct commits to the '$protected_branch' branch are not allowed." 11 | exit 1 12 | fi 13 | done 14 | -------------------------------------------------------------------------------- /rust.bazelrc: -------------------------------------------------------------------------------- 1 | # RUST_BACKTRACE=1 2 | build --action_env=RUST_BACKTRACE=1 3 | run --run_env=RUST_BACKTRACE=1 4 | test --action_env=RUST_BACKTRACE=1 5 | test --test_env=RUST_BACKTRACE=1 6 | 7 | # RUST_BACKTRACE=full 8 | build:debug --action_env=RUST_BACKTRACE=full 9 | run:debug --run_env=RUST_BACKTRACE=full 10 | test:debug --action_env=RUST_BACKTRACE=full 11 | test:debug --test_env=RUST_BACKTRACE=full 12 | -------------------------------------------------------------------------------- /third_party/docsite/.gitignore: -------------------------------------------------------------------------------- 1 | .firebase/ 2 | 3 | # build output 4 | dist/ 5 | # generated types 6 | .astro/ 7 | 8 | # dependencies 9 | node_modules/ 10 | 11 | # logs 12 | npm-debug.log* 13 | yarn-debug.log* 14 | yarn-error.log* 15 | pnpm-debug.log* 16 | 17 | 18 | # environment variables 19 | .env 20 | .env.production 21 | 22 | # macOS-specific files 23 | .DS_Store 24 | 25 | # jetbrains setting folder 26 | .idea/ 27 | -------------------------------------------------------------------------------- /python/.gitignore: -------------------------------------------------------------------------------- 1 | *$py.class 2 | *.egg 3 | *.egg-info/ 4 | *.py[cod] 5 | *.so 6 | .DS_Store 7 | .Python 8 | .cache/ 9 | .coverage 10 | .eggs/ 11 | .genkit 12 | .idea/ 13 | .installed.cfg 14 | .mypy_cache/ 15 | .pytest_cache/ 16 | .ruff_cache/ 17 | .venv 18 | ENV/ 19 | __pycache__/ 20 | build/ 21 | develop-eggs/ 22 | dist/ 23 | downloads/ 24 | eggs/ 25 | lib/ 26 | lib64/ 27 | parts/ 28 | sdist/ 29 | site/ 30 | var/ 31 | venv/ 32 | wheels/ 33 | -------------------------------------------------------------------------------- /python/tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = 3 | py310, 4 | py311, 5 | py312, 6 | py313, 7 | py314 8 | isolated_build = True 9 | skipsdist = True # We install editable, so don't build sdist. 10 | 11 | [testenv] 12 | description = Run tests with pytest 13 | deps = 14 | pytest 15 | pytest-cov 16 | pytest-asyncio 17 | pytest-mock 18 | PyYAML 19 | -e ./dotpromptz 20 | -e ./handlebarrz 21 | commands = 22 | pytest {posargs} 23 | -------------------------------------------------------------------------------- /third_party/docsite/components.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://ui.shadcn.com/schema.json", 3 | "style": "new-york", 4 | "rsc": false, 5 | "tsx": true, 6 | "tailwind": { 7 | "config": "tailwind.config.mjs", 8 | "css": "./src/styles/globals.css", 9 | "baseColor": "zinc", 10 | "cssVariables": true, 11 | "prefix": "" 12 | }, 13 | "aliases": { 14 | "components": "@/components", 15 | "utils": "@/lib/utils" 16 | } 17 | } -------------------------------------------------------------------------------- /third_party/docsite/src/content/docs/implementors.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Implementors 3 | hide_breadcrumbs: true 4 | --- 5 | 6 | Implementing the Dotprompt spec consists of two primary areas of work: 7 | 8 | 1. Implementing the parsing of the Dotprompt format. 9 | 2. Translating the Dotprompt format into an API compatible with one or more generative models. 10 | 11 | ## 🚧 Under Construction 🚧 12 | 13 | This page is under construction, check back soon! -------------------------------------------------------------------------------- /third_party/docsite/src/pages/404.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import { Image } from "astro:assets"; 3 | 4 | import BaseLayout from "@/layouts/BaseLayout.astro"; 5 | --- 6 | 7 | 8 |
9 |
10 |
404
11 |

Unable to find the requested page.

12 |
13 |
14 |
15 | -------------------------------------------------------------------------------- /third_party/docsite/src/pages/index.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import BaseLayout from "@/layouts/BaseLayout.astro"; 3 | import Hero from "@/components/home/hero.astro"; 4 | --- 5 | 6 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/🐞-bug-report--go-.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F41E Bug Report (Go)" 3 | about: Report a bug in the Go implementation of Dotprompt. 4 | title: "[Go][Bug]" 5 | labels: bug, go 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Context 11 | 12 | 13 | ### Expected Behavior 14 | 15 | 16 | ### Actual Behavior 17 | 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/🐞-bug-report--js-.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F41E Bug Report (JS)" 3 | about: Report a bug in the JS implementation of Dotprompt. 4 | title: "[JS][Bug] " 5 | labels: bug, js 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Context 11 | 12 | 13 | ### Expected Behavior 14 | 15 | 16 | ### Actual Behavior 17 | 18 | -------------------------------------------------------------------------------- /go.bazelrc: -------------------------------------------------------------------------------- 1 | # See: https://github.com/bazelbuild/rules_go/blob/master/go/modes.rst#using-the-race-detector 2 | build:race --@io_bazel_rules_go//go/config:race 3 | 4 | build:ci --instrumentation_filter=//...\.* --collect_code_coverage 5 | test:ci --instrumentation_filter=//...\.* --collect_code_coverage 6 | 7 | # Not defining this for both build and test can cause huge cache misses. 8 | #build:linux --config=race 9 | #build:macos --config=race 10 | #build:freebsd --config=race 11 | -------------------------------------------------------------------------------- /third_party/docsite/.vscode/doc.code-snippets: -------------------------------------------------------------------------------- 1 | { 2 | "Doc template": { 3 | "prefix": "docs", 4 | "body": [ 5 | "---", 6 | "title: $1", 7 | "author: hyperoot", 8 | "pubDatetime: $2 #2024-04-09T12:00:00-05:30", 9 | "# modDatetime: ", 10 | "# description: ''", 11 | "draft: true", 12 | "#tags:", 13 | "#- tag1", 14 | "#hide_toc: ", 15 | "#hide_sidenav: ", 16 | "#hide_breadcrumbs: ", 17 | "---", 18 | ], 19 | "description": "Docs template" 20 | } 21 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/🐞-bug-report--python-.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F41E Bug Report (Python)" 3 | about: Report a bug in the Python implementation of Dotprompt. 4 | title: "[Python][Bug]" 5 | labels: bug, python 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Context 11 | 12 | 13 | ### Expected Behavior 14 | 15 | 16 | ### Actual Behavior 17 | 18 | -------------------------------------------------------------------------------- /go/example/example.prompt: -------------------------------------------------------------------------------- 1 | --- 2 | model: "gemini-1.5-flash" 3 | description: "Summarize the input text." 4 | input: 5 | schema: 6 | type: object 7 | properties: 8 | text: 9 | type: string 10 | description: "The text to summarize" 11 | required: 12 | - text 13 | output: 14 | format: "text" 15 | --- 16 | <<>> 17 | Please summarize the following text. 18 | 19 | {{text}} 20 | 21 | <<>> 22 | Yes, I understand. I will summarize it. 23 | -------------------------------------------------------------------------------- /js/vitest.config.mts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2024 Google LLC 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | import { defineConfig } from 'vitest/config'; 7 | 8 | export default defineConfig({ 9 | test: { 10 | include: ['test/**/*.test.ts', 'src/**/*.test.ts'], 11 | environment: 'node', 12 | coverage: { 13 | enabled: true, 14 | provider: 'v8', 15 | reporter: ['text', 'html'], 16 | thresholds: { 17 | autoUpdate: true, 18 | }, 19 | }, 20 | }, 21 | }); 22 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | indent_size = 2 8 | indent_style = space 9 | insert_final_newline = true 10 | max_line_length = 80 11 | trim_trailing_whitespace = true 12 | 13 | [*.{js,jsx,ts,tsx}] 14 | quote_type = single 15 | 16 | [*.py] 17 | indent_size = 4 18 | indent_style = space 19 | max_line_length = 120 20 | quote_type = single 21 | 22 | [{Makefile,go.mod,go.sum,*.go,.gitmodules}] 23 | indent_size = 4 24 | indent_style = tab 25 | -------------------------------------------------------------------------------- /.hooks/commit-message-format-pre-push: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # put this file in: .git/hooks/pre-push 3 | z40=0000000000000000000000000000000000000000 4 | while read _ local_sha _ remote_sha; do 5 | if [ "$local_sha" != $z40 ]; then 6 | if [ "$remote_sha" = $z40 ]; then 7 | # New branch, examine all commits 8 | range="$local_sha" 9 | else 10 | # Update to existing branch, examine new commits 11 | range="$remote_sha..$local_sha" 12 | fi 13 | 14 | # Check for WIP commit 15 | if ! convco check "$range"; then 16 | exit 1 17 | fi 18 | fi 19 | done 20 | -------------------------------------------------------------------------------- /go/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | -------------------------------------------------------------------------------- /java/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | -------------------------------------------------------------------------------- /java/com/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | -------------------------------------------------------------------------------- /java/com/google/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | -------------------------------------------------------------------------------- /bazel/rules_vitest/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | packages: 16 | - js 17 | - third_party/docsite 18 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | -------------------------------------------------------------------------------- /.bazelrc: -------------------------------------------------------------------------------- 1 | # Don't let environment variables like $PATH sneak into the build, which can 2 | # cause massive cache misses when they change. 3 | build --incompatible_strict_action_env 4 | 5 | # Speed up all builds by not checking if output files have been modified. 6 | build --noexperimental_check_output_files 7 | 8 | # Show test logs for failed tests. 9 | test --test_output=errors 10 | 11 | import %workspace%/go.bazelrc 12 | import %workspace%/ts.bazelrc 13 | import %workspace%/java.bazelrc 14 | import %workspace%/rust.bazelrc 15 | import %workspace%/python.bazelrc 16 | 17 | # Allow user overrides. This should be the very last line and this file should 18 | # be in .gitignore. 19 | try-import %workspace%/.user.bazelrc 20 | -------------------------------------------------------------------------------- /python/handlebarrz/tests/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | """Tests for the handlebarrz package.""" 18 | -------------------------------------------------------------------------------- /bazel/java/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | # This package provides Bazel macros for Java spec tests. 18 | -------------------------------------------------------------------------------- /js/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2022" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, 4 | "module": "NodeNext" /* Specify what module code is generated. */, 5 | "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */, 6 | "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, 7 | "strict": true /* Enable all strict type-checking options. */, 8 | "skipLibCheck": true /* Skip type checking all .d.ts files. */, 9 | "noEmit": true, 10 | "typeRoots": ["node_modules/@types"] 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /go/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/google/dotprompt/go 2 | 3 | go 1.24.11 4 | 5 | require ( 6 | github.com/go-viper/mapstructure/v2 v2.4.0 7 | github.com/goccy/go-yaml v1.19.0 8 | github.com/invopop/jsonschema v0.13.0 9 | github.com/stretchr/testify v1.10.0 10 | ) 11 | 12 | require ( 13 | github.com/davecgh/go-spew v1.1.1 // indirect 14 | github.com/pmezard/go-difflib v1.0.0 // indirect 15 | ) 16 | 17 | require ( 18 | github.com/mbleigh/raymond v0.0.0-20250414171441-6b3a58ab9e0a 19 | github.com/wk8/go-ordered-map/v2 v2.1.8 20 | ) 21 | 22 | require ( 23 | github.com/bahlo/generic-list-go v0.2.0 // indirect 24 | github.com/buger/jsonparser v1.1.1 // indirect 25 | github.com/mailru/easyjson v0.9.1 // indirect 26 | gopkg.in/yaml.v3 v3.0.1 // indirect 27 | ) 28 | -------------------------------------------------------------------------------- /third_party/docsite/src/env.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2024 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /// 18 | /// 19 | -------------------------------------------------------------------------------- /kotlin.MODULE.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | """Configuration for Bazel with Kotlin dependencies.""" 18 | 19 | bazel_dep(name = "rules_kotlin", version = "2.2.1") 20 | -------------------------------------------------------------------------------- /taplo.toml: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | [formatting] 18 | align_comments = true 19 | align_entries = true 20 | array_auto_collapse = false 21 | array_trailing_comma = true 22 | reorder_keys = true 23 | trailing_newline = true 24 | -------------------------------------------------------------------------------- /python/handlebarrz/smoke_tests/execute-test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2025 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # SPDX-License-Identifier: Apache-2.0 18 | 19 | echo "Executing for python version $1" 20 | ldd --version 21 | 22 | # linux 23 | uv python install $1 24 | uv run --python $1 handlebarrz_test.py 25 | 26 | -------------------------------------------------------------------------------- /scripts/watch_python_tests: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2025 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # SPDX-License-Identifier: Apache-2.0 17 | 18 | # Watch python tests. 19 | 20 | #set -x 21 | set -euo pipefail 22 | 23 | TOP_DIR=$(git rev-parse --show-toplevel) 24 | 25 | pushd "${TOP_DIR}/python" 26 | uv run ptw -- . 27 | popd 28 | -------------------------------------------------------------------------------- /rs/dotprompt/Cargo.toml: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | [package] 18 | edition = "2024" 19 | name = "dotprompt" 20 | version = "0.1.0" 21 | 22 | [dependencies] 23 | serde.workspace = true 24 | serde_json.workspace = true 25 | 26 | [lints] 27 | workspace = true 28 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | # Disabling pnpm [hoisting](https://pnpm.io/npmrc#hoist) by setting `hoist=false` is recommended on 2 | # projects using rules_js so that pnpm outside of Bazel lays out a node_modules tree similar to what 3 | # rules_js lays out under Bazel (without a hidden node_modules/.pnpm/node_modules). See 4 | # https://github.com/aspect-build/rules_js/blob/7377f2d0387cc2a9251137929b1c53ccdb3fbcf0/docs/npm_import.md#npm_translate_lock 5 | # documentation for more information. 6 | hoist=false 7 | 8 | # Not enabling this because it causes issues with sandboxing. 9 | # 10 | # and introduces errors when building Next.js applications. 11 | # Otherwise, you'd run into errors such as: 12 | # 13 | # node:internal/modules/cjs/loader:1148 14 | # throw err; 15 | # ^ 16 | # 17 | # Error: Cannot find module './node-polyfill-crypto' 18 | # Require stack: 19 | # ... 20 | #shared-workspace-lockfile=false 21 | 22 | #engine-strict = true 23 | -------------------------------------------------------------------------------- /third_party/docsite/src/components/core/NavMenu.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import { Button } from "@/components/ui/button"; 3 | 4 | import { menu_items } from "config"; 5 | 6 | const pathname = new URL(Astro.request.url).pathname; 7 | const pathname_part = pathname.split("/")[1]; 8 | --- 9 | 10 |
11 | { 12 | menu_items.map((item) => ( 13 | 14 | 30 | 31 | )) 32 | } 33 |
34 | -------------------------------------------------------------------------------- /third_party/docsite/.prettierrc.mjs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2024 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** @type {import("prettier").Config} */ 18 | export default { 19 | plugins: ["prettier-plugin-astro"], 20 | overrides: [ 21 | { 22 | files: "*.astro", 23 | options: { 24 | parser: "astro", 25 | }, 26 | }, 27 | ], 28 | }; 29 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/TextPart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | /** 22 | * A message part containing plain text. 23 | * 24 | * @param text The text content. 25 | */ 26 | public record TextPart(String text) implements Part {} 27 | -------------------------------------------------------------------------------- /.github/workflows/labeler.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | name: "Pull Request Labeler" 18 | 19 | on: 20 | - pull_request_target 21 | 22 | jobs: 23 | labeler: 24 | permissions: 25 | contents: read 26 | pull-requests: write 27 | runs-on: ubuntu-latest 28 | steps: 29 | - uses: actions/labeler@v6 30 | -------------------------------------------------------------------------------- /js/src/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2024 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | import { Dotprompt, DotpromptOptions } from './dotprompt.js'; 20 | 21 | export { 22 | PicoschemaOptions, 23 | PicoschemaParser, 24 | picoschema, 25 | } from './picoschema.js'; 26 | export type * from './types.js'; 27 | export { Dotprompt, DotpromptOptions }; 28 | -------------------------------------------------------------------------------- /third_party/docsite/src/components/Card.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import { Terminal, type LucideIcon } from "lucide-react"; 3 | import { Button } from "@/components/ui/button"; 4 | 5 | interface Props { 6 | title: string; 7 | icon?: LucideIcon; 8 | color?: string; 9 | } 10 | 11 | const { title, icon: Icon = Terminal, color = "primary" } = Astro.props; 12 | --- 13 | 14 |
17 |
18 | 25 |

26 | {title} 27 |

28 |
29 |
30 | 31 |
32 |
33 | -------------------------------------------------------------------------------- /python/dotpromptz/src/dotpromptz/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | """Dotpromptz implements the .prompt templates for Python.""" 18 | 19 | from .dotprompt import Dotprompt 20 | 21 | 22 | def package_name() -> str: 23 | """Stub function to test imports.""" 24 | return 'dotpromptz' 25 | 26 | 27 | __all__ = [ 28 | Dotprompt.__name__, 29 | ] 30 | -------------------------------------------------------------------------------- /rs/smoke/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") 18 | 19 | rust_library( 20 | name = "smoke", 21 | srcs = [ 22 | "src/lib.rs", 23 | ], 24 | ) 25 | 26 | rust_test( 27 | name = "smoke_test", 28 | size = "small", 29 | srcs = ["src/lib.rs"], 30 | deps = [":smoke"], 31 | ) 32 | -------------------------------------------------------------------------------- /go/dotprompt/example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2025 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | package dotprompt 18 | 19 | import ( 20 | "testing" 21 | 22 | "github.com/stretchr/testify/assert" 23 | ) 24 | 25 | // Square computes the square of a number. 26 | func Square(n int) int { 27 | return n * n 28 | } 29 | 30 | func TestSquare(t *testing.T) { 31 | assert.Equal(t, 4, Square(2)) 32 | } 33 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/DeletePromptOrPartialOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | /** 22 | * Options for deleting a prompt or partial. 23 | * 24 | * @param variant The specific variant identifier to delete. 25 | */ 26 | public record DeletePromptOrPartialOptions(String variant) {} 27 | -------------------------------------------------------------------------------- /third_party/docsite/src/components/home/hero.astro: -------------------------------------------------------------------------------- 1 | --- 2 | const { class: className } = Astro.props; 3 | import Logo from "../core/Logo.astro"; 4 | --- 5 | 6 |
12 | 13 |

Executable GenAI prompt templates.

14 | 26 |
27 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/DataPart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | import java.util.Map; 22 | 23 | /** 24 | * A content part containing arbitrary structured data. 25 | * 26 | * @param data The structured data content. 27 | */ 28 | public record DataPart(Map data) implements Part {} 29 | -------------------------------------------------------------------------------- /scripts/format_ts_files: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2025 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # SPDX-License-Identifier: Apache-2.0 17 | 18 | #set -x # Uncomment to enable tracing. 19 | set -euo pipefail 20 | 21 | if ((EUID == 0)); then 22 | echo "Please do not run as root" 23 | exit 24 | fi 25 | 26 | TOP_DIR=$(git rev-parse --show-toplevel) 27 | 28 | # Format all TypeScript code. 29 | pushd "${TOP_DIR}" 30 | pnpm run format || exit 1 31 | popd 32 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/MediaContent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | /** 22 | * Describes the content details within a MediaPart. 23 | * 24 | * @param url The URL of the media. 25 | * @param contentType The MIME type of the media. 26 | */ 27 | public record MediaContent(String url, String contentType) {} 28 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/ListPromptsOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | /** 22 | * Options for listing prompts. 23 | * 24 | * @param cursor The cursor to start listing from. 25 | * @param limit The maximum number of items to return. 26 | */ 27 | public record ListPromptsOptions(String cursor, Integer limit) {} 28 | -------------------------------------------------------------------------------- /scripts/format_handlebarrz_files: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2025 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # SPDX-License-Identifier: Apache-2.0 17 | 18 | #set -x # Uncomment to enable tracing. 19 | set -euo pipefail 20 | 21 | if ((EUID == 0)); then 22 | echo "Please do not run as root" 23 | exit 24 | fi 25 | 26 | TOP_DIR=$(git rev-parse --show-toplevel) 27 | 28 | # Format handlebarrz 29 | pushd "${TOP_DIR}/python/handlebarrz" 30 | cargo fmt --all || exit 1 31 | popd 32 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/ListPartialsOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | /** 22 | * Options for listing partials. 23 | * 24 | * @param cursor The cursor to start listing from. 25 | * @param limit The maximum number of items to return. 26 | */ 27 | public record ListPartialsOptions(String cursor, Integer limit) {} 28 | -------------------------------------------------------------------------------- /scripts/format_rust_files: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2025 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # SPDX-License-Identifier: Apache-2.0 17 | 18 | #set -x # Uncomment to enable tracing. 19 | set -euo pipefail 20 | 21 | if ((EUID == 0)); then 22 | echo "Please do not run as root" 23 | exit 24 | fi 25 | 26 | TOP_DIR=$(git rev-parse --show-toplevel) 27 | 28 | # Format all Python code and organize imports. 29 | 30 | pushd "${TOP_DIR}" 31 | cargo fmt --all || exit 1 32 | popd 33 | -------------------------------------------------------------------------------- /third_party/docsite/src/components/docs/TableofContents.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import type { HeadingHierarchy, HeadingProps } from "@/lib/types"; 3 | import { createHeadingHierarchy } from "@/lib/utils"; 4 | 5 | const { headings } = Astro.props as HeadingProps; 6 | const toc: HeadingHierarchy[] = createHeadingHierarchy(headings ?? []); 7 | const hasToC = toc.length > 1; 8 | 9 | // To pass the tailwindcss classes to the astro component 10 | const { class: className } = Astro.props; 11 | --- 12 | 13 | { 14 | hasToC && ( 15 |
16 |

On This Page

17 | 26 |
27 | ) 28 | } 29 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/LoadPromptOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | /** 22 | * Options for loading a prompt. 23 | * 24 | * @param variant The specific variant identifier of the prompt to load. 25 | * @param version A specific version hash to load. 26 | */ 27 | public record LoadPromptOptions(String variant, String version) {} 28 | -------------------------------------------------------------------------------- /python/handlebarrz/smoke_tests/Dockerfile-fedora: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | FROM fedora:latest 17 | 18 | RUN dnf install -y python3 python3-pip && \ 19 | dnf clean all 20 | 21 | WORKDIR /project 22 | COPY . /project/ 23 | 24 | RUN curl -LsSf https://astral.sh/uv/install.sh | sh \ 25 | && . $HOME/.local/bin/env \ 26 | && uv sync --index-strategy unsafe-best-match 27 | 28 | ENV PATH="/root/.local/bin/:$PATH" 29 | 30 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/LoadPartialOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | /** 22 | * Options for loading a partial. 23 | * 24 | * @param variant The specific variant identifier of the partial to load. 25 | * @param version A specific version hash to load. 26 | */ 27 | public record LoadPartialOptions(String variant, String version) {} 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "packageManager": "pnpm@10.25.0", 3 | "scripts": { 4 | "build": "pnpm -C js build", 5 | "format": "pnpm dlx @biomejs/biome check --formatter-enabled=true --linter-enabled=false --fix . && scripts/add_license", 6 | "format:check": "pnpm dlx @biomejs/biome ci --linter-enabled=false --formatter-enabled=true . && scripts/check_license", 7 | "lint": "pnpm dlx @biomejs/biome lint --fix . && scripts/add_license", 8 | "test": "pnpm -C js run test" 9 | }, 10 | "dependencies": { 11 | "handlebars": "^4.7.8", 12 | "yaml": "^2.8.2" 13 | }, 14 | "devDependencies": { 15 | "@biomejs/biome": "^2.3.8", 16 | "@types/node": "^25.0.0", 17 | "@typescript/native-preview": "7.0.0-dev.20251211.1", 18 | "@vitest/coverage-v8": "^4.0.15", 19 | "typescript": "5.9.3", 20 | "vitest": "^4.0.15" 21 | }, 22 | "pnpm": { 23 | "onlyBuiltDependencies": [ 24 | "js" 25 | ], 26 | "overrides": { 27 | "rollup@>=4.0.0 <4.22.4": ">=4.22.4", 28 | "cross-spawn@>=7.0.0 <7.0.5": ">=7.0.5" 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/Prompt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | import java.util.Map; 22 | 23 | /** 24 | * Represents a loaded prompt. 25 | * 26 | * @param template The compiled Handlebars template string. 27 | * @param config Metadata and configuration for the prompt. 28 | */ 29 | public record Prompt(String template, Map config) {} 30 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/resolvers/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | java_library( 20 | name = "resolvers", 21 | srcs = [ 22 | "PartialResolver.java", 23 | "SchemaResolver.java", 24 | "ToolResolver.java", 25 | ], 26 | visibility = ["//visibility:public"], 27 | deps = [ 28 | "//java/com/google/dotprompt/models", 29 | ], 30 | ) 31 | -------------------------------------------------------------------------------- /python/handlebarrz/smoke_tests/Dockerfile-fedora-arm64: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | FROM --platform=linux/arm64 fedora:latest 17 | 18 | RUN dnf install -y python3 python3-pip && \ 19 | dnf clean all 20 | 21 | WORKDIR /project 22 | COPY . /project/ 23 | 24 | RUN curl -LsSf https://astral.sh/uv/install.sh | sh \ 25 | && . $HOME/.local/bin/env \ 26 | && uv sync --index-strategy unsafe-best-match 27 | 28 | ENV PATH="/root/.local/bin/:$PATH" 29 | 30 | -------------------------------------------------------------------------------- /python/handlebarrz/smoke_tests/Dockerfile-redhat: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | FROM registry.access.redhat.com/ubi9/ubi 17 | 18 | RUN yum install -y python3 python3-pip && \ 19 | yum clean all 20 | 21 | WORKDIR /project 22 | COPY . /project/ 23 | 24 | RUN curl -LsSf https://astral.sh/uv/install.sh | sh \ 25 | && . $HOME/.local/bin/env \ 26 | && uv sync --index-strategy unsafe-best-match 27 | 28 | ENV PATH="/root/.local/bin/:$PATH" 29 | 30 | -------------------------------------------------------------------------------- /python/handlebarrz/smoke_tests/pyproject.toml: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | [project] 18 | authors = [{ name = "Abraham Lazaro", email = "lazaromartinez@google.com" }] 19 | dependencies = ["dotprompt-handlebars>=0.0.1.dev1"] 20 | name = "handlebarrz-smoke-tests" 21 | readme = "README.md" 22 | requires-python = ">=3.10" 23 | version = "0.1.0" 24 | 25 | [[tool.uv.index]] 26 | url = "https://test.pypi.org/simple" 27 | -------------------------------------------------------------------------------- /.github/scripts/release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2025 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | 17 | # git clone git@github.com:google/dotprompt.git 18 | # cd js 19 | # pnpm i 20 | # pnpm build 21 | # pnpm test 22 | 23 | # pnpm login --registry https://wombat-dressing-room.appspot.com 24 | 25 | CURRENT=`pwd` 26 | RELEASE_BRANCH="${RELEASE_BRANCH:-main}" 27 | RELEASE_TAG="${RELEASE_TAG:-next}" 28 | 29 | cd js 30 | pnpm publish --tag $RELEASE_TAG --publish-branch $RELEASE_BRANCH --registry https://wombat-dressing-room.appspot.com 31 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/PromptBundle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * A bundle of prompts and partials. 25 | * 26 | * @param prompts The list of prompts in the bundle. 27 | * @param partials The list of partials in the bundle. 28 | */ 29 | public record PromptBundle(List prompts, List partials) {} 30 | -------------------------------------------------------------------------------- /python/handlebarrz/smoke_tests/Dockerfile-debian: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | FROM debian:bookworm 17 | 18 | RUN apt-get update && \ 19 | apt-get install -y python3 python3-pip curl && \ 20 | apt-get clean 21 | 22 | WORKDIR /project 23 | COPY . /project/ 24 | 25 | RUN curl -LsSf https://astral.sh/uv/install.sh | sh \ 26 | && . $HOME/.local/bin/env \ 27 | && uv sync --index-strategy unsafe-best-match 28 | 29 | ENV PATH="/root/.local/bin/:$PATH" 30 | 31 | -------------------------------------------------------------------------------- /python/handlebarrz/smoke_tests/Dockerfile-alpine: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | FROM --platform=linux/arm64 alpine:latest 17 | 18 | RUN apk add --no-cache python3 py3-pip \ 19 | build-base gcc musl-dev curl bash 20 | 21 | WORKDIR /project 22 | COPY . /project/ 23 | 24 | RUN curl -LsSf https://astral.sh/uv/install.sh | sh \ 25 | && source $HOME/.local/bin/env \ 26 | && uv sync --index-strategy unsafe-best-match 27 | 28 | ENV PATH="/root/.local/bin/:$PATH" 29 | 30 | -------------------------------------------------------------------------------- /python/handlebarrz/smoke_tests/Dockerfile-redhat-arm64: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | FROM --platform=linux/arm64 registry.access.redhat.com/ubi9/ubi 17 | 18 | RUN yum install -y python3 python3-pip && \ 19 | yum clean all 20 | 21 | WORKDIR /project 22 | COPY . /project/ 23 | 24 | RUN curl -LsSf https://astral.sh/uv/install.sh | sh \ 25 | && . $HOME/.local/bin/env \ 26 | && uv sync --index-strategy unsafe-best-match 27 | 28 | ENV PATH="/root/.local/bin/:$PATH" 29 | 30 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/MediaPart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | /** 22 | * A part of a message containing media content (e.g. image, video). 23 | * 24 | * @param media The media content details. 25 | */ 26 | public record MediaPart(MediaContent media) implements Part { 27 | public MediaPart(String contentType, String url) { 28 | this(new MediaContent(url, contentType)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/PaginatedPrompts.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * A paginated list of prompt references. 25 | * 26 | * @param prompts The list of prompts. 27 | * @param cursor The cursor for the next page of results. 28 | */ 29 | public record PaginatedPrompts(List prompts, String cursor) 30 | implements PaginatedResponse {} 31 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/smoke/Smoke.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.smoke; 20 | 21 | /** An example of a smoke test to ensure that Java builds work. */ 22 | public final class Smoke { 23 | 24 | /** 25 | * Calculates the square of a integer. 26 | * 27 | * @param n The integer. 28 | * @return The square of the integer. 29 | */ 30 | public static int square(int n) { 31 | return n * n; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /go/example/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") 18 | 19 | go_library( 20 | name = "example_lib", 21 | srcs = ["main.go"], 22 | importpath = "github.com/google/dotprompt/go/example", 23 | visibility = ["//visibility:private"], 24 | deps = ["//go/dotprompt"], 25 | ) 26 | 27 | go_binary( 28 | name = "example", 29 | embed = [":example_lib"], 30 | visibility = ["//visibility:public"], 31 | ) 32 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/PaginatedPartials.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * A paginated list of partial references. 25 | * 26 | * @param partials The list of partials. 27 | * @param cursor The cursor for the next page of results. 28 | */ 29 | public record PaginatedPartials(List partials, String cursor) 30 | implements PaginatedResponse {} 31 | -------------------------------------------------------------------------------- /rs/smoke/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2025 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | //! Smoke test for the build system. 18 | 19 | /// A simple addition function. 20 | #[must_use] 21 | pub const fn add(left: u64, right: u64) -> u64 { 22 | left + right 23 | } 24 | 25 | #[cfg(test)] 26 | mod tests { 27 | use super::*; 28 | 29 | /// Test that the add function works. 30 | #[test] 31 | fn it_works() { 32 | let result = add(2, 2); 33 | assert_eq!(result, 4); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /scripts/format_go_files: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2025 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # SPDX-License-Identifier: Apache-2.0 17 | 18 | #set -x # Uncomment to enable tracing. 19 | set -euo pipefail 20 | 21 | if ((EUID == 0)); then 22 | echo "Please do not run as root" 23 | exit 24 | fi 25 | 26 | GO_VERSION="1.24.11" 27 | 28 | TOP_DIR=$(git rev-parse --show-toplevel) 29 | GO_DIR="$TOP_DIR/go" 30 | 31 | # Modernize and format all Go code. 32 | go mod -C "${GO_DIR}" tidy -go="${GO_VERSION}" || exit 1 33 | go fmt -C "${GO_DIR}" ./... || exit 1 34 | -------------------------------------------------------------------------------- /spec/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | load("@aspect_rules_js//js:defs.bzl", "js_library") 18 | 19 | # Export individual YAML spec files for granular test targets 20 | exports_files(glob(["**/*.yaml"])) 21 | 22 | filegroup( 23 | name = "spec", 24 | srcs = glob(["**/*.yaml"]), 25 | visibility = ["//visibility:public"], 26 | ) 27 | 28 | js_library( 29 | name = "spec_js_lib", 30 | srcs = glob(["**/*.yaml"]), 31 | visibility = ["//visibility:public"], 32 | ) 33 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/Document.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | /** 25 | * Represents an external document, often used for context. 26 | * 27 | * @param content The list of parts making up the document content. 28 | * @param metadata Arbitrary metadata. 29 | */ 30 | public record Document(List content, Map metadata) {} 31 | -------------------------------------------------------------------------------- /python/handlebarrz/smoke_tests/Dockerfile-debian-arm64: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | FROM --platform=linux/arm64 debian:bookworm 17 | 18 | RUN apt-get update && \ 19 | apt-get install -y python3 python3-pip curl && \ 20 | apt-get clean 21 | 22 | WORKDIR /project 23 | COPY . /project/ 24 | 25 | RUN curl -LsSf https://astral.sh/uv/install.sh | sh \ 26 | && . $HOME/.local/bin/env \ 27 | && uv sync --index-strategy unsafe-best-match 28 | 29 | ENV PATH="/root/.local/bin/:$PATH" 30 | 31 | -------------------------------------------------------------------------------- /third_party/docsite/src/layouts/BaseLayout.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import HeadSEO from "@/components/core/HeadSEO.astro"; 3 | import Header from "@/components/core/Header.astro"; 4 | import Footer from "@/components/core/Footer.astro"; 5 | 6 | import type { BaseLayoutProps } from "@/lib/types"; 7 | import { capitalizeFirstLetter } from "@/lib/utils"; 8 | 9 | import { LOCALE, SITE } from "config"; 10 | 11 | const { title, description, ogImage } = Astro.props as BaseLayoutProps; 12 | --- 13 | 14 | 15 | 16 | 17 | 22 | 23 | 24 |
25 |
26 |
27 | 28 |
29 |
30 |
31 | 32 | 33 | -------------------------------------------------------------------------------- /third_party/docsite/src/pages/[...slug].astro: -------------------------------------------------------------------------------- 1 | --- 2 | import { type CollectionEntry, getCollection } from "astro:content"; 3 | import type { GetStaticPaths, MarkdownHeading } from "astro"; 4 | 5 | import DocsLayout from "@/layouts/DocsLayout.astro"; 6 | 7 | import type { Heading } from "@/lib/types"; 8 | 9 | export const getStaticPaths = (async () => { 10 | const docs = await getCollection("docs", ({ data }) => !data.draft); 11 | const headings: MarkdownHeading[][] = await Promise.all( 12 | docs.map((entry) => entry.render().then((data) => data.headings)) 13 | ); 14 | 15 | const posts = docs.map((entry, index) => { 16 | return { 17 | params: { slug: entry.slug }, 18 | props: { entry, headings: headings[index] }, 19 | }; 20 | }); 21 | 22 | return posts; 23 | }) satisfies GetStaticPaths; 24 | 25 | const { entry, headings } = Astro.props as { 26 | entry: CollectionEntry<"docs">; 27 | headings: Heading[]; 28 | }; 29 | 30 | const { Content } = await entry.render(); 31 | const idAndData = { headings, ...entry.data }; 32 | --- 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /MODULE.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | """Google Dotprompt.""" 18 | 19 | module( 20 | name = "dotprompt", 21 | version = "0.0.1", 22 | ) 23 | 24 | bazel_dep(name = "bazel_skylib", version = "1.8.2") 25 | bazel_dep(name = "gazelle", version = "0.47.0") 26 | bazel_dep(name = "platforms", version = "1.0.0") 27 | 28 | include("//:go.MODULE.bazel") 29 | include("//:java.MODULE.bazel") 30 | include("//:rust.MODULE.bazel") 31 | include("//:kotlin.MODULE.bazel") 32 | include("//:ts.MODULE.bazel") 33 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/PendingPart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | import java.util.Map; 22 | 23 | /** 24 | * A content part indicating that content is pending or awaited. 25 | * 26 | * @param metadata Metadata confirming the pending state. 27 | */ 28 | public record PendingPart(Map metadata) implements Part { 29 | public PendingPart() { 30 | this(Map.of("pending", true)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /scripts/build_dists: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2025 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # SPDX-License-Identifier: Apache-2.0 17 | 18 | set -euo pipefail 19 | 20 | if ((EUID == 0)); then 21 | echo "Please do not run as root" 22 | exit 1 23 | fi 24 | 25 | TOP_DIR=$(git rev-parse --show-toplevel) 26 | 27 | # NOTE: Order matters. 28 | PROJECT_DIRS=( 29 | "python/handlebarrz" 30 | "python/dotpromptz" 31 | ) 32 | 33 | for PROJECT_DIR in "${PROJECT_DIRS[@]}"; do 34 | uv \ 35 | --directory="${TOP_DIR}" \ 36 | --project "$PROJECT_DIR" \ 37 | build 38 | done 39 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/PromptRef.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | /** 22 | * A reference to a prompt. 23 | * 24 | * @param name The name of the prompt. 25 | * @param variant The variant name for the prompt. 26 | * @param version The version of the prompt. 27 | */ 28 | public record PromptRef(String name, String variant, String version) { 29 | public PromptRef(String name) { 30 | this(name, null, null); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/RenderedPrompt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | /** 25 | * The result of rendering a prompt template. 26 | * 27 | * @param config The resolved configuration map (after merging model/options). 28 | * @param messages The list of generated messages. 29 | */ 30 | public record RenderedPrompt(Map config, List messages) {} 31 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/PartialRef.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | /** 22 | * A reference to a partial. 23 | * 24 | * @param name The name of the partial. 25 | * @param variant The variant name for the partial. 26 | * @param version The version of the partial. 27 | */ 28 | public record PartialRef(String name, String variant, String version) { 29 | public PartialRef(String name) { 30 | this(name, null, null); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /scripts/format_build_files: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2025 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # SPDX-License-Identifier: Apache-2.0 17 | 18 | #set -x # Uncomment to enable tracing. 19 | set -euo pipefail 20 | 21 | if ((EUID == 0)); then 22 | echo "Please do not run as root" 23 | exit 24 | fi 25 | 26 | TOP_DIR=$(git rev-parse --show-toplevel) 27 | 28 | if ! command -v "buildifier" >/dev/null 2>&1; then 29 | echo "Buildifier not found. Installing via go install..." 30 | go install github.com/bazelbuild/buildtools/buildifier@latest 31 | fi 32 | 33 | buildifier -r "${TOP_DIR}" 34 | -------------------------------------------------------------------------------- /third_party/docsite/src/components/core/BacktoTop.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import { Button } from "@/components/ui/button"; 3 | import { ChevronUpIcon } from "lucide-react"; 4 | --- 5 | 6 |
9 |
10 | 13 |
14 |
15 | 16 | 38 | -------------------------------------------------------------------------------- /rs/smoke/Cargo.toml: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | [package] 18 | authors = ["Yesudeep Mangalapilly "] 19 | categories = ["development-tools"] 20 | description = "A smoke test package for dotprompt workspace." 21 | edition = "2024" 22 | keywords = ["dotprompt", "smoke-test"] 23 | license = "Apache-2.0" 24 | name = "smoke" 25 | readme = "README.md" 26 | repository = "https://github.com/google/dotprompt" 27 | version = "0.1.0" 28 | 29 | [dependencies] 30 | 31 | [lints] 32 | workspace = true 33 | -------------------------------------------------------------------------------- /scripts/format_python_files: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2025 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # SPDX-License-Identifier: Apache-2.0 17 | 18 | #set -x # Uncomment to enable tracing. 19 | set -euo pipefail 20 | 21 | if ((EUID == 0)); then 22 | echo "Please do not run as root" 23 | exit 24 | fi 25 | 26 | TOP_DIR=$(git rev-parse --show-toplevel) 27 | PY_DIR="${TOP_DIR}/python" 28 | 29 | # Format all Python code and organize imports. 30 | uv run --directory "${PY_DIR}" ruff check --select I --fix --preview --unsafe-fixes . || exit 1 31 | uv run --directory "${PY_DIR}" ruff format --preview . || exit 1 32 | -------------------------------------------------------------------------------- /js/src/handlebars-cjs.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | // Type declarations for handlebars/dist/cjs/handlebars.js 20 | // This simply maps the CJS dist path to the official handlebars types 21 | declare module 'handlebars/dist/cjs/handlebars.js' { 22 | // Import and re-export everything from the main handlebars package 23 | // This leverages the official types from node_modules/handlebars/types/index.d.ts 24 | export * from 'handlebars'; 25 | import handlebars from 'handlebars'; 26 | export default handlebars; 27 | } 28 | -------------------------------------------------------------------------------- /js/src/util.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2024 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | export function removeUndefinedFields(obj: any): any { 20 | if (obj === null || typeof obj !== 'object') { 21 | return obj; 22 | } 23 | 24 | if (Array.isArray(obj)) { 25 | return obj.map((item) => removeUndefinedFields(item)); 26 | } 27 | 28 | const result: { [key: string]: any } = {}; 29 | for (const [key, value] of Object.entries(obj)) { 30 | if (value !== undefined) { 31 | result[key] = removeUndefinedFields(value); 32 | } 33 | } 34 | return result; 35 | } 36 | -------------------------------------------------------------------------------- /third_party/docsite/src/content/docs/reference.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Reference Docs 3 | --- 4 | 5 | A Dotprompt template format is made up of four parts: 6 | 7 | ```handlebars 8 | --- 9 | # (1) the Prompt Frontmatter goes here 10 | output: 11 | schema: 12 | # (2) the Picoschema definition goes here 13 | --- 14 | 15 | {{! (3) the Template Content goes here }} 16 | ``` 17 | 18 | When executed, a Dotprompt template renders into (4) Common Model Interface. 19 | 20 | ## Reference Docs 21 | 22 | 1. **[Prompt Frontmatter](/reference/frontmatter):** Included at the start of a Dotprompt template, frontmatter includes model configuration, input/output formatList, and tooling MediaMetadata. 23 | 2. **[Picoschema](/reference/picoschema):** The compact, YAML-optimized schema representation used for describing structured data in a Dotprompt template. 24 | 3. **[Template Content](/reference/template):** The core template of the prompt, based on Handlebars and extended with GenAI-specific capabilities. 25 | 4. **[Common Model Interface](/reference/model):** The "output" of a rendered Dotprompt template, a JSON object containing the rendered messages represented by the template as well as all associated metadata and configuration. 26 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/PaginatedResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | /** 22 | * Base interface for paginated responses. 23 | * 24 | *

This interface defines the common cursor field used for pagination across list operations. 25 | */ 26 | public interface PaginatedResponse { 27 | 28 | /** 29 | * Gets the cursor for fetching the next page of results. 30 | * 31 | * @return The pagination cursor, or null if there are no more results. 32 | */ 33 | String cursor(); 34 | } 35 | -------------------------------------------------------------------------------- /scripts/lint: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2025 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # SPDX-License-Identifier: Apache-2.0 17 | 18 | set -euo pipefail 19 | 20 | if ((EUID == 0)); then 21 | echo "Please do not run as root" 22 | exit 1 23 | fi 24 | 25 | TOP_DIR=$(git rev-parse --show-toplevel) 26 | PY_DIR="${TOP_DIR}/python" 27 | 28 | uv run --directory "${PY_DIR}" ruff check --select I --fix --preview --unsafe-fixes . 29 | # uv run --directory "${PY_DIR}" mypy . 30 | 31 | # Add pylyzer, ty, and pyrefly 32 | #uv run --directory "${PY_DIR}" pylyzer --check . 33 | uv run --directory "${PY_DIR}" ty check 34 | #uv run --directory "${PY_DIR}" pyrefly check 35 | -------------------------------------------------------------------------------- /python/handlebarrz/dockerfile-alpine: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | FROM --platform=linux/arm64 alpine:latest 17 | 18 | RUN apk add --no-cache python3 py3-pip \ 19 | build-base gcc musl-dev curl bash 20 | 21 | ENV PATH="/root/.cargo/bin:$PATH" 22 | ENV PATH="/root/.local/bin/:$PATH" 23 | 24 | RUN curl https://sh.rustup.rs -sSf | sh -s -- -y \ 25 | && source "$HOME/.cargo/env" \ 26 | && rustup target add aarch64-unknown-linux-musl 27 | 28 | WORKDIR /project 29 | COPY pyproject.toml /project/ 30 | 31 | RUN curl -LsSf https://astral.sh/uv/install.sh | sh \ 32 | && source $HOME/.local/bin/env 33 | 34 | -------------------------------------------------------------------------------- /third_party/docsite/src/components/docs/BacktoTop.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import { Button } from "@/components/ui/button"; 3 | 4 | import { ChevronUp } from "lucide-react"; 5 | 6 | // To pass the tailwindcss classes to the astro component 7 | const { class: className } = Astro.props; 8 | --- 9 | 10 | 18 | 19 | 43 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/PromptData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | /** 22 | * Represents a prompt's data including its source code. 23 | * 24 | * @param name The name of the prompt. 25 | * @param variant The variant name for the prompt. 26 | * @param version The version of the prompt. 27 | * @param source The source code of the prompt. 28 | */ 29 | public record PromptData(String name, String variant, String version, String source) { 30 | public PromptData(String name, String source) { 31 | this(name, null, null, source); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/PartialData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | /** 22 | * Represents a partial's data including its source code. 23 | * 24 | * @param name The name of the partial. 25 | * @param variant The variant name for the partial. 26 | * @param version The version of the partial. 27 | * @param source The source code of the partial. 28 | */ 29 | public record PartialData(String name, String variant, String version, String source) { 30 | public PartialData(String name, String source) { 31 | this(name, null, null, source); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /python/handlebarrz/smoke_tests/handlebarrz_test.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | """Test code for smoke tests.""" 18 | 19 | from handlebarrz import HelperOptions, Template 20 | 21 | 22 | def loud_helper(params: list[str], options: HelperOptions) -> str: 23 | """Test helper.""" 24 | # Get the first parameter or use an empty string 25 | text = params[0] if params else '' 26 | return text.upper() 27 | 28 | 29 | template = Template() 30 | template.register_helper('loud', loud_helper) 31 | template_string = '{{loud name}}' 32 | template.register_template('test', template_string) 33 | print(template.render('test', {'name': 'world'})) 34 | -------------------------------------------------------------------------------- /python/handlebarrz/generate-alpine-wheels.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2025 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # SPDX-License-Identifier: Apache-2.0 18 | export UV_LINK_MODE=copy 19 | export PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 20 | 21 | PYTHON_VERSION="python$1" 22 | 23 | echo "building for python version $PYTHON_VERSION" 24 | 25 | # linux 26 | echo "building with maturin for linux alpine" 27 | uv run --python $1 maturin build --release --target aarch64-unknown-linux-musl -i $PYTHON_VERSION 28 | 29 | DIRECTORY="target/wheels/" 30 | 31 | FILES=$(find "$DIRECTORY" -type f -name "*linux_aarch64*") 32 | if [[ -n "$FILES" ]]; then 33 | echo "removing local wheel" 34 | rm -f $FILES 35 | fi 36 | 37 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/Message.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | /** 25 | * Represents a chat message in a prompt. 26 | * 27 | * @param role The role of the message sender (user, model, etc.). 28 | * @param content The list of parts forming the message content. 29 | * @param metadata Arbitrary metadata. 30 | */ 31 | public record Message(Role role, List content, Map metadata) { 32 | public Message(Role role, List content) { 33 | this(role, content, null); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /scripts/update_deps: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2025 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # SPDX-License-Identifier: Apache-2.0 17 | 18 | set -x 19 | set -euo pipefail 20 | 21 | if ((EUID == 0)); then 22 | echo "Please do not run as root" 23 | exit 1 24 | fi 25 | 26 | TOP_DIR=$(git rev-parse --show-toplevel) 27 | 28 | PY_DIR="${TOP_DIR}/python" 29 | HANDLEBARRZ_DIR="${TOP_DIR}/python/handlebarrz" 30 | GO_DIR="${TOP_DIR}/go" 31 | JS_DIR="${TOP_DIR}" 32 | 33 | pushd "${JS_DIR}" 34 | pnpm update -L -r 35 | popd 36 | 37 | pushd "${GO_DIR}" 38 | go get -u ./... 39 | go mod tidy 40 | popd 41 | 42 | pushd "${HANDLEBARRZ_DIR}" 43 | cargo update 44 | popd 45 | 46 | pushd "${PY_DIR}" 47 | uv lock --upgrade 48 | popd 49 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/smoke/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | load("@rules_java//java:defs.bzl", "java_library", "java_test") 18 | 19 | java_library( 20 | name = "smoke", 21 | srcs = ["Smoke.java"], 22 | visibility = ["//visibility:public"], 23 | ) 24 | 25 | java_test( 26 | name = "SmokeTest", 27 | srcs = ["SmokeTest.java"], 28 | test_class = "com.google.dotprompt.smoke.SmokeTest", 29 | deps = [ 30 | ":smoke", 31 | "@maven//:com_github_jknack_handlebars", 32 | "@maven//:com_google_guava_guava", 33 | "@maven//:com_google_truth_truth", 34 | "@maven//:junit_junit", 35 | ], 36 | ) 37 | -------------------------------------------------------------------------------- /python/dotpromptz/src/dotpromptz/models.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | """Pydantic model utilities.""" 18 | 19 | from collections.abc import Sequence 20 | from typing import Any 21 | 22 | from pydantic import BaseModel 23 | 24 | 25 | def dump_models(items: Sequence[BaseModel] | None) -> list[dict[str, Any]]: 26 | """Dumps a list of Pydantic models to a list of dictionaries. 27 | 28 | Args: 29 | items: The list of Pydantic models to dump. 30 | 31 | Returns: 32 | A list of dictionaries. 33 | """ 34 | if not items: 35 | return [] 36 | return [item.model_dump(exclude_none=True, by_alias=True) for item in items] 37 | -------------------------------------------------------------------------------- /python/handlebarrz/dockerfile-arm64: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | FROM --platform=linux/arm64 debian:bookworm 18 | 19 | # Install tools 20 | RUN apt-get update && apt-get install -y python3 \ 21 | python3-pip curl bash 22 | 23 | ENV PATH="/root/.cargo/bin:$PATH" 24 | ENV PATH="/root/.local/bin/:$PATH" 25 | 26 | RUN curl https://sh.rustup.rs -sSf | sh -s -- -y \ 27 | && . "$HOME/.cargo/env" \ 28 | && rustup target add aarch64-unknown-linux-gnu \ 29 | && rustup target add aarch64-apple-darwin 30 | 31 | WORKDIR /project 32 | COPY pyproject.toml /project/ 33 | 34 | RUN curl -LsSf https://astral.sh/uv/install.sh | sh \ 35 | && . $HOME/.local/bin/env 36 | 37 | -------------------------------------------------------------------------------- /third_party/docsite/src/components/docs/Breadcrumbs.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import { 3 | Breadcrumb, 4 | BreadcrumbItem, 5 | BreadcrumbLink, 6 | BreadcrumbList, 7 | } from "@/components/ui/breadcrumb"; 8 | 9 | import type { BreadcrumbsProps } from "@/lib/types"; 10 | import { buildBreadcrumbs } from "@/lib/utils"; 11 | 12 | // Get the current document's slug from route params 13 | const slug: string = Astro.url.pathname; 14 | 15 | // Build the breadcrumb trail 16 | const breadcrumbs: BreadcrumbsProps = buildBreadcrumbs(slug || ""); 17 | 18 | // To pass the tailwindcss classes to the astro component 19 | const { class: className } = Astro.props; 20 | --- 21 | 22 |

23 | 24 | 25 | { 26 | breadcrumbs.map((breadcrumb, index) => ( 27 | 28 | {index < breadcrumbs.length - 1 ? ( 29 | 30 | {breadcrumb.title} 31 | 32 | ) : ( 33 | {breadcrumb.title} 34 | )} 35 | {index < breadcrumbs.length - 1 && / } 36 | 37 | )) 38 | } 39 | 40 | 41 |
42 | -------------------------------------------------------------------------------- /third_party/docsite/src/components/docs/MainContent.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import Datetime from "@/components/core/Datetime"; 3 | 4 | import Breadcrumbs from "@/components/docs/Breadcrumbs.astro"; 5 | 6 | import type { MainContentProps } from "@/lib/types"; 7 | import { capitalizeFirstLetter } from "@/lib/utils"; 8 | 9 | import { docconfig } from "config"; 10 | import BacktoTop from "@/components/core/BacktoTop.astro"; 11 | 12 | const { 13 | title, 14 | author, 15 | pubDatetime, 16 | modDatetime, 17 | description, 18 | draft, 19 | tags, 20 | hide_breadcrumbs, 21 | headings, 22 | } = Astro.props as MainContentProps; 23 | --- 24 | 25 |
26 | {!docconfig.hide_breadcrumbs && !hide_breadcrumbs && } 27 |

{capitalizeFirstLetter(title)}

28 | { 29 | !docconfig.hide_datetime && pubDatetime && ( 30 | 37 | ) 38 | } 39 | {!docconfig.hide_author &&
By {author}
} 40 |
41 | 42 |
43 | 44 |
45 | -------------------------------------------------------------------------------- /.github/release-please.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | # We follow conventional commit format for our commit messages. 18 | # See: https://www.conventionalcommits.org/en/v1.0.0/ 19 | # See: https://github.com/googleapis/release-please#how-should-i-write-my-commits 20 | 21 | handlePrefix: true 22 | primaryBranch: main 23 | plugins: 24 | - "@type": node 25 | applyVersionLabel: false 26 | 27 | types: 28 | - feat 29 | - fix 30 | - docs 31 | - style 32 | - refactor 33 | - perf 34 | - test 35 | - build 36 | - ci 37 | - chore 38 | - revert 39 | 40 | scopes: 41 | - deps 42 | - go 43 | - java 44 | - js 45 | - py 46 | - py/dotpromptz 47 | - py/handlebarrz 48 | - rs 49 | -------------------------------------------------------------------------------- /python/handlebarrz/dockerfile-x86-64: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | FROM ubuntu:latest 17 | 18 | RUN apt-get update && apt-get install -y python3 \ 19 | python3-pip curl bash 20 | 21 | ENV PATH="/root/.cargo/bin:$PATH" 22 | ENV PATH="/root/.local/bin/:$PATH" 23 | 24 | RUN curl https://sh.rustup.rs -sSf | sh -s -- -y \ 25 | && . "$HOME/.cargo/env" \ 26 | && rustup target add x86_64-unknown-linux-gnu \ 27 | && rustup target add x86_64-pc-windows-msvc \ 28 | && rustup target add x86_64-apple-darwin \ 29 | && rustup component add llvm-tools 30 | 31 | WORKDIR /project 32 | COPY pyproject.toml /project/ 33 | 34 | RUN curl -LsSf https://astral.sh/uv/install.sh | sh \ 35 | && . $HOME/.local/bin/env 36 | 37 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/store/DirStoreOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.store; 20 | 21 | import java.nio.file.Path; 22 | 23 | /** 24 | * Configuration options for directory-based prompt stores. 25 | * 26 | * @param directory The base directory where prompt files are stored. 27 | */ 28 | public record DirStoreOptions(Path directory) { 29 | 30 | /** 31 | * Creates options from a string path. 32 | * 33 | * @param directory The directory path as a string. 34 | * @return A new DirStoreOptions instance. 35 | */ 36 | public static DirStoreOptions of(String directory) { 37 | return new DirStoreOptions(Path.of(directory)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /rust.MODULE.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | """Configuration for Bazel with Rust dependencies.""" 18 | 19 | bazel_dep(name = "rules_rust", version = "0.68.1") 20 | 21 | rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") 22 | rust.toolchain( 23 | edition = "2024", 24 | versions = ["1.86.0"], 25 | ) 26 | use_repo(rust, "rust_toolchains") 27 | 28 | register_toolchains("@rust_toolchains//:all") 29 | 30 | crate = use_extension("@rules_rust//crate_universe:extension.bzl", "crate") 31 | crate.from_cargo( 32 | name = "crates", 33 | cargo_lockfile = "//:Cargo.lock", 34 | manifests = [ 35 | "//:Cargo.toml", 36 | "//rs/smoke:Cargo.toml", 37 | ], 38 | ) 39 | use_repo(crate, "crates") 40 | -------------------------------------------------------------------------------- /spec/helpers/media.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | 18 | # Tests for the {{media}} helper which formats media URLs with content type 19 | # information in message content. 20 | 21 | # Tests that media URLs are properly formatted with content type in the 22 | # message content array. 23 | - name: basic 24 | template: "{{media contentType=contentType url=url}}" 25 | tests: 26 | - desc: renders media part 27 | data: { input: { contentType: "image/jpeg", url: "http://a/b/c" } } 28 | expect: 29 | messages: 30 | - role: user 31 | content: 32 | [ 33 | { 34 | media: { "contentType": "image/jpeg", "url": "http://a/b/c" }, 35 | }, 36 | ] 37 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/ToolRequestPart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | import java.util.Map; 22 | 23 | /** 24 | * A content part representing a request to invoke a tool. 25 | * 26 | * @param toolRequest The details of the tool request. 27 | */ 28 | public record ToolRequestPart(ToolRequestContent toolRequest) implements Part {} 29 | 30 | /** 31 | * Describes the details of a tool request. 32 | * 33 | * @param name The name of the tool being requested. 34 | * @param input The input parameters for the tool request. 35 | * @param ref An optional reference identifier. 36 | */ 37 | record ToolRequestContent(String name, Map input, String ref) {} 38 | -------------------------------------------------------------------------------- /scripts/run_python_checks_with_nox: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2025 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # SPDX-License-Identifier: Apache-2.0 17 | 18 | # Run tests for all supported Python versions using tox 19 | 20 | set -euo pipefail 21 | 22 | if ((EUID == 0)); then 23 | echo "Please do not run as root" 24 | exit 1 25 | fi 26 | 27 | TOP_DIR=$(git rev-parse --show-toplevel) 28 | PY_DIR="$TOP_DIR/python" 29 | 30 | echo "=== Running Python lint ===" 31 | uv run --directory "${PY_DIR}" ruff check --select I --fix --preview --unsafe-fixes . 32 | uv run --directory "${PY_DIR}" ty check 33 | 34 | echo "=== Running Python tests (nox) ===" 35 | echo "Project root: ${TOP_DIR}" 36 | echo "Python directory: ${PY_DIR}" 37 | echo "" 38 | 39 | uv run --active --directory "$PY_DIR" nox "$@" 40 | 41 | echo "=== Python tests completed ===" 42 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/ToolResponsePart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | import java.util.Map; 22 | 23 | /** 24 | * A content part representing the result from a tool execution. 25 | * 26 | * @param toolResponse The details of the tool response. 27 | */ 28 | public record ToolResponsePart(ToolResponseContent toolResponse) implements Part {} 29 | 30 | /** 31 | * Describes the details of a tool response. 32 | * 33 | * @param name The name of the tool that produced this response. 34 | * @param output The output data returned by the tool. 35 | * @param ref An optional reference identifier. 36 | */ 37 | record ToolResponseContent(String name, Map output, String ref) {} 38 | -------------------------------------------------------------------------------- /go/example/doc.md: -------------------------------------------------------------------------------- 1 | # Go Dotprompt Library Usage Example 2 | 3 | This directory contains sample code demonstrating how to use the `dotprompt` library in Go. 4 | 5 | ## File Structure 6 | 7 | - `example.prompt`: The prompt definition file. It defines metadata with YAML front matter and the template in the body. 8 | - `main.go`: An executable program that reads, parses, and renders `example.prompt` and outputs the result. 9 | 10 | ## How to Run 11 | 12 | 1. Change the current directory to `go/example`. 13 | ```bash 14 | cd go/example 15 | ``` 16 | 17 | 2. Tidy the dependencies. 18 | ```bash 19 | go mod tidy 20 | ``` 21 | 22 | 3. Run the program. 23 | ```bash 24 | go run main.go 25 | ``` 26 | 27 | ## Output 28 | 29 | When you run the program, the metadata from the `.prompt` file and the messages after applying the data will be displayed on standard output. 30 | 31 | ```text 32 | --- Metadata --- 33 | Model: gemini-1.5-flash 34 | Description: Summarize the input text. 35 | 36 | --- Messages --- 37 | Role: user 38 | Content: Please summarize the following text. 39 | 40 | dotprompt is a library and toolset for managing and executing prompts. It defines metadata with YAML front matter and describes the prompt body with Handlebars templates. This makes it easy to reuse, maintain, and version control prompts. 41 | ---------- 42 | Role: model 43 | Content: Yes, I understand. I will summarize it. 44 | ---------- 45 | -------------------------------------------------------------------------------- /js/.guides/usage.md: -------------------------------------------------------------------------------- 1 | Dotprompt (the `.prompt` file format) is used by creating `.prompt` files with YAML frontmatter and Handlebars to provide rich content for LLMs. A simple example: 2 | 3 | ```handlebars generate_character.prompt 4 | --- 5 | model: googleai/gemini-2.5-flash 6 | input: 7 | schema: 8 | setting: string, where the character lives 9 | personality?: string, the personality of the character 10 | output: 11 | schema: 12 | name: string, the name of the character 13 | skills(array, list of character skills): string 14 | attributes: 15 | strength: number, strength [0-5] 16 | dexterity: number, dexterity [0-10] 17 | --- 18 | 19 | Generate a character who lives in {{setting}}{{#if personality}} with personality {{personality}}{{/if}}. 20 | ``` 21 | 22 | - Dotprompt uses a special YAML-optimized schema definition format. Scalars: `string`, `number`, `boolean`. For arrys use parens: `fieldName(array, desc goes here):`, add descriptions after a comma e.g. `fieldName: boolean, desc goes here`. 23 | - Always use Handlebars syntax for expressions `{{#if ... }}`, NEVER use `{% if ... %}`. 24 | - Available helpers (# for block): `{{#if ...}}`, `{{#unless ...}}`, `{{#each ...}}`, {{json ...}}` (render object as json), `{{role "system"}}` (change message role), `{{media url="..."}}` (insert multimodal content). 25 | - Partials can be created with `_partial_name.prompt` and included with `{{> partial_name}}` inside the prompts directory. -------------------------------------------------------------------------------- /python/tests/smoke/package_test.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | """Smoke tests for package structure.""" 18 | 19 | # TODO: Replace this with proper imports once we have a proper implementation. 20 | from dotpromptz import package_name as dotpromptz_package_name 21 | 22 | 23 | def square(n: int | float) -> int | float: 24 | return n * n 25 | 26 | 27 | def test_package_names() -> None: 28 | assert dotpromptz_package_name() == 'dotpromptz' 29 | 30 | 31 | # TODO: Failing test on purpose to be removed after we complete 32 | # this runtime and stop skipping all failures. 33 | # def test_skip_failures() -> None: 34 | # assert dotpromptz_package_name() == 'skip.failures' 35 | 36 | 37 | def test_square() -> None: 38 | assert square(2) == 4 39 | assert square(3) == 9 40 | assert square(4) == 16 41 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/DataArgument.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | /** 25 | * Data provided to render a prompt. 26 | * 27 | * @param input Input variables for the prompt template. 28 | * @param docs Relevant documents. 29 | * @param messages Previous messages in the history of a multi-turn conversation. 30 | * @param context Additional context for rendering (e.g. `@state`). 31 | */ 32 | public record DataArgument( 33 | Map input, 34 | List docs, 35 | List messages, 36 | Map context) { 37 | 38 | public DataArgument(Map input) { 39 | this(input, null, null, null); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /.github/workflows/golangci-lint.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | name: golangci-lint 18 | on: 19 | push: 20 | branches: 21 | - main 22 | - master 23 | pull_request: 24 | paths: 25 | - "go/**" 26 | - ".github/workflows/golangci-lint.yml" 27 | 28 | permissions: 29 | contents: read 30 | # Optional: allow read access to pull request. Use with `only-new-issues` option. 31 | # pull-requests: read 32 | 33 | jobs: 34 | golangci: 35 | name: lint 36 | runs-on: ubuntu-latest 37 | steps: 38 | - uses: actions/checkout@v6 39 | - uses: actions/setup-go@v6 40 | with: 41 | go-version: stable 42 | - name: golangci-lint 43 | uses: golangci/golangci-lint-action@v6 44 | with: 45 | version: v1.64 46 | working-directory: go 47 | -------------------------------------------------------------------------------- /BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | load("@aspect_rules_js//npm:defs.bzl", "npm_link_package") 18 | load("@gazelle//:def.bzl", "gazelle") 19 | load("@npm//:defs.bzl", "npm_link_all_packages") 20 | 21 | package(default_visibility = ["//visibility:public"]) 22 | 23 | # gazelle:prefix github.com/google/dotprompt 24 | gazelle(name = "gazelle") 25 | 26 | # Building this package creates bazel-bin/node_modules/@google/dotprompt 27 | # so that other packages can depend on this target. 28 | npm_link_package( 29 | name = "node_modules/@google/dotprompt", 30 | src = "//js:pkg", 31 | package = "@google/dotprompt", 32 | visibility = ["//visibility:public"], 33 | ) 34 | 35 | # This macro expands to a npm_link_package for each of the dependencies in 36 | # package.json. 37 | npm_link_all_packages(name = "node_modules") 38 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/ToolDefinition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | import java.util.Map; 23 | 24 | /** 25 | * Defines a tool that can be called by a model. 26 | * 27 | * @param name The unique identifier for the tool. 28 | * @param description A human-readable explanation of the tool's purpose. 29 | * @param inputSchema A schema definition for the expected input parameters. 30 | * @param outputSchema An optional schema definition for the output. 31 | */ 32 | public record ToolDefinition( 33 | String name, 34 | String description, 35 | @JsonProperty("inputSchema") Map inputSchema, 36 | @JsonProperty("outputSchema") Map outputSchema) {} 37 | -------------------------------------------------------------------------------- /third_party/docsite/src/content/docs/implementations.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Implementations 3 | --- 4 | 5 | The following is a community-curated list of Dotprompt implementations in various languages and systems. 6 | 7 | ## Node.js 8 | 9 | | Name | Description | Links | 10 | | --- | --- | --- | 11 | | [Firebase Genkit](https://github.com/firebase/genkit) | The GenAI SDK for app developers. | [Docs](https://firebase.google.com/docs/genkit) [NPM](https://npmjs.com/packages/genkit) | 12 | 13 | ## Go 14 | 15 | | Name | Description | Links | 16 | | --- | --- | --- | 17 | | [Firebase Genkit](https://github.com/firebase/genkit) | The GenAI SDK for app developers. | [Docs](https://firebase.google.com/docs/genkit) [GoDoc](https://pkg.go.dev/github.com/firebase/genkit/go/genkit) | 18 | 19 | ## Dart 20 | 21 | | Name | Description | Links | 22 | | --- | --- | --- | 23 | | [ShipFlutter](https://shipflutter.com/) | A customizable Flutter starter kit. | [Docs](https://shipflutter.com/docs/ai/vertex/) | 24 | | [dartantic_ai](https://pub.dev/packages/dartantic_ai) | A Dart Agent framework inspired by pydantic-ai. | [Docs](https://pub.dev/packages/dartantic_ai) [GitHub](https://github.com/csells/dartantic_ai) | 25 | | [dotprompt_dart](https://pub.dev/packages/dotprompt_dart) | A dotprompt-client parser and validator for Dart; relies on [dartantic_ai](https://pub.dev/packages/dartantic_ai) for execution. | [Docs](https://pub.dev/packages/dotprompt_dart) [GitHub](https://github.com/csells/dotprompt_dart) | 26 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/Part.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | import com.fasterxml.jackson.annotation.JsonSubTypes; 22 | import com.fasterxml.jackson.annotation.JsonTypeInfo; 23 | 24 | /** 25 | * Marker interface for message parts (e.g. text, media). 26 | * 27 | *

Uses Jackson polymorphism to deserialize into specific sub-types. 28 | */ 29 | @JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION) 30 | @JsonSubTypes({ 31 | @JsonSubTypes.Type(value = TextPart.class), 32 | @JsonSubTypes.Type(value = MediaPart.class), 33 | @JsonSubTypes.Type(value = ToolRequestPart.class), 34 | @JsonSubTypes.Type(value = ToolResponsePart.class), 35 | @JsonSubTypes.Type(value = DataPart.class), 36 | @JsonSubTypes.Type(value = PendingPart.class) 37 | }) 38 | public interface Part {} 39 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/helpers/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | load("@rules_java//java:defs.bzl", "java_library", "java_test") 18 | 19 | java_library( 20 | name = "helpers", 21 | srcs = [ 22 | "Helpers.java", 23 | ], 24 | visibility = ["//visibility:public"], 25 | deps = [ 26 | "@maven//:com_fasterxml_jackson_core_jackson_core", 27 | "@maven//:com_fasterxml_jackson_core_jackson_databind", 28 | "@maven//:com_github_jknack_handlebars", 29 | ], 30 | ) 31 | 32 | java_test( 33 | name = "HelpersTest", 34 | srcs = ["HelpersTest.java"], 35 | test_class = "com.google.dotprompt.helpers.HelpersTest", 36 | deps = [ 37 | ":helpers", 38 | "@maven//:com_github_jknack_handlebars", 39 | "@maven//:com_google_truth_truth", 40 | "@maven//:junit_junit", 41 | ], 42 | ) 43 | -------------------------------------------------------------------------------- /go.MODULE.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | """Configuration for Bazel with Go dependencies.""" 18 | 19 | GO_VERSION = "1.24.11" 20 | 21 | bazel_dep(name = "rules_go", version = "0.59.0", repo_name = "io_bazel_rules_go") 22 | 23 | go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk") 24 | go_sdk.download( 25 | name = "go_sdk", 26 | version = GO_VERSION, 27 | ) 28 | use_repo(go_sdk, "go_sdk") 29 | 30 | register_toolchains("@go_sdk//:all") 31 | 32 | go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps") 33 | go_deps.from_file(go_mod = "//go:go.mod") 34 | use_repo( 35 | go_deps, 36 | "com_github_go_viper_mapstructure_v2", 37 | "com_github_goccy_go_yaml", 38 | "com_github_invopop_jsonschema", 39 | "com_github_mbleigh_raymond", 40 | "com_github_stretchr_testify", 41 | "com_github_wk8_go_ordered_map_v2", 42 | ) 43 | -------------------------------------------------------------------------------- /go/dotprompt/test/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 18 | 19 | go_library( 20 | name = "test", 21 | srcs = [ 22 | "spec_parser_func.go", 23 | "types.go", 24 | ], 25 | importpath = "github.com/google/dotprompt/go/dotprompt/test", 26 | visibility = ["//visibility:public"], 27 | deps = [ 28 | "//go/dotprompt", 29 | "@com_github_goccy_go_yaml//:go-yaml", 30 | "@com_github_invopop_jsonschema//:jsonschema", 31 | ], 32 | ) 33 | 34 | go_test( 35 | name = "test_test", 36 | srcs = ["spec_test.go"], 37 | data = ["//spec"], 38 | embed = [":test"], 39 | deps = [ 40 | "//go/dotprompt", 41 | "@com_github_go_viper_mapstructure_v2//:mapstructure", 42 | "@com_github_invopop_jsonschema//:jsonschema", 43 | ], 44 | ) 45 | -------------------------------------------------------------------------------- /go/dotprompt/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2025 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | // Package dotprompt provides functionality for parsing and working with 18 | // dotprompt templates. 19 | // 20 | // Dotprompt is a format for defining prompts for large language models (LLMs) 21 | // with support for templating, history management, and multi-modal content. 22 | // This Go implementation provides types and functions for parsing dotprompt 23 | // templates and converting them into structured messages that can be sent to 24 | // LLM APIs. 25 | // 26 | // The package includes: 27 | // - Type definitions for messages, parts, documents, and other dotprompt 28 | // concepts 29 | // - Functions for parsing dotprompt templates into structured data 30 | // - Utilities for handling message history and multi-modal content 31 | // - Support for extracting and processing frontmatter metadata 32 | package dotprompt 33 | -------------------------------------------------------------------------------- /third_party/docsite/src/content/config.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2024 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { defineCollection, z } from "astro:content"; 18 | import { SITE } from "config"; 19 | 20 | const docs = defineCollection({ 21 | type: "content", 22 | schema: z.object({ 23 | title: z.string(), 24 | author: z.string().default(SITE.author), 25 | sort_order: z.number().optional(), 26 | pubDatetime: z.date().optional(), 27 | modDatetime: z.date().optional().nullable(), 28 | description: z.string().optional(), 29 | draft: z.boolean().default(false), 30 | tags: z.array(z.string()).default([]), 31 | hide_breadcrumbs: z.boolean().optional().default(false), 32 | hide_toc: z.boolean().optional().default(false), 33 | hide_sidenav: z.boolean().optional().default(false), 34 | max_width: z.boolean().optional().default(false), 35 | }), 36 | }); 37 | 38 | export const collections = { 39 | docs, 40 | }; 41 | -------------------------------------------------------------------------------- /scripts/run_tests: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2025 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # SPDX-License-Identifier: Apache-2.0 17 | 18 | set -euo pipefail 19 | 20 | if ((EUID == 0)); then 21 | echo "Please do not run as root" 22 | exit 1 23 | fi 24 | 25 | TOP_DIR=$(git rev-parse --show-toplevel) 26 | 27 | "${TOP_DIR}/scripts/run_go_checks" 28 | if [ $? -ne 0 ]; then 29 | echo "Go tests failed." 30 | exit 1 31 | fi 32 | 33 | "${TOP_DIR}/scripts/run_rust_checks" 34 | if [ $? -ne 0 ]; then 35 | echo "Rust tests failed." 36 | exit 1 37 | fi 38 | 39 | "${TOP_DIR}/scripts/run_handlebarrz_checks" 40 | if [ $? -ne 0 ]; then 41 | echo "Handlebarrz tests failed." 42 | exit 1 43 | fi 44 | 45 | "${TOP_DIR}/scripts/run_python_checks" 46 | if [ $? -ne 0 ]; then 47 | echo "Python tests failed." 48 | exit 1 49 | fi 50 | 51 | "${TOP_DIR}/scripts/run_js_checks" 52 | if [ $? -ne 0 ]; then 53 | echo "JavaScript tests failed." 54 | exit 1 55 | fi 56 | 57 | exit $? 58 | -------------------------------------------------------------------------------- /python/handlebarrz/Cargo.toml: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | [package] 18 | authors = ["Yesudeep Mangalapilly "] 19 | description = "Handlebars library for Python based on handlebars-rust" 20 | documentation = "https://github.com/google/dotprompt" 21 | edition = "2024" 22 | homepage = "https://github.com/google/dotprompt" 23 | license = "Apache-2.0" 24 | name = "handlebarrz" 25 | repository = "https://github.com/google/dotprompt" 26 | version = "0.1.1" 27 | 28 | [lib] 29 | crate-type = ["cdylib"] 30 | name = "handlebarrz" 31 | 32 | [dependencies] 33 | handlebars = "6.3.2" 34 | pyo3 = { version = "0.24.2", features = [ 35 | "extension-module", 36 | "generate-import-lib", 37 | ] } 38 | serde = { version = "1.0", features = ["derive"] } 39 | serde_json = "1.0" 40 | 41 | # TODO: Enable workspace lints once linker errors are fixed. 42 | #[lints] 43 | #workspace = true 44 | -------------------------------------------------------------------------------- /python/dotpromptz/tests/dotpromptz/models_test.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | """Unit tests for the models module.""" 18 | 19 | import unittest 20 | 21 | from pydantic import BaseModel 22 | 23 | from dotpromptz.models import dump_models 24 | 25 | 26 | class TestModel(BaseModel): 27 | """Test model.""" 28 | 29 | name: str 30 | age: int 31 | 32 | 33 | class TestDumpList(unittest.TestCase): 34 | """Unit tests for the dump_list function.""" 35 | 36 | def test_dump_list(self) -> None: 37 | """Test that dump_list returns the correct output.""" 38 | self.assertEqual(dump_models([]), []) 39 | self.assertEqual(dump_models([TestModel(name='test', age=1)]), [{'name': 'test', 'age': 1}]) 40 | self.assertEqual( 41 | dump_models([TestModel(name='test', age=1), TestModel(name='test2', age=2)]), 42 | [{'name': 'test', 'age': 1}, {'name': 'test2', 'age': 2}], 43 | ) 44 | -------------------------------------------------------------------------------- /js/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dotprompt", 3 | "version": "1.1.2", 4 | "description": "Dotprompt: Executable GenAI Prompt Templates", 5 | "main": "dist/index.js", 6 | "types": "dist/index.d.ts", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/google/dotprompt.git", 10 | "directory": "js" 11 | }, 12 | "scripts": { 13 | "compile": "tsup-node src/index.ts --dts --format esm,cjs", 14 | "build": "pnpm run compile && tsc -p ./tsconfig.build.json --noEmit", 15 | "build:native": "pnpm run compile && tsgo -p ./tsconfig.build.json --noEmit", 16 | "watch": "pnpm run compile -- --watch", 17 | "test": "vitest run --coverage", 18 | "test:watch": "vitest" 19 | }, 20 | "keywords": [ 21 | "genai", 22 | "prompting", 23 | "llms", 24 | "templating", 25 | "handlebars" 26 | ], 27 | "author": "", 28 | "license": "ISC", 29 | "devDependencies": { 30 | "@types/node": "25.0.0", 31 | "@typescript/native-preview": "7.0.0-dev.20251211.1", 32 | "@vitest/coverage-v8": "^4.0.15", 33 | "prettier": "^3.7.4", 34 | "tsup": "^8.5.1", 35 | "tsx": "^4.21.0", 36 | "typedoc": "^0.28.15", 37 | "typedoc-plugin-markdown": "^4.9.0", 38 | "typescript": "^5.9.3", 39 | "vitest": "^4.0.15" 40 | }, 41 | "dependencies": { 42 | "handlebars": "^4.7.8", 43 | "yaml": "^2.8.2" 44 | }, 45 | "packageManager": "pnpm@10.2.0", 46 | "pnpm": { 47 | "overrides": { 48 | "rollup@>=4.0.0 <4.22.4": ">=4.22.4", 49 | "cross-spawn@>=7.0.0 <7.0.5": ">=7.0.5" 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /third_party/docsite/src/components/ui/separator.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2024 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import * as React from "react" 18 | import * as SeparatorPrimitive from "@radix-ui/react-separator" 19 | 20 | import { cn } from "@/lib/utils" 21 | 22 | const Separator = React.forwardRef< 23 | React.ElementRef, 24 | React.ComponentPropsWithoutRef 25 | >( 26 | ( 27 | { className, orientation = "horizontal", decorative = true, ...props }, 28 | ref 29 | ) => ( 30 | 41 | ) 42 | ) 43 | Separator.displayName = SeparatorPrimitive.Root.displayName 44 | 45 | export { Separator } 46 | -------------------------------------------------------------------------------- /third_party/docsite/src/components/ui/input.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2024 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import * as React from "react"; 18 | 19 | import { cn } from "@/lib/utils"; 20 | 21 | export interface InputProps 22 | extends React.InputHTMLAttributes {} 23 | 24 | const Input = React.forwardRef( 25 | ({ className, type, ...props }, ref) => { 26 | return ( 27 | 36 | ); 37 | }, 38 | ); 39 | Input.displayName = "Input"; 40 | 41 | export { Input }; 42 | -------------------------------------------------------------------------------- /third_party/docsite/src/components/core/Icons.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2024 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { Mail, type LucideIcon } from "lucide-react"; 18 | 19 | import { 20 | Github, 21 | Facebook, 22 | Instagram, 23 | Linkedin, 24 | X as Twitter, 25 | Twitch, 26 | Youtube, 27 | Whatsapp, 28 | Snapchat, 29 | Pinterest, 30 | Discord, 31 | Gitlab, 32 | Reddit, 33 | Telegram, 34 | Mastodon, 35 | } from "simple-icons-astro"; 36 | 37 | type IconComponent = LucideIcon | ((props: any) => JSX.Element); 38 | 39 | export const ICONS: { [key: string]: IconComponent } = { 40 | Github, 41 | Facebook, 42 | Instagram, 43 | LinkedIn: Linkedin, 44 | Mail, 45 | Twitter, 46 | Twitch, 47 | YouTube: Youtube, 48 | WhatsApp: Whatsapp, 49 | Snapchat, 50 | Pinterest, 51 | Discord, 52 | GitLab: Gitlab, 53 | Reddit, 54 | Telegram, 55 | Mastodon, 56 | }; 57 | 58 | export const getIconByName = (name: string): IconComponent | null => { 59 | return ICONS[name] || null; 60 | }; 61 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | name: "JS checks" 18 | 19 | on: 20 | pull_request: 21 | paths: 22 | - "js/**" 23 | - "spec/**" 24 | - ".github/workflows/test.yml" 25 | jobs: 26 | test: 27 | name: Run tests (Node ${{ matrix.node-version }}) 28 | runs-on: ubuntu-latest 29 | strategy: 30 | matrix: 31 | node-version: ["20", "21", "22", "23"] 32 | steps: 33 | - uses: actions/checkout@v6 34 | 35 | - name: Setup Node.js v${{ matrix.node-version }} 36 | uses: actions/setup-node@v6 37 | with: 38 | node-version: ${{ matrix.node-version }} 39 | 40 | - name: Install pnpm 41 | uses: pnpm/action-setup@v2 42 | with: 43 | version: 10 44 | 45 | - name: Install dependencies 46 | run: pnpm -C js install 47 | 48 | - name: Run tests 49 | run: pnpm -C js test 50 | 51 | - name: Build 52 | run: pnpm -C js build 53 | -------------------------------------------------------------------------------- /go/dotprompt/helper_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2025 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | package dotprompt 18 | 19 | import ( 20 | "testing" 21 | 22 | "github.com/mbleigh/raymond" 23 | "github.com/stretchr/testify/assert" 24 | ) 25 | 26 | // JSON, Media, IfEquals and UnlessEquals functions cannot be tested directly. 27 | // These functions are tested as part of spec tests present under go/test dir. 28 | func TestRoleFn(t *testing.T) { 29 | role := "admin" 30 | expected := "<<>>" 31 | result := RoleFn(role) 32 | assert.Equal(t, raymond.SafeString(expected), result) 33 | } 34 | 35 | func TestHistory(t *testing.T) { 36 | expected := "<<>>" 37 | result := History() 38 | assert.Equal(t, raymond.SafeString(expected), result) 39 | } 40 | 41 | func TestSection(t *testing.T) { 42 | name := "Introduction" 43 | expected := "<<>>" 44 | result := Section(name) 45 | assert.Equal(t, raymond.SafeString(expected), result) 46 | } 47 | -------------------------------------------------------------------------------- /spec/helpers/json.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | 18 | # Tests for the {{json}} helper which serializes JavaScript objects into 19 | # JSON strings with optional indentation. 20 | 21 | # Tests basic JSON serialization without indentation, ensuring objects 22 | # are properly stringified in a compact format. 23 | - name: basic 24 | template: "{{json this}}" 25 | tests: 26 | - desc: renders json in place 27 | data: { input: { test: true } } 28 | expect: 29 | messages: 30 | - role: user 31 | content: [{ text: '{"test":true}' }] 32 | 33 | # Tests JSON serialization with custom indentation, ensuring proper 34 | # formatting for improved readability. 35 | - name: indented 36 | template: "{{json this indent=2}}" 37 | tests: 38 | - desc: renders json in place 39 | data: { input: { test: true } } 40 | expect: 41 | messages: 42 | - role: user 43 | content: [{ text: "{\n \"test\": true\n}" }] 44 | -------------------------------------------------------------------------------- /python/handlebarrz/generate-arm-wheels.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2025 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # SPDX-License-Identifier: Apache-2.0 18 | export UV_LINK_MODE=copy 19 | export PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 20 | 21 | PYTHON_VERSION="python$1" 22 | 23 | echo "building for python version $PYTHON_VERSION" 24 | 25 | # linux 26 | echo "building with maturin for linux" 27 | for i in $(seq 40 -1 24); do 28 | uv run --python $1 maturin build --release --target aarch64-unknown-linux-gnu -i "$PYTHON_VERSION" --compatibility manylinux_2_$i --auditwheel=skip 29 | done 30 | uv run --python $1 maturin build --release --target aarch64-unknown-linux-gnu -i $PYTHON_VERSION 31 | 32 | # macos 33 | echo "building with maturin for macos" 34 | uv run --python $1 maturin build --target aarch64-apple-darwin -i $PYTHON_VERSION --zig 35 | 36 | DIRECTORY="target/wheels/" 37 | 38 | FILES=$(find "$DIRECTORY" -type f -name "*linux_aarch64*") 39 | if [[ -n "$FILES" ]]; then 40 | echo "removing local wheel" 41 | rm -f $FILES 42 | fi 43 | 44 | -------------------------------------------------------------------------------- /third_party/docsite/src/components/core/Footer.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import { Socials } from "config"; 3 | import { getIconByName } from "@/components/core/Icons"; 4 | import { Button } from "@/components/ui/button"; 5 | 6 | // To pass the tailwindcss classes to the astro component 7 | const { class: className } = Astro.props; 8 | --- 9 | 10 |

11 |
12 |

13 | Built by Firebase. The source code 14 | is available on 15 | GitHub. 21 |

22 |
23 | { 24 | Socials.filter((social) => social.active).map((social) => { 25 | const Icon = getIconByName(social.name); 26 | return ( 27 | 34 | 37 | 38 | ); 39 | }) 40 | } 41 |
42 |
43 |
44 | -------------------------------------------------------------------------------- /third_party/docsite/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | load("@aspect_rules_js//js:defs.bzl", "js_library") 18 | load("@aspect_rules_ts//ts:defs.bzl", "ts_config", "ts_project") 19 | 20 | ts_config( 21 | name = "tsconfig", 22 | src = "tsconfig.json", 23 | visibility = [":__subpackages__"], 24 | ) 25 | 26 | #ts_project( 27 | # name = "docsite", 28 | # srcs = glob( 29 | # [ 30 | # "**/*.ts", 31 | # ], 32 | # exclude = [ 33 | # "**/*.test.ts", 34 | # "**/*.bench.ts", 35 | # "**/*.test.tsx", 36 | # "node_modules/**", 37 | # ], 38 | # ), 39 | # out_dir = "dist", 40 | # tsconfig = ":tsconfig", 41 | # visibility = ["//visibility:public"], 42 | # deps = [ 43 | # "//:node_modules/@types/node", 44 | # ], 45 | #) 46 | 47 | js_library( 48 | name = "pkg", 49 | srcs = [ 50 | "package.json", 51 | #":docsite", 52 | ], 53 | visibility = ["//visibility:public"], 54 | ) 55 | -------------------------------------------------------------------------------- /scripts/run_handlebarrz_checks: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2025 Google LLC 3 | # SPDX-License-Identifier: Apache-2.0 4 | 5 | set -euo pipefail 6 | 7 | if ((EUID == 0)); then 8 | echo "Please do not run as root" 9 | exit 1 10 | fi 11 | 12 | SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 13 | TOP_DIR="$(git rev-parse --show-toplevel)" 14 | HANDLEBARRZ_DIR="${TOP_DIR}/python/handlebarrz" 15 | 16 | echo "=== Running Rust tests for Handlebarrz ===" 17 | echo "Project root: ${TOP_DIR}" 18 | echo "Handlebarrz directory: ${HANDLEBARRZ_DIR}" 19 | echo "" 20 | 21 | # Check if cargo is installed 22 | if ! command -v cargo &>/dev/null; then 23 | echo "Error: cargo is not installed. Please install Rust and Cargo." >&2 24 | exit 1 25 | fi 26 | 27 | cd "${HANDLEBARRZ_DIR}" 28 | 29 | CARGO_ARGS=("") 30 | VERBOSE=false 31 | 32 | for arg in "$@"; do 33 | case $arg in 34 | -v | --verbose) 35 | VERBOSE=true 36 | CARGO_ARGS+=("--verbose") 37 | ;; 38 | *) 39 | CARGO_ARGS+=("$arg") 40 | ;; 41 | esac 42 | done 43 | 44 | export RUST_BACKTRACE=1 45 | export PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 46 | 47 | if [ "$VERBOSE" = true ]; then 48 | echo "Running tests in verbose mode..." 49 | cargo test "${CARGO_ARGS[@]}" 50 | else 51 | echo "Running tests..." 52 | cargo test "${CARGO_ARGS[@]}" --quiet 53 | fi 54 | 55 | 56 | echo "=== Run checks for handlebarrz ===" 57 | 58 | pushd "${HANDLEBARRZ_DIR}" &>/dev/null 59 | cargo fmt --all 60 | cargo clippy --all-targets --all-features -- -D warnings 61 | popd &>/dev/null 62 | 63 | echo "=== Done with Rust checks for handlebarrz ===" 64 | 65 | echo "" 66 | echo "=== Rust tests completed ===" 67 | -------------------------------------------------------------------------------- /COMMIT_MESSAGE_TEMPLATE: -------------------------------------------------------------------------------- 1 | feat: 2 | 3 | ISSUE: 4 | 5 | CHANGELOG: 6 | - [ ] 7 | 8 | ## COMMIT MESSAGE FULL EXAMPLE 9 | # 10 | # feat(user-authentication): Implement two-factor authentication 11 | # 12 | # This commit introduces two-factor authentication for enhanced security. 13 | # It uses TOTP and requires users to configure an authenticator app. 14 | # 15 | # ISSUE: #123 16 | # 17 | # CHANGELOG: 18 | # - [ ] Add support for two-factor authentication 19 | # - [ ] Update user login endpoint to require two-factor authentication 20 | # 21 | # BREAKING CHANGE: The API endpoint for user login has been modified. 22 | 23 | ## CONVENTIONAL COMMIT TEMPLATE 24 | # 25 | # Subject line (required, max 50 characters, use imperative mood): 26 | # (): 27 | # Example: feat(user-authentication): Implement two-factor authentication 28 | # 29 | # Body (optional, wrap at 72 characters, explain the change in more detail, mention why and what): 30 | # 31 | 32 | ## TYPES OF CHANGE (choose one): 33 | # - feat: A new feature 34 | # - fix: A bug fix 35 | # - docs: Documentation changes 36 | # - style: Code style changes (formatting, etc.) 37 | # - refactor: Code refactoring (no new features or bug fixes) 38 | # - perf: Performance improvements 39 | # - test: Adding or modifying tests 40 | # - build: Changes that affect the build system or external dependencies 41 | # - ci: Changes to CI configuration files and scripts 42 | # - chore: Routine tasks, build process changes, etc. 43 | # - revert: Revert a previous commit 44 | # 45 | ## SCOPE (optional, specify the affected area, e.g., component, module): 46 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/store/PromptStoreWritable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.store; 20 | 21 | import com.google.dotprompt.models.DeletePromptOrPartialOptions; 22 | import com.google.dotprompt.models.PromptData; 23 | import java.util.concurrent.CompletableFuture; 24 | 25 | /** A PromptStore that also supports writing and deleting. */ 26 | public interface PromptStoreWritable extends PromptStore { 27 | /** 28 | * Saves a prompt in the store. 29 | * 30 | * @param prompt The prompt data to save. 31 | * @return A future that completes when the save is finished. 32 | */ 33 | CompletableFuture save(PromptData prompt); 34 | 35 | /** 36 | * Deletes a prompt from the store. 37 | * 38 | * @param name The name of the prompt to delete. 39 | * @param options Options for deleting the prompt. 40 | * @return A future that completes when the deletion is finished. 41 | */ 42 | CompletableFuture delete(String name, DeletePromptOrPartialOptions options); 43 | } 44 | -------------------------------------------------------------------------------- /scripts/run_bazel_checks: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright 2025 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # SPDX-License-Identifier: Apache-2.0 18 | # 19 | # Builds and tests the Bazel project. 20 | # Installs bazelisk and buildifier if they are not found. 21 | 22 | set -euo pipefail 23 | 24 | if ! command -v "bazelisk" >/dev/null 2>&1; then 25 | echo "Bazelisk not found. Installing via go install..." 26 | go install github.com/bazelbuild/bazelisk@latest 27 | fi 28 | 29 | TOP_DIR=$(git rev-parse --show-toplevel) 30 | 31 | echo "Updating build files..." 32 | "${TOP_DIR}/scripts/gazelle" 33 | 34 | echo "Pinning dependencies..." 35 | bazelisk run @maven//:pin 36 | 37 | echo "Running Bazel build (Java 21)..." 38 | bazelisk build --config=java21 //... 39 | 40 | echo "Running Bazel tests (Java 21)..." 41 | bazelisk test --config=java21 //... --test_output=errors 42 | 43 | #echo "Running Bazel build (Java 17)..." 44 | #bazelisk build --config=java17 //... 45 | # 46 | #echo "Running Bazel tests (Java 17)..." 47 | #bazelisk test --config=java17 //... --test_output=errors 48 | 49 | echo "Bazel build and tests completed successfully." 50 | -------------------------------------------------------------------------------- /third_party/docsite/astro.config.mjs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2024 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { defineConfig } from "astro/config"; 18 | import rehypeExternalLinks from "rehype-external-links"; 19 | import tailwind from "@astrojs/tailwind"; 20 | import react from "@astrojs/react"; 21 | import mdx from "@astrojs/mdx"; 22 | 23 | // https://astro.build/config 24 | export default defineConfig({ 25 | site: "https://google.github.io", 26 | base: "/dotprompt", 27 | markdown: { 28 | smartypants: true, 29 | syntaxHighlight: "shiki", 30 | shikiConfig: { 31 | // theme: "catppuccin-mocha", 32 | themes: { 33 | light: "catppuccin-latte", 34 | dark: "catppuccin-macchiato", 35 | }, 36 | wrap: true, 37 | }, 38 | rehypePlugins: [ 39 | [ 40 | rehypeExternalLinks, 41 | { 42 | target: "_blank", 43 | }, 44 | ], 45 | ], 46 | prefetch: true, 47 | }, 48 | integrations: [ 49 | react(), 50 | tailwind({ 51 | applyBaseStyles: false, 52 | }), 53 | mdx({ 54 | gfm: true, 55 | }), 56 | ], 57 | }); 58 | -------------------------------------------------------------------------------- /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | name: Go checks 18 | 19 | on: 20 | pull_request: 21 | paths: 22 | - "go/**" 23 | - "spec/**" 24 | - ".github/workflows/go.yml" 25 | 26 | jobs: 27 | tests: 28 | runs-on: ubuntu-latest 29 | strategy: 30 | matrix: 31 | # Track only the latest 2 stable versions of Go. 32 | go-version: ["1.24.x", "1.25.x"] 33 | fail-fast: false 34 | 35 | name: Go ${{ matrix.go-version }} Tests 36 | steps: 37 | - name: Checkout Repo 38 | uses: actions/checkout@v6 39 | 40 | - name: Set up Go ${{ matrix.go-version }} 41 | uses: actions/setup-go@v6 42 | with: 43 | go-version: ${{ matrix.go-version }} 44 | 45 | - name: Install govulncheck 46 | run: go install golang.org/x/vuln/cmd/govulncheck@latest 47 | 48 | - name: Check build 49 | run: go build -C go -v ./... 50 | 51 | - name: Run tests 52 | run: go test -C go -v ./... 53 | 54 | - name: Run vulncheck 55 | run: govulncheck -C go ./... 56 | -------------------------------------------------------------------------------- /python/dotpromptz/src/dotpromptz/errors.py: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | """Errors for the dotpromptz package.""" 18 | 19 | 20 | class ResolverFailedError(RuntimeError): 21 | """Raised when a resolver fails.""" 22 | 23 | def __init__(self, name: str, kind: str, reason: str) -> None: 24 | """Initialize the error. 25 | 26 | Args: 27 | name: The name of the object that failed to resolve. 28 | kind: The kind of object that failed to resolve. 29 | reason: The reason the object resolver failed. 30 | """ 31 | self.name = name 32 | self.kind = kind 33 | self.reason = reason 34 | super().__init__(f'{kind} resolver failed for {name}; {reason}') 35 | 36 | def __str__(self) -> str: 37 | """Return a string representation of the error.""" 38 | return f'{self.kind} resolver failed for {self.name}; {self.reason}' 39 | 40 | def __repr__(self) -> str: 41 | """Return a string representation of the error.""" 42 | return f'{self.kind} resolver failed for {self.name}; {self.reason}' 43 | -------------------------------------------------------------------------------- /third_party/docsite/src/components/docs/SideNavMenu.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import { capitalizeFirstLetter } from "@/lib/utils"; 3 | import type { MenuItemWithDraft, SideNavMenuProps } from "@/lib/types"; 4 | 5 | const { items, level } = Astro.props as SideNavMenuProps; 6 | const pathname: string = new URL(Astro.request.url).pathname; 7 | 8 | // To pass the tailwindcss classes to the astro component 9 | const { class: className } = Astro.props; 10 | 11 | function sortChildren(children: MenuItemWithDraft[]) { 12 | console.log("sorting children", children); 13 | return [...children].sort((a, b) => { 14 | if (a.sort_order && b.sort_order) return a.sort_order - b.sort_order; 15 | if (a.sort_order) return -1; 16 | if (b.sort_order) return 1; 17 | return a.slug < b.slug ? -1 : 1; 18 | }); 19 | } 20 | --- 21 | 22 |
    23 | { 24 | items 25 | .filter((item) => !item.draft) 26 | .map((item) => { 27 | const label = item.title 28 | ? capitalizeFirstLetter(item.title) 29 | : capitalizeFirstLetter(item.slug.split("/").pop() || ""); 30 | const className = ` 31 | ${level === 0 ? "font-semibold" : "text-muted-foreground"} 32 | ${pathname === "/" + item.slug ? "text-primary" : "no-underline"} 33 | `.trim(); 34 | return ( 35 |
  • 36 | 37 | {label} 38 | 39 | {item.children.length > 0 && ( 40 | 41 | )} 42 |
  • 43 | ); 44 | }) 45 | } 46 |
47 | -------------------------------------------------------------------------------- /python/handlebarrz/generate-x86-64-wheels.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2025 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # SPDX-License-Identifier: Apache-2.0 18 | export UV_LINK_MODE=copy 19 | export PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 20 | 21 | PYTHON_VERSION="python$1" 22 | 23 | echo "building for python version $PYTHON_VERSION" 24 | 25 | # linux 26 | echo "building with maturin for linux" 27 | for i in $(seq 40 -1 24); do 28 | uv run --python $1 maturin build --release --target x86_64-unknown-linux-gnu -i "$PYTHON_VERSION" --compatibility manylinux_2_$i --auditwheel=skip 29 | done 30 | uv run --python $1 maturin build --release --target x86_64-unknown-linux-gnu -i $PYTHON_VERSION 31 | 32 | # windows 33 | echo "building with maturin for windows" 34 | uv run --python $1 maturin build --target x86_64-pc-windows-msvc -i $1 35 | 36 | # macos 37 | echo "building with maturin for macos" 38 | uv run --python $1 maturin build --target x86_64-apple-darwin -i $1 --zig 39 | 40 | DIRECTORY="target/wheels/" 41 | 42 | FILES=$(find "$DIRECTORY" -type f -name "*linux_x86_64*") 43 | if [ -n "$FILES" ]; then 44 | echo "removing local wheel" 45 | rm -f $FILES 46 | fi 47 | 48 | -------------------------------------------------------------------------------- /scripts/run_js_checks: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2025 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # SPDX-License-Identifier: Apache-2.0 17 | 18 | set -euo pipefail 19 | 20 | if ((EUID == 0)); then 21 | echo "Please do not run as root" 22 | exit 1 23 | fi 24 | 25 | TOP_DIR=$(git rev-parse --show-toplevel) 26 | JS_DIR="${TOP_DIR}/js" 27 | NODE_VERSIONS=( 28 | "20" 29 | "21" 30 | "22" 31 | "23" 32 | ) 33 | 34 | echo "=== Running Node.js tests ===" 35 | echo "Project root: ${TOP_DIR}" 36 | echo "Node.js directory: ${JS_DIR}" 37 | echo "" 38 | 39 | if [[ -z ${NVM_DIR-} ]]; then 40 | echo "NVM_DIR is not set. Please ensure nvm is installed and properly configured." 41 | exit 1 42 | fi 43 | 44 | [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" 45 | 46 | for VERSION in "${NODE_VERSIONS[@]}"; do 47 | echo "Running tests with Node.js ${VERSION}..." 48 | 49 | nvm install "${VERSION}" || true 50 | nvm use "${VERSION}" 51 | pushd "${JS_DIR}" 52 | pnpm install && pnpm run test 53 | if [ $? -ne 0 ]; then 54 | echo "JavaScript tests failed." 55 | exit 1 56 | fi 57 | popd 58 | done 59 | 60 | nvm use default 61 | 62 | echo "=== Node.js tests completed ===" 63 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/store/PromptStoreWritableSync.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.store; 20 | 21 | import com.google.dotprompt.models.DeletePromptOrPartialOptions; 22 | import com.google.dotprompt.models.PromptData; 23 | 24 | /** 25 | * Synchronous interface for reading, writing, and deleting prompts and partials. 26 | * 27 | *

This is the synchronous counterpart to {@link PromptStoreWritable}. Use this interface when 28 | * blocking operations are acceptable and you don't need async handling. 29 | * 30 | * @see PromptStoreWritable 31 | * @see PromptStoreSync 32 | */ 33 | public interface PromptStoreWritableSync extends PromptStoreSync { 34 | 35 | /** 36 | * Saves a prompt in the store. 37 | * 38 | * @param prompt The prompt data to save. 39 | */ 40 | void save(PromptData prompt); 41 | 42 | /** 43 | * Deletes a prompt from the store. 44 | * 45 | * @param name The name of the prompt to delete. 46 | * @param options Options for deleting the prompt. 47 | */ 48 | void delete(String name, DeletePromptOrPartialOptions options); 49 | } 50 | -------------------------------------------------------------------------------- /third_party/docsite/src/pages/llms.txt.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | import { getEntries } from "astro:content"; 20 | import type { APIRoute } from "astro"; 21 | 22 | export const GET: APIRoute = async ({ params, request }) => { 23 | const docs = await getEntries([ 24 | { collection: "docs", slug: "reference" }, 25 | { collection: "docs", slug: "reference/frontmatter" }, 26 | { collection: "docs", slug: "reference/picoschema" }, 27 | { collection: "docs", slug: "reference/template" }, 28 | { collection: "docs", slug: "reference/model" }, 29 | ]); 30 | 31 | return new Response( 32 | `=== Dotprompt Template Format Documentation ===\n\nThe following is a complete reference to authoring files using the Dotprompt executable template format. This reference contains only information about the Dotprompt text format, not surrounding language or framework implementations.\n\n${docs 33 | .map((doc) => { 34 | return `# ${doc.data.title} (/${doc.slug})\n\n${doc.body}`; 35 | }) 36 | .join("")}`, 37 | { headers: { "Content-Type": "text/plain; charset=utf-8" } }, 38 | ); 39 | }; 40 | -------------------------------------------------------------------------------- /spec/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "type": "array", 4 | "items": { 5 | "type": "object", 6 | "properties": { 7 | "name": { 8 | "type": "string" 9 | }, 10 | "template": { 11 | "type": "string" 12 | }, 13 | "schemas": { 14 | "type": "object", 15 | "description": "Registry of schemas to be made available for lookup.", 16 | "additionalProperties": { 17 | "type": "object" 18 | } 19 | }, 20 | "resolverSchemas": { 21 | "type": "object", 22 | "description": "Registry of schemas that are provided by a schema resolver.", 23 | "additionalProperties": { "type": "object" } 24 | }, 25 | "partials": { 26 | "type": "object", 27 | "description": "Registry of partials to be made available.", 28 | "additionalProperties": { 29 | "type": "string" 30 | } 31 | }, 32 | "resolverPartials": { 33 | "type": "object", 34 | "description": "Registry of partials that are provided by a schema resolver.", 35 | "additionalProperties": { "type": "string" } 36 | }, 37 | "tests": { 38 | "type": "array", 39 | "items": { 40 | "type": "object", 41 | "properties": { 42 | "desc": { 43 | "type": "string" 44 | }, 45 | "data": { 46 | "type": "object" 47 | }, 48 | "options": { 49 | "type": "object" 50 | }, 51 | "expect": { 52 | "type": "object" 53 | } 54 | }, 55 | "required": ["expect"] 56 | } 57 | } 58 | }, 59 | "required": ["name", "template", "tests"] 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /third_party/docsite/src/components/core/HeadSEO.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import "@/styles/globals.css"; 3 | // Supports weights 100-800 4 | import "@fontsource-variable/jetbrains-mono"; 5 | // Supports weights 100-900 6 | import "@fontsource/lexend/400.css"; 7 | import "@fontsource/lexend/300.css"; 8 | import "@fontsource/lexend/600.css"; 9 | 10 | import { ViewTransitions } from "astro:transitions"; 11 | 12 | import type { HeadSEOProps } from "@/lib/types"; 13 | 14 | const canonicalURL = new URL(Astro.url); 15 | 16 | if (Astro.props.ogImage === undefined) { 17 | Astro.props.ogImage = new URL("og-image.jpg", canonicalURL); 18 | } 19 | 20 | const { title, description, ogImage } = Astro.props as HeadSEOProps; 21 | --- 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | {title} 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /bazel/rules_vitest/defs.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | """ 18 | This file contains custom rules. 19 | 20 | - vitest_test: Runs tests with Vitest. 21 | """ 22 | 23 | load("@npm//:vitest/package_json.bzl", vitest_bin = "bin") 24 | 25 | def vitest_test(name, srcs, deps = [], data = [], size = "small", run_args = [], visibility = ["//visibility:public"], config = None): 26 | """Runs Vitest tests. 27 | 28 | Args: 29 | name: The name of the test target. 30 | srcs: List of test source files. 31 | deps: List of dependencies. 32 | data: List of data files. 33 | size: Test size (e.g., "small", "medium"). 34 | run_args: Additional arguments to pass to Vitest. 35 | visibility: Target visibility. 36 | config: Optional Vitest configuration file label. 37 | """ 38 | data_deps = srcs + deps + data + [ 39 | "//:node_modules", 40 | ] 41 | if config: 42 | data_deps.append(config) 43 | 44 | vitest_bin.vitest_test( 45 | name = name, 46 | size = size, 47 | args = ["run"] + run_args, 48 | chdir = native.package_name(), 49 | visibility = visibility, 50 | data = data_deps, 51 | ) 52 | -------------------------------------------------------------------------------- /java.MODULE.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | """Configuration for Bazel with Java dependencies.""" 18 | 19 | bazel_dep(name = "rules_java", version = "9.3.0") 20 | bazel_dep(name = "rules_jvm_external", version = "6.9") 21 | 22 | # Register the specific Java toolchain version. 23 | # See https://github.com/bazelbuild/rules_java/blob/master/toolchains.bzl 24 | java_toolchain = use_repo_rule("@rules_java//java:repositories.bzl", "java_toolchain") 25 | 26 | java_toolchain( 27 | name = "jdk", 28 | version = "17", 29 | ) 30 | 31 | maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven") 32 | maven.install( 33 | artifacts = [ 34 | "junit:junit:4.13.2", 35 | "com.google.truth.extensions:truth-proto-extension:1.4.4", 36 | "com.google.truth:truth:1.4.4", 37 | "com.github.jknack:handlebars:4.4.0", 38 | "com.google.guava:guava:33.5.0-jre", 39 | "com.fasterxml.jackson.core:jackson-databind:2.20.1", 40 | "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.20.1", 41 | ], 42 | lock_file = "//:maven_install.json", 43 | repositories = [ 44 | "https://repo1.maven.org/maven2", 45 | ], 46 | ) 47 | use_repo(maven, "maven") 48 | -------------------------------------------------------------------------------- /scripts/publish-java.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2025 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # SPDX-License-Identifier: Apache-2.0 17 | 18 | set -euo pipefail 19 | 20 | # Usage: ./scripts/publish-java.sh 21 | 22 | if [ "$#" -ne 4 ]; then 23 | echo "Usage: $0 " 24 | exit 1 25 | fi 26 | 27 | GPG_KEY_PATH=$1 28 | GPG_PASSPHRASE=$2 29 | MAVEN_USER=$3 30 | MAVEN_PASSWORD=$4 31 | 32 | # Define the deployment repository URL (Sonatype OSSRH) 33 | DEPLOY_ENV="release" # or "snapshot" if desired, but typically we want release for tags. 34 | # Bazel java_export allows specifying deployment via flags or properties. 35 | # We will use the standard command structure generated by java_export. 36 | 37 | echo "Publishing Java artifacts..." 38 | 39 | bazel run //java/com/google/dotprompt:dotprompt_pkg.publish -- \ 40 | --define "maven_repo=https://oss.sonatype.org/service/local/staging/deploy/maven2/" \ 41 | --define "maven_user=$MAVEN_USER" \ 42 | --define "maven_password=$MAVEN_PASSWORD" \ 43 | --define "gpg_sign=true" \ 44 | --define "gpg_key=$GPG_KEY_PATH" \ 45 | --define "gpg_passphrase=$GPG_PASSPHRASE" 46 | 47 | echo "Publishing complete." 48 | -------------------------------------------------------------------------------- /python/handlebarrz/pyproject.toml: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | [project] 18 | authors = [{ name = "Yesudeep Mangalapilly", email = "yesudeep@google.com" }] 19 | classifiers = [ 20 | "Development Status :: 3 - Alpha", 21 | "Programming Language :: Python :: 3", 22 | "Programming Language :: Python :: 3.10", 23 | "Programming Language :: Python :: 3.11", 24 | "Programming Language :: Python :: 3.12", 25 | "Programming Language :: Python :: 3.13", 26 | "Programming Language :: Python :: 3.14", 27 | "Programming Language :: Rust", 28 | "Topic :: Text Processing :: Markup", 29 | "License :: OSI Approved :: Apache Software License", 30 | ] 31 | dependencies = [ 32 | "structlog>=25.2.0", 33 | ] 34 | description = "Handlebars library for Python based on handlebars-rust." 35 | name = "dotpromptz-handlebars" 36 | readme = "README.md" 37 | requires-python = ">=3.10" 38 | version = "0.1.3" 39 | 40 | [build-system] 41 | build-backend = "maturin" 42 | requires = ["maturin>=1.4,<2.0"] 43 | 44 | [tool.maturin] 45 | features = ["pyo3/extension-module"] 46 | module-name = "handlebarrz._native" 47 | python-source = "src" 48 | 49 | [dependency-groups] 50 | dev = [ 51 | "pytest>=8.3.5", 52 | "pytest-cov>=6.0.0", 53 | "maturin[patchelf]>=1.8.3", 54 | "ziglang>=0.14.0", 55 | ] 56 | -------------------------------------------------------------------------------- /.github/workflows/java.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | name: Java checks 18 | 19 | on: 20 | push: 21 | branches: 22 | - main 23 | paths: 24 | - "java/**" 25 | - "spec/**" 26 | - ".github/workflows/java.yml" 27 | pull_request: 28 | paths: 29 | - "java/**" 30 | - "spec/**" 31 | - ".github/workflows/java.yml" 32 | 33 | jobs: 34 | tests: 35 | runs-on: ubuntu-latest 36 | strategy: 37 | matrix: 38 | java-version: ['17', '21', '23', '24'] 39 | fail-fast: false 40 | 41 | name: Java ${{ matrix.java-version }} Tests 42 | steps: 43 | - uses: actions/checkout@v4 44 | 45 | - name: Set up JDK ${{ matrix.java-version }} 46 | uses: actions/setup-java@v4 47 | with: 48 | java-version: ${{ matrix.java-version }} 49 | distribution: 'temurin' 50 | 51 | - name: Setup Bazel 52 | uses: bazelbuild/setup-bazelisk@v3 53 | 54 | - name: Run Tests 55 | # Force Bazel to use the local JDK setup by actions/setup-java 56 | run: | 57 | bazel test \ 58 | --java_runtime_version=local_jdk \ 59 | --tool_java_runtime_version=local_jdk \ 60 | --test_output=errors \ 61 | //java/com/google/dotprompt/... 62 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/models/Role.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | */ 18 | 19 | package com.google.dotprompt.models; 20 | 21 | import com.fasterxml.jackson.annotation.JsonValue; 22 | 23 | /** Represents the role of a message sender in a conversation. */ 24 | public enum Role { 25 | /** User role. */ 26 | USER("user"), 27 | /** Model (AI) role. */ 28 | MODEL("model"), 29 | /** Tool role. */ 30 | TOOL("tool"), 31 | /** System role. */ 32 | SYSTEM("system"); 33 | 34 | private final String value; 35 | 36 | Role(String value) { 37 | this.value = value; 38 | } 39 | 40 | /** 41 | * Returns the string representation of the role. 42 | * 43 | * @return The role name. 44 | */ 45 | @JsonValue 46 | public String getValue() { 47 | return value; 48 | } 49 | 50 | /** 51 | * Parses a string into a Role enum. 52 | * 53 | * @param value The string value (case-insensitive). 54 | * @return The corresponding Role, or USER if invalid/null. 55 | */ 56 | public static Role fromString(String value) { 57 | if (value == null) { 58 | return Role.USER; 59 | } 60 | try { 61 | return Role.valueOf(value.toUpperCase()); 62 | } catch (IllegalArgumentException e) { 63 | return Role.USER; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /scripts/run_python_checks_with_tox: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2025 Google LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # SPDX-License-Identifier: Apache-2.0 17 | 18 | # Run tests for all supported Python versions using tox 19 | 20 | set -euo pipefail 21 | 22 | if ((EUID == 0)); then 23 | echo "Please do not run as root" 24 | exit 1 25 | fi 26 | 27 | TOP_DIR=$(git rev-parse --show-toplevel) 28 | PY_DIR="$TOP_DIR/python" 29 | 30 | echo "=== Running Python lint ===" 31 | uv run --directory "${PY_DIR}" ruff check --select I --fix --preview --unsafe-fixes . 32 | uv run --directory "${PY_DIR}" ty check 33 | 34 | echo "=== Running Python tests ===" 35 | 36 | # Erase any previous coverage data to prevent errors during combine 37 | echo "Erasing previous coverage data..." 38 | uv run --active --directory "$PY_DIR" coverage erase || echo "Coverage erase failed (maybe no data existed?), continuing..." 39 | rm -rf "${PY_DIR}"/.coverage* 40 | 41 | # Build the handlebarrz package. 42 | uv run --active --directory "$PY_DIR/handlebarrz" maturin develop 43 | 44 | # Use uv run to execute tox, passing the --parallel flag to tox 45 | # The '-p auto' flag tells tox to use available CPU cores for parallelism. 46 | # Any arguments passed to this script ($@) are forwarded to tox (and then pytest) 47 | uv run --active --directory "$PY_DIR" tox "$@" 48 | 49 | echo "=== Python tests completed ===" 50 | -------------------------------------------------------------------------------- /java/com/google/dotprompt/parser/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | load("@rules_java//java:defs.bzl", "java_library", "java_test") 18 | 19 | java_library( 20 | name = "parser", 21 | srcs = [ 22 | "Parser.java", 23 | "Picoschema.java", 24 | ], 25 | visibility = ["//visibility:public"], 26 | deps = [ 27 | "//java/com/google/dotprompt/models", 28 | "//java/com/google/dotprompt/resolvers", 29 | "@maven//:com_fasterxml_jackson_core_jackson_databind", 30 | "@maven//:com_fasterxml_jackson_dataformat_jackson_dataformat_yaml", 31 | ], 32 | ) 33 | 34 | java_test( 35 | name = "ParserTest", 36 | srcs = ["ParserTest.java"], 37 | test_class = "com.google.dotprompt.parser.ParserTest", 38 | deps = [ 39 | ":parser", 40 | "//java/com/google/dotprompt/models", 41 | "@maven//:com_google_truth_truth", 42 | "@maven//:junit_junit", 43 | ], 44 | ) 45 | 46 | java_test( 47 | name = "PicoschemaTest", 48 | srcs = ["PicoschemaTest.java"], 49 | test_class = "com.google.dotprompt.parser.PicoschemaTest", 50 | deps = [ 51 | ":parser", 52 | "//java/com/google/dotprompt/resolvers", 53 | "@maven//:com_google_truth_truth", 54 | "@maven//:junit_junit", 55 | ], 56 | ) 57 | -------------------------------------------------------------------------------- /python/tests/smoke/pyproject.toml: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | [project] 18 | classifiers = [ 19 | "Development Status :: 3 - Alpha", 20 | "Environment :: Console", 21 | "Environment :: Web Environment", 22 | "Intended Audience :: Developers", 23 | "Operating System :: OS Independent", 24 | "License :: OSI Approved :: Apache Software License", 25 | "Programming Language :: Python", 26 | "Programming Language :: Python :: 3.10", 27 | "Programming Language :: Python :: 3.11", 28 | "Programming Language :: Python :: 3.12", 29 | "Programming Language :: Python :: 3.13", 30 | "Programming Language :: Python :: 3 :: Only", 31 | "Topic :: Scientific/Engineering :: Artificial Intelligence", 32 | "Topic :: Software Development :: Libraries", 33 | ] 34 | dependencies = [ 35 | "anyio>=4.9.0", 36 | "dotpromptz", 37 | #"handlebars@git+https://github.com/Manurajbharath/handlebars-py.git", 38 | #"js2py@git+https://github.com/a-j-albert/Js2Py---supports-python-3.13.git", 39 | ] 40 | description = "Packaging smoke test" 41 | license = { text = "Apache-2.0" } 42 | name = "smoke" 43 | readme = "README.md" 44 | requires-python = ">=3.10" 45 | version = "0.1.0" 46 | 47 | [tool.pytest] 48 | python_files = ["**/*_test.py"] 49 | testpaths = ["."] 50 | 51 | [tool.hatch.build.targets.wheel] 52 | packages = ["smoke"] 53 | -------------------------------------------------------------------------------- /.github/workflows/deploy.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | name: Deploy to GitHub Pages 18 | 19 | on: 20 | # Trigger the workflow every time you push to the `main` branch 21 | # Using a different branch name? Replace `main` with your branch’s name 22 | push: 23 | branches: [main] 24 | paths: 25 | - "third_party/docsite/**" 26 | # Allows you to run this workflow manually from the Actions tab on GitHub. 27 | workflow_dispatch: 28 | 29 | # Allow this job to clone the repo and create a page deployment 30 | permissions: 31 | contents: read 32 | pages: write 33 | id-token: write 34 | 35 | jobs: 36 | build: 37 | runs-on: ubuntu-latest 38 | steps: 39 | - name: Checkout your repository using git 40 | uses: actions/checkout@v6 41 | - name: Install, build, and upload your site 42 | uses: withastro/action@v3 43 | with: 44 | path: third_party/docsite 45 | node-version: 22 46 | package-manager: pnpm@9.13.2+sha256.ccce81bf7498c5f0f80e31749c1f8f03baba99d168f64590fc7e13fad3ea1938 47 | 48 | deploy: 49 | needs: build 50 | runs-on: ubuntu-latest 51 | environment: 52 | name: github-pages 53 | url: ${{ steps.deployment.outputs.page_url }} 54 | steps: 55 | - name: Deploy to GitHub Pages 56 | id: deployment 57 | uses: actions/deploy-pages@v4 58 | --------------------------------------------------------------------------------