geminiService.ts
Golden-Hour-backend-layer-2/services/geminiService.ts
import { GoogleGenAI } from "@google/genai";
export class GeminiService {
// Use the correct initialization pattern inside methods as per latest guidelines
static async generateContentSummary(title: string, category: string): Promise<string> {
const ai = new GoogleGenAI({ apiKey: process.env.API_KEY });
try {
const response = await ai.models.generateContent({
model: 'gemini-3-flash-preview',
contents: `Generate a short 2-sentence SEO-friendly description for a ${category} item titled "${title}".`,
});
// Directly access .text property as per guidelines
return response.text || "No summary generated.";
} catch (error) {
console.error("Gemini Error:", error);
return "Failed to generate AI summary.";
}
}
static async analyzeBusinessData(data: any): Promise<string> {
const ai = new GoogleGenAI({ apiKey: process.env.API_KEY });
try {
const response = await ai.models.generateContent({
model: 'gemini-3-flash-preview',
contents: `As a business analyst, provide 3 bullet points of insights based on this management dashboard data: ${JSON.stringify(data)}`,
});
// Directly access .text property as per guidelines
return response.text || "No insights available.";
} catch (error) {
console.error("Gemini Error:", error);
return "Analysis unavailable.";
}
}
}
관련 글
App.tsx
App.tsx — typescript source code from the Golden-Hour-backend-layer-2 learning materials (Golden-Hour-backend-layer-2/App.tsx).
글 읽기 →Header.tsx
Header.tsx — typescript source code from the Golden-Hour-backend-layer-2 learning materials (Golden-Hour-backend-layer-2/components/Header.tsx).
글 읽기 →Sidebar.tsx
Sidebar.tsx — typescript source code from the Golden-Hour-backend-layer-2 learning materials (Golden-Hour-backend-layer-2/components/Sidebar.tsx).
글 읽기 →index.tsx
index.tsx — typescript source code from the Golden-Hour-backend-layer-2 learning materials (Golden-Hour-backend-layer-2/index.tsx).
글 읽기 →ContentManagement.tsx
ContentManagement.tsx — typescript source code from the Golden-Hour-backend-layer-2 learning materials (Golden-Hour-backend-layer-2/pages/ContentManagement.tsx).
글 읽기 →CustomerManagement.tsx
CustomerManagement.tsx — typescript source code from the Golden-Hour-backend-layer-2 learning materials (Golden-Hour-backend-layer-2/pages/CustomerManagement.tsx).
글 읽기 →