ソースを参照

make model configurable (#17)

* make model configurable

* update examples

* fix lint

* update env var name

* fix
Chris Tate 5 ヶ月 前
コミット
43756783fe

+ 7 - 2
apps/web/.env.example

@@ -1,4 +1,9 @@
-# AI Gateway API Key (required for /api/generate endpoint)
-# Uses Vercel AI Gateway - automatically authenticated when deployed on Vercel
+# Vercel AI Gateway
+# Automatically authenticated when deployed on Vercel
 # For local development, get your key from https://vercel.com/ai-gateway
 AI_GATEWAY_API_KEY=
+
+# AI Model Configuration
+# Override the default model used for UI generation
+# Default: anthropic/claude-haiku-4.5
+AI_GATEWAY_MODEL=anthropic/claude-haiku-4.5

+ 2 - 1
apps/web/app/api/generate/route.ts

@@ -78,6 +78,7 @@ EXAMPLE (Blog with responsive grid):
 Generate JSONL:`;
 
 const MAX_PROMPT_LENGTH = 140;
+const DEFAULT_MODEL = "anthropic/claude-haiku-4.5";
 
 export async function POST(req: Request) {
   const { prompt } = await req.json();
@@ -85,7 +86,7 @@ export async function POST(req: Request) {
   const sanitizedPrompt = String(prompt || "").slice(0, MAX_PROMPT_LENGTH);
 
   const result = streamText({
-    model: "anthropic/claude-opus-4.5",
+    model: process.env.AI_GATEWAY_MODEL || DEFAULT_MODEL,
     system: SYSTEM_PROMPT,
     prompt: sanitizedPrompt,
     temperature: 0.7,

+ 1 - 1
apps/web/app/docs/ai-sdk/page.tsx

@@ -33,7 +33,7 @@ export async function POST(req: Request) {
     : '';
 
   const result = streamText({
-    model: 'anthropic/claude-opus-4.5',
+    model: 'anthropic/claude-haiku-4.5',
     system: systemPrompt + contextPrompt,
     prompt,
   });

+ 1 - 1
apps/web/app/docs/quick-start/page.tsx

@@ -100,7 +100,7 @@ export async function POST(req: Request) {
   const systemPrompt = generateCatalogPrompt(catalog);
 
   const result = streamText({
-    model: 'anthropic/claude-opus-4.5',
+    model: 'anthropic/claude-haiku-4.5',
     system: systemPrompt,
     prompt,
   });

+ 1 - 1
apps/web/app/docs/streaming/page.tsx

@@ -79,7 +79,7 @@ function App() {
   const { prompt } = await req.json();
   
   const result = streamText({
-    model: 'anthropic/claude-opus-4.5',
+    model: 'anthropic/claude-haiku-4.5',
     system: generateCatalogPrompt(catalog),
     prompt,
   });

+ 7 - 2
examples/dashboard/.env.example

@@ -1,4 +1,9 @@
-# AI Gateway API Key (required for /api/generate endpoint)
-# Uses Vercel AI Gateway - automatically authenticated when deployed on Vercel
+# Vercel AI Gateway
+# Automatically authenticated when deployed on Vercel
 # For local development, get your key from https://vercel.com/ai-gateway
 AI_GATEWAY_API_KEY=
+
+# AI Model Configuration
+# Override the default model used for dashboard generation
+# Default: anthropic/claude-haiku-4.5
+AI_GATEWAY_MODEL=anthropic/claude-haiku-4.5

+ 3 - 1
examples/dashboard/app/api/generate/route.ts

@@ -58,6 +58,8 @@ EXAMPLE - Revenue Dashboard:
 
 Generate JSONL patches now:`;
 
+const DEFAULT_MODEL = "anthropic/claude-haiku-4.5";
+
 export async function POST(req: Request) {
   const { prompt, context } = await req.json();
 
@@ -69,7 +71,7 @@ export async function POST(req: Request) {
   }
 
   const result = streamText({
-    model: "anthropic/claude-opus-4.5",
+    model: process.env.AI_GATEWAY_MODEL || DEFAULT_MODEL,
     system: SYSTEM_PROMPT,
     prompt: fullPrompt,
     temperature: 0.7,

+ 1 - 0
turbo.json

@@ -1,6 +1,7 @@
 {
   "$schema": "https://turborepo.dev/schema.json",
   "ui": "tui",
+  "globalEnv": ["AI_GATEWAY_MODEL"],
   "tasks": {
     "build": {
       "dependsOn": ["^build"],