#!/usr/bin/env python3 import asyncio import os import sys sys.path.insert(0, 'src') from proxy_lite.client import GeminiClient, GeminiClientConfig from proxy_lite.history import MessageHistory, UserMessage, Text from proxy_lite.tools.browser_tool import BrowserTool from proxy_lite.browser.browser import BrowserSession async def test_tool_calling(): # Setup client api_key = os.environ.get("GEMINI_API_KEY") if not api_key: print("❌ GEMINI_API_KEY not set") return config = GeminiClientConfig(api_key=api_key) client = GeminiClient(config=config) # Create a dummy browser tool class DummyBrowserSession: async def __aenter__(self): return self async def __aexit__(self, *args): pass async def open_new_tab_and_go_to(self, url): print(f"✅ Would open new tab and go to: {url}") return True browser_tool = BrowserTool(DummyBrowserSession()) # Create message history messages = MessageHistory() messages.append(UserMessage(content=[Text(text="Please use the open_new_tab_and_go_to tool to navigate to https://google.com")])) print("🚀 Testing Gemini tool calling...") try: # Test tool calling response = await client.create_completion( messages=messages, tools=[browser_tool], temperature=0.7 ) print(f"✅ Response received: {response}") if response.choices[0].message.tool_calls: print(f"✅ Tool calls found: {len(response.choices[0].message.tool_calls)}") for tool_call in response.choices[0].message.tool_calls: print(f" - Tool: {tool_call.function.name}") print(f" - Args: {tool_call.function.arguments}") else: print("❌ No tool calls found") print(f"Content: {response.choices[0].message.content}") except Exception as e: print(f"❌ Error: {e}") import traceback traceback.print_exc() if __name__ == "__main__": asyncio.run(test_tool_calling())