Gemini 2.0 live api, chatbot, audio and vision inp...
# ask-ai
l
Gemini 2.0 live api, chatbot, audio and vision input, audio output, but the metrics show my system tokens are not cached, over threshold already, there are 6000 system tokens.
t
Thanks for reaching out, James. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks so much for reaching out! To better understand what’s going on, could you share a bit more about your setup? For example: • Are you using any particular configurations for caching system tokens? • Which threshold are you referring to, and how have you set it up? • Have you noticed any error messages or logs when the system tokens go over the threshold? Getting these details will really help us figure this out together. Looking forward to your reply!
l
Just the explicit cache method in Gemini doc, you can check that out.
t
Thank you for your question! The Gemini API documentation doesn’t include a specific, publicly documented cache method. That said, there is an internal caching mechanism within the LiveKit Agents framework that helps optimize image serialization. However, this is more behind-the-scenes and isn’t something users can configure or use for general caching purposes. If you had a particular caching method or setup in mind, could you please share a bit more detail? I’d love to help you figure this out. In the meantime, you might also find it helpful to check out the official Gemini API documentation for additional information. Sources: tools/main/README.md | Google Gemini LLM | LiveKit Docs | Google Gemini LLM plugin guide | LiveKit Docs | Gemini Live API plugin | LiveKit Docs | livekit-plugins/livekit-plugins-google/livekit/plugins/google/beta/gemini_t...
l
import os import pathlib import requests import time from google import genai from google.genai import types client = genai.Client() # Download video file url = 'https://storage.googleapis.com/generativeai-downloads/data/SherlockJr._10min.mp4' path_to_video_file = pathlib.Path('SherlockJr._10min.mp4') if not path_to_video_file.exists(): with path_to_video_file.open('wb') as wf: response = requests.get(url, stream=True) for chunk in response.iter_content(chunk_size=32768): wf.write(chunk) # Upload the video using the Files API video_file = client.files.upload(file=path_to_video_file) # Wait for the file to finish processing while video_file.state.name == 'PROCESSING': print('Waiting for video to be processed.') time.sleep(2) video_file = client.files.get(name=video_file.name) print(f'Video processing complete: {video_file.uri}') # You must use an explicit version suffix: "-flash-001", not just "-flash". model='models/gemini-2.0-flash-001' # Create a cache with a 5 minute TTL cache = client.caches.create( model=model, config=types.CreateCachedContentConfig( display_name='sherlock jr movie', # used to identify the cache system_instruction=( 'You are an expert video analyzer, and your job is to answer ' 'the user\'s query based on the video file you have access to.' ), contents=[video_file], ttl="300s", ) ) # Construct a GenerativeModel which uses the created cache. response = client.models.generate_content( model = model, contents= ( 'Introduce different characters in the movie by describing ' 'their personality, looks, and names. Also list the timestamps ' 'they were introduced for the first time.'), config=types.GenerateContentConfig(cached_content=cache.name) ) print(response.usage_metadata) # The output should look something like this: # # prompt_token_count: 696219 # cached_content_token_count: 696190 # candidates_token_count: 214 # total_token_count: 696433 print(response.text)
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!
l
This is the explicit cache method Gemini shows in the doc: import os import pathlib import requests import time from google import genai from google.genai import types client = genai.Client() # Download video file url = 'https://storage.googleapis.com/generativeai-downloads/data/SherlockJr._10min.mp4' path_to_video_file = pathlib.Path('SherlockJr._10min.mp4') if not path_to_video_file.exists(): with path_to_video_file.open('wb') as wf: response = requests.get(url, stream=True) for chunk in response.iter_content(chunk_size=32768): wf.write(chunk) # Upload the video using the Files API video_file = client.files.upload(file=path_to_video_file) # Wait for the file to finish processing while video_file.state.name == 'PROCESSING': print('Waiting for video to be processed.') time.sleep(2) video_file = client.files.get(name=video_file.name) print(f'Video processing complete: {video_file.uri}') # You must use an explicit version suffix: "-flash-001", not just "-flash". model='models/gemini-2.0-flash-001' # Create a cache with a 5 minute TTL cache = client.caches.create( model=model, config=types.CreateCachedContentConfig( display_name='sherlock jr movie', # used to identify the cache system_instruction=( 'You are an expert video analyzer, and your job is to answer ' 'the user\'s query based on the video file you have access to.' ), contents=[video_file], ttl="300s", ) ) # Construct a GenerativeModel which uses the created cache. response = client.models.generate_content( model = model, contents= ( 'Introduce different characters in the movie by describing ' 'their personality, looks, and names. Also list the timestamps ' 'they were introduced for the first time.'), config=types.GenerateContentConfig(cached_content=cache.name) ) print(response.usage_metadata) # The output should look something like this: # # prompt_token_count: 696219 # cached_content_token_count: 696190 # candidates_token_count: 214 # total_token_count: 696433 print(response.text)