better chinese vs

This commit is contained in:
songtianlun 2025-07-03 09:40:23 +08:00
parent 6b02b2d00e
commit 327a32355a
5 changed files with 4715 additions and 13 deletions

View File

@ -22,10 +22,12 @@ npm install
cp .env.example .env.local cp .env.example .env.local
``` ```
3. Add your Replicate API token to `.env.local`: 3. Add your OpenRouter API key to `.env.local`:
``` ```
REPLICATE_API_TOKEN=your_replicate_api_token_here OPENROUTER_API_KEY=your_openrouter_api_key_here
REPLICATE_MODEL=meta/llama-2-70b-chat:02e509c789964a7ea8736978a43525956ef40397be9033abf9fd2badfe68c9e3 OPENROUTER_MODEL=anthropic/claude-3.5-sonnet
OPENROUTER_CHINESE_MODEL=deepseek/deepseek-chat
NEXT_PUBLIC_SITE_URL=https://anything-vs-anything.com
``` ```
4. Run the development server: 4. Run the development server:
@ -44,16 +46,19 @@ npm run dev
## Environment Variables ## Environment Variables
- `REPLICATE_API_TOKEN`: Your Replicate API token (required) - `OPENROUTER_API_KEY`: Your OpenRouter API key (required)
- `REPLICATE_MODEL`: The Replicate model to use (optional, defaults to Llama 2 70B) - `OPENROUTER_MODEL`: The default model to use (optional, defaults to Claude 3.5 Sonnet)
- `OPENROUTER_CHINESE_MODEL`: The model to use for Chinese comparisons (optional, defaults to DeepSeek Chat for better Chinese support)
- `NEXT_PUBLIC_SITE_URL`: Your site URL for API referrer (optional)
## Tech Stack ## Tech Stack
- Next.js 15 with App Router - Next.js 15 with App Router
- TypeScript - TypeScript
- Tailwind CSS - Tailwind CSS
- Replicate AI API - OpenRouter AI API
- React Markdown for table rendering - React Markdown for table rendering
- Automatic Chinese/English model switching for better localization
## Deploy on Vercel ## Deploy on Vercel

4663
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from 'next/server';
export async function POST(request: NextRequest) { export async function POST(request: NextRequest) {
try { try {
const { item1, item2, description1, description2 } = await request.json(); const { item1, item2, description1, description2, language } = await request.json();
if (!item1 || !item2) { if (!item1 || !item2) {
return NextResponse.json( return NextResponse.json(
@ -11,11 +11,41 @@ export async function POST(request: NextRequest) {
); );
} }
const prompt = `Compare ${item1} and ${item2} in a detailed table format. ${ // 根据传入的语言参数判断,默认为英文
description1 ? `Additional context for ${item1}: ${description1}` : '' const isChinese = language === 'zh-CN';
} ${ console.log(`isChinese? [${isChinese}]`)
description2 ? `Additional context for ${item2}: ${description2}` : ''
} const prompt = isChinese ?
`请详细比较 ${item1}${item2},用中文表格格式展示。${description1 ? `\n\n${item1} 的补充信息:${description1}` : ''
}${description2 ? `\n${item2} 的补充信息:${description2}` : ''
}
##
1. **使**
2. ****
3. **使**
4. **使**
##
-
-
-
-
-
- 使 markdown
##
-
- ${item1}
- ${item2}
` :
`Compare ${item1} and ${item2} in a detailed table format. ${description1 ? `Additional context for ${item1}: ${description1}` : ''
} ${description2 ? `Additional context for ${item2}: ${description2}` : ''
}
Please provide a comprehensive comparison in a markdown table format with the following structure: Please provide a comprehensive comparison in a markdown table format with the following structure:
- Create rows for different comparison aspects (features, pros, cons, price range, best use cases, etc.) - Create rows for different comparison aspects (features, pros, cons, price range, best use cases, etc.)
@ -35,7 +65,9 @@ The table should have three columns: Aspect, ${item1}, ${item2}`;
'X-Title': 'Anything vs Anything', 'X-Title': 'Anything vs Anything',
}, },
body: JSON.stringify({ body: JSON.stringify({
model: process.env.OPENROUTER_MODEL || 'anthropic/claude-3.5-sonnet', model: isChinese && process.env.OPENROUTER_CHINESE_MODEL
? process.env.OPENROUTER_CHINESE_MODEL
: process.env.OPENROUTER_MODEL || 'anthropic/claude-3.5-sonnet',
messages: [ messages: [
{ {
role: 'user', role: 'user',

View File

@ -40,6 +40,7 @@ export default function Home() {
item2, item2,
description1, description1,
description2, description2,
language: 'en',
}), }),
}); });

View File

@ -40,6 +40,7 @@ export default function HomePage() {
item2, item2,
description1, description1,
description2, description2,
language: 'zh-CN',
}), }),
}); });