|
|
|
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(): |
|
|
|
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) |
|
|
|
|
|
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()) |
|
|
|
|
|
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: |
|
|
|
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()) |