GeminiProReader¶
Overview¶
The GeminiProReader class is designed to interface with the Google Generative AI models (Gemini Pro) to extract relationships between entities in a given text. It extends the BaseLLMReader class and uses the google-generativeai library to communicate with the API.
Installation¶
- Install the
google-generativeailibrary:pip install google-generativeai
Example Usage¶
Here's an example demonstrating how to use the GeminiProReader class:
from euler.llm_readers import GeminiProReader
# Initialize the GeminiProReader
gemini_reader = GeminiProReader(api_key='your_google_api_key_here')
# Read text and extract relationships
result = gemini_reader.read("Example text to analyze.")
print(result.text if result else "No response received.")
Using LLMReaderFactory¶
The LLMReaderFactory class can be used to easily initialize different LLM readers, including GeminiProReader.
from euler.llm_readers import LLMReaderFactory
# Initialize the GeminiProReader using LLMReaderFactory
gemini_reader = LLMReaderFactory.get_llm_reader(
reader_type='gemini_pro',
api_key='your_google_api_key_here'
)
# Read text and extract relationships
result = gemini_reader.read("Example text to analyze.")
print(result.text if result else "No response received.")
Classes and Methods¶
GeminiConfig¶
The GeminiConfig class is a configuration model that holds the API key and an optional default prompt.
Attributes:
- api_key (str): The API key for accessing the Google Generative AI API.
- default_prompt (Optional[str]): A default prompt to use if no custom prompt is provided.
GeminiProResponse¶
The GeminiProResponse class represents the response from the Gemini Pro API.
Attributes:
- text (str): The response text generated by the Gemini Pro model.
GeminiProReader¶
The GeminiProReader class interfaces with the Google Generative AI models to extract relationships between entities in a given text.
Methods:
- __init__(self, api_key: str, default_prompt: Optional[str] = None): Initializes the reader with the API key and optional default prompt.
- read(self, text: str, custom_prompt: Optional[str] = None) -> Optional[GeminiProResponse]: Reads the text and returns the extracted relationships.
This documentation provides an overview, example usage, and detailed description of the GeminiProReader class and its associated classes and methods.