File size: 2,161 Bytes
c9803a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/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())