UNPKG

pulse-ai-utils

Version:

Utility functions and helpers for AI-powered applications

41 lines (40 loc) 1.79 kB
import OpenAI from 'openai'; import { LLMBase, LLMConfig } from './llm-base'; import { TweetSchema } from 'pulse-type-registry'; import { z } from 'zod'; /** * Gemini Helper - Direct Google Gemini API integration * Supports web search and structured output (in different models) */ export default class GeminiHelper extends LLMBase { private genAI; private webSearchModel; private structuredOutputModel; constructor(apiKey?: string, openaiInstance?: OpenAI, model?: string); /** * Create Gemini helper with model from remote config */ static createWithRemoteConfig(apiKey?: string, openaiInstance?: OpenAI): Promise<GeminiHelper>; protected createOpenAIInstance(config: LLMConfig): OpenAI; protected getProviderName(): string; /** * Generate embeddings using Gemini * Note: Gemini doesn't have a dedicated embedding model yet */ generateEmbedding(text: string): Promise<number[]>; /** * Fetch latest tweets for a given area using two-step Gemini process * Step 1: Web search with Gemini Flash Exp (supports web search) * Step 2: Structure the results with Gemini Flash (supports structured output) */ fetchLatestTweets(area: string, region: string, country: string): Promise<z.infer<typeof TweetSchema>[]>; /** * Fetch local content (events, deals, news, reels, places) using two-step Gemini process * Similar to runQuery and fetchStructuredDataFromWeb but using Gemini's web search */ fetchLocalContent(area: string, region: string, country: string, categories?: string[]): Promise<any[]>; /** * Override the base class method to use Gemini's native API */ query(prompt: string, outputFormat?: any, model?: string, _systemPrompt?: string): Promise<any>; }