UNPKG

aura-ai

Version:

AI-powered marketing strategist CLI tool for developers

52 lines (42 loc) 1.52 kB
import { streamText } from 'ai' import { openai } from '@ai-sdk/openai' import fs from 'fs/promises' // 檢查是否有產品配置 async function checkAuraConfig() { try { await fs.access('./aura.md') return true } catch { return false } } // 讀取產品配置內容 async function getProductContext() { try { const content = await fs.readFile('./aura.md', 'utf-8') return content } catch { return null } } export async function POST(req) { const { messages } = await req.json() // 檢查是否有產品配置 const hasConfig = await checkAuraConfig() const productContext = hasConfig ? await getProductContext() : null // 構建系統提示 const systemPrompt = hasConfig && productContext ? `You are Aura, an AI marketing companion. You help users with marketing strategies based on their product analysis. Product Context: ${productContext} Provide actionable marketing insights, growth strategies, and recommendations based on the product information above.` : `You are Aura, an AI marketing companion. Since no product has been analyzed yet, provide general marketing advice and suggest the user to run /init to analyze their product for personalized insights. Always be helpful with marketing questions but remind them that specific recommendations require product analysis.` const result = streamText({ model: openai('gpt-4o-mini'), system: systemPrompt, messages, }) return result.toDataStreamResponse() }