-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgemini_remote.py
More file actions
47 lines (39 loc) · 1.86 KB
/
gemini_remote.py
File metadata and controls
47 lines (39 loc) · 1.86 KB
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
import asyncio
from datetime import datetime
import os
from google import genai
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client
client = genai.Client(api_key=os.getenv("GEMINI_API_KEY"))
remote_url = "https://mcp.deepwiki.com/mcp"
async def run():
async with streamablehttp_client(remote_url) as (read, write, _):
async with ClientSession(read, write) as session:
await session.initialize()
# Initialize conversation history using simple tuples
config = genai.types.GenerateContentConfig(
temperature=0,
tools=[session],
)
print("Agent is ready. Type 'exit' to quit.")
chat = client.aio.chats.create(model="gemini-2.5-flash", config=config)
while (user_input := input("You: ")).lower() != "exit":
# Append user message to history
response = await chat.send_message(user_input)
if len(response.automatic_function_calling_history) > 0:
if (
response.automatic_function_calling_history[0].parts[0].text
== user_input
):
response.automatic_function_calling_history.pop(0)
for call in response.automatic_function_calling_history:
if call.parts[0].function_call:
print(f"Function call: {call.parts[0].function_call}")
elif call.parts[0].function_response:
print(
f"Function response: {call.parts[0].function_response.response['result'].content[0].text}"
)
print(f"Assistant: {response.text}")
print("Goodbye.")
if __name__ == "__main__":
asyncio.run(run())