Update gemini.py
This commit is contained in:
@@ -336,63 +336,7 @@ class InputParams(BaseModel):
|
||||
class GeminiMultimodalLiveLLMService(LLMService):
|
||||
# Overriding the default adapter to use the Gemini one.
|
||||
adapter_class = GeminiLLMAdapter
|
||||
|
||||
"""Gemini Live LLM Service with multimodal capabilities including File API support.
|
||||
|
||||
This service implements the Gemini Multimodal Live API with support for:
|
||||
- Audio input and output
|
||||
- Image/video input
|
||||
- File API (upload, reference, and management)
|
||||
- Tools/function calling
|
||||
|
||||
Example usage of File API:
|
||||
```python
|
||||
# Initialize the service
|
||||
gemini_service = GeminiMultimodalLiveLLMService(api_key="YOUR_API_KEY")
|
||||
|
||||
# Upload a file from the client
|
||||
file_path = "/path/to/user_uploaded_file.pdf"
|
||||
file_info = await gemini_service.file_api.upload_file(file_path)
|
||||
|
||||
# Get file URI and mime type from response
|
||||
file_uri = file_info["file"]["uri"]
|
||||
mime_type = "application/pdf" # Set appropriate MIME type
|
||||
|
||||
# When starting a new bot session:
|
||||
# 1. Initialize the context
|
||||
context = GeminiMultimodalLiveContext()
|
||||
|
||||
# 2. Add file reference to context BEFORE starting the conversation
|
||||
context.add_file_reference(
|
||||
file_uri=file_uri,
|
||||
mime_type=mime_type,
|
||||
text="Please analyze this document"
|
||||
)
|
||||
|
||||
# 3. Now set the context to start the conversation with file reference included
|
||||
await gemini_service.set_context(context)
|
||||
|
||||
# Gemini now has access to the file reference in its context window
|
||||
# The file URI remains valid for 48 hours before Google deletes it
|
||||
|
||||
# Optional: List all files for this user
|
||||
files = await gemini_service.file_api.list_files()
|
||||
|
||||
# Optional: Get metadata for a specific file
|
||||
file_metadata = await gemini_service.file_api.get_file(file_info["file"]["name"])
|
||||
|
||||
# Optional: Delete a file when no longer needed
|
||||
await gemini_service.file_api.delete_file(file_info["file"]["name"])
|
||||
```
|
||||
|
||||
Notes:
|
||||
- Files are stored for 48 hours on Google's servers
|
||||
- Maximum file size is 2GB
|
||||
- Total storage per project is 20GB
|
||||
- File references should be added to the context BEFORE starting the conversation
|
||||
- The same file reference can be reused for multiple sessions within the 48-hour window
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
|
||||
Reference in New Issue
Block a user