Spaces:
Sleeping
Sleeping
| import { GoogleGenerativeAI } from "@google/generative-ai"; | |
| import { GeneratedTheme } from '../types'; | |
| const getClient = () => { | |
| return new GoogleGenerativeAI({ apiKey: process.env.API_KEY }); | |
| }; | |
| export const generateNFTTheme = async (trend: string): Promise<GeneratedTheme | null> => { | |
| try { | |
| const ai = getClient(); | |
| const prompt = ` | |
| Create a unique and engaging NFT collection theme for a newsletter loyalty program. | |
| The context is: "${trend}". | |
| Provide a name, a short storyline (2 sentences), a visual style description, and 3 hypothetical utility perks for holders. | |
| `; | |
| const response = await ai.models.generateContent({ | |
| model: 'gemini-3-flash-preview', | |
| contents: prompt, | |
| config: { | |
| responseMimeType: "application/json", | |
| responseSchema: { | |
| type: Type.OBJECT, | |
| properties: { | |
| name: { type: Type.STRING }, | |
| storyline: { type: Type.STRING }, | |
| visualStyle: { type: Type.STRING }, | |
| perks: { | |
| type: Type.ARRAY, | |
| items: { type: Type.STRING } | |
| } | |
| }, | |
| required: ["name", "storyline", "visualStyle", "perks"] | |
| } | |
| } | |
| }); | |
| if (response.text) { | |
| return JSON.parse(response.text) as GeneratedTheme; | |
| } | |
| return null; | |
| } catch (error) { | |
| console.error("Error generating theme:", error); | |
| return null; | |
| } | |
| }; | |
| export const analyzeStrategy = async (ideaDescription: string): Promise<string> => { | |
| try { | |
| const ai = getClient(); | |
| const prompt = ` | |
| I am a newsletter creator. I have an engagement strategy: | |
| "${ideaDescription}" | |
| Act as a senior growth marketing consultant. | |
| 1. Analyze the strengths and weaknesses of this model. | |
| 2. Suggest 2 ways to prevent abuse (e.g. people just clicking links without reading). | |
| 3. Suggest a "Golden Ticket" mechanic to make it more exciting. | |
| Format the response with Markdown. Keep it concise. | |
| `; | |
| const response = await ai.models.generateContent({ | |
| model: 'gemini-3-flash-preview', | |
| contents: prompt | |
| }); | |
| return response.text || "No analysis available."; | |
| } catch (error) { | |
| console.error("Error analyzing strategy:", error); | |
| return "Could not generate analysis at this time."; | |
| } | |
| }; | |
| export const generateProposalScript = async (type: 'executive' | 'walkthrough' = 'executive'): Promise<string> => { | |
| try { | |
| const ai = getClient(); | |
| const prompts = { | |
| executive: ` | |
| Write a 60-second professional script for a video proposal to 'the bosses' about the Shib Insider Weekly Trail. | |
| Focus on: | |
| 1. Boosting subscribers through gamification (Shards/NFTs). | |
| 2. Increasing income via high-value sponsor spots. | |
| 3. Technical feasibility (Shibarium L2). | |
| Tone: Visionary, confident, professional. | |
| Return ONLY text. | |
| `, | |
| walkthrough: ` | |
| Write a 45-second energetic voice-over script for a screen recording of the Shib Insider Dashboard. | |
| Narrate the following actions: | |
| - Landing on the dashboard. | |
| - Clicking 'Sync Shard' to verify daily engagement. | |
| - Seeing the 5-shard progress bar fill up. | |
| - The 'Forge Reward' button becoming active on Monday. | |
| - The Minting process (Metamask interaction). | |
| - Finalizing and viewing the NFT in the Vault. | |
| Tone: Excited, fast-paced, "builder" vibe. | |
| Return ONLY text. | |
| ` | |
| }; | |
| const response = await ai.models.generateContent({ | |
| model: 'gemini-3-flash-preview', | |
| contents: prompts[type] | |
| }); | |
| return response.text || ""; | |
| } catch (error) { | |
| console.error("Error generating script:", error); | |
| return "Welcome to the Shib Insider Weekly Trail. A new era of subscriber engagement."; | |
| } | |
| }; | |
| export const generateSpeech = async (text: string): Promise<string | undefined> => { | |
| try { | |
| const ai = getClient(); | |
| const response = await ai.models.generateContent({ | |
| model: "gemini-2.5-flash-preview-tts", | |
| contents: [{ parts: [{ text: `Say professionally and confidently: ${text}` }] }], | |
| config: { | |
| responseModalities: [Modality.AUDIO], | |
| speechConfig: { | |
| voiceConfig: { | |
| prebuiltVoiceConfig: { voiceName: 'Charon' }, | |
| }, | |
| }, | |
| }, | |
| }); | |
| return response.candidates?.[0]?.content?.parts?.[0]?.inlineData?.data; | |
| } catch (error) { | |
| console.error("Error generating speech:", error); | |
| return undefined; | |
| } | |
| }; | |