| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- // This is a mock service. In a real application, you would import and use the @google/genai library.
- // import { GoogleGenAI, Chat } from "@google/genai";
- import { ChatMessage } from '../types';
- // Mock response structure to emulate the real API
- interface MockGenerateContentResponse {
- text: string;
- }
- class MockChat {
- private systemInstruction: string;
- constructor(config?: { systemInstruction: string }) {
- this.systemInstruction = config?.systemInstruction || "You are a helpful assistant.";
- console.log("MockChat initialized with instruction:", this.systemInstruction);
- }
- sendMessage(message: { message: string }): Promise<MockGenerateContentResponse> {
- console.log("MockChat received message:", message.message);
-
- return new Promise(resolve => {
- setTimeout(() => {
- const responses = [
- "That's a very interesting question! Let me think...",
- "Based on your persona settings, I would say the best approach is to be direct and informative.",
- "I'm sorry, I cannot answer that question based on my current knowledge base.",
- "Of course! I can help with that. What are the specific details you need?",
- "Analyzing your request... It seems you're asking about product features. Our product excels in A, B, and C."
- ];
-
- const randomResponse = responses[Math.floor(Math.random() * responses.length)];
- resolve({ text: randomResponse });
- }, 800);
- });
- }
- }
- class MockGoogleGenAI {
- public chats = {
- create: (config?: { systemInstruction: string }) => {
- return new MockChat(config);
- }
- };
- }
- const mockAi = new MockGoogleGenAI();
- let mockChat: MockChat | null = null;
- export const createAIChatSession = (persona: string) => {
- mockChat = mockAi.chats.create({ systemInstruction: persona });
- };
- export const sendChatMessage = async (message: string): Promise<ChatMessage> => {
- if (!mockChat) {
- createAIChatSession("You are a helpful assistant."); // Default persona
- }
-
- const response = await mockChat!.sendMessage({ message });
- const aiResponse: ChatMessage = { id: `msg-ai-${Date.now()}`, sender: 'ai', text: response.text };
- return aiResponse;
- };
- export const polishScript = async (originalScript: string): Promise<string[]> => {
- console.log("Mock polishScript called with:", originalScript);
- // In a real app, you would call Gemini here.
- // const response = await ai.models.generateContent({ model: 'gemini-2.5-flash', contents: `Rewrite the following script in 3 different styles (professional, witty, and casual):\n\n"${originalScript}"` });
- // For now, return mock data.
- return new Promise(resolve => {
- setTimeout(() => {
- resolve([
- `[Professional] We are pleased to welcome you to our presentation. We have some exciting updates to share.`,
- `[Witty] Settle in, folks! You're about to witness a presentation of epic proportions.`,
- `[Casual] Hey everyone, thanks for joining. Let's get started with our presentation.`
- ]);
- }, 1200);
- });
- };
- export const generateArticle = async (topic: string): Promise<{ title: string; summary: string; content: string; }> => {
- console.log("Mock generateArticle called with:", topic);
- // In a real app, you would call Gemini here.
- return new Promise(resolve => {
- setTimeout(() => {
- resolve({
- title: `Exploring the Wonders of ${topic}`,
- summary: `A brief overview of the key aspects and fascinating details surrounding ${topic}. Discover why it's a subject of great interest.`,
- content: `The topic of ${topic} is a multifaceted and deeply engaging subject. Historically, its roots can be traced back to ancient civilizations where it played a pivotal role in culture and daily life. \n\nScientifically, ${topic} presents a complex set of principles that continue to be studied by experts worldwide. The implications of these studies are far-reaching, potentially impacting technology, medicine, and our understanding of the universe. \n\nFrom a cultural standpoint, ${topic} has inspired countless works of art, literature, and music, proving its enduring relevance in the human experience. As we look to the future, the evolution of ${topic} promises even more exciting developments.`
- });
- }, 1500);
- });
- };
- export const mockProductDatabase = [
- { title: "Smart Noise-Cancelling Headphones", price: "$149.99" },
- { title: "Ergonomic Mechanical Keyboard", price: "$89.99" },
- { title: "4K Ultra-HD Webcam", price: "$69.99" },
- { title: "Organic French Press Coffee Beans", price: "$22.50" },
- { title: "Minimalist Desk Lamp with Wireless Charging", price: "$45.00" },
- { title: "Hand-Poured Soy Wax Candle", price: "$18.00" },
- { title: "The Alchemist by Paulo Coelho", price: "$12.99" },
- { title: "Atomic Habits by James Clear", price: "$15.99" },
- { title: "Lightweight Waterproof Hiking Backpack", price: "$79.95" },
- { title: "Insulated Stainless Steel Water Bottle", price: "$25.00" },
- { title: "Professional Chef's Knife - 8 Inch", price: "$120.00" },
- { title: "Non-Stick Ceramic Frying Pan Set", price: "$59.99" },
- { title: "Portable Blender for Shakes and Smoothies", price: "$34.99" },
- { title: "Yoga Mat with Carrying Strap", price: "$29.99" },
- { title: "Adjustable Dumbbell Set", price: "$199.99" },
- ];
- // Simple hash function to get a consistent index from a string
- const simpleHash = (str: string) => {
- let hash = 0;
- for (let i = 0; i < str.length; i++) {
- const char = str.charCodeAt(i);
- hash = (hash << 5) - hash + char;
- hash |= 0; // Convert to 32bit integer
- }
- return Math.abs(hash);
- };
- export const parseProductUrl = async (url: string): Promise<{ title: string; imageUrl: string; price: string; }> => {
- console.log("Mock parseProductUrl called with:", url);
- // In a real app, this might be a backend call that scrapes the page or calls an API.
- // Here, we simulate it by using the URL to predictably pick from a larger mock database.
- return new Promise(resolve => {
- setTimeout(() => {
- const hash = simpleHash(url);
- const product = mockProductDatabase[hash % mockProductDatabase.length];
- const imageUrl = `https://picsum.photos/seed/${encodeURIComponent(url)}/400/400`;
-
- resolve({ ...product, imageUrl });
- }, 800 + Math.random() * 500); // Simulate network delay
- });
- };
|