feat: 중고 판매 장비별 AI 시세 분석 기능 추가

- server/api/ai/market-price.post.ts: 시세 분석 전용 스트리밍 API 추가
  (현재 시세 범위 / 희망가 평가 / 추천 판매가 / 판매 팁)
- UsedSalesMarketPriceAnalysis: 스트리밍 분석 결과 표시 모달 컴포넌트 추가
  (USkeleton 로딩 / whitespace-pre-wrap 텍스트 / 재분석 버튼)
- used-sales/index: sparkles 버튼으로 모달 연동
This commit is contained in:
hyeonggil
2026-03-08 21:27:21 +09:00
parent ce9fce5d44
commit f3ebb6002d
3 changed files with 226 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
import Anthropic from '@anthropic-ai/sdk'
const SYSTEM_PROMPT = `당신은 한국 중고 캠핑 장비 시장 전문가입니다.
사용자가 제공한 장비 정보를 바탕으로 중고 시세를 분석하고 판매 전략을 제안합니다.
분석 항목:
1. **현재 시세 범위**: 해당 장비의 국내 중고 시장 시세 (최저~최고)
2. **희망가 평가**: 제시된 희망가가 적정한지, 높은지, 낮은지 평가
3. **추천 판매가**: 빠른 판매와 적정 수익을 고려한 추천 가격
4. **판매 팁**: 플랫폼별 특성을 고려한 판매 전략 및 주의사항
응답 스타일:
- 한국어로 간결하고 실용적으로 답변
- 구체적인 가격대와 근거 제시
- 마크다운 형식으로 구조화된 답변 제공`
export default defineEventHandler(async (event) => {
const config = useRuntimeConfig()
const body = await readBody(event)
const { itemName, platform, salePrice } = body as {
itemName: string
platform: string
salePrice: number
}
const anthropic = new Anthropic({ apiKey: config.anthropicApiKey })
const userMessage = `다음 캠핑 장비의 중고 시세를 분석해주세요.
- 장비명: ${itemName}
- 판매 플랫폼: ${platform}
- 희망 판매가: ${salePrice.toLocaleString('ko-KR')}`
const stream = anthropic.messages.stream({
model: 'claude-sonnet-4-6',
max_tokens: 1024,
system: SYSTEM_PROMPT,
messages: [{ role: 'user', content: userMessage }]
})
const readableStream = new ReadableStream({
async start(controller) {
stream.on('text', (text) => {
controller.enqueue(new TextEncoder().encode(text))
})
stream.on('finalMessage', () => {
controller.close()
})
stream.on('error', (err) => {
controller.error(err)
})
}
})
return sendStream(event, readableStream)
})