// 82shops Premium Intelligence Gateway Service export interface Listing { id: string; title: string; description: string; price: string; assetType: "physical" | "digital" | "hybrid"; realtyInfo?: { location: string; sqft: number; }; } export interface BuyerPreference { budget: string; interests: string[]; lookingFor: string; } export interface MatchResult { listingId: string; score: number; reason: string; agentRecommendation: string; } // [핵심] API_KEY와 유료 모델 주소 설정 const API_KEY = "사용자님의_유료_API_KEY"; // 여기에 실제 키를 넣으세요 const API_URL = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=${API_KEY}`; export async function matchBuyerWithSellers( preferences: BuyerPreference, listings: Listing[] ): Promise { const systemInstruction = `You are the Senior Global Broker for 82shops. Connect crypto-wealthy buyers with luxury realty. Focus on "Crypto-Realty" lifestyle, security, and elite investment. Always use Google Search to find current Dubai real estate trends.`; const prompt = ` Buyer Preferences: ${JSON.stringify(preferences)} Available Listings: ${JSON.stringify(listings)} Based on real-time market data, provide a JSON array of matches. Each match must have: listingId, score(0-100), reason, agentRecommendation. `; try { const response = await fetch(API_URL, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ contents: [{ role: "user", parts: [{ text: prompt }] }], tools: [{ google_search_retrieval: {} }], // 구글 검색 엔진 탑재 system_instruction: { parts: [{ text: systemInstruction }] } }) }); if (!response.ok) { const errorData = await response.json(); console.error("Gemini API Error:", errorData); return []; } const data = await response.json(); // AI의 답변 텍스트에서 JSON 추출 (정규식 사용으로 안전하게 처리) const textResponse = data.candidates[0].content.parts[0].text; const jsonMatch = textResponse.match(/\[.*\]/s); return jsonMatch ? JSON.parse(jsonMatch[0]) : []; } catch (error) { console.error("Gemini matching error:", error); return []; } }