Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Function Templates — Agent Guide

## What Is This Repo?

Templates for [Knative Functions](https://github.com/knative/func). Users create
functions via `func create -r <this-repo> -l <language> -t <template>`.

```bash
# Example: create a Go function from the "hello" template
func create myfunc -r https://github.com/functions-dev/templates -l go -t hello
```

All files in a template directory are copied to the user's project (except `manifest.yaml`
which holds some metadata that the function will need and hidden files).

## Using Templates (This repository)

Templates are organized as `<language>/<template>/`. The `-l` flag matches the language
directory, the `-t` flag matches the template subdirectory:

```
go/hello/ → func create -l go -t hello
python/echo/ → func create -l python -t echo
rust/echo-cloudevents/ → func create -l rust -t echo-cloudevents
```

### Template Index

Available in all languages (go, node, python, quarkus, rust, springboot, typescript):

| Template | Description |
|---|---|
| `hello` | Returns `{"message":"Hello <Language> World!"}`. Simplest starting point. |
| `echo` | Echoes back the request. GET returns query string, POST returns body. |
| `echo-cloudevents` | Receives a CloudEvent, echoes the data back as a new CloudEvent. |

Go-specific:

| Template | Description |
|---|---|
| `go/blog` | Hugo-powered blog served as static files. Requires `make` to build before use. |
| `go/splash` | Static splash page serving HTML, CSS, and PNG files. |

Python-specific:

| Template | Description |
|---|---|
| `python/pdf-processing` | PDF operations (extract text, metadata, split, merge) via HTTP. |
| `python/mcp` | MCP server exposing basic tools (hello, add_numbers) via Model Context Protocol. |
| `python/mcp-ollama` | Exposes Ollama LLM as MCP tools (list/pull/call models). Needs Ollama. |
| `python/mcp-ollama-rag` | RAG via MCP — combines Ollama with Chroma vector DB for document Q&A. Needs Ollama. |
| `python/ollama-client` | HTTP wrapper that forwards prompts to a local Ollama server. Needs Ollama. |
| `python/llamacpp` | Loads a Granite code model via llama.cpp for local text generation. |

For contributing to this repo, see [CONTRIBUTING.md](CONTRIBUTING.md).
45 changes: 45 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Contributing to Function Templates

## Running Tests

```bash
make test # all runtimes
make test-go # single runtime
make test-python # etc.
```

Detailed logs go to `test-results.log`. Skipped templates and reasons are listed
at the top of the Makefile.

## Adding a New Template

1. Create `<language>/<template-name>/` with function source files
2. Add tests following existing patterns per language:
- Go: `*_test.go`
- Python: `tests/test_func.py`, deps in `pyproject.toml` (under `dependencies` or `[project.optional-dependencies] dev`)
- Node: `test/unit.js` + `test/integration.js`, `npm test` script in `package.json`
- TypeScript: `test/unit.ts` + `test/integration.ts`, `npm test` script in `package.json`
- Rust: `#[cfg(test)]` module in `handler.rs`
- Quarkus/SpringBoot: `src/test/java/`
3. If it needs external services, add to the skip list in Makefile with a comment
4. CI picks it up automatically — both workflows discover templates dynamically

Remember: every file in the template directory gets copied to the user's project
via `func create`. Only include files the user would want.

## CI Workflows

| Workflow | What It Does | Triggers |
|---|---|---|
| `invoke-all.yaml` | Builds and invokes every template end-to-end | push to main, PRs, manual |
| `test-templates.yaml` | Runs unit tests via `make test` | push to main, PRs |

Both workflows discover templates dynamically from the directory structure.

## Key Constraints

- **No git submodules** — `func create` does not fetch them. Use vendored deps or
language-native module systems (e.g. Hugo modules for go/blog).
- **`manifest.yaml`** — Optional per-template config for build settings (builder images,
buildpacks, envs, health endpoints). Not copied to the user's project. Can be defined
at repo, language, or template level with inheritance.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: test test-go test-node test-python test-quarkus test-rust test-springboot test-typescript test-ci invoke-ci
.PHONY: test test-go test-node test-python test-quarkus test-rust test-springboot test-typescript

LOG := test-results.log
START_TIME := $(shell date +%s%3N)
Expand Down
Loading