Files
wehub-resource-sync 0d3cb498a3
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Has been cancelled
Test and Publish Multi-arch Docker Image / test (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Has been cancelled
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Has been cancelled
Validate Renovate Config / Validate Renovate Configuration (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:24:08 +08:00

79 lines
2.0 KiB
Markdown

# config-ts (TypeScript Configuration Example)
You can run this example with:
```bash
npx promptfoo@latest init --example config-ts
cd config-ts
```
This example demonstrates TypeScript configuration for promptfoo, including:
- Type-safe configuration with IDE autocompletion
- Dynamic schema generation using Zod
- Fun translation examples with creative language styles
## Prerequisites
- Node.js ^20.20.0 or >=22.22.0 (Node.js 20 support ends July 30, 2026; Node.js 24 LTS recommended)
- TypeScript loader (`tsx` recommended)
Install dependencies:
```bash
npm install
```
## Running Examples
### Basic TypeScript Configuration
```bash
NODE_OPTIONS="--import tsx" promptfoo eval -c promptfooconfig.ts
```
This example translates text into French and Pirate speak.
### Dynamic Schema Generation
```bash
NODE_OPTIONS="--import tsx" promptfoo eval -c promptfooconfig-with-schema.ts
```
This example shows structured JSON outputs with fun translations into Pirate speak, Shakespeare English, and Gen Z slang.
View results:
```bash
promptfoo view
```
## Examples Overview
### 1. Basic Configuration (`promptfooconfig.ts`)
Demonstrates:
- Type-safe configuration using the `UnifiedConfig` type
- Simple provider configuration with GPT-5 Mini
- Basic translation examples
### 2. Dynamic Schema Generation (`promptfooconfig-with-schema.ts`)
Shows advanced features:
- Zod schema for structured translation responses
- Automatic schema adaptation for different providers (OpenAI and Gemini)
- Structured JSON outputs with multiple fields (translation, language, confidence, funFactor, culturalNotes)
- JavaScript assertions for validating structured outputs
Both OpenAI and Gemini support strict schema enforcement to ensure outputs match your Zod schema exactly.
## TypeScript Support
Node.js currently requires external loaders to run TypeScript files directly:
- Supported Node.js versions support ES modules with the `--import` flag
- The `tsx` loader provides the best developer experience
- Future versions may include native TypeScript support