@@ -19,12 +19,6 @@ class GeminiProvider(BaseProvider):
1919 is called and the google.generativeai package is imported. No manual
2020 initialization is required."""
2121
22- """Provider for Google's Gemini API.
23-
24- This provider is automatically detected and initialized when agentops.init()
25- is called and the google.generativeai package is imported. No manual
26- initialization is required."""
27-
2822 def __init__ (self , client = None ):
2923 """Initialize the Gemini provider.
3024
@@ -66,7 +60,7 @@ def handle_stream_chunk(chunk):
6660 llm_event .returns = chunk
6761 llm_event .agent_id = check_call_stack_for_agent_id ()
6862 llm_event .model = getattr (chunk , "model" , "gemini-1.5-flash" ) # Default if not provided
69- llm_event .prompt = kwargs .get ("contents" , [])
63+ llm_event .prompt = kwargs .get ("prompt" ) or kwargs . get ( " contents" , [])
7064
7165 try :
7266 if hasattr (chunk , "text" ) and chunk .text :
@@ -103,7 +97,7 @@ def stream_handler(stream):
10397 try :
10498 llm_event .returns = response
10599 llm_event .agent_id = check_call_stack_for_agent_id ()
106- llm_event .prompt = kwargs .get ("contents" , [])
100+ llm_event .prompt = kwargs .get ("prompt" ) or kwargs . get ( " contents" , [])
107101 llm_event .completion = response .text
108102 llm_event .model = getattr (response , "model" , "gemini-1.5-flash" )
109103
@@ -144,10 +138,19 @@ def patched_function(self, *args, **kwargs):
144138 init_timestamp = get_ISO_time ()
145139 session = kwargs .pop ("session" , None ) # Always try to pop session, returns None if not present
146140
141+ # Handle positional prompt argument
142+ event_kwargs = kwargs .copy () # Create a copy for event tracking
143+ if args and len (args ) > 0 :
144+ # First argument is the prompt
145+ if "contents" not in kwargs :
146+ kwargs ["contents" ] = args [0 ]
147+ event_kwargs ["prompt" ] = args [0 ] # Store original prompt
148+ args = args [1 :] # Remove prompt from args since we moved it to kwargs
149+
147150 # Call original method and track event
148151 if "generate_content" in _ORIGINAL_METHODS :
149152 result = _ORIGINAL_METHODS ["generate_content" ](self , * args , ** kwargs )
150- return provider .handle_response (result , kwargs , init_timestamp , session = session )
153+ return provider .handle_response (result , event_kwargs , init_timestamp , session = session )
151154 else :
152155 logger .error ("Original generate_content method not found. Cannot proceed with override." )
153156 return None
0 commit comments